[asterisk-users] AMI and ExtensionState command returning bogus 'status' number

Philipp Kempgen philipp.kempgen at amooma.de
Mon Dec 22 18:04:49 CST 2008


Jose P. Espinal schrieb:

> Any Idea why these return values are not 'officially' documented somewhere ?

The official documentation is in the code,
enum ast_extension_states in include/asterisk/pbx.h:

---cut---
/*! \brief Extension states
	\note States can be combined
	- \ref AstExtState
*/
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---

http://www.asterisk.org/doxygen/trunk/pbx_8h.html#28a085b6cb13daa457018c4e0aae43df

What it doesn't tell you is that this is a bit field (well,
it's more or less obvious as the values are set using bit
shifting).
So don't be suprised when AST_EXTENSION_INUSE (1<<0 == 1) and
AST_EXTENSION_RINGING (1<<3 == 8) both occur at the same time
(9 == 1 + 8).

> Philipp Kempgen wrote:
>> Jose P. Espinal schrieb:
>>
>>   
>>> Until now everything is going Ok but something a little (in my oppinion) 
>>> strange is going on with the 'ExtensionState' command;
>>> The problem is that it does not returns the 'Status' as it's suposed to, 
>>> mentioned in the A.T.F.O.T book - version 2.,
>>> where it sais something like:
>>>
>>> "Notes: The following are the possible extension states:
>>> -2  Extension removed
>>> -1  Extension hint not found
>>> 0   Idle
>>> 1  In use
>>> 2  Busy"
>>>
>>> I have confirmed that it is returning the 'Status' as described in 
>>> 'devicestate.h'
>>>     
>>
>> That's not true.
>>
>> Here's a short snippet of some of my code to show you the return
>> values:
>>
>> ---cut---
>> # These states are used in the manager API (since 1.4?) (see
>> # action_extensionstate() in manager.c, enum ast_extension_states in
>> # pbx.h, ast_extension_state() and ast_extension_state2() in pbx.c).
>> # They are different from the device states (AST_DEVICE_...)!
>> #
>> define( 'AST_MGR_EXT_UNKNOWN'  ,        -1  );  # no hint for the extension
>> define( 'AST_MGR_EXT_IDLE'     ,         0  );  # all devices idle (but registered)
>> define( 'AST_MGR_EXT_INUSE'    , 1<<0 /* 1*/);  # one or more devices busy
>> define( 'AST_MGR_EXT_BUSY'     , 1<<1 /* 2*/);  # all devices busy
>> define( 'AST_MGR_EXT_OFFLINE'  , 1<<2 /* 4*/);  # all devices unreachable/not registered
>> define( 'AST_MGR_EXT_RINGING'  , 1<<3 /* 8*/);  # one or more devices ringing
>> define( 'AST_MGR_EXT_ONHOLD'   , 1<<4 /*16*/);  # all devices on hold
>>
>> define( 'AST_MGR_EXT_RINGINUSE', AST_MGR_EXT_INUSE |  # one or more devices busy
>>                                  AST_MGR_EXT_RINGING  # and one or more devices
>>                                       /* 9*/);        # ringing
>> ---cut---
>>
>> (The code is GNU/GPL but I'm sure you can learn from it and write
>> your own should the license be incompatible to yours.)

   Philipp Kempgen

-- 
http://www.das-asterisk-buch.de  -  http://www.the-asterisk-book.com
Amooma GmbH - Bachstr. 126 - 56566 Neuwied  ->  http://www.amooma.de
Geschäftsführer: Stefan Wintermeyer, Handelsregister: Neuwied B14998
-- 



More information about the asterisk-users mailing list