aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Struct.hpp
blob: 7f48d562dddbc1a8dc6f83eb8deeef5669716a00 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
/**
 * @file Struct.h
 * @author Mislav Novakovic <mislav.novakovic@sartura.hr>
 * @brief Sysrepo class header for C struts.
 *
 * @copyright
 * Copyright 2016 Deutsche Telekom AG.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef STRUCT_H
#define STRUCT_H

#include <iostream>
#include <memory>

#include "Sysrepo.hpp"
#include "Internal.hpp"

extern "C" {
#include "../sysrepo.h"
}

namespace sysrepo {

/**
 * @defgroup classes C++/Python
 * @{
 */

/**
 * @brief Class for wrapping sr_data_t.
 * @class Data
 */
class Data
{
public:
    /** Wrapper for [sr_data_t](@ref sr_data_t), for internal use only.*/
    Data(sr_data_t data, sr_type_t type, S_Deleter deleter);
    ~Data();
    /** Getter for binary data.*/
    char *get_binary() const;
    /** Getter for bits.*/
    char *get_bits() const;
    /** Getter for bool.*/
    bool get_bool() const;
    /** Getter for decimal64.*/
    double get_decimal64() const;
    /** Getter for enum.*/
    char *get_enum() const;
    /** Getter for identityref.*/
    char *get_identityref() const;
    /** Getter for instanceid.*/
    char *get_instanceid() const;
    /** Getter for int8.*/
    int8_t get_int8() const;
    /** Getter for int16.*/
    int16_t get_int16() const;
    /** Getter for int32.*/
    int32_t get_int32() const;
    /** Getter for int64.*/
    int64_t get_int64() const;
    /** Getter for string.*/
    char *get_string() const;
    /** Getter for uint8.*/
    uint8_t get_uint8() const;
    /** Getter for uint16.*/
    uint16_t get_uint16() const;
    /** Getter for uint32.*/
    uint32_t get_uint32() const;
    /** Getter for uint64.*/
    uint64_t get_uint64() const;

private:
    sr_data_t _d;
    sr_type_t _t;
    S_Deleter _deleter;
};

/**
 * @brief Class for wrapping sr_val_t.
 * @class Val
 */
