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(c) <2016>, AT&T Intellectual Property. All other rights reserved.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions are met:
19 * 1. Redistributions of source code must retain the above copyright notice,
20 * this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright notice,
22 * this list of conditions and the following disclaimer in the documentation
23 * and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement: This product includes
26 * software developed by the AT&T.
27 * 4. Neither the name of AT&T nor the names of its contributors may be used to
28 * endorse or promote products derived from this software without specific
29 * prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY
32 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY
35 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *****************************************************************************/
48 #include "evel_internal.h"
51 /**************************************************************************//**
52 * Create a new internal event.
54 * @note The mandatory fields on the Fault must be supplied to this factory
55 * function and are immutable once set. Optional fields have explicit
56 * setter functions, but again values may only be set once so that the
57 * Fault has immutable properties.
58 * @param command The condition indicated by the event.
59 * @returns pointer to the newly manufactured ::EVENT_INTERNAL. If the event
60 * is not used (i.e. posted) it must be released using
62 * @retval NULL Failed to create the event.
63 *****************************************************************************/
64 EVENT_INTERNAL * evel_new_internal_event(EVT_HANDLER_COMMAND command)
66 EVENT_INTERNAL * event = NULL;
69 /***************************************************************************/
70 /* Check preconditions. */
71 /***************************************************************************/
72 assert(command < EVT_CMD_MAX_COMMANDS);
74 /***************************************************************************/
75 /* Allocate the fault. */
76 /***************************************************************************/
77 event = malloc(sizeof(EVENT_INTERNAL));
80 log_error_state("Out of memory");
83 memset(event, 0, sizeof(EVENT_INTERNAL));
84 EVEL_DEBUG("New internal event is at %lp", event);
86 /***************************************************************************/
87 /* Initialize the header & the event fields. */
88 /***************************************************************************/
89 evel_init_header(&event->header);
90 event->header.event_domain = EVEL_DOMAIN_INTERNAL;
91 event->command = command;
98 /**************************************************************************//**
99 * Free an internal event.
101 * Free off the event supplied. Will free all the contained allocated memory.
103 * @note It does not free the internal event itself, since that may be part of
104 * a larger structure.
105 *****************************************************************************/
106 void evel_free_internal_event(EVENT_INTERNAL * event)
111 /***************************************************************************/
112 /* Check preconditions. As an internal API we don't allow freeing NULL */
113 /* events as we do on the public API. */
114 /***************************************************************************/
115 assert(event != NULL);
116 assert(event->header.event_domain == EVEL_DOMAIN_INTERNAL);
118 /***************************************************************************/
119 /* Free the header itself. */
120 /***************************************************************************/
121 evel_free_header(&event->header);