d9d9e607fa6bfb97743d9b1b3a7487968a91760c
[demo.git] / vnfs / VES5.0 / evel / evel-library / code / evel_library / evel_option.c
1 /**************************************************************************//**
2  * @file
3  * Source module relating to EVEL_OPTION_ types.
4  *
5  * License
6  * -------
7  *
8  * Copyright(c) <2016>, AT&T Intellectual Property.  All other rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  *    this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  *    this list of conditions and the following disclaimer in the documentation
17  *    and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:  This product includes
20  *    software developed by the AT&T.
21  * 4. Neither the name of AT&T nor the names of its contributors may be used to
22  *    endorse or promote products derived from this software without specific
23  *    prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY
26  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28  * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY
29  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *****************************************************************************/
36
37 #include <assert.h>
38 #include <stdlib.h>
39 #include <string.h>
40
41 #include "evel_internal.h"
42
43 /**************************************************************************//**
44  * Free the underlying resources of an ::EVEL_OPTION_STRING.
45  *
46  * @param option        Pointer to the ::EVEL_OPTION_STRING.
47  *****************************************************************************/
48 void evel_free_option_string(EVEL_OPTION_STRING * const option)
49 {
50   EVEL_ENTER();
51
52   /***************************************************************************/
53   /* Check preconditions.                                                    */
54   /***************************************************************************/
55   assert(option != NULL);
56
57   if (option->is_set)
58   {
59     free(option->value);
60     option->value = NULL;
61     option->is_set = EVEL_FALSE;
62   }
63
64   EVEL_EXIT();
65 }
66
67 /**************************************************************************//**
68  * Initialize an ::EVEL_OPTION_STRING to a not-set state.
69  *
70  * @param option        Pointer to the ::EVEL_OPTION_STRING.
71  *****************************************************************************/
72 void evel_init_option_string(EVEL_OPTION_STRING * const option)
73 {
74   EVEL_ENTER();
75
76   /***************************************************************************/
77   /* Check preconditions.                                                    */
78   /***************************************************************************/
79   assert(option != NULL);
80
81   option->value = NULL;
82   option->is_set = EVEL_FALSE;
83
84   EVEL_EXIT();
85 }
86
87 /**************************************************************************//**
88  * Set the value of an ::EVEL_OPTION_STRING.
89  *
90  * @param option        Pointer to the ::EVEL_OPTION_STRING.
91  * @param value         The value to set.
92  * @param description   Description to be used in logging.
93  *****************************************************************************/
94 void evel_set_option_string(EVEL_OPTION_STRING * const option,
95                             const char * const value,
96                             const char * const description)
97 {
98   EVEL_ENTER();
99
100   /***************************************************************************/
101   /* Check preconditions.                                                    */
102   /***************************************************************************/
103   assert(option != NULL);
104   assert(value != NULL);
105   assert(description != NULL);
106
107   if (option->is_set)
108   {
109     EVEL_ERROR("Ignoring attempt to update %s to %s. %s already set to %s",
110                description, value, description, option->value);
111   }
112   else
113   {
114     EVEL_DEBUG("Setting %s to %s", description, value);
115     option->value = strdup(value);
116     option->is_set = EVEL_TRUE;
117   }
118
119   EVEL_EXIT();
120 }
121
122 /**************************************************************************//**
123  * Force the value of an ::EVEL_OPTION_STRING.
124  *
125  * @param option        Pointer to the ::EVEL_OPTION_STRING.
126  * @param value         The value to set.
127  *****************************************************************************/
128 void evel_force_option_string(EVEL_OPTION_STRING * const option,
129                               const char * const value)
130 {
131   EVEL_ENTER();
132
133   /***************************************************************************/
134   /* Check preconditions.                                                    */
135   /***************************************************************************/
136   assert(option != NULL);
137   assert(option->is_set == EVEL_FALSE);
138   assert(option->value == NULL);
139
140   option->value = strdup(value);
141   option->is_set = EVEL_TRUE;
142
143   EVEL_EXIT();
144 }
145
146 /**************************************************************************//**
147  * Initialize an ::EVEL_OPTION_INT to a not-set state.
148  *
149  * @param option        Pointer to the ::EVEL_OPTION_INT.
150  *****************************************************************************/
151 void evel_init_option_int(EVEL_OPTION_INT * const option)
152 {
153   EVEL_ENTER();
154
155   /***************************************************************************/
156   /* Check preconditions.                                                    */
157   /***************************************************************************/
158   assert(option != NULL);
159
160   option->value = 0;
161   option->is_set = EVEL_FALSE;
162
163   EVEL_EXIT();
164 }
165
166 /**************************************************************************//**
167  * Force the value of an ::EVEL_OPTION_INT.
168  *
169  * @param option        Pointer to the ::EVEL_OPTION_INT.
170  * @param value         The value to set.
171  *****************************************************************************/
172 void evel_force_option_int(EVEL_OPTION_INT * const option,
173                            const int value)
174 {
175   EVEL_ENTER();
176
177   /***************************************************************************/
178   /* Check preconditions.                                                    */
179   /***************************************************************************/
180   assert(option != NULL);
181
182   option->value = value;
183   option->is_set = EVEL_TRUE;
184
185   EVEL_EXIT();
186 }
187
188 /**************************************************************************//**
189  * Set the value of an ::EVEL_OPTION_INT.
190  *
191  * @param option        Pointer to the ::EVEL_OPTION_INT.
192  * @param value         The value to set.
193  * @param description   Description to be used in logging.
194  *****************************************************************************/
195 void evel_set_option_int(EVEL_OPTION_INT * const option,
196                          const int value,
197                          const char * const description)
198 {
199   EVEL_ENTER();
200
201   /***************************************************************************/
202   /* Check preconditions.                                                    */
203   /***************************************************************************/
204   assert(option != NULL);
205   assert(description != NULL);
206
207   if (option->is_set)
208   {
209     EVEL_ERROR("Ignoring attempt to update %s to %d. %s already set to %d",
210                description, value, description, option->value);
211   }
212   else
213   {
214     EVEL_DEBUG("Setting %s to %d", description, value);
215     option->value = value;
216     option->is_set = EVEL_TRUE;
217   }
218
219   EVEL_EXIT();
220 }
221
222 /**************************************************************************//**
223  * Initialize an ::EVEL_OPTION_DOUBLE to a not-set state.
224  *
225  * @param option        Pointer to the ::EVEL_OPTION_DOUBLE.
226  *****************************************************************************/
227 void evel_init_option_double(EVEL_OPTION_DOUBLE * const option)
228 {
229   EVEL_ENTER();
230
231   /***************************************************************************/
232   /* Check preconditions.                                                    */
233   /***************************************************************************/
234   assert(option != NULL);
235
236   option->value = 0.0;
237   option->is_set = EVEL_FALSE;
238
239   EVEL_EXIT();
240 }
241
242 /**************************************************************************//**
243  * Force the value of an ::EVEL_OPTION_DOUBLE.
244  *
245  * @param option        Pointer to the ::EVEL_OPTION_DOUBLE.
246  * @param value         The value to set.
247  *****************************************************************************/
248 void evel_force_option_double(EVEL_OPTION_DOUBLE * const option,
249                               const double value)
250 {
251   EVEL_ENTER();
252
253   /***************************************************************************/
254   /* Check preconditions.                                                    */
255   /***************************************************************************/
256   assert(option != NULL);
257
258   option->value = value;
259   option->is_set = EVEL_TRUE;
260
261   EVEL_EXIT();
262 }
263
264 /**************************************************************************//**
265  * Set the value of an ::EVEL_OPTION_DOUBLE.
266  *
267  * @param option        Pointer to the ::EVEL_OPTION_DOUBLE.
268  * @param value         The value to set.
269  * @param description   Description to be used in logging.
270  *****************************************************************************/
271 void evel_set_option_double(EVEL_OPTION_DOUBLE * const option,
272                             const double value,
273                             const char * const description)
274 {
275   EVEL_ENTER();
276
277   /***************************************************************************/
278   /* Check preconditions.                                                    */
279   /***************************************************************************/
280   assert(option != NULL);
281   assert(description != NULL);
282
283   if (option->is_set)
284   {
285     EVEL_ERROR("Ignoring attempt to update %s to %lf. %s already set to %lf",
286                description, value, description, option->value);
287   }
288   else
289   {
290     EVEL_DEBUG("Setting %s to %lf", description, value);
291     option->value = value;
292     option->is_set = EVEL_TRUE;
293   }
294
295   EVEL_EXIT();
296 }
297
298 /**************************************************************************//**
299  * Initialize an ::EVEL_OPTION_ULL to a not-set state.
300  *
301  * @param option        Pointer to the ::EVEL_OPTION_ULL.
302  *****************************************************************************/
303 void evel_init_option_ull(EVEL_OPTION_ULL * const option)
304 {
305   EVEL_ENTER();
306
307   /***************************************************************************/
308   /* Check preconditions.                                                    */
309   /***************************************************************************/
310   assert(option != NULL);
311   option->value = 0;
312   option->is_set = EVEL_FALSE;
313   EVEL_EXIT();
314 }
315
316 /**************************************************************************//**
317  * Force the value of an ::EVEL_OPTION_ULL.
318  *
319  * @param option        Pointer to the ::EVEL_OPTION_ULL.
320  * @param value         The value to set.
321  *****************************************************************************/
322 void evel_force_option_ull(EVEL_OPTION_ULL * const option,
323                            const unsigned long long value)
324 {
325   EVEL_ENTER();
326
327   /***************************************************************************/
328   /* Check preconditions.                                                    */
329   /***************************************************************************/
330   assert(option != NULL);
331
332   option->value = value;
333   option->is_set = EVEL_TRUE;
334
335   EVEL_EXIT();
336 }
337
338 /**************************************************************************//**
339  * Set the value of an ::EVEL_OPTION_ULL.
340  *
341  * @param option        Pointer to the ::EVEL_OPTION_ULL.
342  * @param value         The value to set.
343  * @param description   Description to be used in logging.
344  *****************************************************************************/
345 void evel_set_option_ull(EVEL_OPTION_ULL * const option,
346                          const unsigned long long value,
347                          const char * const description)
348 {
349   EVEL_ENTER();
350
351   /***************************************************************************/
352   /* Check preconditions.                                                    */
353   /***************************************************************************/
354   assert(option != NULL);
355   assert(description != NULL);
356
357   if (option->is_set)
358   {
359     EVEL_ERROR("Ignoring attempt to update %s to %llu. %s already set to %llu",
360                description, value, description, option->value);
361   }
362   else
363   {
364     EVEL_DEBUG("Setting %s to %llu", description, value);
365     option->value = value;
366     option->is_set = EVEL_TRUE;
367   }
368   EVEL_EXIT();
369 }
370
371
372 /**************************************************************************//**
373  * Initialize an ::EVEL_OPTION_INTHEADER_FIELDS to a not-set state.
374  *
375  * @param option        Pointer to the ::EVEL_OPTION_INTHEADER_FIELDS.
376  *****************************************************************************/
377 void evel_init_option_intheader(EVEL_OPTION_INTHEADER_FIELDS * const option)
378 {
379   EVEL_ENTER();
380
381   /***************************************************************************/
382   /* Check preconditions.                                                    */
383   /***************************************************************************/
384   assert(option != NULL);
385   option->object = NULL;
386   option->is_set = EVEL_FALSE;
387   EVEL_EXIT();
388 }
389
390 /**************************************************************************//**
391  * Force the value of an ::EVEL_OPTION_INTHEADER_FIELDS.
392  *
393  * @param option        Pointer to the ::EVEL_OPTION_INTHEADER_FIELDS.
394  * @param value         The value to set.
395  *****************************************************************************/
396 void evel_force_option_intheader(EVEL_OPTION_INTHEADER_FIELDS * const option,
397                            const void* value)
398 {
399   EVEL_ENTER();
400
401   /***************************************************************************/
402   /* Check preconditions.                                                    */
403   /***************************************************************************/
404   assert(option != NULL);
405
406   option->object = value;
407   option->is_set = EVEL_TRUE;
408
409   EVEL_EXIT();
410 }
411
412 /**************************************************************************//**
413  * Set the value of an ::EVEL_OPTION_INTHEADER_FIELDS.
414  *
415  * @param option        Pointer to the ::EVEL_OPTION_INTHEADER_FIELDS.
416  * @param value         The value to set.
417  * @param description   Description to be used in logging.
418  *****************************************************************************/
419 void evel_set_option_intheader(EVEL_OPTION_INTHEADER_FIELDS * const option,
420                          const void * value,
421                          const char * const description)
422 {
423   EVEL_ENTER();
424
425   /***************************************************************************/
426   /* Check preconditions.                                                    */
427   /***************************************************************************/
428   assert(option != NULL);
429   assert(description != NULL);
430
431   if (option->is_set)
432   {
433     EVEL_ERROR("Ignoring attempt to update %s to %llu. %s already set to %llu",
434                description, value, description, option->object);
435   }
436   else
437   {
438     EVEL_DEBUG("Setting %s to %llu", description, value);
439     option->object = value;
440     option->is_set = EVEL_TRUE;
441   }
442   EVEL_EXIT();
443 }
444
445 /**************************************************************************//**
446  * Free the underlying resources of an ::EVEL_OPTION_INTHEADER_FIELDS.
447  *
448  * @param option        Pointer to the ::EVEL_OPTION_INTHEADER_FIELDS.
449  *****************************************************************************/
450 void evel_free_option_intheader(EVEL_OPTION_INTHEADER_FIELDS * const option)
451 {
452   EVEL_ENTER();
453
454   /***************************************************************************/
455   /* Check preconditions.                                                    */
456   /***************************************************************************/
457   assert(option != NULL);
458
459   if (option->is_set)
460   {
461     free(option->object);
462     option->object = NULL;
463     option->is_set = EVEL_FALSE;
464   }
465
466   EVEL_EXIT();
467 }
468
469 /**************************************************************************//**
470  * Initialize an ::EVEL_OPTION_TIME to a not-set state.
471  *
472  * @param option        Pointer to the ::EVEL_OPTION_TIME.
473  *****************************************************************************/
474 void evel_init_option_time(EVEL_OPTION_TIME * const option)
475 {
476   EVEL_ENTER();
477
478   /***************************************************************************/
479   /* Check preconditions.                                                    */
480   /***************************************************************************/
481   assert(option != NULL);
482   option->value = 0;
483   option->is_set = EVEL_FALSE;
484   EVEL_EXIT();
485 }
486
487 /**************************************************************************//**
488  * Force the value of an ::EVEL_OPTION_TIME.
489  *
490  * @param option        Pointer to the ::EVEL_OPTION_TIME.
491  * @param value         The value to set.
492  *****************************************************************************/
493 void evel_force_option_time(EVEL_OPTION_TIME * const option,
494                             const time_t value)
495 {
496   EVEL_ENTER();
497
498   /***************************************************************************/
499   /* Check preconditions.                                                    */
500   /***************************************************************************/
501   assert(option != NULL);
502
503   option->value = value;
504   option->is_set = EVEL_TRUE;
505
506   EVEL_EXIT();
507 }
508
509 /**************************************************************************//**
510  * Set the value of an ::EVEL_OPTION_TIME.
511  *
512  * @param option        Pointer to the ::EVEL_OPTION_TIME.
513  * @param value         The value to set.
514  * @param description   Description to be used in logging.
515  *****************************************************************************/
516 void evel_set_option_time(EVEL_OPTION_TIME * const option,
517                           const time_t value,
518                           const char * const description)
519 {
520   EVEL_ENTER();
521
522   /***************************************************************************/
523   /* Check preconditions.                                                    */
524   /***************************************************************************/
525   assert(option != NULL);
526   assert(description != NULL);
527
528   if (option->is_set)
529   {
530     EVEL_ERROR("Ignoring attempt to update %s to %d. %s already set to %d",
531                description, value, description, option->value);
532   }
533   else
534   {
535     EVEL_DEBUG("Setting %s to %d", description, value);
536     option->value = value;
537     option->is_set = EVEL_TRUE;
538   }
539   EVEL_EXIT();
540 }