[Asterisk-Dev]Beginner code understanding

someshwarak someshwarak at tataelxsi.co.in
Wed Jun 1 07:41:51 MST 2005


Hi,

Iam beginner to asterisk code and trying to understand the code.

To start with i have started tracing how the code flow is for a call
initiated from the asterisk console to a sip phone sitting on some other
machine.

The asterisk code deals with lot of data structures and function pointers.
Also i would like to know if there is any other better way on understanding
the code. Is there any other document which talks on thread architecture.
The following is my observation only there could be errors or
misinterpretations, will be very thankful some one corrects me if Iam wrong.

here goes my code walk observations:

The following shows the call initiated by a PBX to the sip phone residing in
another machine. The call from PBX can be made from the command prompt Dial
<exten>.
The calls initiated from console will be handled by the thread name
net_console created by the function ast_pthread_create.

1.This net console will use a ast_cli_entry structure.

2. The net_console will determine the corresponding handler function and
invokes the handler function console_dial.
Prototype: console_dial( int fd, int arc, char *argv[])

3. The console_dial function with the data given by the user will call the
routine pbx_extension_helper

pbx_extension_helper (struct ast_channel *c, char *context, char *exten, int
priority, char *callerid, int action) . This routine fills the ast_app data
structure to be used  later by pbx_exec.

This routine now calls pbx_exec.

4. The pbx_exec (  struct ast_channel *c, struct ast_app, ..) will call the
corresponding execute function pointer of  the ast_app structure initialized
to the address of dial_exec routine.

5. The dial execute will parse the user given dial command and will print
the correct usage syntax if the user input is incorrect. After the  parsing
is successful then the corresponding technology is determined and then the
routine  ast_request will be called by passing the technology as one of the
argument.
ast_request( tech ..)

the technology can be sip, h.323 etc.

6. The ast_request defined in channel.c will  fill the ast_channel structure
and depending on the technology variable will call particular handler. For
example in case of Sip will call the routine sip_request defined in
chan_sip.c.

the function pointer in the chan_structure will be assigned with the
corresponding request routine (sip_request).

7. The sip_request routine will build the ast_channel_pvt structure which is
part of ast_channel. The ast_channel_pvt will be used by every channel and
depending on the protocol all the data will be filled accordingly. The
protocol can be sip,h323,zap,iax etc.

8. The ast_request will take the filled in pvt_structure and will initiate
the next action. The dial command is for making a sip_call. The routine
sip_call will be activated by the ast_call routine.

9. The sip_call in defined in channel_sip.c will take the required data from
the ast_pvt_structure and sends the invite message to the destination.


10.After the call is hanged then all the allocated structures are freed.

The asterisk channel will be in one of the following state.
AST_STATE_UP
AST_STATE_DOWN
AST_STATE_RESERVED
AST_STATE_OFFHOOK
AST_STATE_DIALING
AST_STATE_RING
AST_STATE_RINGING
AST_STATE_BUSY
AST_STATE_DOWN


thanks,
Somesh




More information about the asterisk-dev mailing list