aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/subdev_spec_c.cpp
blob: f61653695f28e508660dbfdee30d838635eef895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// Copyright 2015 Ettus Research LLC
//
// SPDX-License-Identifier: GPL-3.0
//

#include <uhd/usrp/subdev_spec.h>

#include <string.h>

uhd_error uhd_subdev_spec_pair_free(
    uhd_subdev_spec_pair_t *subdev_spec_pair
){
    UHD_SAFE_C(
        if(subdev_spec_pair->db_name){
            free(subdev_spec_pair->db_name);
            subdev_spec_pair->db_name = NULL;
        }
        if(subdev_spec_pair->sd_name){
            free(subdev_spec_pair->sd_name);
            subdev_spec_pair->sd_name = NULL;
        }
    )
}

uhd_error uhd_subdev_spec_pairs_equal(
    const uhd_subdev_spec_pair_t* first,
    const uhd_subdev_spec_pair_t* second,
    bool *result_out
){
    UHD_SAFE_C(
        *result_out = (uhd_subdev_spec_pair_c_to_cpp(first) ==
                       uhd_subdev_spec_pair_c_to_cpp(second));
    )
}

uhd_error uhd_subdev_spec_make(
    uhd_subdev_spec_handle* h,
    const char* markup
){
    UHD_SAFE_C(
        (*h) = new uhd_subdev_spec_t;
        std::string markup_cpp(markup);
        if(!markup_cpp.empty()){
            (*h)->subdev_spec_cpp = uhd::usrp::subdev_spec_t(markup_cpp);
        }
    )
}

uhd_error uhd_subdev_spec_free(
    uhd_subdev_spec_handle* h
){
    UHD_SAFE_C(
        delete (*h);
        (*h) = NULL;
    )
}

uhd_error uhd_subdev_spec_size(
    uhd_subdev_spec_handle h,
    size_t *size_out
){
    UHD_SAFE_C_SAVE_ERROR(h,
        *size_out = h->subdev_spec_cpp.size();
    )
}

uhd_error uhd_subdev_spec_push_back(
    uhd_subdev_spec_handle h,
    const char* markup
){
    UHD_SAFE_C_SAVE_ERROR(h,
        h->subdev_spec_cpp.push_back(uhd::usrp::subdev_spec_pair_t(markup));
    )
}

uhd_error uhd_subdev_spec_at(
    uhd_subdev_spec_handle h,
    size_t num,
    uhd_subdev_spec_pair_t *subdev_spec_pair_out
){
    UHD_SAFE_C_SAVE_ERROR(h,
        uhd_subdev_spec_pair_cpp_to_c(
            h->subdev_spec_cpp.at(num),
            subdev_spec_pair_out
        );
    )
}

uhd_error uhd_subdev_spec_to_pp_string(
    uhd_subdev_spec_handle h,
    char* pp_string_out,
    size_t strbuffer_len
){
    UHD_SAFE_C_SAVE_ERROR(h,
        std::string pp_string_cpp = h->subdev_spec_cpp.to_pp_string();
        memset(pp_string_out, '\0', strbuffer_len);
        strncpy(pp_string_out, pp_string_cpp.c_str(), strbuffer_len);
    )
}

uhd_error uhd_subdev_spec_to_string(
    uhd_subdev_spec_handle h,
    char* string_out,
    size_t strbuffer_len
){
    UHD_SAFE_C_SAVE_ERROR(h,
        std::string string_cpp = h->subdev_spec_cpp.to_string();
        memset(string_out, '\0', strbuffer_len);
        strncpy(string_out, string_cpp.c_str(), strbuffer_len);
    )
}

uhd_error uhd_subdev_spec_last_error(
    uhd_subdev_spec_handle h,
    char* error_out,
    size_t strbuffer_len
){
    UHD_SAFE_C(
        memset(error_out, '\0', strbuffer_len);
        strncpy(error_out, h->last_error.c_str(), strbuffer_len);
    )
}

uhd::usrp::subdev_spec_pair_t uhd_subdev_spec_pair_c_to_cpp(
    const uhd_subdev_spec_pair_t *subdev_spec_pair_c
){
    return uhd::usrp::subdev_spec_pair_t(subdev_spec_pair_c->db_name,
                                         subdev_spec_pair_c->sd_name);
}

void uhd_subdev_spec_pair_cpp_to_c(
    const uhd::usrp::subdev_spec_pair_t &subdev_spec_pair_cpp,
    uhd_subdev_spec_pair_t *subdev_spec_pair_c
){
    subdev_spec_pair_c->db_name = strdup(subdev_spec_pair_cpp.db_name.c_str());
    subdev_spec_pair_c->sd_name = strdup(subdev_spec_pair_cpp.sd_name.c_str());
}