Initial VES for DANOS vRouter
[demo.git] / vnfs / VESreporting_vFW5.0_DANOS / evel / evel-library / code / evel_library / evel_option.c
1 /*************************************************************************//**
2  *
3  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
4  *
5  * Unless otherwise specified, all software contained herein is
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and 
15  * limitations under the License.
16  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
17  ****************************************************************************/
18 /**************************************************************************//**
19  * @file
20  * Source module relating to EVEL_OPTION_ types.
21  *
22  ****************************************************************************/
23
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "evel_internal.h"
29
30 /**************************************************************************//**
31  * Free the underlying resources of an ::EVEL_OPTION_STRING.
32  *
33  * @param option        Pointer to the ::EVEL_OPTION_STRING.
34  *****************************************************************************/
35 void evel_free_option_string(EVEL_OPTION_STRING * const option)
36 {
37   EVEL_ENTER();
38
39   /***************************************************************************/
40   /* Check preconditions.                                                    */
41   /***************************************************************************/
42   assert(option != NULL);
43
44   if (option->is_set)
45   {
46     free(option->value);
47     option->value = NULL;
48     option->is_set = EVEL_FALSE;
49   }
50
51   EVEL_EXIT();
52 }
53
54 /**************************************************************************//**
55  * Initialize an ::EVEL_OPTION_STRING to a not-set state.
56  *
57  * @param option        Pointer to the ::EVEL_OPTION_STRING.
58  *****************************************************************************/
59 void evel_init_option_string(EVEL_OPTION_STRING * const option)
60 {
61   EVEL_ENTER();
62
63   /***************************************************************************/
64   /* Check preconditions.                                                    */
65   /***************************************************************************/
66   assert(option != NULL);
67
68   option->value = NULL;
69   option->is_set = EVEL_FALSE;
70
71   EVEL_EXIT();
72 }
73
74 /**************************************************************************//**
75  * Set the value of an ::EVEL_OPTION_STRING.
76  *
77  * @param option        Pointer to the ::EVEL_OPTION_STRING.
78  * @param value         The value to set.
79  * @param description   Description to be used in logging.
80  *****************************************************************************/
81 void evel_set_option_string(EVEL_OPTION_STRING * const option,
82                             const char * const value,
83                             const char * const description)
84 {
85   EVEL_ENTER();
86
87   /***************************************************************************/
88   /* Check preconditions.                                                    */
89   /***************************************************************************/
90   assert(option != NULL);
91   assert(value != NULL);
92   assert(description != NULL);
93
94   if (option->is_set)
95   {
96     EVEL_ERROR("Ignoring attempt to update %s to %s. %s already set to %s",
97                description, value, description, option->value);
98   }
99   else
100   {
101     EVEL_DEBUG("Setting %s to %s", description, value);
102     option->value = strdup(value);
103     option->is_set = EVEL_TRUE;
104   }
105
106   EVEL_EXIT();
107 }
108
109 /**************************************************************************//**
110  * Force the value of an ::EVEL_OPTION_STRING.
111  *
112  * @param option        Pointer to the ::EVEL_OPTION_STRING.
113  * @param value         The value to set.
114  *****************************************************************************/
115 void evel_force_option_string(EVEL_OPTION_STRING * const option,
116                               const char * const value)
117 {
118   EVEL_ENTER();
119
120   /***************************************************************************/
121   /* Check preconditions.                                                    */
122   /***************************************************************************/
123   assert(option != NULL);
124   assert(option->is_set == EVEL_FALSE);
125   assert(option->value == NULL);
126
127   option->value = strdup(value);
128   option->is_set = EVEL_TRUE;
129
130   EVEL_EXIT();
131 }
132
133 /**************************************************************************//**
134  * Initialize an ::EVEL_OPTION_INT to a not-set state.
135  *
136  * @param option        Pointer to the ::EVEL_OPTION_INT.
137  *****************************************************************************/
138 void evel_init_option_int(EVEL_OPTION_INT * const option)
139 {
140   EVEL_ENTER();
141
142   /***************************************************************************/
143   /* Check preconditions.                                                    */
144   /***************************************************************************/
145   assert(option != NULL);
146
147   option->value = 0;
148   option->is_set = EVEL_FALSE;
149
150   EVEL_EXIT();
151 }
152
153 /**************************************************************************//**
154  * Force the value of an ::EVEL_OPTION_INT.
155  *
156  * @param option        Pointer to the ::EVEL_OPTION_INT.
157  * @param value         The value to set.
158  *****************************************************************************/
159 void evel_force_option_int(EVEL_OPTION_INT * const option,
160                            const int value)
161 {
162   EVEL_ENTER();
163
164   /***************************************************************************/
165   /* Check preconditions.                                                    */
166   /***************************************************************************/
167   assert(option != NULL);
168
169   option->value = value;
170   option->is_set = EVEL_TRUE;
171
172   EVEL_EXIT();
173 }
174
175 /**************************************************************************//**
176  * Set the value of an ::EVEL_OPTION_INT.
177  *
178  * @param option        Pointer to the ::EVEL_OPTION_INT.
179  * @param value         The value to set.
180  * @param description   Description to be used in logging.
181  *****************************************************************************/
182 void evel_set_option_int(EVEL_OPTION_INT * const option,
183                          const int value,
184                          const char * const description)
185 {
186   EVEL_ENTER();
187
188   /***************************************************************************/
189   /* Check preconditions.                                                    */
190   /***************************************************************************/
191   assert(option != NULL);
192   assert(description != NULL);
193
194   if (option->is_set)
195   {
196     EVEL_ERROR("Ignoring attempt to update %s to %d. %s already set to %d",
197                description, value, description, option->value);
198   }
199   else
200   {
201     EVEL_DEBUG("Setting %s to %d", description, value);
202     option->value = value;
203     option->is_set = EVEL_TRUE;
204   }
205
206   EVEL_EXIT();
207 }
208
209 /**************************************************************************//**
210  * Initialize an ::EVEL_OPTION_DOUBLE to a not-set state.
211  *
212  * @param option        Pointer to the ::EVEL_OPTION_DOUBLE.
213  *****************************************************************************/
214 void evel_init_option_double(EVEL_OPTION_DOUBLE * const option)
215 {
216   EVEL_ENTER();
217
218   /***************************************************************************/
219   /* Check preconditions.                                                    */
220   /***************************************************************************/
221   assert(option != NULL);
222
223   option->value = 0.0;
224   option->is_set = EVEL_FALSE;
225
226   EVEL_EXIT();
227 }
228
229 /**************************************************************************//**
230  * Force the value of an ::EVEL_OPTION_DOUBLE.
231  *
232  * @param option        Pointer to the ::EVEL_OPTION_DOUBLE.
233  * @param value         The value to set.
234  *****************************************************************************/
235 void evel_force_option_double(EVEL_OPTION_DOUBLE * const option,
236                               const double value)
237 {
238   EVEL_ENTER();
239
240   /***************************************************************************/
241   /* Check preconditions.                                                    */
242   /***************************************************************************/
243   assert(option != NULL);
244
245   option->value = value;
246   option->is_set = EVEL_TRUE;
247
248   EVEL_EXIT();
249 }
250
251 /**************************************************************************//**
252  * Set the value of an ::EVEL_OPTION_DOUBLE.
253  *
254  * @param option        Pointer to the ::EVEL_OPTION_DOUBLE.
255  * @param value         The value to set.
256  * @param description   Description to be used in logging.
257  *****************************************************************************/
258 void evel_set_option_double(EVEL_OPTION_DOUBLE * const option,
259                             const double value,
260                             const char * const description)
261 {
262   EVEL_ENTER();
263
264   /***************************************************************************/
265   /* Check preconditions.                                                    */
266   /***************************************************************************/
267   assert(option != NULL);
268   assert(description != NULL);
269
270   if (option->is_set)
271   {
272     EVEL_ERROR("Ignoring attempt to update %s to %lf. %s already set to %lf",
273                description, value, description, option->value);
274   }
275   else
276   {
277     EVEL_DEBUG("Setting %s to %lf", description, value);
278     option->value = value;
279     option->is_set = EVEL_TRUE;
280   }
281
282   EVEL_EXIT();
283 }
284
285 /**************************************************************************//**
286  * Initialize an ::EVEL_OPTION_ULL to a not-set state.
287  *
288  * @param option        Pointer to the ::EVEL_OPTION_ULL.
289  *****************************************************************************/
290 void evel_init_option_ull(EVEL_OPTION_ULL * const option)
291 {
292   EVEL_ENTER();
293
294   /***************************************************************************/
295   /* Check preconditions.                                                    */
296   /***************************************************************************/
297   assert(option != NULL);
298   option->value = 0;
299   option->is_set = EVEL_FALSE;
300   EVEL_EXIT();
301 }
302
303 /**************************************************************************//**
304  * Force the value of an ::EVEL_OPTION_ULL.
305  *
306  * @param option        Pointer to the ::EVEL_OPTION_ULL.
307  * @param value         The value to set.
308  *****************************************************************************/
309 void evel_force_option_ull(EVEL_OPTION_ULL * const option,
310                            const unsigned long long value)
311 {
312   EVEL_ENTER();
313
314   /***************************************************************************/
315   /* Check preconditions.                                                    */
316   /***************************************************************************/
317   assert(option != NULL);
318
319   option->value = value;
320   option->is_set = EVEL_TRUE;
321
322   EVEL_EXIT();
323 }
324
325 /**************************************************************************//**
326  * Set the value of an ::EVEL_OPTION_ULL.
327  *
328  * @param option        Pointer to the ::EVEL_OPTION_ULL.
329  * @param value         The value to set.
330  * @param description   Description to be used in logging.
331  *****************************************************************************/
332 void evel_set_option_ull(EVEL_OPTION_ULL * const option,
333                          const unsigned long long value,
334                          const char * const description)
335 {
336   EVEL_ENTER();
337
338   /***************************************************************************/
339   /* Check preconditions.                                                    */
340   /***************************************************************************/
341   assert(option != NULL);
342   assert(description != NULL);
343
344   if (option->is_set)
345   {
346     EVEL_ERROR("Ignoring attempt to update %s to %llu. %s already set to %llu",
347                description, value, description, option->value);
348   }
349   else
350   {
351     EVEL_DEBUG("Setting %s to %llu", description, value);
352     option->value = value;
353     option->is_set = EVEL_TRUE;
354   }
355   EVEL_EXIT();
356 }
357
358
359 /**************************************************************************//**
360  * Initialize an ::EVEL_OPTION_INTHEADER_FIELDS to a not-set state.
361  *
362  * @param option        Pointer to the ::EVEL_OPTION_INTHEADER_FIELDS.
363  *****************************************************************************/
364 void evel_init_option_intheader(EVEL_OPTION_INTHEADER_FIELDS * const option)
365 {
366   EVEL_ENTER();
367
368   /***************************************************************************/
369   /* Check preconditions.                                                    */
370   /***************************************************************************/
371   assert(option != NULL);
372   option->object = NULL;
373   option->is_set = EVEL_FALSE;
374   EVEL_EXIT();
375 }
376
377 /**************************************************************************//**
378  * Force the value of an ::EVEL_OPTION_INTHEADER_FIELDS.
379  *
380  * @param option        Pointer to the ::EVEL_OPTION_INTHEADER_FIELDS.
381  * @param value         The value to set.
382  *****************************************************************************/
383 void evel_force_option_intheader(EVEL_OPTION_INTHEADER_FIELDS * const option,
384                            const void* value)
385 {
386   EVEL_ENTER();
387
388   /***************************************************************************/
389   /* Check preconditions.                                                    */
390   /***************************************************************************/
391   assert(option != NULL);
392
393   option->object = value;
394   option->is_set = EVEL_TRUE;
395
396   EVEL_EXIT();
397 }
398
399 /**************************************************************************//**
400  * Set the value of an ::EVEL_OPTION_INTHEADER_FIELDS.
401  *
402  * @param option        Pointer to the ::EVEL_OPTION_INTHEADER_FIELDS.
403  * @param value         The value to set.
404  * @param description   Description to be used in logging.
405  *****************************************************************************/
406 void evel_set_option_intheader(EVEL_OPTION_INTHEADER_FIELDS * const option,
407                          const void * value,
408                          const char * const description)
409 {
410   EVEL_ENTER();
411
412   /***************************************************************************/
413   /* Check preconditions.                                                    */
414   /***************************************************************************/
415   assert(option != NULL);
416   assert(description != NULL);
417
418   if (option->is_set)
419   {
420     EVEL_ERROR("Ignoring attempt to update %s to %llu. %s already set to %llu",
421                description, value, description, option->object);
422   }
423   else
424   {
425     EVEL_DEBUG("Setting %s to %llu", description, value);
426     option->object = value;
427     option->is_set = EVEL_TRUE;
428   }
429   EVEL_EXIT();
430 }
431
432 /**************************************************************************//**
433  * Free the underlying resources of an ::EVEL_OPTION_INTHEADER_FIELDS.
434  *
435  * @param option        Pointer to the ::EVEL_OPTION_INTHEADER_FIELDS.
436  *****************************************************************************/
437 void evel_free_option_intheader(EVEL_OPTION_INTHEADER_FIELDS * const option)
438 {
439   EVEL_ENTER();
440
441   /***************************************************************************/
442   /* Check preconditions.                                                    */
443   /***************************************************************************/
444   assert(option != NULL);
445
446   if (option->is_set)
447   {
448     free(option->object);
449     option->object = NULL;
450     option->is_set = EVEL_FALSE;
451   }
452
453   EVEL_EXIT();
454 }
455
456 /**************************************************************************//**
457  * Initialize an ::EVEL_OPTION_TIME to a not-set state.
458  *
459  * @param option        Pointer to the ::EVEL_OPTION_TIME.
460  *****************************************************************************/
461 void evel_init_option_time(EVEL_OPTION_TIME * const option)
462 {
463   EVEL_ENTER();
464
465   /***************************************************************************/
466   /* Check preconditions.                                                    */
467   /***************************************************************************/
468   assert(option != NULL);
469   option->value = 0;
470   option->is_set = EVEL_FALSE;
471   EVEL_EXIT();
472 }
473
474 /**************************************************************************//**
475  * Force the value of an ::EVEL_OPTION_TIME.
476  *
477  * @param option        Pointer to the ::EVEL_OPTION_TIME.
478  * @param value         The value to set.
479  *****************************************************************************/
480 void evel_force_option_time(EVEL_OPTION_TIME * const option,
481                             const time_t value)
482 {
483   EVEL_ENTER();
484
485   /***************************************************************************/
486   /* Check preconditions.                                                    */
487   /***************************************************************************/
488   assert(option != NULL);
489
490   option->value = value;
491   option->is_set = EVEL_TRUE;
492
493   EVEL_EXIT();
494 }
495
496 /**************************************************************************//**
497  * Set the value of an ::EVEL_OPTION_TIME.
498  *
499  * @param option        Pointer to the ::EVEL_OPTION_TIME.
500  * @param value         The value to set.
501  * @param description   Description to be used in logging.
502  *****************************************************************************/
503 void evel_set_option_time(EVEL_OPTION_TIME * const option,
504                           const time_t value,
505                           const char * const description)
506 {
507   EVEL_ENTER();
508
509   /***************************************************************************/
510   /* Check preconditions.                                                    */
511   /***************************************************************************/
512   assert(option != NULL);
513   assert(description != NULL);
514
515   if (option->is_set)
516   {
517     EVEL_ERROR("Ignoring attempt to update %s to %d. %s already set to %d",
518                description, value, description, option->value);
519   }
520   else
521   {
522     EVEL_DEBUG("Setting %s to %d", description, value);
523     option->value = value;
524     option->is_set = EVEL_TRUE;
525   }
526   EVEL_EXIT();
527 }