Add License to VES library
[demo.git] / vnfs / VES / code / evel_library / evel_service.c
1 /**************************************************************************//**
2  * @file
3  * Implementation of EVEL functions relating to Service.
4  *
5  * License
6  * -------
7  *
8  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *        http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *****************************************************************************/
21
22 #include <string.h>
23 #include <assert.h>
24 #include <stdlib.h>
25
26 #include "evel_throttle.h"
27
28 /**************************************************************************//**
29  * Create a new Service event.
30  *
31  * @note    The mandatory fields on the Service must be supplied to
32  *          this factory function and are immutable once set.  Optional fields
33  *          have explicit setter functions, but again values may only be set
34  *          once so that the event has immutable properties.
35  * @param vendor_id     The vendor id to encode in the event instance id.
36  * @param event_id      The vendor event id to encode in the event instance id.
37  * @returns pointer to the newly manufactured ::EVENT_SERVICE.  If the event
38  *          is not used (i.e. posted) it must be released using
39  *          ::evel_free_service.
40  * @retval  NULL  Failed to create the event.
41  *****************************************************************************/
42 EVENT_SERVICE * evel_new_service(const char * const vendor_id,
43                                  const char * const event_id)
44 {
45   EVENT_SERVICE * event = NULL;
46
47   EVEL_ENTER();
48
49   /***************************************************************************/
50   /* Check preconditions.                                                    */
51   /***************************************************************************/
52   assert(vendor_id != NULL);
53   assert(event_id != NULL);
54
55   /***************************************************************************/
56   /* Allocate the Service event.                                           */
57   /***************************************************************************/
58   event = malloc(sizeof(EVENT_SERVICE));
59   if (event == NULL)
60   {
61     log_error_state("Out of memory");
62     goto exit_label;
63   }
64   memset(event, 0, sizeof(EVENT_SERVICE));
65   EVEL_DEBUG("New Service event is at %lp", event);
66
67   /***************************************************************************/
68   /* Initialize the header & the Service fields.                           */
69   /***************************************************************************/
70   evel_init_header(&event->header);
71   event->header.event_domain = EVEL_DOMAIN_SERVICE;
72   event->major_version = EVEL_SERVICE_MAJOR_VERSION;
73   event->minor_version = EVEL_SERVICE_MINOR_VERSION;
74   evel_init_event_instance_id(&event->instance_id, vendor_id, event_id);
75   evel_init_option_string(&event->correlator);
76   dlist_initialize(&event->additional_fields);
77   evel_init_option_string(&event->codec);
78   evel_init_option_string(&event->callee_side_codec);
79   evel_init_option_string(&event->caller_side_codec);
80   evel_init_option_string(&event->rtcp_data);
81   evel_init_option_string(&event->adjacency_name);
82   evel_init_option_string(&event->endpoint_description);
83   evel_init_option_int(&event->endpoint_jitter);
84   evel_init_option_int(&event->endpoint_rtp_oct_disc);
85   evel_init_option_int(&event->endpoint_rtp_oct_recv);
86   evel_init_option_int(&event->endpoint_rtp_oct_sent);
87   evel_init_option_int(&event->endpoint_rtp_pkt_disc);
88   evel_init_option_int(&event->endpoint_rtp_pkt_recv);
89   evel_init_option_int(&event->endpoint_rtp_pkt_sent);
90   evel_init_option_int(&event->local_jitter);
91   evel_init_option_int(&event->local_rtp_oct_disc);
92   evel_init_option_int(&event->local_rtp_oct_recv);
93   evel_init_option_int(&event->local_rtp_oct_sent);
94   evel_init_option_int(&event->local_rtp_pkt_disc);
95   evel_init_option_int(&event->local_rtp_pkt_recv);
96   evel_init_option_int(&event->local_rtp_pkt_sent);
97   evel_init_option_double(&event->mos_cqe);
98   evel_init_option_int(&event->packets_lost);
99   evel_init_option_double(&event->packet_loss_percent);
100   evel_init_option_int(&event->r_factor);
101   evel_init_option_int(&event->round_trip_delay);
102   evel_init_option_string(&event->phone_number);
103
104 exit_label:
105
106   EVEL_EXIT();
107   return event;
108 }
109
110 /**************************************************************************//**
111  * Set the Event Type property of the Service event.
112  *
113  * @note  The property is treated as immutable: it is only valid to call
114  *        the setter once.  However, we don't assert if the caller tries to
115  *        overwrite, just ignoring the update instead.
116  *
117  * @param event         Pointer to the Service event.
118  * @param type          The Event Type to be set. ASCIIZ string. The caller
119  *                      does not need to preserve the value once the function
120  *                      returns.
121  *****************************************************************************/
122 void evel_service_type_set(EVENT_SERVICE * const event,
123                            const char * const type)
124 {
125   EVEL_ENTER();
126
127   /***************************************************************************/
128   /* Check preconditions and call evel_header_type_set.                      */
129   /***************************************************************************/
130   assert(event != NULL);
131   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
132   evel_header_type_set(&event->header, type);
133
134   EVEL_EXIT();
135 }
136
137 /**************************************************************************//**
138  * Add a name/value pair to the Service, under the additionalFields array.
139  *
140  * The name and value are null delimited ASCII strings.  The library takes
141  * a copy so the caller does not have to preserve values after the function
142  * returns.
143  *
144  * @param event     Pointer to the Service event.
145  * @param name      ASCIIZ string with the field's name.  The caller does not
146  *                  need to preserve the value once the function returns.
147  * @param value     ASCIIZ string with the field's value.  The caller does not
148  *                  need to preserve the value once the function returns.
149  *****************************************************************************/
150 void evel_service_addl_field_add(EVENT_SERVICE * const event,
151                                  const char * const name,
152                                  const char * const value)
153 {
154   OTHER_FIELD * nv_pair = NULL;
155
156   EVEL_ENTER();
157
158   /***************************************************************************/
159   /* Check preconditions.                                                    */
160   /***************************************************************************/
161   assert(event != NULL);
162   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
163   assert(name != NULL);
164   assert(value != NULL);
165
166   EVEL_DEBUG("Adding name=%s value=%s", name, value);
167   nv_pair = malloc(sizeof(OTHER_FIELD));
168   assert(nv_pair != NULL);
169   nv_pair->name = strdup(name);
170   nv_pair->value = strdup(value);
171   assert(nv_pair->name != NULL);
172   assert(nv_pair->value != NULL);
173
174   dlist_push_last(&event->additional_fields, nv_pair);
175
176   EVEL_EXIT();
177 }
178
179 /**************************************************************************//**
180  * Set the Product Id property of the Service event.
181  *
182  * @note  The property is treated as immutable: it is only valid to call
183  *        the setter once.  However, we don't assert if the caller tries to
184  *        overwrite, just ignoring the update instead.
185  *
186  * @param event         Pointer to the Service event.
187  * @param product_id    The vendor product id to be set. ASCIIZ string. The
188  *                      caller does not need to preserve the value once the
189  *                      function returns.
190  *****************************************************************************/
191 void evel_service_product_id_set(EVENT_SERVICE * const event,
192                                  const char * const product_id)
193 {
194   EVEL_ENTER();
195
196   /***************************************************************************/
197   /* Check preconditions and call evel_set_option_string.                    */
198   /***************************************************************************/
199   assert(event != NULL);
200   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
201   evel_set_option_string(&event->instance_id.product_id,
202                          product_id,
203                          "Product Id");
204
205   EVEL_EXIT();
206 }
207
208 /**************************************************************************//**
209  * Set the Subsystem Id property of the Service event.
210  *
211  * @note  The property is treated as immutable: it is only valid to call
212  *        the setter once.  However, we don't assert if the caller tries to
213  *        overwrite, just ignoring the update instead.
214  *
215  * @param event         Pointer to the Service event.
216  * @param subsystem_id  The vendor subsystem id to be set. ASCIIZ string. The
217  *                      caller does not need to preserve the value once the
218  *                      function returns.
219  *****************************************************************************/
220 void evel_service_subsystem_id_set(EVENT_SERVICE * const event,
221                                    const char * const subsystem_id)
222 {
223   EVEL_ENTER();
224
225   /***************************************************************************/
226   /* Check preconditions and call evel_set_option_string.                    */
227   /***************************************************************************/
228   assert(event != NULL);
229   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
230   evel_set_option_string(&event->instance_id.subsystem_id,
231                          subsystem_id,
232                          "Subsystem Id");
233
234   EVEL_EXIT();
235 }
236
237 /**************************************************************************//**
238  * Set the Friendly Name property of the Service event.
239  *
240  * @note  The property is treated as immutable: it is only valid to call
241  *        the setter once.  However, we don't assert if the caller tries to
242  *        overwrite, just ignoring the update instead.
243  *
244  * @param event         Pointer to the Service event.
245  * @param friendly_name The vendor friendly name to be set. ASCIIZ string. The
246  *                      caller does not need to preserve the value once the
247  *                      function returns.
248  *****************************************************************************/
249 void evel_service_friendly_name_set(EVENT_SERVICE * const event,
250                                     const char * const friendly_name)
251 {
252   EVEL_ENTER();
253
254   /***************************************************************************/
255   /* Check preconditions and call evel_set_option_string.                    */
256   /***************************************************************************/
257   assert(event != NULL);
258   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
259   evel_set_option_string(&event->instance_id.event_friendly_name,
260                          friendly_name,
261                          "Friendly Name");
262
263   EVEL_EXIT();
264 }
265
266 /**************************************************************************//**
267  * Set the Correlator property of the Service event.
268  *
269  * @note  The property is treated as immutable: it is only valid to call
270  *        the setter once.  However, we don't assert if the caller tries to
271  *        overwrite, just ignoring the update instead.
272  *
273  * @param event         Pointer to the Service event.
274  * @param correlator    The correlator to be set. ASCIIZ string. The caller
275  *                      does not need to preserve the value once the function
276  *                      returns.
277  *****************************************************************************/
278 void evel_service_correlator_set(EVENT_SERVICE * const event,
279                                  const char * const correlator)
280 {
281   EVEL_ENTER();
282
283   /***************************************************************************/
284   /* Check preconditions and call evel_set_option_string.                    */
285   /***************************************************************************/
286   assert(event != NULL);
287   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
288   evel_set_option_string(&event->correlator,
289                          correlator,
290                          "Correlator");
291
292   EVEL_EXIT();
293 }
294
295 /**************************************************************************//**
296  * Set the Codec property of the Service event.
297  *
298  * @note  The property is treated as immutable: it is only valid to call
299  *        the setter once.  However, we don't assert if the caller tries to
300  *        overwrite, just ignoring the update instead.
301  *
302  * @param event         Pointer to the Service event.
303  * @param codec         The codec to be set. ASCIIZ string. The caller does not
304  *                      need to preserve the value once the function returns.
305  *****************************************************************************/
306 void evel_service_codec_set(EVENT_SERVICE * const event,
307                             const char * const codec)
308 {
309   EVEL_ENTER();
310
311   /***************************************************************************/
312   /* Check preconditions and call evel_set_option_string.                    */
313   /***************************************************************************/
314   assert(event != NULL);
315   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
316   evel_set_option_string(&event->codec,
317                          codec,
318                          "Codec");
319
320   EVEL_EXIT();
321 }
322
323 /**************************************************************************//**
324  * Set the Callee Side Codec property of the Service event.
325  *
326  * @note  The property is treated as immutable: it is only valid to call
327  *        the setter once.  However, we don't assert if the caller tries to
328  *        overwrite, just ignoring the update instead.
329  *
330  * @param event         Pointer to the Service event.
331  * @param codec         The codec to be set. ASCIIZ string. The caller does not
332  *                      need to preserve the value once the function returns.
333  *****************************************************************************/
334 void evel_service_callee_codec_set(EVENT_SERVICE * const event,
335                                    const char * const codec)
336 {
337   EVEL_ENTER();
338
339   /***************************************************************************/
340   /* Check preconditions and call evel_set_option_string.                    */
341   /***************************************************************************/
342   assert(event != NULL);
343   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
344   evel_set_option_string(&event->callee_side_codec,
345                          codec,
346                          "Callee Side Codec");
347
348   EVEL_EXIT();
349 }
350
351 /**************************************************************************//**
352  * Set the Caller Side Codec property of the Service event.
353  *
354  * @note  The property is treated as immutable: it is only valid to call
355  *        the setter once.  However, we don't assert if the caller tries to
356  *        overwrite, just ignoring the update instead.
357  *
358  * @param event         Pointer to the Service event.
359  * @param codec         The codec to be set. ASCIIZ string. The caller does not
360  *                      need to preserve the value once the function returns.
361  *****************************************************************************/
362 void evel_service_caller_codec_set(EVENT_SERVICE * const event,
363                                    const char * const codec)
364 {
365   EVEL_ENTER();
366
367   /***************************************************************************/
368   /* Check preconditions and call evel_set_option_string.                    */
369   /***************************************************************************/
370   assert(event != NULL);
371   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
372   evel_set_option_string(&event->caller_side_codec,
373                          codec,
374                          "Caller Side Codec");
375
376   EVEL_EXIT();
377 }
378
379 /**************************************************************************//**
380  * Set the RTCP Data property of the Service event.
381  *
382  * @note  The property is treated as immutable: it is only valid to call
383  *        the setter once.  However, we don't assert if the caller tries to
384  *        overwrite, just ignoring the update instead.
385  *
386  * @param event         Pointer to the Service event.
387  * @param rtcp_data     The RTCP Data to be set. ASCIIZ string. The caller
388  *                      does not need to preserve the value once the function
389  *                      returns.
390  *****************************************************************************/
391 void evel_service_rtcp_data_set(EVENT_SERVICE * const event,
392                                 const char * const rtcp_data)
393 {
394   EVEL_ENTER();
395
396   /***************************************************************************/
397   /* Check preconditions and call evel_set_option_string.                    */
398   /***************************************************************************/
399   assert(event != NULL);
400   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
401   evel_set_option_string(&event->rtcp_data,
402                          rtcp_data,
403                          "RTCP Data");
404
405   EVEL_EXIT();
406 }
407
408 /**************************************************************************//**
409  * Set the Adjacency Name property of the Service event.
410  *
411  * @note  The property is treated as immutable: it is only valid to call
412  *        the setter once.  However, we don't assert if the caller tries to
413  *        overwrite, just ignoring the update instead.
414  *
415  * @param event         Pointer to the Service event.
416  * @param adjacency_name
417  *                      The adjacency name to be set. ASCIIZ string. The caller
418  *                      does not need to preserve the value once the function
419  *                      returns.
420  *****************************************************************************/
421 void evel_service_adjacency_name_set(EVENT_SERVICE * const event,
422                                      const char * const adjacency_name)
423 {
424   EVEL_ENTER();
425
426   /***************************************************************************/
427   /* Check preconditions and call evel_set_option_string.                    */
428   /***************************************************************************/
429   assert(event != NULL);
430   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
431   evel_set_option_string(&event->adjacency_name,
432                          adjacency_name,
433                          "Adjacency Name");
434
435   EVEL_EXIT();
436 }
437
438 /**************************************************************************//**
439  * Set the Endpoint Descriptor property of the Service event.
440  *
441  * @note  The property is treated as immutable: it is only valid to call
442  *        the setter once.  However, we don't assert if the caller tries to
443  *        overwrite, just ignoring the update instead.
444  *
445  * @param event         Pointer to the Service event.
446  * @param endpoint_desc The endpoint descriptor to be set.
447  *****************************************************************************/
448 void evel_service_endpoint_desc_set(
449                                 EVENT_SERVICE * const event,
450                                 const EVEL_SERVICE_ENDPOINT_DESC endpoint_desc)
451 {
452   EVEL_ENTER();
453
454   /***************************************************************************/
455   /* Check preconditions and call evel_set_option_string.                    */
456   /***************************************************************************/
457   assert(event != NULL);
458   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
459   evel_set_option_string(&event->endpoint_description,
460                          evel_service_endpoint_desc(endpoint_desc),
461                          "Endpoint Description");
462
463   EVEL_EXIT();
464 }
465
466 /**************************************************************************//**
467  * Set the Endpoint Jitter property of the Service event.
468  *
469  * @note  The property is treated as immutable: it is only valid to call
470  *        the setter once.  However, we don't assert if the caller tries to
471  *        overwrite, just ignoring the update instead.
472  *
473  * @param event         Pointer to the Service event.
474  * @param jitter        The jitter to be set.
475  *****************************************************************************/
476 void evel_service_endpoint_jitter_set(EVENT_SERVICE * const event,
477                                       const int jitter)
478 {
479   EVEL_ENTER();
480
481   /***************************************************************************/
482   /* Check preconditions and call evel_set_option_string.                    */
483   /***************************************************************************/
484   assert(event != NULL);
485   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
486   evel_set_option_int(&event->endpoint_jitter,
487                       jitter,
488                       "Endpoint Jitter");
489
490   EVEL_EXIT();
491 }
492
493 /**************************************************************************//**
494  * Set the Endpoint Rtp Octets Discarded property of the Service event.
495  *
496  * @note  The property is treated as immutable: it is only valid to call
497  *        the setter once.  However, we don't assert if the caller tries to
498  *        overwrite, just ignoring the update instead.
499  *
500  * @param event         Pointer to the Service event.
501  * @param rtp_oct_disc  The discard count.
502  *****************************************************************************/
503 void evel_service_endpoint_rtp_oct_disc_set(EVENT_SERVICE * const event,
504                                             const int rtp_oct_disc)
505 {
506   EVEL_ENTER();
507
508   /***************************************************************************/
509   /* Check preconditions and call evel_set_option_string.                    */
510   /***************************************************************************/
511   assert(event != NULL);
512   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
513   evel_set_option_int(&event->endpoint_rtp_oct_disc,
514                       rtp_oct_disc,
515                       "Endpoint Rtp Octets Discarded");
516
517   EVEL_EXIT();
518 }
519
520 /**************************************************************************//**
521  * Set the Endpoint Rtp Octets Received property of the Service event.
522  *
523  * @note  The property is treated as immutable: it is only valid to call
524  *        the setter once.  However, we don't assert if the caller tries to
525  *        overwrite, just ignoring the update instead.
526  *
527  * @param event         Pointer to the Service event.
528  * @param rtp_oct_recv  The receive count.
529  *****************************************************************************/
530 void evel_service_endpoint_rtp_oct_recv_set(EVENT_SERVICE * const event,
531                                             const int rtp_oct_recv)
532 {
533   EVEL_ENTER();
534
535   /***************************************************************************/
536   /* Check preconditions and call evel_set_option_string.                    */
537   /***************************************************************************/
538   assert(event != NULL);
539   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
540   evel_set_option_int(&event->endpoint_rtp_oct_recv,
541                       rtp_oct_recv,
542                       "Endpoint Rtp Octets Received");
543
544   EVEL_EXIT();
545 }
546
547 /**************************************************************************//**
548  * Set the Endpoint Rtp Octets Sent property of the Service event.
549  *
550  * @note  The property is treated as immutable: it is only valid to call
551  *        the setter once.  However, we don't assert if the caller tries to
552  *        overwrite, just ignoring the update instead.
553  *
554  * @param event         Pointer to the Service event.
555  * @param rtp_oct_sent  The send count.
556  *****************************************************************************/
557 void evel_service_endpoint_rtp_oct_sent_set(EVENT_SERVICE * const event,
558                                             const int rtp_oct_sent)
559 {
560   EVEL_ENTER();
561
562   /***************************************************************************/
563   /* Check preconditions and call evel_set_option_string.                    */
564   /***************************************************************************/
565   assert(event != NULL);
566   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
567   evel_set_option_int(&event->endpoint_rtp_oct_sent,
568                       rtp_oct_sent,
569                       "Endpoint Rtp Octets Sent");
570
571   EVEL_EXIT();
572 }
573
574 /**************************************************************************//**
575  * Set the Endpoint Rtp Packets Discarded property of the Service event.
576  *
577  * @note  The property is treated as immutable: it is only valid to call
578  *        the setter once.  However, we don't assert if the caller tries to
579  *        overwrite, just ignoring the update instead.
580  *
581  * @param event         Pointer to the Service event.
582  * @param rtp_pkt_disc  The discard count.
583  *****************************************************************************/
584 void evel_service_endpoint_rtp_pkt_disc_set(EVENT_SERVICE * const event,
585                                             const int rtp_pkt_disc)
586 {
587   EVEL_ENTER();
588
589   /***************************************************************************/
590   /* Check preconditions and call evel_set_option_string.                    */
591   /***************************************************************************/
592   assert(event != NULL);
593   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
594   evel_set_option_int(&event->endpoint_rtp_pkt_disc,
595                       rtp_pkt_disc,
596                       "Endpoint Rtp Packets Discarded");
597
598   EVEL_EXIT();
599 }
600
601 /**************************************************************************//**
602  * Set the Endpoint Rtp Packets Received property of the Service event.
603  *
604  * @note  The property is treated as immutable: it is only valid to call
605  *        the setter once.  However, we don't assert if the caller tries to
606  *        overwrite, just ignoring the update instead.
607  *
608  * @param event         Pointer to the Service event.
609  * @param rtp_pkt_recv  The receive count.
610  *****************************************************************************/
611 void evel_service_endpoint_rtp_pkt_recv_set(EVENT_SERVICE * const event,
612                                             const int rtp_pkt_recv)
613 {
614   EVEL_ENTER();
615
616   /***************************************************************************/
617   /* Check preconditions and call evel_set_option_string.                    */
618   /***************************************************************************/
619   assert(event != NULL);
620   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
621   evel_set_option_int(&event->endpoint_rtp_pkt_recv,
622                       rtp_pkt_recv,
623                       "Endpoint Rtp Packets Received");
624
625   EVEL_EXIT();
626 }
627
628 /**************************************************************************//**
629  * Set the Endpoint Rtp Packets Sent property of the Service event.
630  *
631  * @note  The property is treated as immutable: it is only valid to call
632  *        the setter once.  However, we don't assert if the caller tries to
633  *        overwrite, just ignoring the update instead.
634  *
635  * @param event         Pointer to the Service event.
636  * @param rtp_pkt_sent  The send count.
637  *****************************************************************************/
638 void evel_service_endpoint_rtp_pkt_sent_set(EVENT_SERVICE * const event,
639                                             const int rtp_pkt_sent)
640 {
641   EVEL_ENTER();
642
643   /***************************************************************************/
644   /* Check preconditions and call evel_set_option_string.                    */
645   /***************************************************************************/
646   assert(event != NULL);
647   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
648   evel_set_option_int(&event->endpoint_rtp_pkt_sent,
649                       rtp_pkt_sent,
650                       "Endpoint Rtp Packets Sent");
651
652   EVEL_EXIT();
653 }
654
655 /**************************************************************************//**
656  * Set the Local Jitter property of the Service event.
657  *
658  * @note  The property is treated as immutable: it is only valid to call
659  *        the setter once.  However, we don't assert if the caller tries to
660  *        overwrite, just ignoring the update instead.
661  *
662  * @param event         Pointer to the Service event.
663  * @param jitter        The jitter to be set.
664  *****************************************************************************/
665 void evel_service_local_jitter_set(EVENT_SERVICE * const event,
666                                    const int jitter)
667 {
668   EVEL_ENTER();
669
670   /***************************************************************************/
671   /* Check preconditions and call evel_set_option_string.                    */
672   /***************************************************************************/
673   assert(event != NULL);
674   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
675   evel_set_option_int(&event->local_jitter,
676                       jitter,
677                       "Local Jitter");
678
679   EVEL_EXIT();
680 }
681
682 /**************************************************************************//**
683  * Set the Local Rtp Octets Discarded property of the Service event.
684  *
685  * @note  The property is treated as immutable: it is only valid to call
686  *        the setter once.  However, we don't assert if the caller tries to
687  *        overwrite, just ignoring the update instead.
688  *
689  * @param event         Pointer to the Service event.
690  * @param rtp_oct_disc  The discard count.
691  *****************************************************************************/
692 void evel_service_local_rtp_oct_disc_set(EVENT_SERVICE * const event,
693                                          const int rtp_oct_disc)
694 {
695   EVEL_ENTER();
696
697   /***************************************************************************/
698   /* Check preconditions and call evel_set_option_string.                    */
699   /***************************************************************************/
700   assert(event != NULL);
701   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
702   evel_set_option_int(&event->local_rtp_oct_disc,
703                       rtp_oct_disc,
704                       "Local Rtp Octets Discarded");
705
706   EVEL_EXIT();
707 }
708
709 /**************************************************************************//**
710  * Set the Local Rtp Octets Received property of the Service event.
711  *
712  * @note  The property is treated as immutable: it is only valid to call
713  *        the setter once.  However, we don't assert if the caller tries to
714  *        overwrite, just ignoring the update instead.
715  *
716  * @param event         Pointer to the Service event.
717  * @param rtp_oct_recv  The receive count.
718  *****************************************************************************/
719 void evel_service_local_rtp_oct_recv_set(EVENT_SERVICE * const event,
720                                          const int rtp_oct_recv)
721 {
722   EVEL_ENTER();
723
724   /***************************************************************************/
725   /* Check preconditions and call evel_set_option_string.                    */
726   /***************************************************************************/
727   assert(event != NULL);
728   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
729   evel_set_option_int(&event->local_rtp_oct_recv,
730                       rtp_oct_recv,
731                       "Local Rtp Octets Received");
732
733   EVEL_EXIT();
734 }
735
736 /**************************************************************************//**
737  * Set the Local Rtp Octets Sent property of the Service event.
738  *
739  * @note  The property is treated as immutable: it is only valid to call
740  *        the setter once.  However, we don't assert if the caller tries to
741  *        overwrite, just ignoring the update instead.
742  *
743  * @param event         Pointer to the Service event.
744  * @param rtp_oct_sent  The send count.
745  *****************************************************************************/
746 void evel_service_local_rtp_oct_sent_set(EVENT_SERVICE * const event,
747                                          const int rtp_oct_sent)
748 {
749   EVEL_ENTER();
750
751   /***************************************************************************/
752   /* Check preconditions and call evel_set_option_string.                    */
753   /***************************************************************************/
754   assert(event != NULL);
755   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
756   evel_set_option_int(&event->local_rtp_oct_sent,
757                       rtp_oct_sent,
758                       "Local Rtp Octets Sent");
759
760   EVEL_EXIT();
761 }
762
763 /**************************************************************************//**
764  * Set the Local Rtp Packets Discarded property of the Service event.
765  *
766  * @note  The property is treated as immutable: it is only valid to call
767  *        the setter once.  However, we don't assert if the caller tries to
768  *        overwrite, just ignoring the update instead.
769  *
770  * @param event         Pointer to the Service event.
771  * @param rtp_pkt_disc  The discard count.
772  *****************************************************************************/
773 void evel_service_local_rtp_pkt_disc_set(EVENT_SERVICE * const event,
774                                          const int rtp_pkt_disc)
775 {
776   EVEL_ENTER();
777
778   /***************************************************************************/
779   /* Check preconditions and call evel_set_option_string.                    */
780   /***************************************************************************/
781   assert(event != NULL);
782   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
783   evel_set_option_int(&event->local_rtp_pkt_disc,
784                       rtp_pkt_disc,
785                       "Local Rtp Packets Discarded");
786
787   EVEL_EXIT();
788 }
789
790 /**************************************************************************//**
791  * Set the Local Rtp Packets Received property of the Service event.
792  *
793  * @note  The property is treated as immutable: it is only valid to call
794  *        the setter once.  However, we don't assert if the caller tries to
795  *        overwrite, just ignoring the update instead.
796  *
797  * @param event         Pointer to the Service event.
798  * @param rtp_pkt_recv  The receive count.
799  *****************************************************************************/
800 void evel_service_local_rtp_pkt_recv_set(EVENT_SERVICE * const event,
801                                          const int rtp_pkt_recv)
802 {
803   EVEL_ENTER();
804
805   /***************************************************************************/
806   /* Check preconditions and call evel_set_option_string.                    */
807   /***************************************************************************/
808   assert(event != NULL);
809   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
810   evel_set_option_int(&event->local_rtp_pkt_recv,
811                       rtp_pkt_recv,
812                       "Local Rtp Packets Received");
813
814   EVEL_EXIT();
815 }
816
817 /**************************************************************************//**
818  * Set the Local Rtp Packets Sent property of the Service event.
819  *
820  * @note  The property is treated as immutable: it is only valid to call
821  *        the setter once.  However, we don't assert if the caller tries to
822  *        overwrite, just ignoring the update instead.
823  *
824  * @param event         Pointer to the Service event.
825  * @param rtp_pkt_sent  The send count.
826  *****************************************************************************/
827 void evel_service_local_rtp_pkt_sent_set(EVENT_SERVICE * const event,
828                                          const int rtp_pkt_sent)
829 {
830   EVEL_ENTER();
831
832   /***************************************************************************/
833   /* Check preconditions and call evel_set_option_string.                    */
834   /***************************************************************************/
835   assert(event != NULL);
836   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
837   evel_set_option_int(&event->local_rtp_pkt_sent,
838                       rtp_pkt_sent,
839                       "Local Rtp Packets Sent");
840
841   EVEL_EXIT();
842 }
843
844 /**************************************************************************//**
845  * Set the Mos Cqe property of the Service event.
846  *
847  * @note  The property is treated as immutable: it is only valid to call
848  *        the setter once.  However, we don't assert if the caller tries to
849  *        overwrite, just ignoring the update instead.
850  *
851  * @param event         Pointer to the Service event.
852  * @param mos_cqe       The mosCqe to be set.
853  *****************************************************************************/
854 void evel_service_mos_cqe_set(EVENT_SERVICE * const event,
855                               const double mos_cqe)
856 {
857   EVEL_ENTER();
858
859   /***************************************************************************/
860   /* Check preconditions and call evel_set_option_string.                    */
861   /***************************************************************************/
862   assert(event != NULL);
863   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
864   evel_set_option_double(&event->mos_cqe,
865                          mos_cqe,
866                          "Mos Cqe");
867
868   EVEL_EXIT();
869 }
870
871 /**************************************************************************//**
872  * Set the Packets Lost property of the Service event.
873  *
874  * @note  The property is treated as immutable: it is only valid to call
875  *        the setter once.  However, we don't assert if the caller tries to
876  *        overwrite, just ignoring the update instead.
877  *
878  * @param event         Pointer to the Service event.
879  * @param packets_lost  The number of packets lost to be set.
880  *****************************************************************************/
881 void evel_service_packets_lost_set(EVENT_SERVICE * const event,
882                                    const int packets_lost)
883 {
884   EVEL_ENTER();
885
886   /***************************************************************************/
887   /* Check preconditions and call evel_set_option_string.                    */
888   /***************************************************************************/
889   assert(event != NULL);
890   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
891   evel_set_option_int(&event->packets_lost,
892                       packets_lost,
893                       "Packets Lost");
894
895   EVEL_EXIT();
896 }
897
898 /**************************************************************************//**
899  * Set the packet Loss Percent property of the Service event.
900  *
901  * @note  The property is treated as immutable: it is only valid to call
902  *        the setter once.  However, we don't assert if the caller tries to
903  *        overwrite, just ignoring the update instead.
904  *
905  * @param event         Pointer to the Service event.
906  * @param packet_loss_percent
907  *                      The packet loss in percent.
908  *****************************************************************************/
909 void evel_service_packet_loss_percent_set(EVENT_SERVICE * const event,
910                                           const double packet_loss_percent)
911 {
912   EVEL_ENTER();
913
914   /***************************************************************************/
915   /* Check preconditions and call evel_set_option_string.                    */
916   /***************************************************************************/
917   assert(event != NULL);
918   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
919   evel_set_option_double(&event->packet_loss_percent,
920                          packet_loss_percent,
921                          "Packet Loss Percent");
922
923   EVEL_EXIT();
924 }
925
926 /**************************************************************************//**
927  * Set the R Factor property of the Service event.
928  *
929  * @note  The property is treated as immutable: it is only valid to call
930  *        the setter once.  However, we don't assert if the caller tries to
931  *        overwrite, just ignoring the update instead.
932  *
933  * @param event         Pointer to the Service event.
934  * @param r_factor      The R Factor to be set.
935  *****************************************************************************/
936 void evel_service_r_factor_set(EVENT_SERVICE * const event,
937                                const int r_factor)
938 {
939   EVEL_ENTER();
940
941   /***************************************************************************/
942   /* Check preconditions and call evel_set_option_string.                    */
943   /***************************************************************************/
944   assert(event != NULL);
945   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
946   evel_set_option_int(&event->r_factor,
947                       r_factor,
948                       "R Factor");
949
950   EVEL_EXIT();
951 }
952
953 /**************************************************************************//**
954  * Set the Round Trip Delay property of the Service event.
955  *
956  * @note  The property is treated as immutable: it is only valid to call
957  *        the setter once.  However, we don't assert if the caller tries to
958  *        overwrite, just ignoring the update instead.
959  *
960  * @param event         Pointer to the Service event.
961  * @param round_trip_delay
962  *                      The Round trip delay to be set.
963  *****************************************************************************/
964 void evel_service_round_trip_delay_set(EVENT_SERVICE * const event,
965                                        const int round_trip_delay)
966 {
967   EVEL_ENTER();
968
969   /***************************************************************************/
970   /* Check preconditions and call evel_set_option_string.                    */
971   /***************************************************************************/
972   assert(event != NULL);
973   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
974   evel_set_option_int(&event->round_trip_delay,
975                       round_trip_delay,
976                       "Round Trip Delay");
977
978   EVEL_EXIT();
979 }
980
981 /**************************************************************************//**
982  * Set the Phone Number property of the Service event.
983  *
984  * @note  The property is treated as immutable: it is only valid to call
985  *        the setter once.  However, we don't assert if the caller tries to
986  *        overwrite, just ignoring the update instead.
987  *
988  * @param event         Pointer to the Service event.
989  * @param phone_number  The Phone Number to be set. ASCIIZ string. The caller
990  *                      does not need to preserve the value once the function
991  *                      returns.
992  *****************************************************************************/
993 void evel_service_phone_number_set(EVENT_SERVICE * const event,
994                                    const char * const phone_number)
995 {
996   EVEL_ENTER();
997
998   /***************************************************************************/
999   /* Check preconditions and call evel_set_option_string.                    */
1000   /***************************************************************************/
1001   assert(event != NULL);
1002   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
1003   evel_set_option_string(&event->phone_number,
1004                          phone_number,
1005                          "Phone Number");
1006
1007   EVEL_EXIT();
1008 }
1009
1010 /**************************************************************************//**
1011  * Encode the Service in JSON according to AT&T's schema for the
1012  * event type.
1013  *
1014  * @param jbuf          Pointer to the ::EVEL_JSON_BUFFER to encode into.
1015  * @param event         Pointer to the ::EVENT_HEADER to encode.
1016  *****************************************************************************/
1017 void evel_json_encode_service(EVEL_JSON_BUFFER * const jbuf,
1018                                 EVENT_SERVICE * const event)
1019 {
1020   OTHER_FIELD * nv_pair = NULL;
1021   DLIST_ITEM * dlist_item = NULL;
1022
1023   EVEL_ENTER();
1024
1025   /***************************************************************************/
1026   /* Check preconditions.                                                    */
1027   /***************************************************************************/
1028   assert(event != NULL);
1029   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
1030
1031   evel_json_encode_header(jbuf, &event->header);
1032   evel_json_open_named_object(jbuf, "serviceEventsFields");
1033
1034   /***************************************************************************/
1035   /* Mandatory fields                                                        */
1036   /***************************************************************************/
1037   evel_json_encode_instance_id(jbuf, &event->instance_id);
1038   evel_enc_version(jbuf,
1039                    "serviceEventsFieldsVersion",
1040                    event->major_version,
1041                    event->minor_version);
1042
1043   /***************************************************************************/
1044   /* Optional fields                                                         */
1045   /***************************************************************************/
1046   evel_enc_kv_opt_string(jbuf, "correlator", &event->correlator);
1047
1048   /***************************************************************************/
1049   /* Checkpoint, so that we can wind back if all fields are suppressed.      */
1050   /***************************************************************************/
1051   evel_json_checkpoint(jbuf);
1052   if (evel_json_open_opt_named_list(jbuf, "additionalFields"))
1053   {
1054     bool added = false;
1055
1056     dlist_item = dlist_get_first(&event->additional_fields);
1057     while (dlist_item != NULL)
1058     {
1059       nv_pair = (OTHER_FIELD *) dlist_item->item;
1060       assert(nv_pair != NULL);
1061
1062       if (!evel_throttle_suppress_nv_pair(jbuf->throttle_spec,
1063                                           "additionalFields",
1064                                           nv_pair->name))
1065       {
1066         evel_json_open_object(jbuf);
1067         evel_enc_kv_string(jbuf, "name", nv_pair->name);
1068         evel_enc_kv_string(jbuf, "value", nv_pair->value);
1069         evel_json_close_object(jbuf);
1070         added = true;
1071       }
1072       dlist_item = dlist_get_next(dlist_item);
1073     }
1074     evel_json_close_list(jbuf);
1075
1076     /*************************************************************************/
1077     /* If we've not written anything, rewind to before we opened the list.   */
1078     /*************************************************************************/
1079     if (!added)
1080     {
1081       evel_json_rewind(jbuf);
1082     }
1083   }
1084
1085   /***************************************************************************/
1086   /* Optional fields within JSON equivalent object: codecSelected            */
1087   /***************************************************************************/
1088   evel_json_checkpoint(jbuf);
1089   if (evel_json_open_opt_named_object(jbuf, "codecSelected"))
1090   {
1091     bool added = false;
1092     added |= evel_enc_kv_opt_string(jbuf,
1093                                     "codec",
1094                                     &event->codec);
1095     evel_json_close_object(jbuf);
1096
1097     /*************************************************************************/
1098     /* If the object is empty, rewind to before we opened it.                */
1099     /*************************************************************************/
1100     if (!added)
1101     {
1102       evel_json_rewind(jbuf);
1103     }
1104   }
1105
1106   /***************************************************************************/
1107   /* Optional fields within JSON equivalent object: codecSelectedTranscoding */
1108   /***************************************************************************/
1109   evel_json_checkpoint(jbuf);
1110   if (evel_json_open_opt_named_object(jbuf, "codecSelectedTranscoding"))
1111   {
1112     bool added = false;
1113     added |= evel_enc_kv_opt_string(jbuf,
1114                                     "calleeSideCodec",
1115                                     &event->callee_side_codec);
1116     added |= evel_enc_kv_opt_string(jbuf,
1117                                     "callerSideCodec",
1118                                     &event->caller_side_codec);
1119     evel_json_close_object(jbuf);
1120
1121     /*************************************************************************/
1122     /* If the object is empty, rewind to before we opened it.                */
1123     /*************************************************************************/
1124     if (!added)
1125     {
1126       evel_json_rewind(jbuf);
1127     }
1128   }
1129
1130   /***************************************************************************/
1131   /* Optional fields within JSON equivalent object: midCallRtcp              */
1132   /***************************************************************************/
1133   evel_json_checkpoint(jbuf);
1134   if (evel_json_open_opt_named_object(jbuf, "midCallRtcp"))
1135   {
1136     bool added = false;
1137     added |= evel_enc_kv_opt_string(jbuf,
1138                                     "rtcpData",
1139                                     &event->rtcp_data);
1140     evel_json_close_object(jbuf);
1141
1142     /*************************************************************************/
1143     /* If the object is empty, rewind to before we opened it.                */
1144     /*************************************************************************/
1145     if (!added)
1146     {
1147       evel_json_rewind(jbuf);
1148     }
1149   }
1150
1151   /***************************************************************************/
1152   /* Optional fields within JSON equivalent object: endOfCallVqmSummaries    */
1153   /***************************************************************************/
1154   evel_json_checkpoint(jbuf);
1155   if (evel_json_open_opt_named_object(jbuf, "endOfCallVqmSummaries"))
1156   {
1157     bool added = false;
1158     added |= evel_enc_kv_opt_string(jbuf,
1159                                     "adjacencyName",
1160                                     &event->adjacency_name);
1161     added |= evel_enc_kv_opt_string(jbuf,
1162                                     "endpointDescription",
1163                                     &event->endpoint_description);
1164     added |= evel_enc_kv_opt_int(jbuf,
1165                                  "endpointJitter",
1166                                  &event->endpoint_jitter);
1167     added |= evel_enc_kv_opt_int(jbuf,
1168                                  "endpointRtpOctetsDiscarded",
1169                                  &event->endpoint_rtp_oct_disc);
1170     added |= evel_enc_kv_opt_int(jbuf,
1171                                  "endpointRtpOctetsReceived",
1172                                  &event->endpoint_rtp_oct_recv);
1173     added |= evel_enc_kv_opt_int(jbuf,
1174                                  "endpointRtpOctetsSent",
1175                                  &event->endpoint_rtp_oct_sent);
1176     added |= evel_enc_kv_opt_int(jbuf,
1177                                  "endpointRtpPacketsDiscarded",
1178                                  &event->endpoint_rtp_pkt_disc);
1179     added |= evel_enc_kv_opt_int(jbuf,
1180                                  "endpointRtpPacketsReceived",
1181                                  &event->endpoint_rtp_pkt_recv);
1182     added |= evel_enc_kv_opt_int(jbuf,
1183                                  "endpointRtpPacketsSent",
1184                                  &event->endpoint_rtp_pkt_sent);
1185     added |= evel_enc_kv_opt_int(jbuf,
1186                                  "localJitter",
1187                                  &event->local_jitter);
1188     added |= evel_enc_kv_opt_int(jbuf,
1189                                  "localRtpOctetsDiscarded",
1190                                  &event->local_rtp_oct_disc);
1191     added |= evel_enc_kv_opt_int(jbuf,
1192                                  "localRtpOctetsReceived",
1193                                  &event->local_rtp_oct_recv);
1194     added |= evel_enc_kv_opt_int(jbuf,
1195                                  "localRtpOctetsSent",
1196                                  &event->local_rtp_oct_sent);
1197     added |= evel_enc_kv_opt_int(jbuf,
1198                                  "localRtpPacketsDiscarded",
1199                                  &event->local_rtp_pkt_disc);
1200     added |= evel_enc_kv_opt_int(jbuf,
1201                                  "localRtpPacketsReceived",
1202                                  &event->local_rtp_pkt_recv);
1203     added |= evel_enc_kv_opt_int(jbuf,
1204                                  "localRtpPacketsSent",
1205                                  &event->local_rtp_pkt_sent);
1206     added |= evel_enc_kv_opt_double(jbuf,
1207                                     "mosCqe",
1208                                     &event->mos_cqe);
1209     added |= evel_enc_kv_opt_int(jbuf,
1210                                  "packetsLost",
1211                                  &event->packets_lost);
1212     added |= evel_enc_kv_opt_double(jbuf,
1213                                     "packetLossPercent",
1214                                     &event->packet_loss_percent);
1215     added |= evel_enc_kv_opt_int(jbuf,
1216                                  "rFactor",
1217                                  &event->r_factor);
1218     added |= evel_enc_kv_opt_int(jbuf,
1219                                  "roundTripDelay",
1220                                  &event->round_trip_delay);
1221     evel_json_close_object(jbuf);
1222
1223     /*************************************************************************/
1224     /* If the object is empty, rewind to before we opened it.                */
1225     /*************************************************************************/
1226     if (!added)
1227     {
1228       evel_json_rewind(jbuf);
1229     }
1230   }
1231
1232   /***************************************************************************/
1233   /* Optional fields within JSON equivalent object: marker                   */
1234   /***************************************************************************/
1235   evel_json_checkpoint(jbuf);
1236   if (evel_json_open_opt_named_object(jbuf, "marker"))
1237   {
1238     bool added = false;
1239     added |= evel_enc_kv_opt_string(jbuf, "phoneNumber", &event->phone_number);
1240     evel_json_close_object(jbuf);
1241
1242     /*************************************************************************/
1243     /* If the object is empty, rewind to before we opened it.                */
1244     /*************************************************************************/
1245     if (!added)
1246     {
1247       evel_json_rewind(jbuf);
1248     }
1249   }
1250
1251   evel_json_close_object(jbuf);
1252
1253   EVEL_EXIT();
1254 }
1255
1256 /**************************************************************************//**
1257  * Free a Service event.
1258  *
1259  * Free off the event supplied.  Will free all the contained allocated memory.
1260  *
1261  * @note It does not free the event itself, since that may be part of a larger
1262  * structure.
1263  *****************************************************************************/
1264 void evel_free_service(EVENT_SERVICE * const event)
1265 {
1266   OTHER_FIELD * nv_pair = NULL;
1267
1268   EVEL_ENTER();
1269
1270   /***************************************************************************/
1271   /* Check preconditions.                                                    */
1272   /***************************************************************************/
1273   assert(event != NULL);
1274   assert(event->header.event_domain == EVEL_DOMAIN_SERVICE);
1275
1276   /***************************************************************************/
1277   /* Free all internal strings then the header itself.                       */
1278   /***************************************************************************/
1279   nv_pair = dlist_pop_last(&event->additional_fields);
1280   while (nv_pair != NULL)
1281   {
1282     EVEL_DEBUG("Freeing Other Field (%s, %s)", nv_pair->name, nv_pair->value);
1283     free(nv_pair->name);
1284     free(nv_pair->value);
1285     free(nv_pair);
1286     nv_pair = dlist_pop_last(&event->additional_fields);
1287   }
1288   evel_free_option_string(&event->correlator);
1289   evel_free_option_string(&event->codec);
1290   evel_free_option_string(&event->callee_side_codec);
1291   evel_free_option_string(&event->caller_side_codec);
1292   evel_free_option_string(&event->rtcp_data);
1293   evel_free_option_string(&event->adjacency_name);
1294   evel_free_option_string(&event->endpoint_description);
1295   evel_free_option_string(&event->phone_number);
1296   evel_free_event_instance_id(&event->instance_id);
1297   evel_free_header(&event->header);
1298
1299   EVEL_EXIT();
1300 }