Nyx Node
Loading...
Searching...
No Matches
indi_light.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_light_prop_new(STR_t name, STR_t label, nyx_state_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 /*----------------------------------------------------------------------------------------------------------------*/
28
29 nyx_dict_set_string_unref(result, "<>", "defLight", false);
30
31 /*----------------------------------------------------------------------------------------------------------------*/
32
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
36 /*----------------------------------------------------------------------------------------------------------------*/
37
38 nyx_dict_set_string_unref(result, "$", nyx_state_to_str(value), false);
39
40 /*----------------------------------------------------------------------------------------------------------------*/
41
42 return result;
43}
44
45/*--------------------------------------------------------------------------------------------------------------------*/
46/* PROP SETTER & GETTER */
47/*--------------------------------------------------------------------------------------------------------------------*/
48
50{
51 return nyx_dict_set_string(prop, "$", nyx_state_to_str(value), false);
52}
53
54/*--------------------------------------------------------------------------------------------------------------------*/
55
57{
58 return nyx_str_to_state(nyx_dict_get_string(prop, "$"));
59}
60
61/*--------------------------------------------------------------------------------------------------------------------*/
62/* VECTOR */
63/*--------------------------------------------------------------------------------------------------------------------*/
64
65nyx_dict_t *nyx_light_vector_new(
66 STR_t device,
67 STR_t name,
68 nyx_state_t state,
69 nyx_dict_t *props[],
70 const nyx_opts_t *opts
71) {
72 nyx_dict_t *result = nyx_dict_new();
73
74 nyx_list_t *children = nyx_list_new();
75
76 /*----------------------------------------------------------------------------------------------------------------*/
77
78 nyx_dict_set_string_unref(result, "<>", "defLightVector", false);
79
80 /*----------------------------------------------------------------------------------------------------------------*/
81
82 nyx_dict_set_string_unref(result, "@client", "unknown", false);
83 nyx_dict_set_string_unref(result, "@device", nyx_string_dup(device), true);
84 nyx_dict_set_string_unref(result, "@name", nyx_string_dup(name), true);
85
86 nyx_dict_set_string_unref(result, "@state", nyx_state_to_str(state), false);
87
88 /*----------------------------------------------------------------------------------------------------------------*/
89
90 internal_set_opts(result, opts);
91
92 /*----------------------------------------------------------------------------------------------------------------*/
93
94 nyx_dict_set(result, "children", children);
95
96 if(props) for(; *props != NULL; props++)
97 {
98 nyx_list_push(children, *props);
99
100 nyx_object_unref(*props);
101 }
102
103 nyx_object_unref(children);
104
105 /*----------------------------------------------------------------------------------------------------------------*/
106
107 return result;
108}
109
110/*--------------------------------------------------------------------------------------------------------------------*/
111/* SET VECTOR */
112/*--------------------------------------------------------------------------------------------------------------------*/
113
114nyx_dict_t *nyx_light_set_vector_new(const nyx_dict_t *vector)
115{
116 return internal_prop_to_set_vector(vector, "setLightVector", "oneLight");
117}
118
119/*--------------------------------------------------------------------------------------------------------------------*/
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.
bool nyx_light_prop_set(const nyx_dict_t *prop, nyx_state_t value)
Sets the new value of the provided property object.
Definition indi_light.c:49
nyx_state_t nyx_light_prop_get(const nyx_dict_t *prop)
Gets the value of the provided property object.
Definition indi_light.c:56
nyx_state_t
Vector state hint.
Definition nyx_node.h:1913
Struct describing the options for INDI / Nyx vectors.
Definition nyx_node.h:2049