Nyx Node
Loading...
Searching...
No Matches
indi_blob.c
1/* NyxNode
2 * Author: Jérôme ODIER <jerome.odier@lpsc.in2p3.fr>
3 * SPDX-License-Identifier: GPL-2.0-only (Mongoose backend) or GPL-3.0+
4 */
5
6/*--------------------------------------------------------------------------------------------------------------------*/
7
8#include <stdio.h>
9
10#include "../nyx_node_internal.h"
11
12/*--------------------------------------------------------------------------------------------------------------------*/
13/* PROP */
14/*--------------------------------------------------------------------------------------------------------------------*/
15
16nyx_dict_t *nyx_blob_prop_new(STR_t name, STR_t label, STR_t format, size_t size, BUFF_t buff, bool managed)
17{
18 if(label == NULL || label[0] == '\0')
19 {
20 label = name;
21 }
22
23 if(format == NULL || format[0] == '\0')
24 {
25 format = "raw";
26 }
27
28 if(size == 0x00 || buff == NULL)
29 {
30 size = 0x00;
31 buff = ("");
32
33 managed = false;
34 }
35
36 /*----------------------------------------------------------------------------------------------------------------*/
37
38 nyx_dict_t *result = nyx_dict_new();
39
40 /*----------------------------------------------------------------------------------------------------------------*/
41
42 nyx_dict_set_string_unref(result, "<>", "defBLOB", false);
43
44 /*----------------------------------------------------------------------------------------------------------------*/
45
46 nyx_dict_set_string_unref(result, "@name", nyx_string_dup(name), true);
47 nyx_dict_set_string_unref(result, "@label", nyx_string_dup(label), true);
48 nyx_dict_set_string_unref(result, "@format", nyx_string_dup(format), true);
49
50 /*----------------------------------------------------------------------------------------------------------------*/
51
52 nyx_dict_set_buff_unref(result, "$", size, buff, managed);
53
54 /*----------------------------------------------------------------------------------------------------------------*/
55
56 return result;
57}
58
59/*--------------------------------------------------------------------------------------------------------------------*/
60/* PROP SETTER & GETTER */
61/*--------------------------------------------------------------------------------------------------------------------*/
62
63bool nyx_blob_prop_set(const nyx_dict_t *prop, size_t size, BUFF_t buff, bool managed)
64{
65 if(size == 0x00 || buff == NULL)
66 {
67 size = 0x00;
68 buff = ("");
69
70 managed = false;
71 }
72
73 return nyx_dict_set_buff(prop, "$", size, buff, managed);
74}
75
76/*--------------------------------------------------------------------------------------------------------------------*/
77
78void nyx_blob_prop_get(const nyx_dict_t *prop, size_t *size, buff_t *buff)
79{
80 return nyx_dict_get_buff(prop, "$", size, buff);
81}
82
83/*--------------------------------------------------------------------------------------------------------------------*/
84/* VECTOR */
85/*--------------------------------------------------------------------------------------------------------------------*/
86
87nyx_dict_t *nyx_blob_vector_new(
88 STR_t device,
89 STR_t name,
90 nyx_state_t state,
91 nyx_perm_t perm,
92 nyx_dict_t *props[],
93 const nyx_opts_t *opts
94) {
95 nyx_dict_t *result = nyx_dict_new();
96
97 nyx_list_t *children = nyx_list_new();
98
99 /*----------------------------------------------------------------------------------------------------------------*/
100
101 nyx_dict_set_string_unref(result, "<>", "defBLOBVector", false);
102
103 /*----------------------------------------------------------------------------------------------------------------*/
104
105 nyx_dict_set_string_unref(result, "@client", "unknown", false);
106 nyx_dict_set_string_unref(result, "@device", nyx_string_dup(device), true);
107 nyx_dict_set_string_unref(result, "@name", nyx_string_dup(name), true);
108
109 nyx_dict_set_string_unref(result, "@state", nyx_state_to_str(state), false);
110 nyx_dict_set_string_unref(result, "@perm", nyx_perm_to_str(perm), false);
111
112 /*----------------------------------------------------------------------------------------------------------------*/
113
114 internal_set_opts(result, opts);
115
116 /*----------------------------------------------------------------------------------------------------------------*/
117
118 nyx_dict_set(result, "children", children);
119
120 if(props) for(; *props != NULL; props++)
121 {
122 nyx_list_push(children, *props);
123
124 nyx_object_unref(*props);
125 }
126
127 nyx_object_unref(children);
128
129 /*----------------------------------------------------------------------------------------------------------------*/
130
131 return result;
132}
133
134/*--------------------------------------------------------------------------------------------------------------------*/
135/* SET VECTOR */
136/*--------------------------------------------------------------------------------------------------------------------*/
137
138nyx_dict_t *nyx_blob_set_vector_new(const nyx_dict_t *vector)
139{
140 return internal_prop_to_set_vector(vector, "setBLOBVector", "oneBLOB");
141}
142
143/*--------------------------------------------------------------------------------------------------------------------*/
Struct describing a JSON dict object.
Struct describing a JSON list object.
#define STR_t
Alias for const char *.
Definition nyx_node.h:71
#define buff_t
Alias for void *.
Definition nyx_node.h:67
#define BUFF_t
Alias for const void *.
Definition nyx_node.h:68
__NYX_NULLABLE__ str_t nyx_string_dup(__NYX_NULLABLE__ STR_t s)
Similar to libc strdup.
nyx_perm_t
Vector permission hint.
Definition nyx_node.h:1948
nyx_state_t
Vector state hint.
Definition nyx_node.h:1913
Struct describing the options for INDI / Nyx vectors.
Definition nyx_node.h:2049