class Val
{
public:
    /** Constructor for an empty value.*/
    Val();
    /** Wrapper for [sr_val_t](@ref sr_val_t).*/
    Val(sr_val_t *val, S_Deleter deleter);
    /** Constructor for string value, type can be SR_STRING_T, SR_BINARY_T, SR_BITS_T, SR_ENUM_T,
     * SR_IDENTITYREF_T and SR_INSTANCEID_T.*/
    Val(const char *val, sr_type_t type = SR_STRING_T);
    /** Constructor for bool value.*/
    Val(bool bool_val, sr_type_t type = SR_BOOL_T);
    /** Constructor for decimal64 value.*/
    Val(double decimal64_val);
    /** Constructor for int8 value, C++ only.*/
    Val(int8_t int8_val, sr_type_t type);
    /** Constructor for int16 value, C++ only.*/
    Val(int16_t int16_val, sr_type_t type);
    /** Constructor for int32 value, C++ only.*/
    Val(int32_t int32_val, sr_type_t type);
    /** Constructor for int64 value, type can be SR_INT8_T, SR_INT16_T, SR_INT32_T,
     * SR_INT64_T, SR_UINT8_T, SR_UINT16_T and SR_UINT32_T,*/
    Val(int64_t int64_val, sr_type_t type);
    /** Constructor for uint8 value, C++ only.*/
    Val(uint8_t uint8_val, sr_type_t type);
    /** Constructor for uint16 value, C++ only.*/
    Val(uint16_t uint16_val, sr_type_t type);
    /** Constructor for uint32 value, C++ only.*/
    Val(uint32_t uint32_val, sr_type_t type);
    /** Constructor for uint64 value, C++ only.*/
    Val(uint64_t uint64_val, sr_type_t type);
   ~Val();
    /** Setter for string value, type can be SR_STRING_T, SR_BINARY_T, SR_BITS_T, SR_ENUM_T,
     * SR_IDENTITYREF_T and SR_INSTANCEID_T.*/
    void set(const char *xpath, const char *val, sr_type_t type = SR_STRING_T);
    /** Setter for bool value.*/
    void set(const char *xpath, bool bool_val, sr_type_t type = SR_BOOL_T);
    /** Setter for decimal64 value.*/
    void set(const char *xpath, double decimal64_val);
    /** Setter for int8 value, C++ only.*/
    void set(const char *xpath, int8_t int8_val, sr_type_t type);
    /** Setter for int16 value, C++ only.*/
    void set(const char *xpath, int16_t int16_val, sr_type_t type);
    /** Setter for int32 value, C++ only.*/
    void set(const char *xpath, int32_t int32_val, sr_type_t type);
    /** Setter for int64 value, type can be SR_INT8_T, SR_INT16_T, SR_INT32_T,
     * SR_INT64_T, SR_UINT8_T, SR_UINT16_T and SR_UINT32_T,*/
    void set(const char *xpath, int64_t int64_val, sr_type_t type);
    /** Setter for uint8 value, C++ only.*/
    void set(const char *xpath, uint8_t uint8_val, sr_type_t type);
    /** Setter for uint16 value, C++ only.*/
    void set(const char *xpath, uint16_t uint16_val, sr_type_t type);
    /** Setter for uint32 value, C++ only.*/
    void set(const char *xpath, uint32_t uint32_val, sr_type_t type);
    /** Setter for uint64 value, C++ only.*/
    void set(const char *xpath, uint64_t uint64_val, sr_type_t type);
    /** Getter for xpath.*/
    char *xpath() {return _val->xpath;};
    /** Setter for xpath.*/
    void xpath_set(char *xpath);
    /** Getter for type.*/
    sr_type_t type() {return _val->type;};
    /** Getter for dflt.*/
    bool dflt() {return _val->dflt;};
    /** Setter for dflt.*/
    void dflt_set(bool data) {_val->dflt = data;};
    /** Getter for data.*/
    S_Data data() {S_Data data(new Data(_val->data, _val->type, _deleter)); return data;};
    /** Wrapper for [sr_print_val_mem](@ref sr_print_val_mem) */
    std::string to_string();
    /** Wrapper for [sr_val_to_string](@ref sr_val_to_string) */
    std::string val_to_string();
    /** Wrapper for [sr_dup_val](@ref sr_dup_val) */
    S_Val dup();

    friend class Session;
    friend class Subscribe;

private:
    sr_val_t *_val;
    S_Deleter _deleter;
};

/**
 * @brief Class for wrapping sr_val_t array.
 * @class Vals
 */
class Vals
{
public:
    /** Wrapper for [sr_val_t](@ref sr_val_t) array, internal use only.*/
    Vals(const sr_val_t *vals, const size_t cnt, S_Deleter deleter = nullptr);
    /** Wrapper for [sr_val_t](@ref sr_val_t) array, internal use only.*/
    Vals(sr_val_t **vals, size_t *cnt, S_Deleter deleter = nullptr);
    /** Wrapper for [sr_val_t](@ref sr_val_t) array, create n-array.*/
    Vals(size_t cnt);
    /** Constructor for an empty [sr_val_t](@ref sr_val_t) array.*/
    Vals();
    ~Vals();
    /** Getter for [sr_val_t](@ref sr_val_t), get the n-th element in array.*/
    S_Val val(size_t n);
    /** Getter for array size */
    size_t val_cnt() {return _cnt;};
    /** Wrapper for [sr_dup_values](@ref sr_dup_values) */
    S_Vals dup();

    friend class Session;
    friend class Subscribe;

private:
    size_t _cnt;
    sr_val_t *_vals;
    S_Deleter _deleter;
};

/**
 * @brief Class for wrapping sr_val_t in callbacks.
 * @class Vals_holder
 */
class Vals_Holder
{
public:
    /** Wrapper for [sr_val_t](@ref sr_val_t) array, used only in callbacks.*/
    Vals_Holder(sr_val_t **vals, size_t *cnt);
    /** Create [sr_val_t](@ref sr_val_t) array of n size.*/
    S_Vals allocate(size_t n);
    ~Vals_Holder();

private:
    size_t *p_cnt;
    sr_val_t **p_vals;
    bool _allocate;
};

