Modified hardcoded eventname id to user defined
[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  * @param event_name  Unique Event Name confirming Domain AsdcModel Description
47  * @param event_id    A universal identifier of the event for: troubleshooting correlation, analysis, etc
48  * @returns pointer to the newly manufactured ::EVENT_INTERNAL.  If the event
49  *          is not used (i.e. posted) it must be released using
50  *          ::evel_free_event.
51  * @retval  NULL  Failed to create the event.
52  *****************************************************************************/
53 EVENT_INTERNAL * evel_new_internal_event(EVT_HANDLER_COMMAND command,const char* ev_name, const char *ev_id)
54 {
55   EVENT_INTERNAL * event = NULL;
56   EVEL_ENTER();
57
58   /***************************************************************************/
59   /* Check preconditions.                                                    */
60   /***************************************************************************/
61   assert(command < EVT_CMD_MAX_COMMANDS);
62
63   /***************************************************************************/
64   /* Allocate the fault.                                                     */
65   /***************************************************************************/
66   event = malloc(sizeof(EVENT_INTERNAL));
67   if (event == NULL)
68   {
69     log_error_state("Out of memory");
70     goto exit_label;
71   }
72   memset(event, 0, sizeof(EVENT_INTERNAL));
73   EVEL_DEBUG("New internal event is at %lp", event);
74
75   /***************************************************************************/
76   /* Initialize the header & the event fields.                               */
77   /***************************************************************************/
78   evel_init_header_nameid(&event->header,ev_name,ev_id);
79   event->header.event_domain = EVEL_DOMAIN_INTERNAL;
80   event->command = command;
81
82 exit_label:
83   EVEL_EXIT();
84   return event;
85 }
86
87 /**************************************************************************//**
88  * Free an internal event.
89  *
90  * Free off the event supplied.  Will free all the contained allocated memory.
91  *
92  * @note It does not free the internal event itself, since that may be part of
93  * a larger structure.
94  *****************************************************************************/
95 void evel_free_internal_event(EVENT_INTERNAL * event)
96 {
97
98   EVEL_ENTER();
99
100   /***************************************************************************/
101   /* Check preconditions.  As an internal API we don't allow freeing NULL    */
102   /* events as we do on the public API.                                      */
103   /***************************************************************************/
104   assert(event != NULL);
105   assert(event->header.event_domain == EVEL_DOMAIN_INTERNAL);
106
107   /***************************************************************************/
108   /* Free the header itself.                                                 */
109   /***************************************************************************/
110   evel_free_header(&event->header);
111
112   EVEL_EXIT();
113 }