1 /**************************************************************************//**
3 * Implementation of EVEL functions relating to the internal events.
5 * Internal events are never expected to be sent to the JSON API but comply
6 * with interfaces for regular event types. The primary use-case is to enable
7 * the foreground processing to communicate with the background event handling
8 * processing in an orderly fashion. At present the only use is to initiate an
9 * orderly shutdown of the Event Handler thread.
14 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
16 * Licensed under the Apache License, Version 2.0 (the "License");
17 * you may not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 * http://www.apache.org/licenses/LICENSE-2.0
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
26 *****************************************************************************/
33 #include "evel_internal.h"
36 /**************************************************************************//**
37 * Create a new internal event.
39 * @note The mandatory fields on the Fault must be supplied to this factory
40 * function and are immutable once set. Optional fields have explicit
41 * setter functions, but again values may only be set once so that the
42 * Fault has immutable properties.
43 * @param command The condition indicated by the event.
44 * @returns pointer to the newly manufactured ::EVENT_INTERNAL. If the event
45 * is not used (i.e. posted) it must be released using
47 * @retval NULL Failed to create the event.
48 *****************************************************************************/
49 EVENT_INTERNAL * evel_new_internal_event(EVT_HANDLER_COMMAND command)
51 EVENT_INTERNAL * event = NULL;
54 /***************************************************************************/
55 /* Check preconditions. */
56 /***************************************************************************/
57 assert(command < EVT_CMD_MAX_COMMANDS);
59 /***************************************************************************/
60 /* Allocate the fault. */
61 /***************************************************************************/
62 event = malloc(sizeof(EVENT_INTERNAL));
65 log_error_state("Out of memory");
68 memset(event, 0, sizeof(EVENT_INTERNAL));
69 EVEL_DEBUG("New internal event is at %lp", event);
71 /***************************************************************************/
72 /* Initialize the header & the event fields. */
73 /***************************************************************************/
74 evel_init_header(&event->header);
75 event->header.event_domain = EVEL_DOMAIN_INTERNAL;
76 event->command = command;
83 /**************************************************************************//**
84 * Free an internal event.
86 * Free off the event supplied. Will free all the contained allocated memory.
88 * @note It does not free the internal event itself, since that may be part of
90 *****************************************************************************/
91 void evel_free_internal_event(EVENT_INTERNAL * event)
96 /***************************************************************************/
97 /* Check preconditions. As an internal API we don't allow freeing NULL */
98 /* events as we do on the public API. */
99 /***************************************************************************/
100 assert(event != NULL);
101 assert(event->header.event_domain == EVEL_DOMAIN_INTERNAL);
103 /***************************************************************************/
104 /* Free the header itself. */
105 /***************************************************************************/
106 evel_free_header(&event->header);