1 /*************************************************************************//**
3 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
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
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.
17 ****************************************************************************/
19 /**************************************************************************//**
21 * Source module implementing EVEL Batch API.
23 * This file implements the EVEL Batch API which is intended to provide a
24 * simple wrapper around packaging multiple EVEL messages into single HTTP(S) package
25 * This is implemented per VES 5.3 standards. Currently max size of package is 160K
27 ****************************************************************************/
34 #include "evel_internal.h"
36 /**************************************************************************//**
37 * Create a new empty Batch event.
39 * @note The mandatory fields on the Batch must be supplied to this factory
40 * function and are immutable once set. Optional fields have explicit
41 * setter functions, but again values may only be set once so that the
42 * Batch has immutable properties.
43 * @params Event name and Event id are dummy strings. Not encoded into JSON
44 * @returns pointer to the newly manufactured ::EVENT_HEADER. If the event is
45 * not used (i.e. posted) it must be released using ::evel_free_batch.
46 * @retval NULL Failed to create the event.
47 *****************************************************************************/
48 EVENT_HEADER * evel_new_batch(const char* ev_name, const char *ev_id)
50 EVENT_HEADER * other = NULL;
53 /***************************************************************************/
54 /* Check preconditions. */
55 /***************************************************************************/
57 /***************************************************************************/
58 /* Allocate the Batch. */
59 /***************************************************************************/
60 other = malloc(sizeof(EVENT_HEADER));
63 log_error_state("Out of memory");
66 memset(other, 0, sizeof(EVENT_HEADER));
67 EVEL_DEBUG("New Batch is at %lp", other);
69 /***************************************************************************/
70 /* Initialize the header & the Batch fields. Optional string values are */
71 /* uninitialized (NULL). */
72 /***************************************************************************/
73 evel_init_header_nameid(other,ev_name,ev_id);
74 other->event_domain = EVEL_DOMAIN_BATCH;
75 other->major_version = EVEL_BATCH_MAJOR_VERSION;
76 other->minor_version = EVEL_BATCH_MINOR_VERSION;
78 dlist_initialize(&other->batch_events);
86 /**************************************************************************//**
87 * Add an additional VES Message into Batch Event
89 * The function may be called as many times without reaching 160K max json size
91 * The max limit is only checked at encoding time and error generated
93 * @param batchev Pointer to already created new Batch Event.
94 * @param child Pointer to additional VES Event
95 *****************************************************************************/
96 void evel_batch_add_event(EVENT_HEADER * batchev, EVENT_HEADER *child)
100 /***************************************************************************/
101 /* Check preconditions. */
102 /***************************************************************************/
103 assert(batchev != NULL);
104 assert(batchev->event_domain == EVEL_DOMAIN_BATCH);
105 assert(child != NULL);
107 EVEL_DEBUG("Adding Batch event");
109 dlist_push_last(&batchev->batch_events, child);
115 /**************************************************************************//**
116 * Free a Batch Event.
118 * Free off the Batch supplied. Will free all the contained VES message memory.
120 * @note It does not free the Batch itself, since that may be part of a
122 *****************************************************************************/
123 void evel_free_batch(EVENT_HEADER * event)
125 EVENT_HEADER * batch_field = NULL;
129 /***************************************************************************/
130 /* Check preconditions. As an internal API we don't allow freeing NULL */
131 /* events as we do on the public API. */
132 /***************************************************************************/
133 assert(event != NULL);
134 assert(event->event_domain == EVEL_DOMAIN_BATCH);
136 /***************************************************************************/
137 /* Free all internal strings then the header itself. */
138 /***************************************************************************/
139 batch_field = dlist_pop_last(&event->batch_events);
140 while (batch_field != NULL)
142 EVEL_DEBUG("Freeing Batch Event (%s, %s)",
143 batch_field->event_name,
144 batch_field->event_id);
145 evel_free_event(batch_field);
146 batch_field = dlist_pop_last(&event->batch_events);
148 evel_free_header(event);