Nyx Node
Loading...
Searching...
No Matches
nyx_node.h
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#ifndef NYX_NODE_H
9#define NYX_NODE_H
10
11/*--------------------------------------------------------------------------------------------------------------------*/
12
13#include <stddef.h>
14#include <stdint.h>
15#include <stdbool.h>
16
17/*--------------------------------------------------------------------------------------------------------------------*/
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/*--------------------------------------------------------------------------------------------------------------------*/
24
25#ifndef ARDUINO
26# pragma clang diagnostic push
27# pragma ide diagnostic ignored "OCUnusedMacroInspection"
28# pragma ide diagnostic ignored "UnreachableCallsOfFunction"
29#endif
30
31/*--------------------------------------------------------------------------------------------------------------------*/
32
33double nan(const char *tag);
34
35/*--------------------------------------------------------------------------------------------------------------------*/
36
37#define __NULLABLE__ \
38 /* do nothing */
39
40#define __ZEROABLE__ \
41 /* do nothing */
42
43#define __UNUSED__ \
44 __attribute__((unused))
45
46#define __INLINE__ \
47 __attribute__((always_inline)) static inline
48
49/*--------------------------------------------------------------------------------------------------------------------*/
50
51typedef /*-*/ void *buff_t;
52typedef const void *BUFF_t;
53
54typedef /*-*/ char *str_t;
55typedef const char *STR_t;
56
57/*--------------------------------------------------------------------------------------------------------------------*/
58/* MEMORY */
59/*--------------------------------------------------------------------------------------------------------------------*/
64/*--------------------------------------------------------------------------------------------------------------------*/
65
71
72/*--------------------------------------------------------------------------------------------------------------------*/
73
79
80/*--------------------------------------------------------------------------------------------------------------------*/
81
86__ZEROABLE__ size_t nyx_memory_free(
87 __NULLABLE__ buff_t buff
88);
89
90/*--------------------------------------------------------------------------------------------------------------------*/
91
96__NULLABLE__ buff_t nyx_memory_alloc(
97 __ZEROABLE__ size_t size
98);
99
100/*--------------------------------------------------------------------------------------------------------------------*/
101
106__NULLABLE__ buff_t nyx_memory_realloc(
107 __NULLABLE__ buff_t buff,
108 __ZEROABLE__ size_t size
109);
110
111/*--------------------------------------------------------------------------------------------------------------------*/
112/* LOGGER */
113/*--------------------------------------------------------------------------------------------------------------------*/
119/*--------------------------------------------------------------------------------------------------------------------*/
120
125typedef enum nyx_log_level_e
126{
127 NYX_LOG_LEVEL_NONE = 0,
128 NYX_LOG_LEVEL_FATAL = 1,
129 NYX_LOG_LEVEL_ERROR = 2,
130 NYX_LOG_LEVEL_INFO = 3,
131 NYX_LOG_LEVEL_DEBUG = 4,
132 NYX_LOG_LEVEL_VERBOSE = 5,
133
135
136/*--------------------------------------------------------------------------------------------------------------------*/
137
145 nyx_log_level_t level
146);
147
148/*--------------------------------------------------------------------------------------------------------------------*/
149
154void nyx_log(
155 nyx_log_level_t level,
156 STR_t file,
157 STR_t func,
158 int line,
159 STR_t fmt,
160 ...
161);
162
163/*--------------------------------------------------------------------------------------------------------------------*/
164
172#define NYX_LOG_FATAL(fmt, ...) \
173 do { nyx_log(NYX_LOG_LEVEL_FATAL, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(1)
174
182#define NYX_LOG_ERROR(fmt, ...) \
183 do { nyx_log(NYX_LOG_LEVEL_ERROR, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
184
192#define NYX_LOG_INFO(fmt, ...) \
193 do { nyx_log(NYX_LOG_LEVEL_INFO, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
194
202#define NYX_LOG_DEBUG(fmt, ...) \
203 do { nyx_log(NYX_LOG_LEVEL_DEBUG, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
204
212#define NYX_LOG_VERBOSE(fmt, ...) \
213 do { nyx_log(NYX_LOG_LEVEL_VERBOSE, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); } while(0)
214
215/*--------------------------------------------------------------------------------------------------------------------*/
216/* UTILITIES */
217/*--------------------------------------------------------------------------------------------------------------------*/
223/*--------------------------------------------------------------------------------------------------------------------*/
224
235 uint8_t result_mac[6],
236 uint8_t mac0,
237 uint8_t mac1,
238 STR_t node_id
239);
240
241/*--------------------------------------------------------------------------------------------------------------------*/
242
252__NULLABLE__ str_t nyx_base64_encode(
253 __NULLABLE__ size_t *result_len,
254 __ZEROABLE__ size_t size,
255 __NULLABLE__ BUFF_t buff
256);
257
258/*--------------------------------------------------------------------------------------------------------------------*/
259
269__NULLABLE__ buff_t nyx_base64_decode(
270 __NULLABLE__ size_t *result_size,
271 __ZEROABLE__ size_t len,
272 __NULLABLE__ STR_t str
273);
274
275/*--------------------------------------------------------------------------------------------------------------------*/
276
286uint32_t nyx_hash32(
287 __ZEROABLE__ size_t size,
288 __NULLABLE__ BUFF_t buff,
289 uint32_t seed
290);
291
292/*--------------------------------------------------------------------------------------------------------------------*/
293/* OBJECT */
294/*--------------------------------------------------------------------------------------------------------------------*/
300/*--------------------------------------------------------------------------------------------------------------------*/
301
302#define NYX_OBJECT_MAGIC 0x65656565U
303
304/*--------------------------------------------------------------------------------------------------------------------*/
305
306#define NYX_FLAGS_DISABLED ((uint64_t) 0x0000000000000001U)
307/* 0b0000000000000000000000000000000_0000000000000000000000000000000_01 */
308
309#define NYX_FLAGS_BLOB_MASK ((uint64_t) 0x00000001FFFFFFFCU)
310/* 0b0000000000000000000000000000000_1111111111111111111111111111111_00 */
311
312#define NYX_FLAGS_STREAM_MASK ((uint64_t) 0xFFFFFFFE00000000U)
313/* 0b1111111111111111111111111111111_0000000000000000000000000000000_00 */
314
315/*--------------------------------------------------------------------------------------------------------------------*/
316
331
332/*--------------------------------------------------------------------------------------------------------------------*/
333
338typedef struct nyx_object_s
339{
340 uint32_t magic;
341 uint64_t flags;
342
344
345 __NULLABLE__ struct nyx_node_s *node;
346
347 __NULLABLE__ struct nyx_object_s *parent;
348
349 __NULLABLE__ void (* in_callback)(
350 struct nyx_object_s *object,
351 bool modified
352 );
353 __NULLABLE__ void (* out_callback)(
354 struct nyx_object_s *object,
355 bool modified
356 );
357
359
360/*--------------------------------------------------------------------------------------------------------------------*/
361
372 __ZEROABLE__ size_t size,
373 __NULLABLE__ BUFF_t buff
374);
375
385 __NULLABLE__ STR_t text
386);
387
388/*--------------------------------------------------------------------------------------------------------------------*/
389
398 __NULLABLE__ nyx_object_t *object
399);
400
401/*--------------------------------------------------------------------------------------------------------------------*/
402
413 __NULLABLE__ const nyx_object_t *object1,
414 __NULLABLE__ const nyx_object_t *object2
415);
416
417/*--------------------------------------------------------------------------------------------------------------------*/
418
428 __NULLABLE__ const nyx_object_t *object
429);
430
431/*--------------------------------------------------------------------------------------------------------------------*/
432
442 __NULLABLE__ const nyx_object_t *object
443);
444
445/*--------------------------------------------------------------------------------------------------------------------*/
446/* NULL */
447/*--------------------------------------------------------------------------------------------------------------------*/
453/*--------------------------------------------------------------------------------------------------------------------*/
454
459typedef struct
460{
462
463} nyx_null_t;
464
465/*--------------------------------------------------------------------------------------------------------------------*/
466
475
484 /*-*/ nyx_null_t *object
485);
486
496 const nyx_null_t *object
497);
498
499/*--------------------------------------------------------------------------------------------------------------------*/
500/* NUMBER */
501/*--------------------------------------------------------------------------------------------------------------------*/
507/*--------------------------------------------------------------------------------------------------------------------*/
508
513typedef struct
514{
516
517 double value;
518
520
521/*--------------------------------------------------------------------------------------------------------------------*/
522
531
532/*--------------------------------------------------------------------------------------------------------------------*/
533
542 /*-*/ nyx_number_t *object
543);
544
545/*--------------------------------------------------------------------------------------------------------------------*/
546
556 const nyx_number_t *object
557);
558
559/*--------------------------------------------------------------------------------------------------------------------*/
560
565bool nyx_number_set_alt(
566 /*-*/ nyx_number_t *object,
567 double value,
568 bool notify
569);
570
580__INLINE__ bool nyx_number_set(nyx_number_t *object, double value)
581{
582 return nyx_number_set_alt(object, value, true);
583}
584
585/*--------------------------------------------------------------------------------------------------------------------*/
586
596 const nyx_number_t *object
597);
598
599/*--------------------------------------------------------------------------------------------------------------------*/
600
609__INLINE__ nyx_number_t *nyx_number_from(double value)
610{
611 nyx_number_t *result = nyx_number_new();
612
613 nyx_number_set(result, value);
614
615 return result;
616}
617
618/*--------------------------------------------------------------------------------------------------------------------*/
619/* BOOLEAN */
620/*--------------------------------------------------------------------------------------------------------------------*/
626/*--------------------------------------------------------------------------------------------------------------------*/
627
632typedef struct
633{
635
636 bool value;
637
639
640/*--------------------------------------------------------------------------------------------------------------------*/
641
650
651/*--------------------------------------------------------------------------------------------------------------------*/
652
661 /*-*/ nyx_boolean_t *object
662);
663
664/*--------------------------------------------------------------------------------------------------------------------*/
665
675 const nyx_boolean_t *object
676);
677
678/*--------------------------------------------------------------------------------------------------------------------*/
679
684bool nyx_boolean_set_alt(
685 /*-*/ nyx_boolean_t *object,
686 bool value,
687 bool notify
688);
689
699__INLINE__ bool nyx_boolean_set(nyx_boolean_t *object, bool value)
700{
701 return nyx_boolean_set_alt(object, value, true);
702}
703
704/*--------------------------------------------------------------------------------------------------------------------*/
705
715 const nyx_boolean_t *object
716);
717
718/*--------------------------------------------------------------------------------------------------------------------*/
719
728__INLINE__ nyx_boolean_t *nyx_boolean_from(bool value)
729{
730 nyx_boolean_t *result = nyx_boolean_new();
731
732 nyx_boolean_set(result, value);
733
734 return result;
735}
736
737/*--------------------------------------------------------------------------------------------------------------------*/
738/* STRING */
739/*--------------------------------------------------------------------------------------------------------------------*/
745/*--------------------------------------------------------------------------------------------------------------------*/
746
751typedef struct
752{
754
755 size_t length;
756 str_t value;
757
758 bool dyn;
759
761
762/*--------------------------------------------------------------------------------------------------------------------*/
763
772
773/*--------------------------------------------------------------------------------------------------------------------*/
774
783 /*-*/ nyx_string_t *object
784);
785
786/*--------------------------------------------------------------------------------------------------------------------*/
787
797 const nyx_string_t *object
798);
799
800/*--------------------------------------------------------------------------------------------------------------------*/
801
806void nyx_string_get_buff(
807 const nyx_string_t *object,
808 __NULLABLE__ size_t *result_size,
809 __NULLABLE__ buff_t *result_buff,
810 bool base64_decode
811);
812
813/*--------------------------------------------------------------------------------------------------------------------*/
814
819bool nyx_string_set_dup_alt(
820 /*-*/ nyx_string_t *object,
821 STR_t value,
822 bool notify
823);
824
834__INLINE__ bool nyx_string_set_dup(nyx_string_t *object, STR_t value)
835{
836 return nyx_string_set_dup_alt(object, value, true);
837}
838
839/*--------------------------------------------------------------------------------------------------------------------*/
840
845bool nyx_string_set_ref_alt(
846 /*-*/ nyx_string_t *object,
847 STR_t value,
848 bool notify
849);
850
860__INLINE__ bool nyx_string_set_ref(nyx_string_t *object, STR_t value)
861{
862 return nyx_string_set_ref_alt(object, value, true);
863}
864
865/*--------------------------------------------------------------------------------------------------------------------*/
866
871bool nyx_string_set_buff_alt(
872 /*-*/ nyx_string_t *object,
873 __ZEROABLE__ size_t size,
874 __NULLABLE__ BUFF_t buff,
875 bool base64_encode,
876 bool notify
877);
878
890__INLINE__ bool nyx_string_set_buff(nyx_string_t *object, size_t size, BUFF_t buff, bool base64_encode)
891{
892 return nyx_string_set_buff_alt(object, size, buff, base64_encode, true);
893}
894
895/*--------------------------------------------------------------------------------------------------------------------*/
896
906 const nyx_string_t *object
907);
908
909/*--------------------------------------------------------------------------------------------------------------------*/
910
920 const nyx_string_t *object
921);
922
923/*--------------------------------------------------------------------------------------------------------------------*/
924
934 const nyx_string_t *object
935);
936
937/*--------------------------------------------------------------------------------------------------------------------*/
938
947__INLINE__ nyx_string_t *nyx_string_from_dup(STR_t value)
948{
949 nyx_string_t *result = nyx_string_new();
950
951 nyx_string_set_dup(result, value);
952
953 return result;
954}
955
956/*--------------------------------------------------------------------------------------------------------------------*/
957
966__INLINE__ nyx_string_t *nyx_string_from_ref(STR_t value)
967{
968 nyx_string_t *result = nyx_string_new();
969
970 nyx_string_set_ref(result, value);
971
972 return result;
973}
974
975/*--------------------------------------------------------------------------------------------------------------------*/
976
987__INLINE__ nyx_string_t *nyx_string_from_buff(size_t size, BUFF_t buff, bool base64_encode)
988{
989 nyx_string_t *result = nyx_string_new();
990
991 nyx_string_set_buff(result, size, buff, base64_encode);
992
993 return result;
994}
995
996/*--------------------------------------------------------------------------------------------------------------------*/
997
1002#define nyx_string_set nyx_string_set_dup
1003
1008#define nyx_string_from nyx_string_from_dup
1009
1010/*--------------------------------------------------------------------------------------------------------------------*/
1011/* DICT */
1012/*--------------------------------------------------------------------------------------------------------------------*/
1018/*--------------------------------------------------------------------------------------------------------------------*/
1019
1024typedef struct
1025{
1027
1028 struct nyx_dict_node_s *head;
1029 struct nyx_dict_node_s *tail;
1030
1031} nyx_dict_t;
1032
1033/*--------------------------------------------------------------------------------------------------------------------*/
1034
1035typedef struct
1036{
1037 int idx;
1038
1040
1041 struct nyx_dict_node_s *head;
1042
1044
1045/*--------------------------------------------------------------------------------------------------------------------*/
1046
1047#define NYX_DICT_ITER(object) \
1048 ((nyx_dict_iter_t) {.idx = 0, .type = ((nyx_dict_t *) (object))->base.type, .head = ((nyx_dict_t *) (object))->head})
1049
1050/*--------------------------------------------------------------------------------------------------------------------*/
1051
1060
1061/*--------------------------------------------------------------------------------------------------------------------*/
1062
1071 /*-*/ nyx_dict_t *object
1072);
1073
1074/*--------------------------------------------------------------------------------------------------------------------*/
1075
1084 /*-*/ nyx_dict_t *object
1085);
1086
1087/*--------------------------------------------------------------------------------------------------------------------*/
1088
1098 /*-*/ nyx_dict_t *object,
1099 STR_t key
1100);
1101
1102/*--------------------------------------------------------------------------------------------------------------------*/
1103
1115 nyx_dict_iter_t *iter,
1116 STR_t *key,
1117 nyx_object_t **object
1118);
1119
1120/*--------------------------------------------------------------------------------------------------------------------*/
1121
1132 const nyx_dict_t *object,
1133 STR_t key
1134);
1135
1136/*--------------------------------------------------------------------------------------------------------------------*/
1137
1142bool nyx_dict_set_alt(
1143 /*-*/ nyx_dict_t *object,
1144 STR_t key,
1145 buff_t value,
1146 bool notify
1147);
1148
1159__INLINE__ bool nyx_dict_set(nyx_dict_t *object, STR_t key, buff_t value)
1160{
1161 return nyx_dict_set_alt(object, key, value, true);
1162}
1163
1164/*--------------------------------------------------------------------------------------------------------------------*/
1165
1175 const nyx_dict_t *object
1176);
1177
1178/*--------------------------------------------------------------------------------------------------------------------*/
1179
1189 const nyx_dict_t *object
1190);
1191
1192/*--------------------------------------------------------------------------------------------------------------------*/
1193
1203__INLINE__ double nyx_dict_get_number(const nyx_dict_t *object, STR_t key)
1204{
1205 nyx_object_t *number = nyx_dict_get(object, key);
1206
1207 return (number != NULL && number->type == NYX_TYPE_NUMBER) ? nyx_number_get((nyx_number_t *) number)
1208 : nan("1")
1209 ;
1210}
1211
1212/*--------------------------------------------------------------------------------------------------------------------*/
1213
1223__INLINE__ STR_t nyx_dict_get_string(const nyx_dict_t *object, STR_t key)
1224{
1225 nyx_object_t *string = nyx_dict_get(object, key);
1226
1227 return (string != NULL && string->type == NYX_TYPE_STRING) ? nyx_string_get((nyx_string_t *) string)
1228 : NULL
1229 ;
1230}
1231
1232/*--------------------------------------------------------------------------------------------------------------------*/
1233/* LIST */
1234/*--------------------------------------------------------------------------------------------------------------------*/
1240/*--------------------------------------------------------------------------------------------------------------------*/
1241
1246typedef struct
1247{
1249
1250 struct nyx_list_node_s *head;
1251 struct nyx_list_node_s *tail;
1252
1253} nyx_list_t;
1254
1255/*--------------------------------------------------------------------------------------------------------------------*/
1256
1257typedef struct
1258{
1259 int idx;
1260
1262
1263 struct nyx_list_node_s *head;
1264
1266
1267/*--------------------------------------------------------------------------------------------------------------------*/
1268
1269#define NYX_LIST_ITER(object) \
1270 ((nyx_list_iter_t) {.idx = 0, .type = ((nyx_list_t *) (object))->base.type, .head = ((nyx_list_t *) (object))->head})
1271
1272/*--------------------------------------------------------------------------------------------------------------------*/
1273
1282
1283/*--------------------------------------------------------------------------------------------------------------------*/
1284
1293 /*-*/ nyx_list_t *object
1294);
1295
1296/*--------------------------------------------------------------------------------------------------------------------*/
1297
1306 /*-*/ nyx_list_t *object
1307);
1308
1309/*--------------------------------------------------------------------------------------------------------------------*/
1310
1320 /*-*/ nyx_list_t *object,
1321 int idx
1322);
1323
1324/*--------------------------------------------------------------------------------------------------------------------*/
1325
1337 nyx_list_iter_t *iter,
1338 int *idx,
1339 nyx_object_t **object
1340);
1341
1342/*--------------------------------------------------------------------------------------------------------------------*/
1343
1354 const nyx_list_t *object,
1355 int idx
1356);
1357
1358/*--------------------------------------------------------------------------------------------------------------------*/
1359
1364nyx_list_t *nyx_list_set_alt(
1365 /*-*/ nyx_list_t *object,
1366 size_t idx,
1367 buff_t value,
1368 bool notify
1369);
1370
1380__INLINE__ bool nyx_list_push(nyx_list_t *object, buff_t value)
1381{
1382 return nyx_list_set_alt(object, -1, value, true);
1383}
1384
1385/*--------------------------------------------------------------------------------------------------------------------*/
1386
1396 const nyx_list_t *object
1397);
1398
1399/*--------------------------------------------------------------------------------------------------------------------*/
1400
1410 const nyx_list_t *object
1411);
1412
1413/*--------------------------------------------------------------------------------------------------------------------*/
1414
1424__INLINE__ double nyx_list_get_number(const nyx_list_t *object, int idx)
1425{
1426 nyx_object_t *number = nyx_list_get(object, idx);
1427
1428 return (number != NULL && number->type == NYX_TYPE_NUMBER) ? nyx_number_get((nyx_number_t *) number)
1429 : nan("1")
1430 ;
1431}
1432
1433/*--------------------------------------------------------------------------------------------------------------------*/
1434
1444__INLINE__ STR_t nyx_list_get_string(const nyx_list_t *object, int idx)
1445{
1446 nyx_object_t *string = nyx_list_get(object, idx);
1447
1448 return (string != NULL && string->type == NYX_TYPE_STRING) ? nyx_string_get((nyx_string_t *) string)
1449 : NULL
1450 ;
1451}
1452
1453/*--------------------------------------------------------------------------------------------------------------------*/
1454/* XMLDOC */
1455/*--------------------------------------------------------------------------------------------------------------------*/
1461/*--------------------------------------------------------------------------------------------------------------------*/
1462
1476
1477/*--------------------------------------------------------------------------------------------------------------------*/
1478
1483typedef struct nyx_xmldoc_s
1484{
1485 str_t name;
1486 nyx_xml_type_t type;
1487 str_t data;
1488
1489 struct nyx_xmldoc_s *next;
1490 struct nyx_xmldoc_s *parent;
1491
1492 struct nyx_xmldoc_s *children;
1493 struct nyx_xmldoc_s *attributes;
1494
1495 bool self_closing;
1496
1497} nyx_xmldoc_t;
1498
1499/*--------------------------------------------------------------------------------------------------------------------*/
1500
1511 __ZEROABLE__ size_t size,
1512 __NULLABLE__ BUFF_t buff
1513);
1514
1515/*--------------------------------------------------------------------------------------------------------------------*/
1516
1526 __NULLABLE__ STR_t text
1527);
1528
1529/*--------------------------------------------------------------------------------------------------------------------*/
1530
1539 __NULLABLE__ nyx_xmldoc_t *xmldoc
1540);
1541
1542/*--------------------------------------------------------------------------------------------------------------------*/
1543
1553 const nyx_xmldoc_t *xmldoc
1554);
1555
1556/*--------------------------------------------------------------------------------------------------------------------*/
1557/* VALIDATION */
1558/*--------------------------------------------------------------------------------------------------------------------*/
1564/*--------------------------------------------------------------------------------------------------------------------*/
1565
1571
1572/*--------------------------------------------------------------------------------------------------------------------*/
1573
1579
1580/*--------------------------------------------------------------------------------------------------------------------*/
1581
1592 __NULLABLE__ const nyx_xmldoc_t *xmldoc
1593);
1594
1595/*--------------------------------------------------------------------------------------------------------------------*/
1596/* TRANSFORM */
1597/*--------------------------------------------------------------------------------------------------------------------*/
1603/*--------------------------------------------------------------------------------------------------------------------*/
1604
1614 __NULLABLE__ const nyx_xmldoc_t *xmldoc,
1615 bool validate
1616);
1617
1618/*--------------------------------------------------------------------------------------------------------------------*/
1619
1629 __NULLABLE__ const nyx_object_t *object,
1630 bool validate
1631);
1632
1633/*--------------------------------------------------------------------------------------------------------------------*/
1634/* NYX */
1635/*--------------------------------------------------------------------------------------------------------------------*/
1641/*--------------------------------------------------------------------------------------------------------------------*/
1642
1643#define NYX_INDI_VERSION "1.7"
1644
1645/*--------------------------------------------------------------------------------------------------------------------*/
1646
1647typedef enum
1648{
1649 NYX_STATE_IDLE = 200,
1650 NYX_STATE_OK = 201,
1651 NYX_STATE_BUSY = 202,
1652 NYX_STATE_ALERT = 203,
1653
1654} nyx_state_t;
1655
1656/*--------------------------------------------------------------------------------------------------------------------*/
1657
1658STR_t nyx_state_to_str(
1659 nyx_state_t state
1660);
1661
1662/*--------------------------------------------------------------------------------------------------------------------*/
1663
1664nyx_state_t nyx_str_to_state(
1665 STR_t state
1666);
1667
1668/*--------------------------------------------------------------------------------------------------------------------*/
1669
1670typedef enum
1671{
1672 NYX_PERM_RO = 300,
1673 NYX_PERM_WO = 301,
1674 NYX_PERM_RW = 302,
1675
1676} nyx_perm_t;
1677
1678/*--------------------------------------------------------------------------------------------------------------------*/
1679
1680STR_t nyx_perm_to_str(
1681 nyx_perm_t perm
1682);
1683
1684/*--------------------------------------------------------------------------------------------------------------------*/
1685
1686nyx_perm_t nyx_str_to_perm(
1687 STR_t perm
1688);
1689
1690/*--------------------------------------------------------------------------------------------------------------------*/
1691
1692typedef enum
1693{
1694 NYX_RULE_ONE_OF_MANY = 400,
1695 NYX_RULE_AT_MOST_ONE = 401,
1696 NYX_RULE_ANY_OF_MANY = 402,
1697
1698} nyx_rule_t;
1699
1700/*--------------------------------------------------------------------------------------------------------------------*/
1701
1702STR_t nyx_rule_to_str(
1703 nyx_rule_t rule
1704);
1705
1706/*--------------------------------------------------------------------------------------------------------------------*/
1707
1708nyx_rule_t nyx_str_to_rule(
1709 STR_t rule
1710);
1711
1712/*--------------------------------------------------------------------------------------------------------------------*/
1713
1714typedef enum
1715{
1716 NYX_ONOFF_ON = 500,
1717 NYX_ONOFF_OFF = 501,
1718
1719} nyx_onoff_t;
1720
1721/*--------------------------------------------------------------------------------------------------------------------*/
1722
1723STR_t nyx_onoff_to_str(
1724 nyx_onoff_t onoff
1725);
1726
1727/*--------------------------------------------------------------------------------------------------------------------*/
1728
1729nyx_onoff_t nyx_str_to_onoff(
1730 STR_t onoff
1731);
1732
1733/*--------------------------------------------------------------------------------------------------------------------*/
1734
1735typedef enum
1736{
1737 NYX_BLOB_NEVER = 600,
1738 NYX_BLOB_ALSO = 601,
1739 NYX_BLOB_ONLY = 602,
1740
1741} nyx_blob_t;
1742
1743/*--------------------------------------------------------------------------------------------------------------------*/
1744
1745STR_t nyx_blob_to_str(
1746 nyx_blob_t blob
1747);
1748
1749/*--------------------------------------------------------------------------------------------------------------------*/
1750
1751nyx_blob_t nyx_str_to_blob(
1752 STR_t blob
1753);
1754
1755/*--------------------------------------------------------------------------------------------------------------------*/
1756
1757typedef enum
1758{
1759 NYX_STREAM_NEVER = 700,
1760 NYX_STREAM_ALSO = 701,
1761 NYX_STREAM_ONLY = 702,
1762
1763} nyx_stream_t;
1764
1765/*--------------------------------------------------------------------------------------------------------------------*/
1766
1767STR_t nyx_stream_to_str(
1768 nyx_stream_t stream
1769);
1770
1771/*--------------------------------------------------------------------------------------------------------------------*/
1772
1773nyx_stream_t nyx_str_to_stream(
1774 STR_t stream
1775);
1776
1777/*--------------------------------------------------------------------------------------------------------------------*/
1778
1779typedef struct
1780{
1781 __NULLABLE__ STR_t label;
1782 __NULLABLE__ STR_t group;
1783 __NULLABLE__ double timeout;
1784 __NULLABLE__ STR_t message;
1785
1786} nyx_opts_t;
1787
1788/*--------------------------------------------------------------------------------------------------------------------*/
1789
1794nyx_string_t *nyx_format_int_to_string(
1795 nyx_string_t *format,
1796 int value
1797);
1798
1803int nyx_format_string_to_int(
1804 nyx_string_t *format,
1805 nyx_string_t *value
1806);
1807
1808/*--------------------------------------------------------------------------------------------------------------------*/
1809
1814nyx_string_t *nyx_format_long_to_string(
1815 nyx_string_t *format,
1816 long value
1817);
1818
1823long nyx_format_string_to_long(
1824 nyx_string_t *format,
1825 nyx_string_t *value
1826);
1827
1828/*--------------------------------------------------------------------------------------------------------------------*/
1829
1834nyx_string_t *nyx_format_double_to_string(
1835 nyx_string_t *format,
1836 double value
1837);
1838
1843double nyx_format_string_to_double(
1844 nyx_string_t *format,
1845 nyx_string_t *value
1846);
1847
1848/*--------------------------------------------------------------------------------------------------------------------*/
1854/*--------------------------------------------------------------------------------------------------------------------*/
1855
1869 STR_t name,
1870 __NULLABLE__ STR_t label,
1871 STR_t format,
1872 double min,
1873 double max,
1874 double step,
1875 double value
1876);
1877
1878/*--------------------------------------------------------------------------------------------------------------------*/
1879
1880__INLINE__ bool nyx_number_def_set_int(nyx_dict_t *def, int value)
1881{
1882 nyx_string_t *format = (nyx_string_t *) nyx_dict_get(def, "@format");
1883
1884 nyx_string_t *string = nyx_format_int_to_string(format, value);
1885
1886 return nyx_dict_set(def, "$", string);
1887}
1888
1889/*--------------------------------------------------------------------------------------------------------------------*/
1890
1891__INLINE__ int nyx_number_def_get_int(const nyx_dict_t *def)
1892{
1893 nyx_string_t *format = (nyx_string_t *) nyx_dict_get(def, "@format");
1894
1895 nyx_string_t *string = (nyx_string_t *) nyx_dict_get(def, "$");
1896
1897 return nyx_format_string_to_int(format, string);
1898}
1899
1900/*--------------------------------------------------------------------------------------------------------------------*/
1901
1902__INLINE__ bool nyx_number_def_set_long(nyx_dict_t *def, long value)
1903{
1904 nyx_string_t *format = (nyx_string_t *) nyx_dict_get(def, "@format");
1905
1906 nyx_string_t *string = nyx_format_long_to_string(format, value);
1907
1908 return nyx_dict_set(def, "$", string);
1909}
1910
1911/*--------------------------------------------------------------------------------------------------------------------*/
1912
1913__INLINE__ long nyx_number_def_get_long(const nyx_dict_t *def)
1914{
1915 nyx_string_t *format = (nyx_string_t *) nyx_dict_get(def, "@format");
1916
1917 nyx_string_t *string = (nyx_string_t *) nyx_dict_get(def, "$");
1918
1919 return nyx_format_string_to_long(format, string);
1920}
1921
1922/*--------------------------------------------------------------------------------------------------------------------*/
1923
1924__INLINE__ bool nyx_number_def_set_double(nyx_dict_t *def, double value)
1925{
1926 nyx_string_t *format = (nyx_string_t *) nyx_dict_get(def, "@format");
1927
1928 nyx_string_t *string = nyx_format_double_to_string(format, value);
1929
1930 return nyx_dict_set(def, "$", string);
1931}
1932
1933/*--------------------------------------------------------------------------------------------------------------------*/
1934
1935__INLINE__ double nyx_number_def_get_double(const nyx_dict_t *def)
1936{
1937 nyx_string_t *format = (nyx_string_t *) nyx_dict_get(def, "@format");
1938
1939 nyx_string_t *string = (nyx_string_t *) nyx_dict_get(def, "$");
1940
1941 return nyx_format_string_to_double(format, string);
1942}
1943
1944/*--------------------------------------------------------------------------------------------------------------------*/
1945
1958 STR_t device,
1959 STR_t name,
1960 nyx_state_t state,
1961 nyx_perm_t perm,
1962 nyx_dict_t *defs[],
1963 __NULLABLE__ const nyx_opts_t *opts
1964);
1965
1966/*--------------------------------------------------------------------------------------------------------------------*/
1967
1972nyx_dict_t *nyx_number_set_vector_new(
1973 const nyx_dict_t *def_vector
1974);
1975
1976/*--------------------------------------------------------------------------------------------------------------------*/
1982/*--------------------------------------------------------------------------------------------------------------------*/
1983
1993 STR_t name,
1994 __NULLABLE__ STR_t label,
1995 STR_t value
1996);
1997
1998/*--------------------------------------------------------------------------------------------------------------------*/
1999
2000__INLINE__ bool nyx_text_def_set(nyx_dict_t *def, STR_t value)
2001{
2002 return nyx_dict_set(def, "$", nyx_string_from(value));
2003}
2004
2005/*--------------------------------------------------------------------------------------------------------------------*/
2006
2007__INLINE__ STR_t nyx_text_def_get(const nyx_dict_t *def)
2008{
2009 return nyx_string_get((nyx_string_t *) nyx_dict_get(def, "$"));
2010}
2011
2012/*--------------------------------------------------------------------------------------------------------------------*/
2013
2026 STR_t device,
2027 STR_t name,
2028 nyx_state_t state,
2029 nyx_perm_t perm,
2030 nyx_dict_t *defs[],
2031 __NULLABLE__ const nyx_opts_t *opts
2032);
2033
2034/*--------------------------------------------------------------------------------------------------------------------*/
2035
2040nyx_dict_t *nyx_text_set_vector_new(
2041 const nyx_dict_t *def_vector
2042);
2043
2044/*--------------------------------------------------------------------------------------------------------------------*/
2050/*--------------------------------------------------------------------------------------------------------------------*/
2051
2061 STR_t name,
2062 __NULLABLE__ STR_t label,
2063 nyx_state_t value
2064);
2065
2066/*--------------------------------------------------------------------------------------------------------------------*/
2067
2068__INLINE__ bool nyx_light_def_set(nyx_dict_t *def, nyx_state_t value)
2069{
2070 return nyx_dict_set(def, "$", nyx_string_from(nyx_state_to_str(value)));
2071}
2072
2073/*--------------------------------------------------------------------------------------------------------------------*/
2074
2075__INLINE__ nyx_state_t nyx_light_def_get(const nyx_dict_t *def)
2076{
2077 return nyx_str_to_state(((nyx_string_t *) nyx_dict_get(def, "$"))->value);
2078}
2079
2080/*--------------------------------------------------------------------------------------------------------------------*/
2081
2093 STR_t device,
2094 STR_t name,
2095 nyx_state_t state,
2096 nyx_dict_t *defs[],
2097 __NULLABLE__ const nyx_opts_t *opts
2098);
2099
2100/*--------------------------------------------------------------------------------------------------------------------*/
2101
2106nyx_dict_t *nyx_light_set_vector_new(
2107 const nyx_dict_t *def_vector
2108);
2109
2110/*--------------------------------------------------------------------------------------------------------------------*/
2116/*--------------------------------------------------------------------------------------------------------------------*/
2117
2127 STR_t name,
2128 __NULLABLE__ STR_t label,
2129 nyx_onoff_t value
2130);
2131
2132/*--------------------------------------------------------------------------------------------------------------------*/
2133
2134__INLINE__ bool nyx_switch_def_set(nyx_dict_t *def, nyx_onoff_t value)
2135{
2136 return nyx_dict_set(def, "$", nyx_string_from(nyx_onoff_to_str(value)));
2137}
2138
2139/*--------------------------------------------------------------------------------------------------------------------*/
2140
2141__INLINE__ nyx_onoff_t nyx_switch_def_get(const nyx_dict_t *def)
2142{
2143 return nyx_str_to_onoff(((nyx_string_t *) nyx_dict_get(def, "$"))->value);
2144}
2145
2146/*--------------------------------------------------------------------------------------------------------------------*/
2147
2161 STR_t device,
2162 STR_t name,
2163 nyx_state_t state,
2164 nyx_perm_t perm,
2165 nyx_rule_t rule,
2166 nyx_dict_t *defs[],
2167 __NULLABLE__ const nyx_opts_t *opts
2168);
2169
2170/*--------------------------------------------------------------------------------------------------------------------*/
2171
2176nyx_dict_t *nyx_switch_set_vector_new(
2177 const nyx_dict_t *def_vector
2178);
2179
2180/*--------------------------------------------------------------------------------------------------------------------*/
2186/*--------------------------------------------------------------------------------------------------------------------*/
2187
2198 STR_t name,
2199 __NULLABLE__ STR_t label,
2200 STR_t value,
2201 STR_t format
2202);
2203
2204/*--------------------------------------------------------------------------------------------------------------------*/
2205
2206__INLINE__ bool nyx_blob_def_set(nyx_dict_t *def, size_t size, BUFF_t buff, bool base64_encode)
2207{
2208 return nyx_dict_set(def, "$", nyx_string_from_buff(size, buff, base64_encode));
2209}
2210
2211/*--------------------------------------------------------------------------------------------------------------------*/
2212
2213__INLINE__ void nyx_blob_def_get(const nyx_dict_t *def, size_t *size, buff_t *buff, bool base64_decode)
2214{
2215 nyx_string_get_buff((nyx_string_t *) nyx_dict_get(def, "$"), size, buff, base64_decode);
2216}
2217
2218/*--------------------------------------------------------------------------------------------------------------------*/
2219
2232 STR_t device,
2233 STR_t name,
2234 nyx_state_t state,
2235 nyx_perm_t perm,
2236 nyx_dict_t *defs[],
2237 __NULLABLE__ const nyx_opts_t *opts
2238);
2239
2240/*--------------------------------------------------------------------------------------------------------------------*/
2241
2246nyx_dict_t *nyx_blob_set_vector_new(
2247 const nyx_dict_t *def_vector
2248);
2249
2250/*--------------------------------------------------------------------------------------------------------------------*/
2256/*--------------------------------------------------------------------------------------------------------------------*/
2257
2266 STR_t name,
2267 __NULLABLE__ STR_t label
2268);
2269
2270/*--------------------------------------------------------------------------------------------------------------------*/
2271
2283 STR_t device,
2284 STR_t name,
2285 nyx_state_t state,
2286 nyx_dict_t *defs[],
2287 __NULLABLE__ const nyx_opts_t *opts
2288);
2289
2290/*--------------------------------------------------------------------------------------------------------------------*/
2291
2296nyx_dict_t *nyx_stream_set_vector_new(
2297 const nyx_dict_t *def_vector
2298);
2299
2300/*--------------------------------------------------------------------------------------------------------------------*/
2306/*--------------------------------------------------------------------------------------------------------------------*/
2307
2316 STR_t device,
2317 STR_t message
2318);
2319
2320/*--------------------------------------------------------------------------------------------------------------------*/
2326/*--------------------------------------------------------------------------------------------------------------------*/
2327
2328nyx_dict_t *nyx_del_property_new(
2329 STR_t device,
2330 __NULLABLE__ STR_t name,
2331 __NULLABLE__ STR_t message
2332);
2333
2334/*--------------------------------------------------------------------------------------------------------------------*/
2335/* NODE */
2336/*--------------------------------------------------------------------------------------------------------------------*/
2342/*--------------------------------------------------------------------------------------------------------------------*/
2343
2349typedef struct nyx_node_s nyx_node_t;
2350
2351/*--------------------------------------------------------------------------------------------------------------------*/
2352
2357typedef enum
2358{
2361
2362} nyx_event_t;
2363
2364/*--------------------------------------------------------------------------------------------------------------------*/
2365
2377typedef void (* nyx_mqtt_handler_t)(
2378 nyx_node_t *node,
2379 nyx_event_t event,
2380 size_t topic_size,
2381 BUFF_t topic_buff,
2382 size_t message_size,
2383 BUFF_t message_buff
2384);
2385
2386/*--------------------------------------------------------------------------------------------------------------------*/
2387
2409 STR_t node_id,
2410 nyx_dict_t *def_vectors[],
2411
2412 __NULLABLE__ STR_t indi_url,
2413
2414 __NULLABLE__ STR_t mqtt_url,
2415 __NULLABLE__ STR_t mqtt_username,
2416 __NULLABLE__ STR_t mqtt_password,
2417
2418 __NULLABLE__ nyx_mqtt_handler_t mqtt_handler,
2419
2420 __NULLABLE__ STR_t redis_url,
2421 __NULLABLE__ STR_t redis_username,
2422 __NULLABLE__ STR_t redis_password,
2423
2424 int retry_ms,
2425 bool enable_xml,
2426 bool validate_xml
2427);
2428
2429/*--------------------------------------------------------------------------------------------------------------------*/
2430
2440 nyx_node_t *node,
2441 bool free_vectors
2442);
2443
2444/*--------------------------------------------------------------------------------------------------------------------*/
2445
2455 nyx_node_t *node,
2456 int timeout_ms
2457);
2458
2459/*--------------------------------------------------------------------------------------------------------------------*/
2460
2472 nyx_node_t *node,
2473 /*--------*/ STR_t device,
2474 __NULLABLE__ STR_t name,
2475 __NULLABLE__ STR_t message
2476);
2477
2478/*--------------------------------------------------------------------------------------------------------------------*/
2479
2491 nyx_node_t *node,
2492 /*--------*/ STR_t device,
2493 __NULLABLE__ STR_t name,
2494 __NULLABLE__ STR_t message
2495);
2496
2497/*--------------------------------------------------------------------------------------------------------------------*/
2498
2509 nyx_node_t *node,
2510 STR_t device,
2511 STR_t message
2512);
2513
2514/*--------------------------------------------------------------------------------------------------------------------*/
2515
2525 nyx_node_t *node,
2526 STR_t topic
2527);
2528
2529/*--------------------------------------------------------------------------------------------------------------------*/
2530
2542 nyx_node_t *node,
2543 STR_t topic,
2544 __ZEROABLE__ size_t message_size,
2545 __NULLABLE__ BUFF_t message_buff
2546);
2547
2548/*--------------------------------------------------------------------------------------------------------------------*/
2549
2568 nyx_node_t *node,
2569 STR_t device,
2570 STR_t stream,
2571 bool check,
2572 size_t max_len,
2573 __ZEROABLE__ size_t n_fields,
2574 const str_t field_names[],
2575 const size_t field_sizes[],
2576 const buff_t field_buffs[]
2577);
2578
2579/*--------------------------------------------------------------------------------------------------------------------*/
2581/*--------------------------------------------------------------------------------------------------------------------*/
2582
2583#ifndef ARDUINO
2584# pragma clang diagnostic pop
2585#endif
2586
2587/*--------------------------------------------------------------------------------------------------------------------*/
2588
2589#ifdef __cplusplus
2590}
2591#endif
2592
2593/*--------------------------------------------------------------------------------------------------------------------*/
2594
2595#endif /* NYX_NODE_H */
2596
2597/*--------------------------------------------------------------------------------------------------------------------*/
void nyx_boolean_free(nyx_boolean_t *object)
Frees memory of the provided JSON boolean object.
bool nyx_boolean_get(const nyx_boolean_t *object)
Get the value of the provided JSON boolean object.
nyx_boolean_t * nyx_boolean_new()
Allocates a new JSON boolean object.
__INLINE__ nyx_boolean_t * nyx_boolean_from(bool value)
Returns a JSON boolean object holding the value of the provided argument.
Definition nyx_node.h:728
__INLINE__ bool nyx_boolean_set(nyx_boolean_t *object, bool value)
Set the value of the provided JSON boolean object.
Definition nyx_node.h:699
str_t nyx_boolean_to_string(const nyx_boolean_t *object)
Returns a string representing the provided JSON boolean object.
__INLINE__ double nyx_dict_get_number(const nyx_dict_t *object, STR_t key)
Definition nyx_node.h:1203
size_t nyx_dict_size(const nyx_dict_t *object)
Gets the number of items in the provided JSON dict object.
bool nyx_dict_iterate(nyx_dict_iter_t *iter, STR_t *key, nyx_object_t **object)
str_t nyx_dict_to_string(const nyx_dict_t *object)
Returns a string representing the provided JSON dict object.
nyx_dict_t * nyx_dict_new()
Allocates a new JSON dict object.
nyx_object_t * nyx_dict_get(const nyx_dict_t *object, STR_t key)
void nyx_dict_del(nyx_dict_t *object, STR_t key)
void nyx_dict_clear(nyx_dict_t *object)
Clears the content of the provided JSON dict object.
__INLINE__ bool nyx_dict_set(nyx_dict_t *object, STR_t key, buff_t value)
Definition nyx_node.h:1159
void nyx_dict_free(nyx_dict_t *object)
Frees memory of the provided JSON dict object.
__INLINE__ STR_t nyx_dict_get_string(const nyx_dict_t *object, STR_t key)
Definition nyx_node.h:1223
__INLINE__ STR_t nyx_list_get_string(const nyx_list_t *object, int idx)
Definition nyx_node.h:1444
bool nyx_list_iterate(nyx_list_iter_t *iter, int *idx, nyx_object_t **object)
nyx_object_t * nyx_list_get(const nyx_list_t *object, int idx)
str_t nyx_list_to_string(const nyx_list_t *object)
Returns a string representing the provided JSON list object.
void nyx_list_del(nyx_list_t *object, int idx)
__INLINE__ double nyx_list_get_number(const nyx_list_t *object, int idx)
Definition nyx_node.h:1424
void nyx_list_free(nyx_list_t *object)
Frees memory of the provided JSON list object.
size_t nyx_list_size(const nyx_list_t *object)
Gets the number of items in the provided JSON list object.
__INLINE__ bool nyx_list_push(nyx_list_t *object, buff_t value)
Definition nyx_node.h:1380
nyx_list_t * nyx_list_new()
Allocates a new JSON list.
void nyx_list_clear(nyx_list_t *object)
Clears the content of the provided JSON list object.
nyx_log_level_e
Nyx log levels.
Definition nyx_node.h:126
void nyx_set_log_level(nyx_log_level_t level)
Sets the log level threshold.
enum nyx_log_level_e nyx_log_level_t
Nyx log levels.
void nyx_memory_initialize()
Initialize the memory subsystem.
bool nyx_memory_finalize()
Finalize the memory subsystem.
__NULLABLE__ buff_t nyx_memory_realloc(__NULLABLE__ buff_t buff, __ZEROABLE__ size_t size)
Similar to libc realloc except that a memory overflow causes the node to stop.
__NULLABLE__ buff_t nyx_memory_alloc(__ZEROABLE__ size_t size)
Similar to libc malloc except that a memory overflow causes the node to stop.
__ZEROABLE__ size_t nyx_memory_free(__NULLABLE__ buff_t buff)
Similar to libc free except that it returns the amount of memory freed.
void(* nyx_mqtt_handler_t)(nyx_node_t *node, nyx_event_t event, size_t topic_size, BUFF_t topic_buff, size_t message_size, BUFF_t message_buff)
MQTT event handler.
Definition nyx_node.h:2377
void nyx_node_poll(nyx_node_t *node, int timeout_ms)
Performs a single poll iteration.
void nyx_mqtt_sub(nyx_node_t *node, STR_t topic)
If MQTT is enabled, subscribes to a topic.
bool nyx_stream_pub(nyx_node_t *node, STR_t device, STR_t stream, bool check, size_t max_len, __ZEROABLE__ size_t n_fields, const str_t field_names[], const size_t field_sizes[], const buff_t field_buffs[])
If Redis is enabled, publishes an entry to a stream, see https://redis.io/commands/xadd/.
nyx_event_t
Nyx TCP or MQTT event type.
Definition nyx_node.h:2358
void nyx_node_send_message(nyx_node_t *node, STR_t device, STR_t message)
Sends a message to the clients.
void nyx_node_enable(nyx_node_t *node, STR_t device, __NULLABLE__ STR_t name, __NULLABLE__ STR_t message)
Enables a whole device or a definition vector.
void nyx_node_disable(nyx_node_t *node, STR_t device, __NULLABLE__ STR_t name, __NULLABLE__ STR_t message)
Disables a whole device or a definition vector.
void nyx_mqtt_pub(nyx_node_t *node, STR_t topic, __ZEROABLE__ size_t message_size, __NULLABLE__ BUFF_t message_buff)
If MQTT is enabled, publishes a message to a topic.
nyx_node_t * nyx_node_initialize(STR_t node_id, nyx_dict_t *def_vectors[], __NULLABLE__ STR_t indi_url, __NULLABLE__ STR_t mqtt_url, __NULLABLE__ STR_t mqtt_username, __NULLABLE__ STR_t mqtt_password, __NULLABLE__ nyx_mqtt_handler_t mqtt_handler, __NULLABLE__ STR_t redis_url, __NULLABLE__ STR_t redis_username, __NULLABLE__ STR_t redis_password, int retry_ms, bool enable_xml, bool validate_xml)
Initializes the Nyx node.
void nyx_node_finalize(nyx_node_t *node, bool free_vectors)
Finalizes the Nyx node.
@ NYX_EVENT_OPEN
A connection is opened.
Definition nyx_node.h:2359
@ NYX_EVENT_MSG
A message is received.
Definition nyx_node.h:2360
str_t nyx_null_to_string(const nyx_null_t *object)
Returns a string representing the provided JSON null object.
nyx_null_t * nyx_null_new()
Allocates a new JSON null object.
void nyx_null_free(nyx_null_t *object)
Frees memory of the provided JSON null object.
double nyx_number_get(const nyx_number_t *object)
Get the value of the provided JSON number object.
nyx_number_t * nyx_number_new()
Allocates a new JSON number object.
str_t nyx_number_to_string(const nyx_number_t *object)
Returns a string representing the provided JSON number object.
__INLINE__ nyx_number_t * nyx_number_from(double value)
Returns a JSON number object holding the value of the provided argument.
Definition nyx_node.h:609
void nyx_number_free(nyx_number_t *object)
Frees memory of the provided JSON number object.
__INLINE__ bool nyx_number_set(nyx_number_t *object, double value)
Set the value of the provided JSON number object.
Definition nyx_node.h:580
nyx_dict_t * nyx_blob_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx BLOB vector.
nyx_dict_t * nyx_blob_def_new(STR_t name, __NULLABLE__ STR_t label, STR_t value, STR_t format)
Allocates a new INDI / Nyx BLOB.
nyx_dict_t * nyx_light_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx light vector.
nyx_dict_t * nyx_light_def_new(STR_t name, __NULLABLE__ STR_t label, nyx_state_t value)
Allocates a new INDI / Nyx light.
nyx_dict_t * nyx_message_new(STR_t device, STR_t message)
Allocates a new INDI / Nyx message.
nyx_dict_t * nyx_number_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx number vector.
nyx_dict_t * nyx_number_def_new(STR_t name, __NULLABLE__ STR_t label, STR_t format, double min, double max, double step, double value)
Allocates a new INDI / Nyx number.
nyx_dict_t * nyx_stream_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new Nyx stream vector.
nyx_dict_t * nyx_stream_def_new(STR_t name, __NULLABLE__ STR_t label)
Allocates a new INDI / Nyx Stream.
nyx_dict_t * nyx_switch_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_rule_t rule, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx switch vector.
nyx_dict_t * nyx_switch_def_new(STR_t name, __NULLABLE__ STR_t label, nyx_onoff_t value)
Allocates a new INDI / Nyx switch.
nyx_dict_t * nyx_text_def_new(STR_t name, __NULLABLE__ STR_t label, STR_t value)
Allocates a new INDI / Nyx text.
nyx_dict_t * nyx_text_def_vector_new(STR_t device, STR_t name, nyx_state_t state, nyx_perm_t perm, nyx_dict_t *defs[], __NULLABLE__ const nyx_opts_t *opts)
Allocates a new INDI / Nyx text vector.
str_t nyx_object_to_string(__NULLABLE__ const nyx_object_t *object)
Returns a string representing the provided object.
__NULLABLE__ nyx_object_t * nyx_object_parse(__NULLABLE__ STR_t text)
Parses a JSON object from a string.
bool nyx_object_equal(__NULLABLE__ const nyx_object_t *object1, __NULLABLE__ const nyx_object_t *object2)
Compares two JSON objects.
nyx_type_t
JSON object types.
Definition nyx_node.h:322
void nyx_object_free(__NULLABLE__ nyx_object_t *object)
Frees memory of the provided JSON object.
str_t nyx_object_to_cstring(__NULLABLE__ const nyx_object_t *object)
Returns a C/C++ string representing the provided object.
nyx_object_t * nyx_object_parse_buff(__ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff)
Parses a JSON object from a string buffer.
@ NYX_TYPE_DICT
Dict object.
Definition nyx_node.h:327
@ NYX_TYPE_LIST
List object.
Definition nyx_node.h:328
@ NYX_TYPE_BOOLEAN
Boolean object.
Definition nyx_node.h:324
@ NYX_TYPE_NUMBER
Number object.
Definition nyx_node.h:325
@ NYX_TYPE_NULL
Null object.
Definition nyx_node.h:323
@ NYX_TYPE_STRING
String object.
Definition nyx_node.h:326
__INLINE__ nyx_string_t * nyx_string_from_dup(STR_t value)
Returns a JSON string object holding the value of the provided argument (string duplication).
Definition nyx_node.h:947
nyx_string_t * nyx_string_new()
Allocates a new JSON string object.
__INLINE__ nyx_string_t * nyx_string_from_ref(STR_t value)
Returns a JSON string object holding the value of the provided argument (string reference).
Definition nyx_node.h:966
size_t nyx_string_length(const nyx_string_t *object)
Returns the length of the string representing the provided JSON string object.
str_t nyx_string_to_string(const nyx_string_t *object)
Returns a string representing the provided JSON string object.
__INLINE__ bool nyx_string_set_ref(nyx_string_t *object, STR_t value)
Set the value of the provided JSON string object (string reference).
Definition nyx_node.h:860
str_t nyx_string_to_cstring(const nyx_string_t *object)
Returns a C/C++ string representing the provided JSON string object.
__INLINE__ bool nyx_string_set_buff(nyx_string_t *object, size_t size, BUFF_t buff, bool base64_encode)
Set the value of the provided JSON string object (buffer reference or base64 encoding).
Definition nyx_node.h:890
__INLINE__ bool nyx_string_set_dup(nyx_string_t *object, STR_t value)
Set the value of the provided JSON string object (string duplication).
Definition nyx_node.h:834
#define nyx_string_from
Alias to nyx_string_from_dup.
Definition nyx_node.h:1008
STR_t nyx_string_get(const nyx_string_t *object)
Get the value of the provided JSON string object.
__INLINE__ nyx_string_t * nyx_string_from_buff(size_t size, BUFF_t buff, bool base64_encode)
Returns a JSON string object holding the value of the provided argument (buffer reference or base64 e...
Definition nyx_node.h:987
void nyx_string_free(nyx_string_t *object)
Frees memory of the provided JSON string object.
__NULLABLE__ nyx_object_t * nyx_xmldoc_to_object(__NULLABLE__ const nyx_xmldoc_t *xmldoc, bool validate)
Convert an XML Nyx / INDI command to the JSON one.
__NULLABLE__ nyx_xmldoc_t * nyx_object_to_xmldoc(__NULLABLE__ const nyx_object_t *object, bool validate)
Convert an JSON Nyx / INDI command to the XML one.
__NULLABLE__ str_t nyx_base64_encode(__NULLABLE__ size_t *result_len, __ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff)
Encodes a buffer to a Base64-encoded string.
__NULLABLE__ buff_t nyx_base64_decode(__NULLABLE__ size_t *result_size, __ZEROABLE__ size_t len, __NULLABLE__ STR_t str)
Decodes a Base64-encoded string to a buffer.
uint32_t nyx_hash32(__ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff, uint32_t seed)
Hashes a buffer using the MurmurHash2 algorithm.
void nyx_generate_mac_addr(uint8_t result_mac[6], uint8_t mac0, uint8_t mac1, STR_t node_id)
Generates a MAC address based on a node identifier.
bool nyx_validation_check(__NULLABLE__ const nyx_xmldoc_t *xmldoc)
Validate the provided XML command using the XSD schema extended with INDI and Nyx additions.
bool nyx_validation_finalize()
Initialize the XML validation subsystem.
bool nyx_validation_initialize()
Initialize the XML validation subsystem.
nyx_xml_type_t
XML node types.
Definition nyx_node.h:1468
str_t nyx_xmldoc_to_string(const nyx_xmldoc_t *xmldoc)
Returns a string representing the provided XML document.
void nyx_xmldoc_free(__NULLABLE__ nyx_xmldoc_t *xmldoc)
Frees memory of the provided XML document.
nyx_xmldoc_t * nyx_xmldoc_parse_buff(__ZEROABLE__ size_t size, __NULLABLE__ BUFF_t buff)
Parses an XML document from a string buffer.
nyx_xmldoc_t * nyx_xmldoc_parse(__NULLABLE__ STR_t text)
Parses an XML document from a string.
@ NYX_XML_CDATA
CDATA content.
Definition nyx_node.h:1472
@ NYX_XML_ELEM
Element node.
Definition nyx_node.h:1469
@ NYX_XML_COMMENT
Comment node.
Definition nyx_node.h:1471
@ NYX_XML_TEXT
Text content.
Definition nyx_node.h:1473
@ NYX_XML_ATTR
Attribute node.
Definition nyx_node.h:1470
Struct describing a JSON boolean.
Definition nyx_node.h:633
bool value
???
Definition nyx_node.h:636
nyx_object_t base
???
Definition nyx_node.h:634
Definition nyx_node.h:1036
nyx_type_t type
???
Definition nyx_node.h:1039
struct nyx_dict_node_s * head
???
Definition nyx_node.h:1041
int idx
???
Definition nyx_node.h:1037
Struct describing a JSON dict.
Definition nyx_node.h:1025
struct nyx_dict_node_s * tail
???
Definition nyx_node.h:1029
struct nyx_dict_node_s * head
???
Definition nyx_node.h:1028
nyx_object_t base
???
Definition nyx_node.h:1026
Definition nyx_node.h:1258
int idx
???
Definition nyx_node.h:1259
struct nyx_list_node_s * head
???
Definition nyx_node.h:1263
nyx_type_t type
???
Definition nyx_node.h:1261
Struct describing a JSON list.
Definition nyx_node.h:1247
nyx_object_t base
???
Definition nyx_node.h:1248
struct nyx_list_node_s * head
???
Definition nyx_node.h:1250
struct nyx_list_node_s * tail
???
Definition nyx_node.h:1251
Opaque struct describing a Nyx node.
Struct describing a JSON null value.
Definition nyx_node.h:460
nyx_object_t base
???
Definition nyx_node.h:461
Struct describing a JSON number.
Definition nyx_node.h:514
double value
???
Definition nyx_node.h:517
nyx_object_t base
???
Definition nyx_node.h:515
Definition nyx_node.h:339
uint32_t magic
Magic number, must always be NYX_OBJECT_MAGIC.
Definition nyx_node.h:340
__NULLABLE__ void(* in_callback)(struct nyx_object_s *object, bool modified)
Callback triggered when a client modifies this object.
Definition nyx_node.h:349
__NULLABLE__ struct nyx_object_s * parent
Pointer to the parent object.
Definition nyx_node.h:347
nyx_type_t type
Type of object, see nyx_type_t.
Definition nyx_node.h:343
uint64_t flags
Mask of flags, see NYX_FLAGS_XXX definitions.
Definition nyx_node.h:341
__NULLABLE__ struct nyx_node_s * node
Pointer to the associated Nyx node.
Definition nyx_node.h:345
__NULLABLE__ void(* out_callback)(struct nyx_object_s *object, bool modified)
Callback triggered when the server modifies this object.
Definition nyx_node.h:353
Definition nyx_node.h:1780
Struct describing a JSON string.
Definition nyx_node.h:752
bool dyn
???
Definition nyx_node.h:758
str_t value
???
Definition nyx_node.h:756
nyx_object_t base
???
Definition nyx_node.h:753
size_t length
???
Definition nyx_node.h:755
Definition nyx_node.h:1484