/**
 * @brief Class for wrapping sr_val_iter_t.
 * @class Val_Iter
 */
class Val_Iter
{
public:
    /** Wrapper for [sr_val_iter_t](@ref sr_val_iter_t).*/
    Val_Iter(sr_val_iter_t *iter = nullptr);
    ~Val_Iter();
    /** Getter for [sr_val_iter_t](@ref sr_val_iter_t).*/
    sr_val_iter_t *iter() {return _iter;};

private:
    sr_val_iter_t *_iter;
};

/**
 * @brief Class for wrapping sr_change_iter_t.
 * @class Change_Iter
 */
class Change_Iter
{
public:
    /** Wrapper for [sr_change_iter_t](@ref sr_change_iter_t).*/
    Change_Iter(sr_change_iter_t *iter = nullptr);
    ~Change_Iter();
    /** Getter for [sr_change_iter_t](@ref sr_change_iter_t).*/
    sr_change_iter_t *iter() {return _iter;};

private:
    sr_change_iter_t *_iter;
};

/**
 * @brief Class for wrapping sr_error_info_t.
 * @class Error
 */
class Error
{
public:
    /** Constructor for an empty [sr_error_info_t](@ref sr_error_info_t).*/
    Error();
    /** Wrapper for [sr_error_info_t](@ref sr_error_info_t).*/
    Error(const sr_error_info_t *info);
    ~Error();
    /** Getter for message.*/
    const char *message() const {if (_info) return _info->message; else return nullptr;};
    /** Getter for xpath.*/
    const char *xpath() const {if (_info) return _info->xpath; else return nullptr;};

    friend class Session;

private:
    const sr_error_info_t *_info;
};

/**
 * @brief Class for wrapping sr_error_info_t array.
 * @class Errors
 */
class Errors
{
public:
    /** Constructor for an empty [sr_error_info_t](@ref sr_error_info_t) array.*/
    Errors();
    ~Errors();
    /** Getter for [sr_error_info_t](@ref sr_error_info_t), get the n-th element in array.*/
    S_Error error(size_t n);
    /** Getter for array size.*/
    size_t error_cnt() {return _cnt;};

    friend class Session;

private:
    size_t _cnt;
    const sr_error_info_t *_info;
};

/**
 * @brief Class for wrapping sr_sch_revision_t array.
 * @class Schema_Revision
 */
class Schema_Revision
{
public:
    /** Wrapper for [sr_sch_revision_t](@ref sr_sch_revision_t).*/
    Schema_Revision(sr_sch_revision_t rev);
    ~Schema_Revision();
    /** Getter for revision.*/
    const char *revision() const {return _rev.revision;};
    /** Getter for file_path_yang.*/
    const char *file_path_yang() const {return _rev.file_path_yang;};
    /** Getter for file_path_yin.*/
    const char *file_path_yin() const {return _rev.file_path_yin;};

private:
    sr_sch_revision_t _rev;
};

/**
 * @brief Class for wrapping sr_sch_submodule_t.
 * @class Schema_Submodule
 */
class Schema_Submodule
{
public:
    /** Wrapper for [sr_sch_submodule_t](@ref sr_sch_submodule_t).*/
    Schema_Submodule(sr_sch_submodule_t sub, S_Deleter deleter);
    ~Schema_Submodule();
    /** Getter for submodule_name.*/
    const char *submodule_name() const {return _sub.submodule_name;};
    /** Getter for revision.*/
    S_Schema_Revision revision();

private:
    sr_sch_submodule_t _sub;
    S_Deleter _deleter;
};

/**
 * @brief Class for wrapping sr_schema_t.
 * @class Yang_Schema
 */
