1 /*************************************************************************//**
3 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
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
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.
16 ****************************************************************************/
18 /**************************************************************************//**
20 * Implementation of EVEL functions relating to the internal events.
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.
28 ****************************************************************************/
35 #include "evel_internal.h"
38 /**************************************************************************//**
39 * Create a new internal event.
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
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)
55 EVENT_INTERNAL * event = NULL;
58 /***************************************************************************/
59 /* Check preconditions. */
60 /***************************************************************************/
61 assert(command < EVT_CMD_MAX_COMMANDS);
63 /***************************************************************************/
64 /* Allocate the fault. */
65 /***************************************************************************/
66 event = malloc(sizeof(EVENT_INTERNAL));
69 log_error_state("Out of memory");
72 memset(event, 0, sizeof(EVENT_INTERNAL));
73 EVEL_DEBUG("New internal event is at %lp", event);
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;
87 /**************************************************************************//**
88 * Free an internal event.
90 * Free off the event supplied. Will free all the contained allocated memory.
92 * @note It does not free the internal event itself, since that may be part of
94 *****************************************************************************/
95 void evel_free_internal_event(EVENT_INTERNAL * event)
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);
107 /***************************************************************************/
108 /* Free the header itself. */
109 /***************************************************************************/
110 evel_free_header(&event->header);