· 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 ÇÑ´Ù.



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.0055 sec