10#include "../nyx_node_internal.h"
16static nyx_dict_t *_prop_new(
STR_t name,
STR_t label,
STR_t format, nyx_variant_t min, nyx_variant_t max, nyx_variant_t step, nyx_variant_t value)
18 if(label == NULL || label[0] ==
'\0')
29 nyx_dict_set_string_unref(result,
"<>",
"defNumber",
false);
33 nyx_dict_set_string_unref(result,
"@name",
nyx_string_dup(name),
true);
34 nyx_dict_set_string_unref(result,
"@label",
nyx_string_dup(label),
true);
35 nyx_dict_set_string_unref(result,
"@format",
nyx_string_dup(format),
true);
37 nyx_dict_set_string_unref(result,
"@min", internal_variant_to_string(format, min),
true);
38 nyx_dict_set_string_unref(result,
"@max", internal_variant_to_string(format, max),
true);
39 nyx_dict_set_string_unref(result,
"@step", internal_variant_to_string(format, step),
true);
43 nyx_dict_set_string_unref(result,
"$", internal_variant_to_string(format, value),
true);
52nyx_dict_t *nyx_number_prop_new_int(
STR_t name,
STR_t label,
STR_t format, int32_t min, int32_t max, int32_t step, int32_t value)
54 return _prop_new(name, label, format, NYX_VARIANT_FROM_INT(min), NYX_VARIANT_FROM_INT(max), NYX_VARIANT_FROM_INT(step), NYX_VARIANT_FROM_INT(value));
57nyx_dict_t *nyx_number_prop_new_uint(
STR_t name,
STR_t label,
STR_t format, uint32_t min, uint32_t max, uint32_t step, uint32_t value)
59 return _prop_new(name, label, format, NYX_VARIANT_FROM_UINT(min), NYX_VARIANT_FROM_UINT(max), NYX_VARIANT_FROM_UINT(step), NYX_VARIANT_FROM_UINT(value));
62nyx_dict_t *nyx_number_prop_new_long(
STR_t name,
STR_t label,
STR_t format, int64_t min, int64_t max, int64_t step, int64_t value)
64 return _prop_new(name, label, format, NYX_VARIANT_FROM_LONG(min), NYX_VARIANT_FROM_LONG(max), NYX_VARIANT_FROM_LONG(step), NYX_VARIANT_FROM_LONG(value));
67nyx_dict_t *nyx_number_prop_new_ulong(
STR_t name,
STR_t label,
STR_t format, uint64_t min, uint64_t max, uint64_t step, uint64_t value)
69 return _prop_new(name, label, format, NYX_VARIANT_FROM_ULONG(min), NYX_VARIANT_FROM_ULONG(max), NYX_VARIANT_FROM_ULONG(step), NYX_VARIANT_FROM_ULONG(value));
72nyx_dict_t *nyx_number_prop_new_double(
STR_t name,
STR_t label,
STR_t format,
double min,
double max,
double step,
double value)
74 return _prop_new(name, label, format, NYX_VARIANT_FROM_DOUBLE(min), NYX_VARIANT_FROM_DOUBLE(max), NYX_VARIANT_FROM_DOUBLE(step), NYX_VARIANT_FROM_DOUBLE(value));
81static bool _prop_set(
const nyx_dict_t *prop, nyx_variant_t value)
83 STR_t format = nyx_dict_get_string(prop,
"@format");
85 return nyx_dict_set_string(prop,
"$", internal_variant_to_string(format, value),
true);
92 return _prop_set(prop, NYX_VARIANT_FROM_INT(value));
97 return _prop_set(prop, NYX_VARIANT_FROM_UINT(value));
102 return _prop_set(prop, NYX_VARIANT_FROM_LONG(value));
107 return _prop_set(prop, NYX_VARIANT_FROM_ULONG(value));
112 return _prop_set(prop, NYX_VARIANT_FROM_DOUBLE(value));
117static nyx_variant_t _prop_get(
const nyx_dict_t *prop)
119 STR_t format = nyx_dict_get_string(prop,
"@format");
121 return internal_string_to_variant(format, nyx_dict_get_string(prop,
"$"));
128 return _prop_get(prop).value._int;
133 return _prop_get(prop).value._uint;
138 return _prop_get(prop).value._long;
143 return _prop_get(prop).value._ulong;
148 return _prop_get(prop).value._double;
169 nyx_dict_set_string_unref(result,
"<>",
"defNumberVector",
false);
173 nyx_dict_set_string_unref(result,
"@client",
"unknown",
false);
174 nyx_dict_set_string_unref(result,
"@device",
nyx_string_dup(device),
true);
175 nyx_dict_set_string_unref(result,
"@name",
nyx_string_dup(name),
true);
177 nyx_dict_set_string_unref(result,
"@state", nyx_state_to_str(state),
false);
178 nyx_dict_set_string_unref(result,
"@perm", nyx_perm_to_str(perm),
false);
182 internal_set_opts(result, opts);
186 nyx_dict_set(result,
"children", children);
188 if(props)
for(; *props != NULL; props++)
190 nyx_list_push(children, *props);
192 nyx_object_unref(*props);
195 nyx_object_unref(children);
208 return internal_prop_to_set_vector(vector,
"setNumberVector",
"oneNumber");
Struct describing a JSON dict object.
Struct describing a JSON list object.
#define STR_t
Alias for const char *.
__NYX_NULLABLE__ str_t nyx_string_dup(__NYX_NULLABLE__ STR_t s)
Similar to libc strdup.
int64_t nyx_number_prop_get_long(const nyx_dict_t *prop)
Gets the value of the provided property object.
int32_t nyx_number_prop_get_int(const nyx_dict_t *prop)
Gets the value of the provided property object.
bool nyx_number_prop_set_int(nyx_dict_t *prop, int32_t value)
Sets the new value of the provided property object.
double nyx_number_prop_get_double(const nyx_dict_t *prop)
Gets the value of the provided property object.
uint64_t nyx_number_prop_get_ulong(const nyx_dict_t *prop)
Gets the value of the provided property object.
bool nyx_number_prop_set_ulong(nyx_dict_t *prop, uint64_t value)
Sets the new value of the provided property object.
bool nyx_number_prop_set_long(nyx_dict_t *prop, int64_t value)
Sets the new value of the provided property object.
bool nyx_number_prop_set_uint(nyx_dict_t *prop, uint32_t value)
Sets the new value of the provided property object.
uint32_t nyx_number_prop_get_uint(const nyx_dict_t *prop)
Gets the value of the provided property object.
bool nyx_number_prop_set_double(nyx_dict_t *prop, double value)
Sets the new value of the provided property object.
nyx_perm_t
Vector permission hint.
nyx_state_t
Vector state hint.
Struct describing the options for INDI / Nyx vectors.