class Yang_Schema
{
public:
    /** Wrapper for [sr_schema_t](@ref sr_schema_t).*/
    Yang_Schema(sr_schema_t *sch, S_Deleter deleter);
    ~Yang_Schema();
    /** Getter for module_name.*/
    const char *module_name() const {return _sch->module_name;};
    /** Getter for ns.*/
    const char *ns() const {return _sch->ns;};
    /** Getter for prefix.*/
    const char *prefix() const {return _sch->prefix;};
    /** Getter for implemented.*/
    bool implemented() const {return _sch->implemented;};
    /** Getter for revision.*/
    S_Schema_Revision revision();
    /** Getter for submodule.*/
    S_Schema_Submodule submodule(size_t n);
    /** Getter for submodule_cnt.*/
    size_t submodule_cnt() const {return _sch->submodule_count;};
    /** Getter for enabled_features.*/
    char *enabled_features(size_t n);
    /** Getter for enabled_features_cnt.*/
    size_t enabled_feature_cnt() const {return _sch->enabled_feature_cnt;};

    friend class Session;

private:
    sr_schema_t *_sch;
    S_Deleter _deleter;
};

/**
 * @brief Class for wrapping sr_schema_t array.
 * @class Yang_Schemas
 */
class Yang_Schemas
{
public:
    /** Constructor for an empty [sr_schema_t](@ref sr_schema_t) array.*/
    Yang_Schemas();
    ~Yang_Schemas();
    /** Getter for [sr_schema_t](@ref sr_schema_t) array, get the n-th element in array.*/
    S_Yang_Schema schema(size_t n);
    /** Getter for array size.*/
    size_t schema_cnt() const {return _cnt;};

    friend class Session;

private:
    size_t _cnt;
    sr_schema_t *_sch;
    S_Deleter _deleter;
};

/**
 * @brief Class for wrapping sr_fd_change_t.
 * @class Fd_Change
 */
class Fd_Change
{
public:
    /** Wrapper for [sr_fd_change_t](@ref sr_fd_change_t).*/
    Fd_Change(sr_fd_change_t *ch);
    ~Fd_Change();
    /** Getter for fd.*/
    int fd() const {return _ch->fd;};
    /** Getter for events.*/
    int events() const {return _ch->events;};
    /** Getter for action.*/
    sr_fd_action_t action() const {return _ch->action;};

private:
    sr_fd_change_t *_ch;
};

/**
 * @brief Class for wrapping sr_fd_change_t array.
 * @class Fd_Changes
 */
class Fd_Changes
{
public:
    /** Wrapper for [sr_fd_change_t](@ref sr_fd_change_t) array.*/
    Fd_Changes(sr_fd_change_t *ch, size_t cnt);
    ~Fd_Changes();
    /** Getter for [sr_fd_change_t](@ref sr_fd_change_t) array, get the n-th element in array.*/
    S_Fd_Change fd_change(size_t n);

private:
    sr_fd_change_t *_ch;
    size_t _cnt;
};

/**
 * @brief Class for wrapping sr_val_iter_t.
 * @class Fd_Changes
 */
class Iter_Value
{

public:
    /** Wrapper for [sr_val_iter_t](@ref sr_val_iter_t).*/
    Iter_Value(sr_val_iter_t *iter = nullptr);
    ~Iter_Value();
    /** Setter for [sr_val_iter_t](@ref sr_val_iter_t).*/
    void Set(sr_val_iter_t *iter);

    friend class Session;

private:
    sr_val_iter_t *_iter;
};

/**
 * @brief Class for wrapping sr_change_iter_t.
 * @class Iter_Change
 */
class Iter_Change
{

public:
    /** Wrapper for [sr_change_iter_t](@ref sr_change_iter_t).*/
    Iter_Change(sr_change_iter_t *iter = nullptr);
    ~Iter_Change();

    friend class Session;

private:
    sr_change_iter_t *_iter;
};

/**
 * @brief Class for wrapping sr_change_oper_t.
 * @class Change
 */
class Change
{
public:
    /** Constructor for an empty [sr_change_oper_t](@ref sr_change_oper_t).*/
    Change();
    ~Change();
    /** Getter for sr_change_oper_t.*/
    sr_change_oper_t oper() {return _oper;};
    /** Getter for new sr_val_t.*/
    S_Val new_val();
    /** Getter for old sr_val_t.*/
    S_Val old_val();

    friend class Session;

private:
    sr_change_oper_t _oper;
    sr_val_t *_new;
    sr_val_t *_old;
    S_Deleter _deleter_new;
    S_Deleter _deleter_old;
};

/**@} */
}
#endif