Nyx Node
Loading...
Searching...
No Matches
indi_switch.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_switch_prop_new(STR_t name, STR_t label, nyx_onoff_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("defSwitch"));
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_dict_set(result, "$", nyx_string_from_dup(nyx_onoff_to_str(value)));
33
34 /*----------------------------------------------------------------------------------------------------------------*/
35
36 return result;
37}
38
39/*--------------------------------------------------------------------------------------------------------------------*/
40/* PROP SETTER & GETTER */
41/*--------------------------------------------------------------------------------------------------------------------*/
42
44{
45 return nyx_dict_set(prop, "$", nyx_string_from_dup(nyx_onoff_to_str(value)));
46}
47
48/*--------------------------------------------------------------------------------------------------------------------*/
49
51{
52 return nyx_str_to_onoff(nyx_string_get((nyx_string_t *) nyx_dict_get(prop, "$")));
53}
54
55/*--------------------------------------------------------------------------------------------------------------------*/
56/* VECTOR */
57/*--------------------------------------------------------------------------------------------------------------------*/
58
59nyx_dict_t *nyx_switch_vector_new(
60 STR_t device,
61 STR_t name,
62 nyx_state_t state,
63 nyx_perm_t perm,
64 nyx_rule_t rule,
65 nyx_dict_t *props[],
66 const nyx_opts_t *opts
67) {
68 /*----------------------------------------------------------------------------------------------------------------*/
69
70 nyx_dict_t *result = nyx_dict_new();
71
72 nyx_list_t *children = nyx_list_new();
73
74 /*----------------------------------------------------------------------------------------------------------------*/
75
76 nyx_dict_set(result, "<>", nyx_string_from_dup("defSwitchVector"));
77
78 nyx_dict_set(result, "children", children);
79
80 /*----------------------------------------------------------------------------------------------------------------*/
81
82 nyx_dict_set(result, "@client", nyx_string_from_dup("unknown"));
83 nyx_dict_set(result, "@device", nyx_string_from_dup(device));
84 nyx_dict_set(result, "@name", nyx_string_from_dup(name));
85
86 nyx_dict_set(result, "@state", nyx_string_from_dup(nyx_state_to_str(state)));
87 nyx_dict_set(result, "@perm", nyx_string_from_dup(nyx_perm_to_str(perm)));
88 nyx_dict_set(result, "@rule", nyx_string_from_dup(nyx_rule_to_str(rule)));
89
90 /*----------------------------------------------------------------------------------------------------------------*/
91
92 internal_set_opts(result, opts);
93
94 /*----------------------------------------------------------------------------------------------------------------*/
95
96 for(; *props != NULL; props++) nyx_list_push(children, *props);
97
98 /*----------------------------------------------------------------------------------------------------------------*/
99
100 return result;
101}
102
103/*--------------------------------------------------------------------------------------------------------------------*/
104/* SET VECTOR */
105/*--------------------------------------------------------------------------------------------------------------------*/
106
107nyx_dict_t *nyx_switch_set_vector_new(const nyx_dict_t *vector)
108{
109 return internal_prop_to_set_vector(vector, "setSwitchVector", "oneSwitch");
110}
111
112/*--------------------------------------------------------------------------------------------------------------------*/
#define STR_t
Alias for const char *.
Definition nyx_node.h:71
bool nyx_switch_prop_set(nyx_dict_t *prop, nyx_onoff_t value)
Sets the new value of the provided property object.
Definition indi_switch.c:43
nyx_onoff_t nyx_switch_prop_get(const nyx_dict_t *prop)
Gets the current value of the provided property object.
Definition indi_switch.c:50
nyx_perm_t
Vector permission hint.
Definition nyx_node.h:1816
nyx_state_t
Vector state hint.
Definition nyx_node.h:1781
nyx_onoff_t
Switch state.
Definition nyx_node.h:1884
nyx_rule_t
Switch vector rule hint.
Definition nyx_node.h:1850
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