Nyx Node
Loading...
Searching...
No Matches
indi_text.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_text_prop_new(STR_t name, STR_t label, STR_t value, bool managed)
17{
18 if(label == NULL || label[0] == '\0')
19 {
20 label = name;
21 }
22
23 if(value == NULL)
24 {
25 value = "";
26
27 managed = false;
28 }
29
30 /*----------------------------------------------------------------------------------------------------------------*/
31
32 nyx_dict_t *result = nyx_dict_new();
33
34 /*----------------------------------------------------------------------------------------------------------------*/
35
36 nyx_dict_set_string_unref(result, "<>", "defText", false);
37
38 /*----------------------------------------------------------------------------------------------------------------*/
39
40 nyx_dict_set_string_unref(result, "@name", nyx_string_dup(name), true);
41 nyx_dict_set_string_unref(result, "@label", nyx_string_dup(label), true);
42
43 /*----------------------------------------------------------------------------------------------------------------*/
44
45 nyx_dict_set_string_unref(result, "$", value, managed);
46
47 /*----------------------------------------------------------------------------------------------------------------*/
48
49 return result;
50}
51
52/*--------------------------------------------------------------------------------------------------------------------*/
53/* PROP SETTER & GETTER */
54/*--------------------------------------------------------------------------------------------------------------------*/
55
56bool nyx_text_prop_set(const nyx_dict_t *prop, STR_t value, bool managed)
57{
58 if(value == NULL)
59 {
60 value = "";
61
62 managed = false;
63 }
64
65 return nyx_dict_set_string(prop, "$", nyx_string_dup(value), managed);
66}
67
68/*--------------------------------------------------------------------------------------------------------------------*/
69
71{
72 return nyx_dict_get_string(prop, "$");
73}
74
75/*--------------------------------------------------------------------------------------------------------------------*/
76/* VECTOR */
77/*--------------------------------------------------------------------------------------------------------------------*/
78
79nyx_dict_t *nyx_text_vector_new(
80 STR_t device,
81 STR_t name,
82 nyx_state_t state,
83 nyx_perm_t perm,
84 nyx_dict_t *props[],
85 const nyx_opts_t *opts
86) {
87 nyx_dict_t *result = nyx_dict_new();
88
89 nyx_list_t *children = nyx_list_new();
90
91 /*----------------------------------------------------------------------------------------------------------------*/
92
93 nyx_dict_set_string_unref(result, "<>", "defTextVector", false);
94
95 /*----------------------------------------------------------------------------------------------------------------*/
96
97 nyx_dict_set_string_unref(result, "@client", "unknown", false);
98 nyx_dict_set_string_unref(result, "@device", nyx_string_dup(device), true);
99 nyx_dict_set_string_unref(result, "@name", nyx_string_dup(name), true);
100
101 nyx_dict_set_string_unref(result, "@state", nyx_state_to_str(state), false);
102 nyx_dict_set_string_unref(result, "@perm", nyx_perm_to_str(perm), false);
103
104 /*----------------------------------------------------------------------------------------------------------------*/
105
106 internal_set_opts(result, opts);
107
108 /*----------------------------------------------------------------------------------------------------------------*/
109
110 nyx_dict_set(result, "children", children);
111
112 if(props) for(; *props != NULL; props++)
113 {
114 nyx_list_push(children, *props);
115
116 nyx_object_unref(*props);
117 }
118
119 nyx_object_unref(children);
120
121 /*----------------------------------------------------------------------------------------------------------------*/
122
123 return result;
124}
125
126/*--------------------------------------------------------------------------------------------------------------------*/
127/* SET VECTOR */
128/*--------------------------------------------------------------------------------------------------------------------*/
129
130nyx_dict_t *nyx_text_set_vector_new(const nyx_dict_t *vector)
131{
132 return internal_prop_to_set_vector(vector, "setTextVector", "oneText");
133}
134
135/*--------------------------------------------------------------------------------------------------------------------*/
Struct describing a JSON dict object.
Struct describing a JSON list object.
#define STR_t
Alias for const char *.
Definition nyx_node.h:71
__NYX_NULLABLE__ str_t nyx_string_dup(__NYX_NULLABLE__ STR_t s)
Similar to libc strdup.
STR_t nyx_text_prop_get(const nyx_dict_t *prop)
Gets the text value of the provided property object.
Definition indi_text.c:70
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