[asterisk-users] AMI extension states

Philipp Kempgen philipp.kempgen at amooma.de
Thu Sep 20 11:59:51 CDT 2007


Anthony Francis wrote:

> Here is what I use.
> 
> sub devstate2str($)
> {
>   #func name stolen directly from asterisk
>   #takes int devstate and returns string val
>   my $ids              = shift;
>   my $devstatestring   = {};
>   $devstatestring->{0} = "Unknown";     #0 AST_DEVICE_UNKNOWN | Valid, 
> but unknown state
>   $devstatestring->{1} = "Not in use";  #1 AST_DEVICE_NOT_INUSE | Not used
>   $devstatestring->{2} = "In use";      #2 AST_DEVICE IN USE | In use
>   $devstatestring->{3} = "Busy";        #3 AST_DEVICE_BUSY | Busy
>   $devstatestring->{4} = "Invalid";     #4 AST_DEVICE_INVALID | Invalid 
> - not known to Asterisk
>   $devstatestring->{5} = "Unavailable"; #5 AST_DEVICE_UNAVAILABLE | 
> Unavailable (not registred)
>   $devstatestring->{6} = "Ringing";     #6 AST_DEVICE_RINGING | Ring, 
> ring, ring
>   return $devstatestring->{$ids};
> }
> 
> LIke the comment says, I stole it direct from the source. A code of 16 
> may be a typo in which case you have found a bug.
> 
> Philipp Kempgen wrote:
>> Hi,
>>
>> Is there a list of all the extension states as sent by the
>> manager interface? (I know I could look them up in the source
>> but that involves some "backtracing".)
>>
>> The ones I know are:
>>
>> -1: no hint for the extension
>>  0: registered && idle
>>  1: busy
>>  4: unreachable, not registered
>>  8: ringing
>>
>> I've recently seen 16 (== hold?) but can't find that value
>> documented anywhere.

Thanks, but I think device states are different from extension states.
(Please correct me If I'm mistaken.)

Device states from devicestate.h:
---cut---
/*! Device is valid but channel didn't know state */
#define AST_DEVICE_UNKNOWN	0
/*! Device is not used */
#define AST_DEVICE_NOT_INUSE	1
/*! Device is in use */
#define AST_DEVICE_INUSE	2
/*! Device is busy */
#define AST_DEVICE_BUSY		3
/*! Device is invalid */
#define AST_DEVICE_INVALID	4
/*! Device is unavailable */
#define AST_DEVICE_UNAVAILABLE	5
/*! Device is ringing */
#define AST_DEVICE_RINGING	6
/*! Device is ringing *and* in use */
#define AST_DEVICE_RINGINUSE	7
/*! Device is on hold */
#define AST_DEVICE_ONHOLD	8
---cut---

I was looking for the extension states as sent by the manager interface.
Extension states from pbx.h:
---cut---
/*! \brief Extension states */
enum ast_extension_states {
	AST_EXTENSION_REMOVED = -2,	/*!< Extension removed */
	AST_EXTENSION_DEACTIVATED = -1,	/*!< Extension hint removed */
	AST_EXTENSION_NOT_INUSE = 0,	/*!< No device INUSE or BUSY  */
	AST_EXTENSION_INUSE = 1 << 0,	/*!< One or more devices INUSE */
	AST_EXTENSION_BUSY = 1 << 1,	/*!< All devices BUSY */
	AST_EXTENSION_UNAVAILABLE = 1 << 2, /*!< All devices UNAVAILABLE/UNREGISTERED */
	AST_EXTENSION_RINGING = 1 << 3,	/*!< All devices RINGING */
	AST_EXTENSION_ONHOLD = 1 << 4,	/*!< All devices ONHOLD */
};
---cut---

1<<4 == 16, so probably this is the value I observed.
But there some mangling occurs in ast_extension_state2() in pbx.c like
if (inuse && ring)
		return (AST_EXTENSION_INUSE | AST_EXTENSION_RINGING);
which would return
1<<0 | 1<<3 == 1|8 == 9
So the extension state is some kind of a bit mask.

I think I have found what I was looking for. :)

Thanks,
  Philipp Kempgen

-- 
amooma GmbH - Bachstr. 126 - 56566 Neuwied - http://www.amooma.de
    Let's use IT to solve problems and not to create new ones.
          Asterisk? -> http://www.das-asterisk-buch.de
              My pick of the month: rfc 2822 3.6.5

Geschäftsführer: Stefan Wintermeyer
Handelsregister: Neuwied B 14998



More information about the asterisk-users mailing list