1 // Copyright 2011 Juri Glass, Mathias Runge, Nadim El Sayed
2 // DAI-Labor, TU-Berlin
3 //
4 // This file is part of libSML.
5 //
6 // libSML is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // libSML is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libSML.  If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef SML_TREE_H_
20 #define	SML_TREE_H_
21 
22 #include "sml_shared.h"
23 #include "sml_octet_string.h"
24 #include "sml_value.h"
25 #include "sml_time.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #define SML_PROC_PAR_VALUE_TAG_VALUE 		0x01
32 #define SML_PROC_PAR_VALUE_TAG_PERIOD_ENTRY 	0x02
33 #define SML_PROC_PAR_VALUE_TAG_TUPEL_ENTRY 	0x03
34 #define SML_PROC_PAR_VALUE_TAG_TIME		0x04
35 
36 // what a messy tupel ...
37 typedef struct {
38 	octet_string *server_id;
39 	sml_time *sec_index;
40 	u64 *status;
41 
42 	sml_unit *unit_pA;
43 	i8 *scaler_pA;
44 	i64 *value_pA;
45 
46 	sml_unit *unit_R1;
47 	i8 *scaler_R1;
48 	i64 *value_R1;
49 
50 	sml_unit *unit_R4;
51 	i8 *scaler_R4;
52 	i64 *value_R4;
53 
54 	octet_string *signature_pA_R1_R4;
55 
56 	sml_unit *unit_mA;
57 	i8 *scaler_mA;
58 	i64 *value_mA;
59 
60 	sml_unit *unit_R2;
61 	i8 *scaler_R2;
62 	i64 *value_R2;
63 
64 	sml_unit *unit_R3;
65 	i8 *scaler_R3;
66 	i64 *value_R3;
67 
68 	octet_string *signature_mA_R2_R3;
69 } sml_tupel_entry;
70 
71 typedef struct {
72 	octet_string *obj_name;
73 	sml_unit *unit;
74 	i8 *scaler;
75 	sml_value *value;
76 	octet_string *value_signature;
77 } sml_period_entry;
78 
79 typedef struct {
80 	u8 *tag;
81 	union {
82 		sml_value *value;
83 		sml_period_entry *period_entry;
84 		sml_tupel_entry *tupel_entry;
85 		sml_time *time;
86 	} data;
87 } sml_proc_par_value;
88 
89 typedef struct s_tree{
90 	octet_string *parameter_name;
91 	sml_proc_par_value *parameter_value; // optional
92 	struct s_tree **child_list; // optional
93 
94 	int child_list_len;
95 } sml_tree;
96 
97 typedef struct {
98 	int path_entries_len;
99 	octet_string **path_entries;
100 } sml_tree_path;
101 
102 // sml_tree;
103 sml_tree *sml_tree_init();
104 sml_tree *sml_tree_parse(sml_buffer *buf);
105 void sml_tree_add_tree(sml_tree *base_tree, sml_tree *tree);
106 void sml_tree_write(sml_tree *tree, sml_buffer *buf);
107 void sml_tree_free(sml_tree *tree);
108 
109 // sml_tree_path;
110 sml_tree_path *sml_tree_path_init();
111 sml_tree_path *sml_tree_path_parse(sml_buffer *buf);
112 void sml_tree_path_add_path_entry(sml_tree_path *tree_path, octet_string *entry);
113 void sml_tree_path_write(sml_tree_path *tree_path, sml_buffer *buf);
114 void sml_tree_path_free(sml_tree_path *tree_path);
115 
116 // sml_proc_par_value;
117 sml_proc_par_value *sml_proc_par_value_init();
118 sml_proc_par_value *sml_proc_par_value_parse(sml_buffer *buf);
119 void sml_proc_par_value_write(sml_proc_par_value *value, sml_buffer *buf);
120 void sml_proc_par_value_free(sml_proc_par_value *value);
121 
122 // sml_tupel_entry;
123 sml_tupel_entry *sml_tupel_entry_init();
124 sml_tupel_entry *sml_tupel_entry_parse(sml_buffer *buf);
125 void sml_tupel_entry_write(sml_tupel_entry *tupel, sml_buffer *buf);
126 void sml_tupel_entry_free(sml_tupel_entry *tupel);
127 
128 // sml_period_entry;
129 sml_period_entry *sml_period_entry_init();
130 sml_period_entry *sml_period_entry_parse(sml_buffer *buf);
131 void sml_period_entry_write(sml_period_entry *period, sml_buffer *buf);
132 void sml_period_entry_free(sml_period_entry *period);
133 
134 #ifdef __cplusplus
135 }
136 #endif
137 
138 
139 #endif /* SML_TREE_H_ */
140 
141