libamxp  1.4.0
Patterns C Implementation
amxp_signal.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 
55 
56 #if !defined(__AMXP_SIGNAL_H__)
57 #define __AMXP_SIGNAL_H__
58 
59 #ifdef __cplusplus
60 extern "C"
61 {
62 #endif
63 
64 #include <amxc/amxc_variant.h>
65 
103 typedef struct _amxp_signal_mngr {
104  amxc_htable_t signals;
105  amxc_lqueue_t signal_queue;
106  amxc_llist_t regexp_slots;
107  amxc_llist_it_t it;
108  bool enabled;
109  bool deleted;
110  bool triggered;
111  bool suspended;
113 
119 typedef struct _amxp_signal {
120  amxc_htable_it_t hit;
121  amxc_llist_t slots;
122  const char* name;
124  bool triggered;
126 
137 typedef void (* amxp_deferred_fn_t) (const amxc_var_t* const data,
138  void* const priv);
152 int amxp_sigmngr_new(amxp_signal_mngr_t** sig_mngr);
153 
168 
183 
198 
215 int amxp_sigmngr_add_signal(amxp_signal_mngr_t* const sig_mngr,
216  const char* name);
217 
242  const char* name);
263  const char* name);
264 
283  const char* name,
284  const amxc_var_t* const data);
285 
311 int amxp_sigmngr_emit_signal(const amxp_signal_mngr_t* const sig_mngr,
312  const char* name,
313  const amxc_var_t* const data);
314 
342  const amxc_var_t* const data,
343  void* priv);
359 int amxp_sigmngr_enable(amxp_signal_mngr_t* const sig_mngr,
360  bool enable);
361 
381 int amxp_sigmngr_suspend(amxp_signal_mngr_t* const sig_mngr);
382 
401 int amxp_sigmngr_resume(amxp_signal_mngr_t* const sig_mngr);
402 
422 int amxp_signal_new(amxp_signal_mngr_t* sig_mngr,
423  amxp_signal_t** signal,
424  const char* name);
425 
443 int amxp_signal_delete(amxp_signal_t** signal);
444 
459 void amxp_signal_trigger(amxp_signal_t* const signal,
460  const amxc_var_t* const data);
461 
478 int amxp_signal_emit(const amxp_signal_t* const signal,
479  const amxc_var_t* const data);
480 
495 int amxp_signal_read(void);
496 
505 int amxp_signal_fd(void);
506 
517 int amxp_signal_disconnect_all(amxp_signal_t* const signal);
518 
529 const char* amxp_signal_name(const amxp_signal_t* const signal);
530 
541 bool amxp_signal_has_slots(const amxp_signal_t* const signal);
542 
543 #ifdef __cplusplus
544 }
545 #endif
546 
547 #endif // __AMXP_SIGNAL_H__
int amxp_sigmngr_add_signal(amxp_signal_mngr_t *const sig_mngr, const char *name)
Adds a signal to a signal manager.
Definition: amxp_signal.c:433
struct _amxp_signal_mngr amxp_signal_mngr_t
Structure containing the signal manager information.
int amxp_sigmngr_init(amxp_signal_mngr_t *sig_mngr)
Initializing function, initializes members of the amxp_signal_mngr_t structure.
Definition: amxp_signal.c:377
int amxp_sigmngr_new(amxp_signal_mngr_t **sig_mngr)
Constructor function, creates a new signal manager instance.
Definition: amxp_signal.c:330
int amxp_sigmngr_clean(amxp_signal_mngr_t *sig_mngr)
Clean-up functions, cleans-up all members of a amxp_signal_mngr_t structure.
Definition: amxp_signal.c:405
void amxp_sigmngr_trigger_signal(amxp_signal_mngr_t *const sig_mngr, const char *name, const amxc_var_t *const data)
Triggers a signal.
Definition: amxp_signal.c:492
int amxp_sigmngr_remove_signal(amxp_signal_mngr_t *const sig_mngr, const char *name)
Removes a signal from a signal manager.
Definition: amxp_signal.c:448
amxp_signal_t * amxp_sigmngr_find_signal(const amxp_signal_mngr_t *const sig_mngr, const char *name)
Get the pointer to the signal.
Definition: amxp_signal.c:475
int amxp_sigmngr_delete(amxp_signal_mngr_t **sig_mngr)
Destructor function, deletes a signal manager instance.
Definition: amxp_signal.c:349
int amxp_sigmngr_suspend(amxp_signal_mngr_t *const sig_mngr)
Suspends the handling of signals for the signal manager.
Definition: amxp_signal.c:571
int amxp_sigmngr_deferred_call(amxp_signal_mngr_t *const sig_mngr, amxp_deferred_fn_t fn, const amxc_var_t *const data, void *priv)
Defers a function call.
Definition: amxp_signal.c:536
bool amxp_signal_has_slots(const amxp_signal_t *const signal)
Checks if the signal has slots conencted.
Definition: amxp_signal.c:821
int amxp_signal_read(void)
Reads from the amxp signal file descriptor.
Definition: amxp_signal.c:769
const char * amxp_signal_name(const amxp_signal_t *const signal)
Gets the name of the signal.
Definition: amxp_signal.c:817
int amxp_sigmngr_enable(amxp_signal_mngr_t *const sig_mngr, bool enable)
Enables or disables the signal manager.
Definition: amxp_signal.c:561
int amxp_signal_new(amxp_signal_mngr_t *sig_mngr, amxp_signal_t **signal, const char *name)
Constructor function, creates a new signal.
Definition: amxp_signal.c:620
void amxp_signal_trigger(amxp_signal_t *const signal, const amxc_var_t *const data)
Triggers a signal.
Definition: amxp_signal.c:691
int amxp_signal_emit(const amxp_signal_t *const signal, const amxc_var_t *const data)
Emits a signal.
Definition: amxp_signal.c:742
int amxp_sigmngr_resume(amxp_signal_mngr_t *const sig_mngr)
Resumes the handling of signals for the signal manager.
Definition: amxp_signal.c:595
struct _amxp_signal amxp_signal_t
Structure containing the signal information.
int amxp_signal_fd(void)
Gets the amxp signal file descriptor.
Definition: amxp_signal.c:841
int amxp_signal_disconnect_all(amxp_signal_t *const signal)
Disconnects all slots from the signal.
Definition: amxp_signal.c:806
int amxp_signal_delete(amxp_signal_t **signal)
Destructor function, deletes a signal.
Definition: amxp_signal.c:669
int amxp_sigmngr_emit_signal(const amxp_signal_mngr_t *const sig_mngr, const char *name, const amxc_var_t *const data)
Emits a signal.
Definition: amxp_signal.c:514
void(* amxp_deferred_fn_t)(const amxc_var_t *const data, void *const priv)
Deferred callback function signature.
Definition: amxp_signal.h:137
Structure containing the signal manager information.
Definition: amxp_signal.h:103
amxc_llist_it_t it
Definition: amxp_signal.h:107
amxc_htable_t signals
Definition: amxp_signal.h:104
amxc_lqueue_t signal_queue
Definition: amxp_signal.h:105
amxc_llist_t regexp_slots
Definition: amxp_signal.h:106
Structure containing the signal information.
Definition: amxp_signal.h:119
amxc_llist_t slots
Definition: amxp_signal.h:121
amxp_signal_mngr_t * mngr
Definition: amxp_signal.h:123
amxc_htable_it_t hit
Definition: amxp_signal.h:120
const char * name
Definition: amxp_signal.h:122