58 #define AST_MODULE "res_ais"
67 const SaEvtEventHandleT event_handle,
const SaSizeT event_datalen);
90 SaEvtSubscriptionIdT
id;
106 SaEvtChannelHandleT handle;
124 const SaEvtEventHandleT event_handle,
const SaSizeT event_datalen)
130 static unsigned char buf[4096];
131 struct ast_event *event_dup, *
event = (
void *) buf;
133 SaSizeT
len =
sizeof(buf);
135 if (event_datalen > len) {
137 "for the allocated size %u. Change the code to increase the size.\n",
138 (
unsigned int) event_datalen, (
unsigned int) len);
143 ast_debug(1,
"Ignoring event that's too small. %u < %u\n",
144 (
unsigned int) event_datalen,
149 ais_res = saEvtEventDataGet(event_handle, event, &len);
150 if (ais_res != SA_AIS_OK) {
164 memcpy(event_dup, event, len);
171 const char *filter_str = NULL;
186 SaEvtEventHandleT event_handle;
188 struct event_channel *event_channel = data;
189 SaClmClusterNodeT local_node;
190 SaEvtEventPatternArrayT pattern_array;
191 SaEvtEventPatternT pattern;
193 const char *filter_str;
194 SaEvtEventIdT event_id;
204 ais_res = saEvtEventAllocate(event_channel->
handle, &event_handle);
205 if (ais_res != SA_AIS_OK) {
211 ais_res = saClmClusterNodeGet(
clm_handle, SA_CLM_LOCAL_NODE_ID,
212 SA_TIME_ONE_SECOND, &local_node);
213 if (ais_res != SA_AIS_OK) {
215 goto return_event_free;
219 len = strlen(filter_str) + 1;
220 pattern.pattern = (SaUint8T *) filter_str;
221 pattern.patternSize =
len;
222 pattern.allocatedSize =
len;
224 pattern_array.allocatedNumber = 1;
225 pattern_array.patternsNumber = 1;
226 pattern_array.patterns = &pattern;
232 ais_res = saEvtEventAttributesSet(event_handle, &pattern_array,
233 SA_EVT_LOWEST_PRIORITY, SA_TIME_ONE_MINUTE, &local_node.nodeName);
234 if (ais_res != SA_AIS_OK) {
236 goto return_event_free;
240 ais_res = saEvtEventPublish(event_handle,
242 if (ais_res != SA_AIS_ERR_TRY_AGAIN) {
248 if (ais_res != SA_AIS_OK) {
250 goto return_event_free;
254 ais_res = saEvtEventFree(event_handle);
255 if (ais_res != SA_AIS_OK) {
263 struct event_channel *event_channel;
267 e->
command =
"ais evt show event channels";
269 "Usage: ais evt show event channels\n"
270 " List configured event channels for the (EVT) Eventing service.\n";
281 "=============================================================\n"
282 "=== Event Channels ==========================================\n"
283 "=============================================================\n"
288 struct publish_event *publish_event;
291 ast_cli(a->
fd,
"=== ---------------------------------------------------------\n"
292 "=== Event Channel Name: %s\n", event_channel->
name);
295 ast_cli(a->
fd,
"=== ==> Publishing Event Type: %s\n",
300 ast_cli(a->
fd,
"=== ==> Subscribing to Event Type: %s\n",
304 ast_cli(a->
fd,
"=== ---------------------------------------------------------\n"
309 ast_cli(a->
fd,
"=============================================================\n"
321 struct event_channel *ec;
325 struct publish_event *pe;
328 ast_debug(1,
"Dumping cache for event channel '%s'\n", ec->
name);
339 struct publish_event *publish_event;
349 ast_log(
LOG_WARNING,
"publish_event option given with invalid value '%s'\n", event_type);
357 if (!(publish_event =
ast_calloc(1,
sizeof(*publish_event)))) {
374 SaEvtEventFilterArrayT filter_array;
376 const char *filter_str = NULL;
382 filter.filterType = SA_EVT_EXACT_FILTER;
383 len = strlen(filter_str) + 1;
384 filter.filter.allocatedSize =
len;
385 filter.filter.patternSize =
len;
386 filter.filter.pattern = (SaUint8T *) filter_str;
388 filter_array.filtersNumber = 1;
389 filter_array.filters = &
filter;
391 ais_res = saEvtEventSubscribe(event_channel->
handle, &filter_array,
392 subscribe_event->
id);
412 ast_log(
LOG_WARNING,
"subscribe_event option given with invalid value '%s'\n", event_type);
420 if (!(subscribe_event =
ast_calloc(1,
sizeof(*subscribe_event)))) {
428 if (ais_res != SA_AIS_OK) {
431 free(subscribe_event);
441 struct event_channel *event_channel;
443 SaNameT sa_name = { 0, };
447 if (!strcasecmp(event_channel->
name, cat))
453 "configuration. Second instance ignored.\n", cat);
457 if (!(event_channel =
ast_calloc(1,
sizeof(*event_channel) + strlen(cat))))
460 strcpy(event_channel->
name, cat);
462 sa_name.length = strlen((
char *) sa_name.value);
463 ais_res = saEvtChannelOpen(
evt_handle, &sa_name,
464 SA_EVT_CHANNEL_PUBLISHER | SA_EVT_CHANNEL_SUBSCRIBER | SA_EVT_CHANNEL_CREATE,
465 SA_TIME_MAX, &event_channel->
handle);
466 if (ais_res != SA_AIS_OK) {
473 if (!strcasecmp(var->
name,
"type")) {
475 }
else if (!strcasecmp(var->
name,
"publish_event")) {
477 }
else if (!strcasecmp(var->
name,
"subscribe_event")) {
492 static const char filename[] =
"ais.conf";
494 const char *cat = NULL;
503 if (!strcasecmp(cat,
"general"))
512 if (!strcasecmp(type,
"event_channel")) {
537 ais_res = saEvtEventUnsubscribe(event_channel->
handle, subscribe_event->
id);
538 if (ais_res != SA_AIS_OK) {
542 free(subscribe_event);
547 struct publish_event *publish_event;
556 ais_res = saEvtChannelClose(event_channel->
handle);
557 if (ais_res != SA_AIS_OK) {
567 struct event_channel *event_channel;
603 if (ais_res != SA_AIS_OK) {
struct event_channel::@356 publish_events
#define AST_CLI_DEFINE(fn, txt,...)
void evt_event_deliver_cb(SaEvtSubscriptionIdT subscription_id, const SaEvtEventHandleT event_handle, const SaSizeT event_datalen)
Asterisk main include file. File version handling, generic pbx functions.
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
static struct ast_cli_entry ais_cli[]
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
int ast_ais_evt_load_module(void)
enum ast_event_type ast_event_get_type(const struct ast_event *event)
Get the type for an event.
void ast_ais_evt_membership_changed(void)
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
static void add_publish_event(struct event_channel *event_channel, const char *event_type)
int ast_event_queue_and_cache(struct ast_event *event)
Queue and cache an event.
descriptor for a cli entry.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
static void event_channel_destroy(struct event_channel *event_channel)
static void load_config(void)
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
static void queue_event(struct ast_event *ast_event)
Structure for variables, used for configurations and for channel variables.
int ast_enable_distributed_devstate(void)
Enable distributed device state processing.
struct subscribe_event::@354 entry
static char * ais_evt_show_event_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Configuration File Parser.
static const SaEvtCallbacksT evt_callbacks
static void publish_event_destroy(struct publish_event *publish_event)
static void add_subscribe_event(struct event_channel *event_channel, const char *event_type)
void ast_cli(int fd, const char *fmt,...)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return * the previous value of *p. This can be used to handle reference co...
Entity ID Used by All events Payload type: RAW This IE indicates which server the event originated fr...
static void build_event_channel(struct ast_config *cfg, const char *cat)
int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2)
Compare two EIDs.
int args
This gets set in ast_cli_register()
static void subscribe_event_destroy(const struct event_channel *event_channel, struct subscribe_event *subscribe_event)
static struct @353 supported_event_types[]
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define ast_debug(level,...)
Log a DEBUG message.
ast_event_type
Event types.
#define ast_config_load(filename, flags)
Load a config file.
Usage of the SAForum AIS (Application Interface Specification)
#define AST_RWLIST_TRAVERSE
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
A set of macros to manage forward-linked lists.
void evt_channel_open_cb(SaInvocationT invocation, SaEvtChannelHandleT channel_handle, SaAisErrorT error)
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
const void * ast_event_get_ie_raw(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has a raw payload.
void ast_event_dump_cache(const struct ast_event_sub *event_sub)
Dump the event cache for the subscriber.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
static const char * type_to_filter_str(enum ast_event_type type)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void ast_event_cb(const struct ast_event *ast_event, void *data)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
struct ast_event_sub * sub
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
int ast_ais_evt_unload_module(void)
size_t ast_event_minimum_length(void)
Get the minimum length of an ast_event.
#define AST_RWLIST_REMOVE_HEAD
Structure used to handle boolean flags.
Support for logging to various files, console and syslog Configuration in file logger.conf.
struct ast_eid ast_eid_default
Global EID.
static void destroy_event_channels(void)
#define AST_RWLIST_INSERT_TAIL
SaEvtChannelHandleT handle
Standard Command Line Interface.
struct ast_event_sub * ast_event_subscribe(enum ast_event_type event_type, ast_event_cb_t cb, const char *description, void *userdata,...)
Subscribe to events.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
const char * ais_err2str(SaAisErrorT error)
static SaAisErrorT evt_init_res
static SaAisErrorT set_egress_subscription(struct event_channel *event_channel, struct subscribe_event *subscribe_event)
size_t ast_event_get_size(const struct ast_event *event)
Get the size of an event.
struct ast_variable * next
#define CONFIG_STATUS_FILEINVALID
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Asterisk module definitions.
struct ast_event_sub * ast_event_unsubscribe(struct ast_event_sub *event_sub)
Un-subscribe from events.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.