1 /*************************************************************************//**
3 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
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
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 ****************************************************************************/
19 /**************************************************************************//**
21 * Implementation of EVEL functions relating to the internal events.
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.
29 ****************************************************************************/
36 #include "evel_internal.h"
39 /**************************************************************************//**
40 * Create a new internal event.
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
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)
56 EVENT_INTERNAL * event = NULL;
59 /***************************************************************************/
60 /* Check preconditions. */
61 /***************************************************************************/
62 assert(command < EVT_CMD_MAX_COMMANDS);
64 /***************************************************************************/
65 /* Allocate the fault. */
66 /***************************************************************************/
67 event = malloc(sizeof(EVENT_INTERNAL));
70 log_error_state("Out of memory");
73 memset(event, 0, sizeof(EVENT_INTERNAL));
74 EVEL_DEBUG("New internal event is at %lp", event);
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;
88 /**************************************************************************//**
89 * Free an internal event.
91 * Free off the event supplied. Will free all the contained allocated memory.
93 * @note It does not free the internal event itself, since that may be part of
95 *****************************************************************************/
96 void evel_free_internal_event(EVENT_INTERNAL * event)
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);
108 /***************************************************************************/
109 /* Free the header itself. */
110 /***************************************************************************/
111 evel_free_header(&event->header);