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)
17{
18 if(label == NULL || label[0] == '\0')
19 {
20 label = name;
21 }
22
23 /*----------------------------------------------------------------------------------------------------------------*/
24
25 nyx_dict_t *result = nyx_dict_new();
26
27 nyx_dict_set(result, "<>", nyx_string_from_dup("defText"));
28
29 nyx_dict_set(result, "@name", nyx_string_from_dup(name));
30 nyx_dict_set(result, "@label", nyx_string_from_dup(label));
31
32 nyx_text_prop_set(result, value);
33
34 /*----------------------------------------------------------------------------------------------------------------*/
35
36 return result;
37}
38
39/*--------------------------------------------------------------------------------------------------------------------*/
40/* PROP SETTER & GETTER */
41/*--------------------------------------------------------------------------------------------------------------------*/
42
43bool nyx_text_prop_set(nyx_dict_t *prop, STR_t value)
44{
45 if(value == NULL)
46 {
47 value = "";
48 }
49
50 return nyx_dict_set(prop, "$", nyx_string_from_dup(value));
51}
52
53/*--------------------------------------------------------------------------------------------------------------------*/
54
56{
57 return nyx_string_get((nyx_string_t *) nyx_dict_get(prop, "$"));
58}
59
60/*--------------------------------------------------------------------------------------------------------------------*/
61/* VECTOR */
62/*--------------------------------------------------------------------------------------------------------------------*/
63
64nyx_dict_t *nyx_text_vector_new(
65 STR_t device,
66 STR_t name,
67 nyx_state_t state,
68 nyx_perm_t perm,
69 nyx_dict_t *props[],
70 const nyx_opts_t *opts
71) {
72 /*----------------------------------------------------------------------------------------------------------------*/
73
74 nyx_dict_t *result = nyx_dict_new();
75
76 nyx_list_t *children = nyx_list_new();
77
78 /*----------------------------------------------------------------------------------------------------------------*/
79
80 nyx_dict_set(result, "<>", nyx_string_from_dup("defTextVector"));
81
82 nyx_dict_set(result, "children", children);
83
84 /*----------------------------------------------------------------------------------------------------------------*/
85
86 nyx_dict_set(result, "@client", nyx_string_from_dup("unknown"));
87 nyx_dict_set(result, "@device", nyx_string_from_dup(device));
88 nyx_dict_set(result, "@name", nyx_string_from_dup(name));
89
90 nyx_dict_set(result, "@state", nyx_string_from_dup(nyx_state_to_str(state)));
91 nyx_dict_set(result, "@perm", nyx_string_from_dup(nyx_perm_to_str(perm)));
92
93 /*----------------------------------------------------------------------------------------------------------------*/
94
95 internal_set_opts(result, opts);
96
97 /*----------------------------------------------------------------------------------------------------------------*/
98
99 for(; *props != NULL; props++) nyx_list_push(children, *props);
100
101 /*----------------------------------------------------------------------------------------------------------------*/
102
103 return result;
104}
105
106/*--------------------------------------------------------------------------------------------------------------------*/
107/* SET VECTOR */
108/*--------------------------------------------------------------------------------------------------------------------*/
109
110nyx_dict_t *nyx_text_set_vector_new(const nyx_dict_t *vector)
111{
112 return internal_prop_to_set_vector(vector, "setTextVector", "oneText");
113}
114
115/*--------------------------------------------------------------------------------------------------------------------*/
#define STR_t
Alias for const char *.
Definition nyx_node.h:71
STR_t nyx_text_prop_get(const nyx_dict_t *prop)
Gets the current value of the provided property object.
Definition indi_text.c:55
nyx_perm_t
Vector permission hint.
Definition nyx_node.h:1816
nyx_state_t
Vector state hint.
Definition nyx_node.h:1781
Struct describing a JSON dict object.
Struct describing a JSON list object.
Struct describing the options for INDI / Nyx vectors.
Definition nyx_node.h:1917
Struct describing a JSON string object.
Definition nyx_node.h:900