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