Wed Apr 6 11:30:08 2011

Asterisk developer's documentation


res_ais.c File Reference

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)
 ASTERISK_FILE_VERSION (__FILE__,"$Revision: 284597 $")
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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .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_infoast_module_info = &__mod_info
struct {
   pthread_t   id
   unsigned int   stop:1
dispatch_thread


Detailed Description

Usage of the SAForum AIS (Application Interface Specification).

Author:
Russell Bryant <russell@digium.com>
This file contains the common code between the uses of the different AIS services.

Note:
This module is still considered experimental, as it exposes the internal binary format of events between Asterisk servers over a network. However, this format is still subject to change between 1.6.X releases.

Definition in file res_ais.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 198 of file res_ais.c.

static void __unreg_module ( void   )  [static]

Definition at line 198 of file res_ais.c.

const char* ais_err2str ( SaAisErrorT  error  ) 

Definition at line 102 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().

00103 {
00104    int x;
00105 
00106    for (x = 0; x < ARRAY_LEN(ais_errors); x++) {
00107       if (ais_errors[x].error == error)
00108          return ais_errors[x].desc;
00109    }
00110 
00111    return "Unknown";
00112 }

ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision: 284597 $"   
)

static void* dispatch_thread_handler ( void *  data  )  [static]

Definition at line 114 of file res_ais.c.

References ast_log(), ast_poll, clm_handle, dispatch_thread, errno, evt_handle, and LOG_ERROR.

Referenced by load_module().

00115 {
00116    SaSelectionObjectT clm_fd, evt_fd;
00117    int res;
00118    struct pollfd pfd[2] = { { .events = POLLIN, }, { .events = POLLIN, } };
00119    SaAisErrorT ais_res;
00120 
00121    ais_res = saClmSelectionObjectGet(clm_handle, &clm_fd);
00122    if (ais_res != SA_AIS_OK) {
00123       ast_log(LOG_ERROR, "Failed to retrieve select fd for CLM service.  "
00124          "This module will not operate.\n");
00125       return NULL;
00126    }
00127 
00128    ais_res = saEvtSelectionObjectGet(evt_handle, &evt_fd);
00129    if (ais_res != SA_AIS_OK) {
00130       ast_log(LOG_ERROR, "Failed to retrieve select fd for EVT service.  "
00131          "This module will not operate.\n");
00132       return NULL;
00133    }
00134 
00135    pfd[0].fd = clm_fd;
00136    pfd[1].fd = evt_fd;
00137 
00138    while (!dispatch_thread.stop) {
00139       pfd[0].revents = 0;
00140       pfd[1].revents = 0;
00141 
00142       res = ast_poll(pfd, 2, -1);
00143       if (res == -1 && errno != EINTR && errno != EAGAIN) {
00144          ast_log(LOG_ERROR, "Select error (%s) dispatch thread going away now, "
00145             "and the module will no longer operate.\n", strerror(errno));
00146          break;
00147       }
00148 
00149       if (pfd[0].revents & POLLIN) {
00150          saClmDispatch(clm_handle,   SA_DISPATCH_ALL);
00151       }
00152       if (pfd[1].revents & POLLIN) {
00153          saEvtDispatch(evt_handle,   SA_DISPATCH_ALL);
00154       }
00155    }
00156 
00157    return NULL;
00158 }

static int load_module ( void   )  [static]

Definition at line 160 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(), and LOG_ERROR.

00161 {
00162    if (ast_ais_clm_load_module())
00163       goto return_error;
00164 
00165    if (ast_ais_evt_load_module())
00166       goto evt_failed;
00167 
00168    if (ast_pthread_create_background(&dispatch_thread.id, NULL, 
00169       dispatch_thread_handler, NULL)) {
00170       ast_log(LOG_ERROR, "Error starting AIS dispatch thread.\n");
00171       goto dispatch_failed;
00172    }
00173 
00174    return AST_MODULE_LOAD_SUCCESS;
00175 
00176 dispatch_failed:
00177    ast_ais_evt_unload_module();
00178 evt_failed:
00179    ast_ais_clm_unload_module();
00180 return_error:
00181    return AST_MODULE_LOAD_DECLINE;
00182 }

static int unload_module ( void   )  [static]

Definition at line 184 of file res_ais.c.

References ast_ais_clm_unload_module(), ast_ais_evt_unload_module(), AST_PTHREADT_NULL, and dispatch_thread.

00185 {
00186    ast_ais_clm_unload_module();
00187    ast_ais_evt_unload_module();
00188 
00189    if (dispatch_thread.id != AST_PTHREADT_NULL) {
00190       dispatch_thread.stop = 1;
00191       pthread_kill(dispatch_thread.id, SIGURG); /* poke! */
00192       pthread_join(dispatch_thread.id, NULL);
00193    }
00194 
00195    return 0;
00196 }


Variable Documentation

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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 198 of file res_ais.c.

struct ais_error ais_errors[] [static]

Referenced by ais_err2str().

SaVersionT ais_version = { 'B', 1, 1 }

Definition at line 67 of file res_ais.c.

Referenced by ast_ais_clm_load_module(), and ast_ais_evt_load_module().

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 198 of file res_ais.c.

struct { ... } dispatch_thread [static]

Referenced by dispatch_thread_handler(), load_module(), and unload_module().

pthread_t id

Definition at line 61 of file res_ais.c.

unsigned int stop

Definition at line 62 of file res_ais.c.


Generated on Wed Apr 6 11:30:08 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7