#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "ais.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/cli.h"
#include "asterisk/logger.h"
#include "asterisk/event.h"
#include "asterisk/config.h"
#include "asterisk/linkedlists.h"
#include "asterisk/devicestate.h"
Go to the source code of this file.
Data Structures | |
struct | event_channel |
struct | event_channels |
struct | publish_event |
struct | subscribe_event |
Defines | |
#define | AST_MODULE "res_ais" |
Functions | |
static void | add_publish_event (struct event_channel *event_channel, const char *event_type) |
static void | add_subscribe_event (struct event_channel *event_channel, const char *event_type) |
static char * | ais_evt_show_event_channels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
int | ast_ais_evt_load_module (void) |
void | ast_ais_evt_membership_changed (void) |
int | ast_ais_evt_unload_module (void) |
static void | ast_event_cb (const struct ast_event *ast_event, void *data) |
ASTERISK_FILE_VERSION (__FILE__,"$Revision: 369001 $") | |
static void | build_event_channel (struct ast_config *cfg, const char *cat) |
static void | destroy_event_channels (void) |
static void | event_channel_destroy (struct event_channel *event_channel) |
void | evt_channel_open_cb (SaInvocationT invocation, SaEvtChannelHandleT channel_handle, SaAisErrorT error) |
void | evt_event_deliver_cb (SaEvtSubscriptionIdT subscription_id, const SaEvtEventHandleT event_handle, const SaSizeT event_datalen) |
static void | load_config (void) |
static void | publish_event_destroy (struct publish_event *publish_event) |
static void | queue_event (struct ast_event *ast_event) |
static SaAisErrorT | set_egress_subscription (struct event_channel *event_channel, struct subscribe_event *subscribe_event) |
static void | subscribe_event_destroy (const struct event_channel *event_channel, struct subscribe_event *subscribe_event) |
static const char * | type_to_filter_str (enum ast_event_type type) |
Variables | |
static struct ast_cli_entry | ais_cli [] |
static const SaEvtCallbacksT | evt_callbacks |
SaEvtHandleT | evt_handle |
static SaAisErrorT | evt_init_res |
struct { | |
const char * str | |
enum ast_event_type type | |
} | supported_event_types [] |
static int | unique_id |
Definition in file evt.c.
static void add_publish_event | ( | struct event_channel * | event_channel, | |
const char * | event_type | |||
) | [static] |
Definition at line 335 of file evt.c.
References ARRAY_LEN, ast_calloc, ast_enable_distributed_devstate(), ast_event_cb(), AST_EVENT_DEVICE_STATE_CHANGE, ast_event_dump_cache(), AST_EVENT_IE_END, ast_event_subscribe(), AST_LIST_INSERT_TAIL, ast_log(), subscribe_event::entry, LOG_DEBUG, LOG_WARNING, event_channel::publish_events, str, and supported_event_types.
Referenced by build_event_channel().
00336 { 00337 int i; 00338 enum ast_event_type type = -1; 00339 struct publish_event *publish_event; 00340 00341 for (i = 0; i < ARRAY_LEN(supported_event_types); i++) { 00342 if (!strcasecmp(event_type, supported_event_types[i].str)) { 00343 type = supported_event_types[i].type; 00344 break; 00345 } 00346 } 00347 00348 if (type == -1) { 00349 ast_log(LOG_WARNING, "publish_event option given with invalid value '%s'\n", event_type); 00350 return; 00351 } 00352 00353 if (type == AST_EVENT_DEVICE_STATE_CHANGE && ast_enable_distributed_devstate()) { 00354 return; 00355 } 00356 00357 if (!(publish_event = ast_calloc(1, sizeof(*publish_event)))) { 00358 return; 00359 } 00360 00361 publish_event->type = type; 00362 ast_log(LOG_DEBUG, "Subscribing to event type %d\n", type); 00363 publish_event->sub = ast_event_subscribe(type, ast_event_cb, "AIS", event_channel, 00364 AST_EVENT_IE_END); 00365 ast_event_dump_cache(publish_event->sub); 00366 00367 AST_LIST_INSERT_TAIL(&event_channel->publish_events, publish_event, entry); 00368 }
static void add_subscribe_event | ( | struct event_channel * | event_channel, | |
const char * | event_type | |||
) | [static] |
Definition at line 397 of file evt.c.
References ais_err2str(), ARRAY_LEN, ast_atomic_fetchadd_int(), ast_calloc, ast_enable_distributed_devstate(), AST_EVENT_DEVICE_STATE_CHANGE, AST_LIST_INSERT_TAIL, ast_log(), subscribe_event::entry, free, LOG_ERROR, LOG_WARNING, set_egress_subscription(), str, event_channel::subscribe_events, supported_event_types, and unique_id.
00398 { 00399 int i; 00400 enum ast_event_type type = -1; 00401 struct subscribe_event *subscribe_event; 00402 SaAisErrorT ais_res; 00403 00404 for (i = 0; i < ARRAY_LEN(supported_event_types); i++) { 00405 if (!strcasecmp(event_type, supported_event_types[i].str)) { 00406 type = supported_event_types[i].type; 00407 break; 00408 } 00409 } 00410 00411 if (type == -1) { 00412 ast_log(LOG_WARNING, "subscribe_event option given with invalid value '%s'\n", event_type); 00413 return; 00414 } 00415 00416 if (type == AST_EVENT_DEVICE_STATE_CHANGE && ast_enable_distributed_devstate()) { 00417 return; 00418 } 00419 00420 if (!(subscribe_event = ast_calloc(1, sizeof(*subscribe_event)))) { 00421 return; 00422 } 00423 00424 subscribe_event->type = type; 00425 subscribe_event->id = ast_atomic_fetchadd_int(&unique_id, +1); 00426 00427 ais_res = set_egress_subscription(event_channel, subscribe_event); 00428 if (ais_res != SA_AIS_OK) { 00429 ast_log(LOG_ERROR, "Error setting up egress subscription: %s\n", 00430 ais_err2str(ais_res)); 00431 free(subscribe_event); 00432 return; 00433 } 00434 00435 AST_LIST_INSERT_TAIL(&event_channel->subscribe_events, subscribe_event, entry); 00436 }
static char* ais_evt_show_event_channels | ( | struct ast_cli_entry * | e, | |
int | cmd, | |||
struct ast_cli_args * | a | |||
) | [static] |
Definition at line 261 of file evt.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli(), AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, subscribe_event::entry, ast_cli_args::fd, event_channel::name, event_channel::publish_events, event_channel::subscribe_events, subscribe_event::type, publish_event::type, type_to_filter_str(), and ast_cli_entry::usage.
00262 { 00263 struct event_channel *event_channel; 00264 00265 switch (cmd) { 00266 case CLI_INIT: 00267 e->command = "ais evt show event channels"; 00268 e->usage = 00269 "Usage: ais evt show event channels\n" 00270 " List configured event channels for the (EVT) Eventing service.\n"; 00271 return NULL; 00272 00273 case CLI_GENERATE: 00274 return NULL; /* no completion */ 00275 } 00276 00277 if (a->argc != e->args) 00278 return CLI_SHOWUSAGE; 00279 00280 ast_cli(a->fd, "\n" 00281 "=============================================================\n" 00282 "=== Event Channels ==========================================\n" 00283 "=============================================================\n" 00284 "===\n"); 00285 00286 AST_RWLIST_RDLOCK(&event_channels); 00287 AST_RWLIST_TRAVERSE(&event_channels, event_channel, entry) { 00288 struct publish_event *publish_event; 00289 struct subscribe_event *subscribe_event; 00290 00291 ast_cli(a->fd, "=== ---------------------------------------------------------\n" 00292 "=== Event Channel Name: %s\n", event_channel->name); 00293 00294 AST_LIST_TRAVERSE(&event_channel->publish_events, publish_event, entry) { 00295 ast_cli(a->fd, "=== ==> Publishing Event Type: %s\n", 00296 type_to_filter_str(publish_event->type)); 00297 } 00298 00299 AST_LIST_TRAVERSE(&event_channel->subscribe_events, subscribe_event, entry) { 00300 ast_cli(a->fd, "=== ==> Subscribing to Event Type: %s\n", 00301 type_to_filter_str(subscribe_event->type)); 00302 } 00303 00304 ast_cli(a->fd, "=== ---------------------------------------------------------\n" 00305 "===\n"); 00306 } 00307 AST_RWLIST_UNLOCK(&event_channels); 00308 00309 ast_cli(a->fd, "=============================================================\n" 00310 "\n"); 00311 00312 return CLI_SUCCESS; 00313 }
int ast_ais_evt_load_module | ( | void | ) |
Definition at line 576 of file evt.c.
References ais_cli, ais_err2str(), ais_version, ARRAY_LEN, ast_cli_register_multiple(), ast_log(), evt_callbacks, evt_handle, evt_init_res, load_config(), and LOG_ERROR.
Referenced by load_module().
00577 { 00578 evt_init_res = saEvtInitialize(&evt_handle, &evt_callbacks, &ais_version); 00579 if (evt_init_res != SA_AIS_OK) { 00580 ast_log(LOG_ERROR, "Could not initialize eventing service: %s\n", 00581 ais_err2str(evt_init_res)); 00582 return -1; 00583 } 00584 00585 load_config(); 00586 00587 ast_cli_register_multiple(ais_cli, ARRAY_LEN(ais_cli)); 00588 00589 return 0; 00590 }
void ast_ais_evt_membership_changed | ( | void | ) |
Definition at line 319 of file evt.c.
References ast_debug, ast_event_dump_cache(), AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, subscribe_event::entry, event_channel::name, event_channel::publish_events, and publish_event::sub.
Referenced by dispatch_thread_handler().
00320 { 00321 struct event_channel *ec; 00322 00323 AST_RWLIST_RDLOCK(&event_channels); 00324 AST_RWLIST_TRAVERSE(&event_channels, ec, entry) { 00325 struct publish_event *pe; 00326 00327 AST_LIST_TRAVERSE(&ec->publish_events, pe, entry) { 00328 ast_debug(1, "Dumping cache for event channel '%s'\n", ec->name); 00329 ast_event_dump_cache(pe->sub); 00330 } 00331 } 00332 AST_RWLIST_UNLOCK(&event_channels); 00333 }
int ast_ais_evt_unload_module | ( | void | ) |
Definition at line 592 of file evt.c.
References ais_err2str(), ast_log(), destroy_event_channels(), evt_handle, evt_init_res, and LOG_ERROR.
Referenced by load_module(), and unload_module().
00593 { 00594 SaAisErrorT ais_res; 00595 00596 if (evt_init_res != SA_AIS_OK) { 00597 return 0; 00598 } 00599 00600 destroy_event_channels(); 00601 00602 ais_res = saEvtFinalize(evt_handle); 00603 if (ais_res != SA_AIS_OK) { 00604 ast_log(LOG_ERROR, "Problem stopping eventing service: %s\n", 00605 ais_err2str(ais_res)); 00606 return -1; 00607 } 00608 00609 return 0; 00610 }
static void ast_event_cb | ( | const struct ast_event * | ast_event, | |
void * | data | |||
) | [static] |
Definition at line 184 of file evt.c.
References ais_err2str(), ast_eid_cmp(), ast_eid_default, ast_event_get_ie_raw(), ast_event_get_size(), ast_event_get_type(), AST_EVENT_IE_EID, ast_log(), clm_handle, event_channel::handle, len(), LOG_DEBUG, LOG_ERROR, and type_to_filter_str().
Referenced by add_publish_event().
00185 { 00186 SaEvtEventHandleT event_handle; 00187 SaAisErrorT ais_res; 00188 struct event_channel *event_channel = data; 00189 SaClmClusterNodeT local_node; 00190 SaEvtEventPatternArrayT pattern_array; 00191 SaEvtEventPatternT pattern; 00192 SaSizeT len; 00193 const char *filter_str; 00194 SaEvtEventIdT event_id; 00195 00196 ast_log(LOG_DEBUG, "Got an event to forward\n"); 00197 00198 if (ast_eid_cmp(&ast_eid_default, ast_event_get_ie_raw(ast_event, AST_EVENT_IE_EID))) { 00199 /* If the event didn't originate from this server, don't send it back out. */ 00200 ast_log(LOG_DEBUG, "Returning here\n"); 00201 return; 00202 } 00203 00204 ais_res = saEvtEventAllocate(event_channel->handle, &event_handle); 00205 if (ais_res != SA_AIS_OK) { 00206 ast_log(LOG_ERROR, "Error allocating event: %s\n", ais_err2str(ais_res)); 00207 ast_log(LOG_DEBUG, "Returning here\n"); 00208 return; 00209 } 00210 00211 ais_res = saClmClusterNodeGet(clm_handle, SA_CLM_LOCAL_NODE_ID, 00212 SA_TIME_ONE_SECOND, &local_node); 00213 if (ais_res != SA_AIS_OK) { 00214 ast_log(LOG_ERROR, "Error getting local node name: %s\n", ais_err2str(ais_res)); 00215 goto return_event_free; 00216 } 00217 00218 filter_str = type_to_filter_str(ast_event_get_type(ast_event)); 00219 len = strlen(filter_str) + 1; 00220 pattern.pattern = (SaUint8T *) filter_str; 00221 pattern.patternSize = len; 00222 pattern.allocatedSize = len; 00223 00224 pattern_array.allocatedNumber = 1; 00225 pattern_array.patternsNumber = 1; 00226 pattern_array.patterns = &pattern; 00227 00228 /*! 00229 * /todo Make retention time configurable 00230 * /todo Make event priorities configurable 00231 */ 00232 ais_res = saEvtEventAttributesSet(event_handle, &pattern_array, 00233 SA_EVT_LOWEST_PRIORITY, SA_TIME_ONE_MINUTE, &local_node.nodeName); 00234 if (ais_res != SA_AIS_OK) { 00235 ast_log(LOG_ERROR, "Error setting event attributes: %s\n", ais_err2str(ais_res)); 00236 goto return_event_free; 00237 } 00238 00239 for (;;) { 00240 ais_res = saEvtEventPublish(event_handle, 00241 ast_event, ast_event_get_size(ast_event), &event_id); 00242 if (ais_res != SA_AIS_ERR_TRY_AGAIN) { 00243 break; 00244 } 00245 sched_yield(); 00246 } 00247 00248 if (ais_res != SA_AIS_OK) { 00249 ast_log(LOG_ERROR, "Error publishing event: %s\n", ais_err2str(ais_res)); 00250 goto return_event_free; 00251 } 00252 00253 return_event_free: 00254 ais_res = saEvtEventFree(event_handle); 00255 if (ais_res != SA_AIS_OK) { 00256 ast_log(LOG_ERROR, "Error freeing allocated event: %s\n", ais_err2str(ais_res)); 00257 } 00258 ast_log(LOG_DEBUG, "Returning here (event_free)\n"); 00259 }
ASTERISK_FILE_VERSION | ( | __FILE__ | , | |
"$Revision: 369001 $" | ||||
) |
static void build_event_channel | ( | struct ast_config * | cfg, | |
const char * | cat | |||
) | [static] |
Definition at line 438 of file evt.c.
References add_publish_event(), ais_err2str(), ast_calloc, ast_copy_string(), ast_log(), AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_variable_browse(), subscribe_event::entry, evt_handle, free, LOG_ERROR, LOG_WARNING, event_channel::name, and var.
Referenced by load_config().
00439 { 00440 struct ast_variable *var; 00441 struct event_channel *event_channel; 00442 SaAisErrorT ais_res; 00443 SaNameT sa_name = { 0, }; 00444 00445 AST_RWLIST_WRLOCK(&event_channels); 00446 AST_RWLIST_TRAVERSE(&event_channels, event_channel, entry) { 00447 if (!strcasecmp(event_channel->name, cat)) 00448 break; 00449 } 00450 AST_RWLIST_UNLOCK(&event_channels); 00451 if (event_channel) { 00452 ast_log(LOG_WARNING, "Event channel '%s' was specified twice in " 00453 "configuration. Second instance ignored.\n", cat); 00454 return; 00455 } 00456 00457 if (!(event_channel = ast_calloc(1, sizeof(*event_channel) + strlen(cat)))) 00458 return; 00459 00460 strcpy(event_channel->name, cat); 00461 ast_copy_string((char *) sa_name.value, cat, sizeof(sa_name.value)); 00462 sa_name.length = strlen((char *) sa_name.value); 00463 ais_res = saEvtChannelOpen(evt_handle, &sa_name, 00464 SA_EVT_CHANNEL_PUBLISHER | SA_EVT_CHANNEL_SUBSCRIBER | SA_EVT_CHANNEL_CREATE, 00465 SA_TIME_MAX, &event_channel->handle); 00466 if (ais_res != SA_AIS_OK) { 00467 ast_log(LOG_ERROR, "Error opening event channel: %s\n", ais_err2str(ais_res)); 00468 free(event_channel); 00469 return; 00470 } 00471 00472 for (var = ast_variable_browse(cfg, cat); var; var = var->next) { 00473 if (!strcasecmp(var->name, "type")) { 00474 continue; 00475 } else if (!strcasecmp(var->name, "publish_event")) { 00476 add_publish_event(event_channel, var->value); 00477 } else if (!strcasecmp(var->name, "subscribe_event")) { 00478 add_subscribe_event(event_channel, var->value); 00479 } else { 00480 ast_log(LOG_WARNING, "Event channel '%s' contains invalid option '%s'\n", 00481 event_channel->name, var->name); 00482 } 00483 } 00484 00485 AST_RWLIST_WRLOCK(&event_channels); 00486 AST_RWLIST_INSERT_TAIL(&event_channels, event_channel, entry); 00487 AST_RWLIST_UNLOCK(&event_channels); 00488 }
static void destroy_event_channels | ( | void | ) | [static] |
Definition at line 565 of file evt.c.
References AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, event_channel::entry, and event_channel_destroy().
Referenced by ast_ais_evt_unload_module().
00566 { 00567 struct event_channel *event_channel; 00568 00569 AST_RWLIST_WRLOCK(&event_channels); 00570 while ((event_channel = AST_RWLIST_REMOVE_HEAD(&event_channels, entry))) { 00571 event_channel_destroy(event_channel); 00572 } 00573 AST_RWLIST_UNLOCK(&event_channels); 00574 }
static void event_channel_destroy | ( | struct event_channel * | event_channel | ) | [static] |
Definition at line 545 of file evt.c.
References ais_err2str(), AST_LIST_REMOVE_HEAD, ast_log(), subscribe_event::entry, free, LOG_ERROR, publish_event_destroy(), event_channel::publish_events, subscribe_event_destroy(), and event_channel::subscribe_events.
Referenced by destroy_event_channels().
00546 { 00547 struct publish_event *publish_event; 00548 struct subscribe_event *subscribe_event; 00549 SaAisErrorT ais_res; 00550 00551 while ((publish_event = AST_LIST_REMOVE_HEAD(&event_channel->publish_events, entry))) 00552 publish_event_destroy(publish_event); 00553 while ((subscribe_event = AST_LIST_REMOVE_HEAD(&event_channel->subscribe_events, entry))) 00554 subscribe_event_destroy(event_channel, subscribe_event); 00555 00556 ais_res = saEvtChannelClose(event_channel->handle); 00557 if (ais_res != SA_AIS_OK) { 00558 ast_log(LOG_ERROR, "Error closing event channel '%s': %s\n", 00559 event_channel->name, ais_err2str(ais_res)); 00560 } 00561 00562 free(event_channel); 00563 }
void evt_channel_open_cb | ( | SaInvocationT | invocation, | |
SaEvtChannelHandleT | channel_handle, | |||
SaAisErrorT | error | |||
) |
void evt_event_deliver_cb | ( | SaEvtSubscriptionIdT | subscription_id, | |
const SaEvtEventHandleT | event_handle, | |||
const SaSizeT | event_datalen | |||
) |
Definition at line 123 of file evt.c.
References ais_err2str(), ast_debug, ast_eid_cmp(), ast_eid_default, ast_event_get_ie_raw(), AST_EVENT_IE_EID, ast_event_minimum_length(), ast_log(), ast_malloc, len(), LOG_ERROR, and queue_event().
00125 { 00126 /* It is important to note that this works because we *know* that this 00127 * function will only be called by a single thread, the dispatch_thread. 00128 * If this module gets changed such that this is no longer the case, this 00129 * should get changed to a thread-local buffer, instead. */ 00130 static unsigned char buf[4096]; 00131 struct ast_event *event_dup, *event = (void *) buf; 00132 SaAisErrorT ais_res; 00133 SaSizeT len = sizeof(buf); 00134 00135 if (event_datalen > len) { 00136 ast_log(LOG_ERROR, "Event received with size %u, which is too big\n" 00137 "for the allocated size %u. Change the code to increase the size.\n", 00138 (unsigned int) event_datalen, (unsigned int) len); 00139 return; 00140 } 00141 00142 if (event_datalen < ast_event_minimum_length()) { 00143 ast_debug(1, "Ignoring event that's too small. %u < %u\n", 00144 (unsigned int) event_datalen, 00145 (unsigned int) ast_event_minimum_length()); 00146 return; 00147 } 00148 00149 ais_res = saEvtEventDataGet(event_handle, event, &len); 00150 if (ais_res != SA_AIS_OK) { 00151 ast_log(LOG_ERROR, "Error retrieving event payload: %s\n", 00152 ais_err2str(ais_res)); 00153 return; 00154 } 00155 00156 if (!ast_eid_cmp(&ast_eid_default, ast_event_get_ie_raw(event, AST_EVENT_IE_EID))) { 00157 /* Don't feed events back in that originated locally. */ 00158 return; 00159 } 00160 00161 if (!(event_dup = ast_malloc(len))) 00162 return; 00163 00164 memcpy(event_dup, event, len); 00165 00166 queue_event(event_dup); 00167 }
static void load_config | ( | void | ) | [static] |
Definition at line 490 of file evt.c.
References ast_category_browse(), ast_config_destroy(), ast_config_load, ast_log(), ast_variable_retrieve(), build_event_channel(), CONFIG_STATUS_FILEINVALID, and LOG_WARNING.
00491 { 00492 static const char filename[] = "ais.conf"; 00493 struct ast_config *cfg; 00494 const char *cat = NULL; 00495 struct ast_flags config_flags = { 0 }; 00496 00497 if (!(cfg = ast_config_load(filename, config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) 00498 return; 00499 00500 while ((cat = ast_category_browse(cfg, cat))) { 00501 const char *type; 00502 00503 if (!strcasecmp(cat, "general")) 00504 continue; 00505 00506 if (!(type = ast_variable_retrieve(cfg, cat, "type"))) { 00507 ast_log(LOG_WARNING, "Invalid entry in %s defined with no type!\n", 00508 filename); 00509 continue; 00510 } 00511 00512 if (!strcasecmp(type, "event_channel")) { 00513 build_event_channel(cfg, cat); 00514 } else { 00515 ast_log(LOG_WARNING, "Entry in %s defined with invalid type '%s'\n", 00516 filename, type); 00517 } 00518 } 00519 00520 ast_config_destroy(cfg); 00521 }
static void publish_event_destroy | ( | struct publish_event * | publish_event | ) | [static] |
Definition at line 523 of file evt.c.
References ast_event_unsubscribe(), free, and publish_event::sub.
Referenced by event_channel_destroy().
00524 { 00525 ast_event_unsubscribe(publish_event->sub); 00526 00527 free(publish_event); 00528 }
static void queue_event | ( | struct ast_event * | ast_event | ) | [static] |
Definition at line 118 of file evt.c.
References ast_event_queue_and_cache().
Referenced by evt_event_deliver_cb().
00119 { 00120 ast_event_queue_and_cache(ast_event); 00121 }
static SaAisErrorT set_egress_subscription | ( | struct event_channel * | event_channel, | |
struct subscribe_event * | subscribe_event | |||
) | [static] |
Definition at line 370 of file evt.c.
References filter(), event_channel::handle, subscribe_event::id, len(), subscribe_event::type, and type_to_filter_str().
Referenced by add_subscribe_event().
00372 { 00373 SaAisErrorT ais_res; 00374 SaEvtEventFilterArrayT filter_array; 00375 SaEvtEventFilterT filter; 00376 const char *filter_str = NULL; 00377 SaSizeT len; 00378 00379 /* We know it's going to be valid. It was checked earlier. */ 00380 filter_str = type_to_filter_str(subscribe_event->type); 00381 00382 filter.filterType = SA_EVT_EXACT_FILTER; 00383 len = strlen(filter_str) + 1; 00384 filter.filter.allocatedSize = len; 00385 filter.filter.patternSize = len; 00386 filter.filter.pattern = (SaUint8T *) filter_str; 00387 00388 filter_array.filtersNumber = 1; 00389 filter_array.filters = &filter; 00390 00391 ais_res = saEvtEventSubscribe(event_channel->handle, &filter_array, 00392 subscribe_event->id); 00393 00394 return ais_res; 00395 }
static void subscribe_event_destroy | ( | const struct event_channel * | event_channel, | |
struct subscribe_event * | subscribe_event | |||
) | [static] |
Definition at line 530 of file evt.c.
References ais_err2str(), ast_log(), free, event_channel::handle, subscribe_event::id, and LOG_ERROR.
Referenced by event_channel_destroy().
00532 { 00533 SaAisErrorT ais_res; 00534 00535 /* saEvtChannelClose() will actually do this automatically, but it just 00536 * feels cleaner to go ahead and do it manually ... */ 00537 ais_res = saEvtEventUnsubscribe(event_channel->handle, subscribe_event->id); 00538 if (ais_res != SA_AIS_OK) { 00539 ast_log(LOG_ERROR, "Error unsubscribing: %s\n", ais_err2str(ais_res)); 00540 } 00541 00542 free(subscribe_event); 00543 }
static const char* type_to_filter_str | ( | enum ast_event_type | type | ) | [static] |
Definition at line 169 of file evt.c.
References ARRAY_LEN, and supported_event_types.
Referenced by ais_evt_show_event_channels(), ast_event_cb(), and set_egress_subscription().
00170 { 00171 const char *filter_str = NULL; 00172 int i; 00173 00174 for (i = 0; i < ARRAY_LEN(supported_event_types); i++) { 00175 if (supported_event_types[i].type == type) { 00176 filter_str = supported_event_types[i].str; 00177 break; 00178 } 00179 } 00180 00181 return filter_str; 00182 }
struct ast_cli_entry ais_cli[] [static] |
Initial value:
{ { .handler = ais_evt_show_event_channels , .summary = "Show configured event channels" ,__VA_ARGS__ }, }
const SaEvtCallbacksT evt_callbacks [static] |
Initial value:
{ .saEvtChannelOpenCallback = evt_channel_open_cb, .saEvtEventDeliverCallback = evt_event_deliver_cb, }
Definition at line 69 of file evt.c.
Referenced by ast_ais_evt_load_module().
SaEvtHandleT evt_handle |
Definition at line 61 of file evt.c.
Referenced by ast_ais_evt_load_module(), ast_ais_evt_unload_module(), build_event_channel(), and dispatch_thread_handler().
SaAisErrorT evt_init_res [static] |
Definition at line 62 of file evt.c.
Referenced by ast_ais_evt_load_module(), and ast_ais_evt_unload_module().
struct { ... } supported_event_types[] [static] |
Referenced by add_publish_event(), add_subscribe_event(), and type_to_filter_str().
enum ast_event_type type |
int unique_id [static] |
Used to provide unique id's to egress subscriptions
Definition at line 83 of file evt.c.
Referenced by add_subscribe_event().