channel.txt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. Implementing a Channel
  2. ======================
  3. * What is a channel?
  4. A channel is a unit which brings in a call to the Asterisk PBX. A channel
  5. could be connected to a real telephone (like the Internet Phone Jack) or
  6. to a logical call (like an Internet phone call). Asterisk makes no
  7. distinction between "FXO" and "FXS" style channels (that is, it doesn't
  8. distinguish between telephone lines and telephones).
  9. Every call is placed or received on a distinct channel. Asterisk uses a
  10. channel driver (typically named chan_xxx.so) to support each type of
  11. hardware.
  12. * What do I need to create a channel?
  13. In order to support a new piece of hardware you need to write a channel
  14. driver. The easiest way to do so is to look at an existing channel driver
  15. and model your own code after it.
  16. * What's the general architecture?
  17. Typically, a channel reads a configuration file on startup which tells it
  18. something about the hardware it's going to be servicing. Then, it
  19. launches a thread which monitors all the idle channels (See the chan_modem
  20. or the chan_ixj for an example of this). When a "RING" or equivalent is
  21. detected, the monitoring thread should allocate a channel structure and
  22. assign all the callbacks to it (see ixj_new, for example), and then call
  23. ast_pbx_start on that channel. ast_pbx_start will launch a new thread to
  24. handle the channel as long as the call is up, so once pbx_start has
  25. successfully been run, the monitor should no longer monitor that channel.
  26. The PBX thread will use the channel, reading, writing, calling, etc., and
  27. multiplexing that channel with others using select() on the channel's
  28. file descriptor (if your channel doesn't have an associated file
  29. descriptor, you'll need to emulate one somehow, perhaps along the lines of
  30. what the translator API does with its channel.
  31. When the PBX is finished with the line, it will hang up the line, at which
  32. point it the hardware should again be monitored by the monitoring thread.