Initial VES for DANOS vRouter
[demo.git] / vnfs / VESreporting_vFW5.0_DANOS / evel / evel-library / code / evel_library / evel_internal_event.c
1 /*************************************************************************//**
2  *
3  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
4  *
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
10  *
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.
16  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
17  ****************************************************************************/
18
19 /**************************************************************************//**
20  * @file
21  * Implementation of EVEL functions relating to the internal events.
22  *
23  * Internal events are never expected to be sent to the JSON API but comply
24  * with interfaces for regular event types.  The primary use-case is to enable
25  * the foreground processing to communicate with the background event handling
26  * processing in an orderly fashion.  At present the only use is to initiate an
27  * orderly shutdown of the Event Handler thread.
28  *
29  ****************************************************************************/
30
31 #include <string.h>
32 #include <assert.h>
33 #include <stdlib.h>
34
35 #include "evel.h"
36 #include "evel_internal.h"
37
38
39 /**************************************************************************//**
40  * Create a new internal event.
41  *
42  * @note    The mandatory fields on the Fault must be supplied to this factory
43  *          function and are immutable once set.  Optional fields have explicit
44  *          setter functions, but again values may only be set once so that the
45  *          Fault has immutable properties.
46  * @param   command   The condition indicated by the event.
47  * @param event_name  Unique Event Name confirming Domain AsdcModel Description
48  * @param event_id    A universal identifier of the event for: troubleshooting correlation, analysis, etc
49  * @returns pointer to the newly manufactured ::EVENT_INTERNAL.  If the event
50  *          is not used (i.e. posted) it must be released using
51  *          ::evel_free_event.
52  * @retval  NULL  Failed to create the event.
53  *****************************************************************************/
54 EVENT_INTERNAL * evel_new_internal_event(EVT_HANDLER_COMMAND command,const char* ev_name, const char *ev_id)
55 {
56   EVENT_INTERNAL * event = NULL;
57   EVEL_ENTER();
58
59   /***************************************************************************/
60   /* Check preconditions.                                                    */
61   /***************************************************************************/
62   assert(command < EVT_CMD_MAX_COMMANDS);
63
64   /***************************************************************************/
65   /* Allocate the fault.                                                     */
66   /***************************************************************************/
67   event = malloc(sizeof(EVENT_INTERNAL));
68   if (event == NULL)
69   {
70     log_error_state("Out of memory");
71     goto exit_label;
72   }
73   memset(event, 0, sizeof(EVENT_INTERNAL));
74   EVEL_DEBUG("New internal event is at %lp", event);
75
76   /***************************************************************************/
77   /* Initialize the header & the event fields.                               */
78   /***************************************************************************/
79   evel_init_header_nameid(&event->header,ev_name,ev_id);
80   event->header.event_domain = EVEL_DOMAIN_INTERNAL;
81   event->command = command;
82
83 exit_label:
84   EVEL_EXIT();
85   return event;
86 }
87
88 /**************************************************************************//**
89  * Free an internal event.
90  *
91  * Free off the event supplied.  Will free all the contained allocated memory.
92  *
93  * @note It does not free the internal event itself, since that may be part of
94  * a larger structure.
95  *****************************************************************************/
96 void evel_free_internal_event(EVENT_INTERNAL * event)
97 {
98
99   EVEL_ENTER();
100
101   /***************************************************************************/
102   /* Check preconditions.  As an internal API we don't allow freeing NULL    */
103   /* events as we do on the public API.                                      */
104   /***************************************************************************/
105   assert(event != NULL);
106   assert(event->header.event_domain == EVEL_DOMAIN_INTERNAL);
107
108   /***************************************************************************/
109   /* Free the header itself.                                                 */
110   /***************************************************************************/
111   evel_free_header(&event->header);
112
113   EVEL_EXIT();
114 }