Add License to VES library
[demo.git] / vnfs / VES / code / evel_library / evel_internal_event.c
1 /**************************************************************************//**
2  * @file
3  * Implementation of EVEL functions relating to the internal events.
4  *
5  * Internal events are never expected to be sent to the JSON API but comply
6  * with interfaces for regular event types.  The primary use-case is to enable
7  * the foreground processing to communicate with the background event handling
8  * processing in an orderly fashion.  At present the only use is to initiate an
9  * orderly shutdown of the Event Handler thread.
10  *
11  * License
12  * -------
13  *
14  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
15  *
16  * Licensed under the Apache License, Version 2.0 (the "License");
17  * you may not use this file except in compliance with the License.
18  * You may obtain a copy of the License at
19  *        http://www.apache.org/licenses/LICENSE-2.0
20  *
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS,
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  * See the License for the specific language governing permissions and
25  * limitations under the License.
26  *****************************************************************************/
27
28 #include <string.h>
29 #include <assert.h>
30 #include <stdlib.h>
31
32 #include "evel.h"
33 #include "evel_internal.h"
34
35
36 /**************************************************************************//**
37  * Create a new internal event.
38  *
39  * @note    The mandatory fields on the Fault 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  *          Fault has immutable properties.
43  * @param   command   The condition indicated by the event.
44  * @returns pointer to the newly manufactured ::EVENT_INTERNAL.  If the event
45  *          is not used (i.e. posted) it must be released using
46  *          ::evel_free_event.
47  * @retval  NULL  Failed to create the event.
48  *****************************************************************************/
49 EVENT_INTERNAL * evel_new_internal_event(EVT_HANDLER_COMMAND command)
50 {
51   EVENT_INTERNAL * event = NULL;
52   EVEL_ENTER();
53
54   /***************************************************************************/
55   /* Check preconditions.                                                    */
56   /***************************************************************************/
57   assert(command < EVT_CMD_MAX_COMMANDS);
58
59   /***************************************************************************/
60   /* Allocate the fault.                                                     */
61   /***************************************************************************/
62   event = malloc(sizeof(EVENT_INTERNAL));
63   if (event == NULL)
64   {
65     log_error_state("Out of memory");
66     goto exit_label;
67   }
68   memset(event, 0, sizeof(EVENT_INTERNAL));
69   EVEL_DEBUG("New internal event is at %lp", event);
70
71   /***************************************************************************/
72   /* Initialize the header & the event fields.                               */
73   /***************************************************************************/
74   evel_init_header(&event->header);
75   event->header.event_domain = EVEL_DOMAIN_INTERNAL;
76   event->command = command;
77
78 exit_label:
79   EVEL_EXIT();
80   return event;
81 }
82
83 /**************************************************************************//**
84  * Free an internal event.
85  *
86  * Free off the event supplied.  Will free all the contained allocated memory.
87  *
88  * @note It does not free the internal event itself, since that may be part of
89  * a larger structure.
90  *****************************************************************************/
91 void evel_free_internal_event(EVENT_INTERNAL * event)
92 {
93
94   EVEL_ENTER();
95
96   /***************************************************************************/
97   /* Check preconditions.  As an internal API we don't allow freeing NULL    */
98   /* events as we do on the public API.                                      */
99   /***************************************************************************/
100   assert(event != NULL);
101   assert(event->header.event_domain == EVEL_DOMAIN_INTERNAL);
102
103   /***************************************************************************/
104   /* Free the header itself.                                                 */
105   /***************************************************************************/
106   evel_free_header(&event->header);
107
108   EVEL_EXIT();
109 }