Usage of the SAForum AIS (Application Interface Specification). More...
#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <pthread.h>
#include "ais/ais.h"
#include "asterisk/module.h"
#include "asterisk/options.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/utils.h"
#include "asterisk/cli.h"
Go to the source code of this file.
Data Structures | |
struct | ais_error |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
const char * | ais_err2str (SaAisErrorT error) |
int | ast_ais_cmd (enum ast_ais_cmd cmd) |
ASTERISK_FILE_VERSION (__FILE__,"$Revision: 359053 $") | |
static void * | dispatch_thread_handler (void *data) |
static int | load_module (void) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "SAForum AIS" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static struct ais_error | ais_errors [] |
SaVersionT | ais_version = { 'B', 1, 1 } |
static struct ast_module_info * | ast_module_info = &__mod_info |
struct { | |
int alert_pipe [2] | |
pthread_t id | |
unsigned int stop:1 | |
} | dispatch_thread |
Usage of the SAForum AIS (Application Interface Specification).
This file contains the common code between the uses of the different AIS services.
Definition in file res_ais.c.
const char* ais_err2str | ( | SaAisErrorT | error | ) |
Definition at line 105 of file res_ais.c.
References ais_errors, ARRAY_LEN, and ais_error::desc.
Referenced by add_subscribe_event(), ast_ais_clm_load_module(), ast_ais_clm_unload_module(), ast_ais_evt_load_module(), ast_ais_evt_unload_module(), ast_event_cb(), build_event_channel(), event_channel_destroy(), evt_event_deliver_cb(), and subscribe_event_destroy().
00106 { 00107 int x; 00108 00109 for (x = 0; x < ARRAY_LEN(ais_errors); x++) { 00110 if (ais_errors[x].error == error) 00111 return ais_errors[x].desc; 00112 } 00113 00114 return "Unknown"; 00115 }
int ast_ais_cmd | ( | enum ast_ais_cmd | cmd | ) |
Definition at line 182 of file res_ais.c.
References ast_debug, and dispatch_thread.
00183 { 00184 int res; 00185 00186 res = write(dispatch_thread.alert_pipe[1], (char *) &cmd, sizeof(cmd)); 00187 00188 ast_debug(1, "AIS cmd: %d, res: %d\n", cmd, res); 00189 00190 return res; 00191 }
ASTERISK_FILE_VERSION | ( | __FILE__ | , | |
"$Revision: 359053 $" | ||||
) |
static void* dispatch_thread_handler | ( | void * | data | ) | [static] |
Definition at line 117 of file res_ais.c.
References ARRAY_LEN, AST_AIS_CMD_EXIT, AST_AIS_CMD_MEMBERSHIP_CHANGED, ast_ais_evt_membership_changed(), ast_debug, ast_log(), ast_poll, clm_handle, dispatch_thread, errno, evt_handle, and LOG_ERROR.
Referenced by load_module().
00118 { 00119 SaSelectionObjectT clm_fd, evt_fd; 00120 int res; 00121 struct pollfd pfd[3] = { 00122 { .events = POLLIN, }, 00123 { .events = POLLIN, }, 00124 { .events = POLLIN, }, 00125 }; 00126 SaAisErrorT ais_res; 00127 00128 ais_res = saClmSelectionObjectGet(clm_handle, &clm_fd); 00129 if (ais_res != SA_AIS_OK) { 00130 ast_log(LOG_ERROR, "Failed to retrieve select fd for CLM service. " 00131 "This module will not operate.\n"); 00132 return NULL; 00133 } 00134 00135 ais_res = saEvtSelectionObjectGet(evt_handle, &evt_fd); 00136 if (ais_res != SA_AIS_OK) { 00137 ast_log(LOG_ERROR, "Failed to retrieve select fd for EVT service. " 00138 "This module will not operate.\n"); 00139 return NULL; 00140 } 00141 00142 pfd[0].fd = clm_fd; 00143 pfd[1].fd = evt_fd; 00144 pfd[2].fd = dispatch_thread.alert_pipe[0]; 00145 00146 while (!dispatch_thread.stop) { 00147 pfd[0].revents = 0; 00148 pfd[1].revents = 0; 00149 pfd[2].revents = 0; 00150 00151 res = ast_poll(pfd, ARRAY_LEN(pfd), -1); 00152 if (res == -1 && errno != EINTR && errno != EAGAIN) { 00153 ast_log(LOG_ERROR, "Select error (%s) dispatch thread going away now, " 00154 "and the module will no longer operate.\n", strerror(errno)); 00155 break; 00156 } 00157 00158 if (pfd[0].revents & POLLIN) { 00159 saClmDispatch(clm_handle, SA_DISPATCH_ALL); 00160 } 00161 if (pfd[1].revents & POLLIN) { 00162 saEvtDispatch(evt_handle, SA_DISPATCH_ALL); 00163 } 00164 if (pfd[2].revents & POLLIN) { 00165 enum ast_ais_cmd cmd; 00166 ast_debug(1, "Got a command in the poll() loop\n"); 00167 if (read(dispatch_thread.alert_pipe[0], &cmd, sizeof(cmd)) != -1) { 00168 switch (cmd) { 00169 case AST_AIS_CMD_MEMBERSHIP_CHANGED: 00170 ast_ais_evt_membership_changed(); 00171 break; 00172 case AST_AIS_CMD_EXIT: 00173 break; 00174 } 00175 } 00176 } 00177 } 00178 00179 return NULL; 00180 }
static int load_module | ( | void | ) | [static] |
Definition at line 193 of file res_ais.c.
References ast_ais_clm_load_module(), ast_ais_clm_unload_module(), ast_ais_evt_load_module(), ast_ais_evt_unload_module(), ast_log(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_pthread_create_background, dispatch_thread, dispatch_thread_handler(), errno, and LOG_ERROR.
00194 { 00195 if (pipe(dispatch_thread.alert_pipe) == -1) { 00196 ast_log(LOG_ERROR, "Failed to create alert pipe: %s (%d)\n", 00197 strerror(errno), errno); 00198 goto return_error; 00199 } 00200 00201 if (ast_ais_clm_load_module()) 00202 goto clm_failed; 00203 00204 if (ast_ais_evt_load_module()) 00205 goto evt_failed; 00206 00207 if (ast_pthread_create_background(&dispatch_thread.id, NULL, 00208 dispatch_thread_handler, NULL)) { 00209 ast_log(LOG_ERROR, "Error starting AIS dispatch thread.\n"); 00210 goto dispatch_failed; 00211 } 00212 00213 return AST_MODULE_LOAD_SUCCESS; 00214 00215 dispatch_failed: 00216 ast_ais_evt_unload_module(); 00217 evt_failed: 00218 ast_ais_clm_unload_module(); 00219 clm_failed: 00220 close(dispatch_thread.alert_pipe[0]); 00221 close(dispatch_thread.alert_pipe[1]); 00222 return_error: 00223 return AST_MODULE_LOAD_DECLINE; 00224 }
static int unload_module | ( | void | ) | [static] |
Definition at line 226 of file res_ais.c.
References ast_ais_clm_unload_module(), AST_AIS_CMD_EXIT, ast_ais_evt_unload_module(), ast_log(), AST_PTHREADT_NULL, dispatch_thread, errno, and LOG_ERROR.
00227 { 00228 ast_ais_clm_unload_module(); 00229 ast_ais_evt_unload_module(); 00230 00231 if (dispatch_thread.id != AST_PTHREADT_NULL) { 00232 dispatch_thread.stop = 1; 00233 if (ast_ais_cmd(AST_AIS_CMD_EXIT) == -1) { 00234 ast_log(LOG_ERROR, "Failed to write to pipe: %s (%d)\n", 00235 strerror(errno), errno); 00236 } 00237 pthread_join(dispatch_thread.id, NULL); 00238 } 00239 00240 if (dispatch_thread.alert_pipe[0] != -1) { 00241 close(dispatch_thread.alert_pipe[0]); 00242 dispatch_thread.alert_pipe[0] = -1; 00243 } 00244 00245 if (dispatch_thread.alert_pipe[1] != -1) { 00246 close(dispatch_thread.alert_pipe[1]); 00247 dispatch_thread.alert_pipe[1] = -1; 00248 } 00249 00250 return 0; 00251 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "SAForum AIS" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
struct ais_error ais_errors[] [static] |
Referenced by ais_err2str().
SaVersionT ais_version = { 'B', 1, 1 } |
Definition at line 70 of file res_ais.c.
Referenced by ast_ais_clm_load_module(), and ast_ais_evt_load_module().
int alert_pipe[2] |
struct ast_module_info* ast_module_info = &__mod_info [static] |
struct { ... } dispatch_thread [static] |
Referenced by ast_ais_cmd(), dispatch_thread_handler(), load_module(), and unload_module().
unsigned int stop |
Definition at line 64 of file res_ais.c.
Referenced by controlplayback_exec(), cops_gate_cmd(), handle_controlstreamfile(), multiplexed_thread_function(), pktccops_show_pools(), and queue_exec().