· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Asterisk Ver0-1-0/Asterisk DotC

AsteriskVer0-1-0/AsteriskDotC


* int main(int argc, char *argv[])
  • root 인지 점검. root 가 아니면 exit(1)
  • argument 를 점검하여 해당하는 variable 설정
    • d, v, q
  • option_verbose 가 설정되어 있으면, 메시지 출력
  • signal 처리 함수 설정
    • urg_handler
    • quit_handler
  • init_logger()
  • load_pbx()
  • load_modules()
  • select(0,NULL,NULL,NULL,NULL);
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout);

select  checks to see if any sockets are ready for reading ( readfds ), writing ( writefds ), or have an exceptional condition pending ( exceptfds ). timeout  specifies the maximum time for select  to complete. nfds  specifies the maximum number of sockets to check. If timeout  is a null pointer, select  blocks indefinitely. timeout  points to a timeval  structure. A timeout  value of 0 causes select  to return immediately. This behavior is useful in applications that periodically poll their sockets. The arrival of out-of-band data is the only possible exceptional condition. fd_set  is a type defined in the <sys/types.h>  header file. fd_set  defines a set of file descriptors on which select  operates. Passing NULL  for any of the three fd_set  arguments specifies that select  should not monitor that condition. On return, each of the input sets is modified to indicate the subset of descriptions that are ready. These may be found by using the FD_ISSET macro. 

timeout is an upper bound on the amount of time elapsed before select returns. It may be zero, causing select to return immediately. (This is useful for polling.) If timeout is NULL (no timeout), select can block indefinitely.
즉, timeout값이 0일 경우에는 폴링에 해당되며, timeout이 NULL일 경우에는 타임아웃의 상한선이 없다는 의미로 해석되어 I/O가 발생하지 않으면 블록됩니다.
  • return 0;

init_logger


* logger.c
  • #define AST_EVENT_LOG AST_LOG_DIR "/" EVENTLOG
  • static FILE *eventlog = NULL;
    • asterisk.h:#define AST_LOG_DIR "/var/log/asterisk"
    • #define EVENTLOG "event_log" include/staerisk/logger.h

* int init_logger(void)
  • /var/log/asterisk 디렉토리를 생성한다. 이미 존재하면 오류 return
  • /var/log/asterisk 디렉토리에서 event_log 파일을 append 모드로 open 하고 pointer 를 return 한다.
    • 오류면 null 을 return
  • 파일을 open 하였으면, 로그를 기록하고 return 0
  • 파일 open 에 실패하였으면 오류메시지를 출력하고 return -1

load_pbx


* pbx.c
static struct pbx_builtin {
        char name[AST_MAX_APP];
        int (*execute)(struct ast_channel *chan, void *data);
} builtins[] =
{
        /* These applications are built into the PBX core and do not
           need separate modules */
        { "Answer", pbx_builtin_answer },
        { "Goto", pbx_builtin_goto },
        { "Hangup", pbx_builtin_hangup },
        { "DigitTimeout", pbx_builtin_dtimeout },
        { "ResponseTimeout", pbx_builtin_rtimeout },
        { "BackGround", pbx_builtin_background },
        { "Wait", pbx_builtin_wait },
};

* int load_pbx(void)
  • for (x=0;x
    • if (ast_register_application(builtinsx.name, builtinsx.execute)) {
    • }
  • }
  • return 0;
  • builtins 의 size 를 pbx_builtin 의 size 로 나누어 for loop 를 돌림으로소, 7 개의 builtin application 을 등록시킨다.

load_modules


* module.h:#define AST_MODULE_CONFIG "modules.conf" include/asterisk/

* asterisk.h:#define AST_CONFIG_DIR "/etc/asterisk"

* asterisk.h:#define AST_MODULE_DIR "/usr/lib/asterisk/modules"

* int load_modules()
  • cfg = ast_load(AST_MODULE_CONFIG);
  • if (cfg) {
    • v = ast_variable_browse(cfg, "modules"); /* module context 를 읽어 ast_variable structure 의 point v 를 설정한다 */
    • while(v) {
      • v->name 이 load 면 해당하는 v->value 를 load 한다.
        • ast_load_resource(v->value) 가 실패하면 return -1
      • v=v->next;
    • }
  • }
  • if (!cfg || ast_true(ast_variable_retrieve(cfg, "modules", "autoload"))) {
    • modules context 에 autoload keyword 가 true 로 설정되어 있으면
    • mods = opendir(AST_MODULE_DIR);
    • if (mods) {
      • while((d = readdir(mods))) {
        • 파일의 extension 이 .so 면
          • modules context 를 읽어 ast_variable structure 의 point v 를 설정한다
          • keyword 가 noload 인 것을 찾아, v->value 가 파일명과 일치하면 다음 파일명을 읽는다.
          • 파일명과 일치하는 것이 없으면, ast_load_resource(d->d_name) 을 사용하여 module 을 load 한다.
          • load 에 실패하면 return -1
        • }
      • };
    • } else {
    • }
  • }
  • ast_destroy(cfg);
  • return 0;

  • /etc/asterisk/modules.conf 파일을 읽어, ast_config structure 의 pointer cfg 를 return 한다.
    • cfg 가 null 이면 아무일도 안하고 return 한다.
    • modules context 를 찾은후, keyword 가 load 인 것을 찾아 keyword 의 value 에 해당되는 module 을 ast_load_resource(v->value) 함수를 사용하여 load 한다.
    • autoload 가 설정되어 있으면, /usr/lib/asterisk/modules 디렉토리 밑의 .so 파일을 load 한다.
      • 단 noload 로 설정되어 있는 module 은 skip 한다.

ID
Password
Join
Put not your trust in money, but put your money in trust.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2010-07-01 18:44:15
Processing time 0.0056 sec