text
stringlengths
0
152
CHAPTER 13
Device States
Out of clutter, find simplicity.
—Albert Einstein
It is often useful to be able to determine the state of the devices that are attached to a
telephone system. For example, a receptionist might require the ability to see the sta‐
tuses of everyone in the office in order to determine whether somebody can take a
phone call. Asterisk itself needs this same information. As another example, if you
were building a call queue, as discussed in Chapter 12, Asterisk needs to know when
an agent is available so that another call can be delivered. This chapter discusses
device state concepts in Asterisk, as well as how devices and applications use and
access this information.
Device States
There are two categories of devices that Asterisk provides state information for: chan‐
nel devices (such as PJSIP endpoints) and virtual devices (which are built-in services
that one might wish to monitor, such as conference rooms).
To reference the state of a channel, you do so in exactly the same way you would with
Dial(), for example DEVICE_STATE(PJSIP/000f300B0B02), whereas to reference the
state of a virtual device, the format is virtual device type:identifier, for example
DEVICE_STATE(ConfBridge:1234).
Virtual devices include things that are inside Asterisk but provide useful state
information (see Table 13-1).
239
Table 13-1. Devices for which Asterisk can provide state information
Device
PJSIP/channel name
ConfBridge:confer
ence bridge
Custom:custom name
Park:exten@context
Calendar:calendar
name
Description
Many channels can have their state monitored, but the PJSIP channel offers by far the
most amount of useful data; thus, monitoring SIP devices is the most common use of
DEVICE_STATE.
The state of a MeetMe conference bridge. The state will reflect whether or not the
conference bridge currently has participants called in. More information on using
MeetMe() for call conferencing can be found in Chapter 11.
Custom device states. These states have custom names and are modified using the
DEVICE_STATE() function. Example usage can be found in “Using Custom Device
States” on page 244.
The state of a spot in a call parking lot. The state information will reflect whether or not a
caller is currently parked at that extension. More information about call parking in Asterisk
can be found in “Call Parking” on page 195.
Calendar state. Asterisk will use the contents of the named calendar to set the state to
available or busy.
Checking Device States
The DEVICE_STATE() dialplan function reads the current state of a device.
exten => 7012,1,Answer()
same => n,Set(DeviceIdent=PJSIP/000f300B0B02)
same => n,Verbose(3,${DeviceIdent} is ${DEVICE_STATE($DeviceIdent})})
same => n,Hangup()
If we call extension 7012 from the same device that we are checking the state of, the
following verbose message comes up on the Asterisk console:
-- PJSIP/000f300B0B02 is INUSE
Chapter 17 discusses the Asterisk Manager Interface (AMI). The
GetVar manager action can be used to retrieve device state values
in an external program. You can use it to get the value of a normal
variable, or to return a value from a dialplan function such as
DEVICE_STATE().
Here is a list of the values that the DEVICE_STATE() function will return (depending,
of course, on what was found):
• UNKNOWN
• NOT_INUSE
• INUSE
• BUSY
• INVALID
240
|
Chapter 13: Device States
• UNAVAILABLE
• RINGING
• RINGINUSE
• ONHOLD