2005-07-08 21:15:41 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2005-07-08 21:15:41 +00:00
|
|
|
*
|
2008-06-10 15:12:17 +00:00
|
|
|
* Copyright (C) 1999 - 2008, Digium, Inc.
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
|
|
|
* Mark Spencer <markster@digium.com>
|
2008-06-10 15:12:17 +00:00
|
|
|
* Russell Bryant <russell@digium.com>
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
2005-07-08 21:15:41 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Device state management
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
2012-03-22 19:51:16 +00:00
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2008-06-10 15:12:17 +00:00
|
|
|
* \author Russell Bryant <russell@digium.com>
|
2006-11-30 18:22:10 +00:00
|
|
|
*
|
|
|
|
* \arg \ref AstExtState
|
2005-07-08 21:15:41 +00:00
|
|
|
*/
|
2007-08-10 16:24:11 +00:00
|
|
|
|
2006-11-30 17:15:54 +00:00
|
|
|
/*! \page AstExtState Extension and device states in Asterisk
|
2008-06-10 15:12:17 +00:00
|
|
|
*
|
|
|
|
* (Note that these descriptions of device states and extension
|
|
|
|
* states have not been updated to the way things work
|
|
|
|
* in Asterisk 1.6.)
|
2006-11-30 17:15:54 +00:00
|
|
|
*
|
|
|
|
* Asterisk has an internal system that reports states
|
|
|
|
* for an extension. By using the dialplan priority -1,
|
|
|
|
* also called a \b hint, a connection can be made from an
|
|
|
|
* extension to one or many devices. The state of the extension
|
|
|
|
* now depends on the combined state of the devices.
|
|
|
|
*
|
|
|
|
* The device state is basically based on the current calls.
|
|
|
|
* If the devicestate engine can find a call from or to the
|
|
|
|
* device, it's in use.
|
2012-03-22 19:51:16 +00:00
|
|
|
*
|
|
|
|
* Some channel drivers implement a callback function for
|
2006-11-30 17:15:54 +00:00
|
|
|
* a better level of reporting device states. The SIP channel
|
2012-03-22 19:51:16 +00:00
|
|
|
* has a complicated system for this, which is improved
|
2006-11-30 17:15:54 +00:00
|
|
|
* by adding call limits to the configuration.
|
2012-03-22 19:51:16 +00:00
|
|
|
*
|
2006-11-30 17:15:54 +00:00
|
|
|
* Functions that want to check the status of an extension
|
|
|
|
* register themself as a \b watcher.
|
|
|
|
* Watchers in this system can subscribe either to all extensions
|
|
|
|
* or just a specific extensions.
|
|
|
|
*
|
|
|
|
* For non-device related states, there's an API called
|
2007-05-23 02:55:22 +00:00
|
|
|
* devicestate providers. This is an extendible system for
|
2006-11-30 17:15:54 +00:00
|
|
|
* delivering state information from outside sources or
|
|
|
|
* functions within Asterisk. Currently we have providers
|
|
|
|
* for app_meetme.c - the conference bridge - and call
|
|
|
|
* parking (metermaids).
|
|
|
|
*
|
2012-03-22 19:51:16 +00:00
|
|
|
* There are manly three subscribers to extension states
|
2006-11-30 17:15:54 +00:00
|
|
|
* within Asterisk:
|
|
|
|
* - AMI, the manager interface
|
|
|
|
* - app_queue.c - the Queue dialplan application
|
2012-03-22 19:51:16 +00:00
|
|
|
* - SIP subscriptions, a.k.a. "blinking lamps" or
|
2006-11-30 17:15:54 +00:00
|
|
|
* "buddy lists"
|
|
|
|
*
|
2006-11-30 18:22:10 +00:00
|
|
|
* The CLI command "show hints" show last known state
|
|
|
|
*
|
2007-05-23 02:55:22 +00:00
|
|
|
* \note None of these handle user states, like an IM presence
|
2012-09-10 19:49:30 +00:00
|
|
|
* system. res_xmpp.c can subscribe and watch such states
|
2006-11-30 17:15:54 +00:00
|
|
|
* in jabber/xmpp based systems.
|
|
|
|
*
|
2006-11-30 20:34:23 +00:00
|
|
|
* \section AstDevStateArch Architecture for devicestates
|
2006-11-30 18:22:10 +00:00
|
|
|
*
|
2012-03-22 19:51:16 +00:00
|
|
|
* When a channel driver or asterisk app changes state for
|
2006-11-30 18:22:10 +00:00
|
|
|
* a watched object, it alerts the core. The core queues
|
|
|
|
* a change. When the change is processed, there's a query
|
|
|
|
* sent to the channel driver/provider if there's a function
|
|
|
|
* to handle that, otherwise a channel walk is issued to find
|
|
|
|
* a channel that involves the object.
|
2012-03-22 19:51:16 +00:00
|
|
|
*
|
2006-11-30 18:22:10 +00:00
|
|
|
* The changes are queued and processed by a separate thread.
|
2012-03-22 19:51:16 +00:00
|
|
|
* This thread calls the watchers subscribing to status
|
|
|
|
* changes for the object. For manager, this results
|
2006-11-30 18:22:10 +00:00
|
|
|
* in events. For SIP, NOTIFY requests.
|
|
|
|
*
|
2006-11-30 18:25:51 +00:00
|
|
|
* - Device states
|
2012-03-22 19:51:16 +00:00
|
|
|
* \arg \ref devicestate.c
|
|
|
|
* \arg \ref devicestate.h
|
2006-11-30 20:34:23 +00:00
|
|
|
*
|
|
|
|
* \section AstExtStateArch Architecture for extension states
|
2012-03-22 19:51:16 +00:00
|
|
|
*
|
2006-11-30 20:34:23 +00:00
|
|
|
* Hints are connected to extension. If an extension changes state
|
|
|
|
* it checks the hint devices. If there is a hint, the callbacks into
|
|
|
|
* device states are checked. The aggregated state is set for the hint
|
|
|
|
* and reported back.
|
|
|
|
*
|
2006-11-30 18:25:51 +00:00
|
|
|
* - Extension states
|
2007-07-23 14:32:04 +00:00
|
|
|
* \arg \ref AstENUM ast_extension_states
|
2012-03-22 19:51:16 +00:00
|
|
|
* \arg \ref pbx.c
|
|
|
|
* \arg \ref pbx.h
|
2006-11-30 20:34:23 +00:00
|
|
|
* - Structures
|
2007-06-07 23:07:25 +00:00
|
|
|
* - \ref ast_state_cb struct. Callbacks for watchers
|
2006-11-30 20:34:23 +00:00
|
|
|
* - Callback ast_state_cb_type
|
2007-06-07 23:07:25 +00:00
|
|
|
* - \ref ast_hint struct.
|
2012-03-22 19:51:16 +00:00
|
|
|
* - Functions
|
2006-11-30 20:34:23 +00:00
|
|
|
* - ast_extension_state_add()
|
|
|
|
* - ast_extension_state_del()
|
|
|
|
* - ast_get_hint()
|
2012-03-22 19:51:16 +00:00
|
|
|
*
|
2006-11-30 17:15:54 +00:00
|
|
|
*/
|
2005-07-08 21:15:41 +00:00
|
|
|
|
2012-06-15 16:20:16 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2007-11-20 22:18:21 +00:00
|
|
|
#include "asterisk/_private.h"
|
2005-07-08 21:15:41 +00:00
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/linkedlists.h"
|
|
|
|
#include "asterisk/devicestate.h"
|
|
|
|
#include "asterisk/pbx.h"
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
#include "asterisk/app.h"
|
2013-04-16 15:33:59 +00:00
|
|
|
#include "asterisk/astobj2.h"
|
|
|
|
#include "asterisk/stasis.h"
|
Merge major changes to the way device state is passed around Asterisk. The two
places that cared about device states were app_queue and the hint code in pbx.c.
The changes include converting it to use the Asterisk event system, as well as
other efficiency improvements.
* app_queue: This module used to register a callback into devicestate.c to
monitor device state changes. Now, it is just a subscriber to Asterisk
events with the type, device state.
* pbx.c hints: Previously, the device state processing thread in devicestate.c
would call ast_hint_state_changed() each time the state of a device changed.
Then, that code would go looking for all the hints that monitor that device,
and call their callbacks. All of this blocked the device state processing
thread. Now, the hint code is a subscriber of Asterisk events with the
type, device state. Furthermore, when this code receives a device state
change event, it queues it up to be processed by another thread so that it
doesn't block one of the event processing threads.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@66958 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-06-01 23:34:43 +00:00
|
|
|
#include "asterisk/event.h"
|
2013-04-16 15:33:59 +00:00
|
|
|
#include "asterisk/devicestate.h"
|
|
|
|
|
|
|
|
#define DEVSTATE_TOPIC_BUCKETS 57
|
2005-07-08 21:15:41 +00:00
|
|
|
|
2006-04-04 18:24:41 +00:00
|
|
|
/*! \brief Device state strings for printing */
|
2009-05-12 13:59:35 +00:00
|
|
|
static const char * const devstatestring[][2] = {
|
2008-11-04 18:47:20 +00:00
|
|
|
{ /* 0 AST_DEVICE_UNKNOWN */ "Unknown", "UNKNOWN" }, /*!< Valid, but unknown state */
|
|
|
|
{ /* 1 AST_DEVICE_NOT_INUSE */ "Not in use", "NOT_INUSE" }, /*!< Not used */
|
|
|
|
{ /* 2 AST_DEVICE IN USE */ "In use", "INUSE" }, /*!< In use */
|
|
|
|
{ /* 3 AST_DEVICE_BUSY */ "Busy", "BUSY" }, /*!< Busy */
|
|
|
|
{ /* 4 AST_DEVICE_INVALID */ "Invalid", "INVALID" }, /*!< Invalid - not known to Asterisk */
|
|
|
|
{ /* 5 AST_DEVICE_UNAVAILABLE */ "Unavailable", "UNAVAILABLE" }, /*!< Unavailable (not registered) */
|
|
|
|
{ /* 6 AST_DEVICE_RINGING */ "Ringing", "RINGING" }, /*!< Ring, ring, ring */
|
|
|
|
{ /* 7 AST_DEVICE_RINGINUSE */ "Ring+Inuse", "RINGINUSE" }, /*!< Ring and in use */
|
2009-07-08 22:02:54 +00:00
|
|
|
{ /* 8 AST_DEVICE_ONHOLD */ "On Hold", "ONHOLD" }, /*!< On Hold */
|
2005-07-20 00:34:01 +00:00
|
|
|
};
|
|
|
|
|
2008-07-25 21:20:03 +00:00
|
|
|
/*!\brief Mapping for channel states to device states */
|
|
|
|
static const struct chan2dev {
|
|
|
|
enum ast_channel_state chan;
|
|
|
|
enum ast_device_state dev;
|
|
|
|
} chan2dev[] = {
|
|
|
|
{ AST_STATE_DOWN, AST_DEVICE_NOT_INUSE },
|
|
|
|
{ AST_STATE_RESERVED, AST_DEVICE_INUSE },
|
|
|
|
{ AST_STATE_OFFHOOK, AST_DEVICE_INUSE },
|
|
|
|
{ AST_STATE_DIALING, AST_DEVICE_INUSE },
|
|
|
|
{ AST_STATE_RING, AST_DEVICE_INUSE },
|
|
|
|
{ AST_STATE_RINGING, AST_DEVICE_RINGING },
|
|
|
|
{ AST_STATE_UP, AST_DEVICE_INUSE },
|
|
|
|
{ AST_STATE_BUSY, AST_DEVICE_BUSY },
|
|
|
|
{ AST_STATE_DIALING_OFFHOOK, AST_DEVICE_INUSE },
|
|
|
|
{ AST_STATE_PRERING, AST_DEVICE_RINGING },
|
|
|
|
{ -100, -100 },
|
|
|
|
};
|
|
|
|
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
/*! \brief A device state provider (not a channel) */
|
|
|
|
struct devstate_prov {
|
|
|
|
char label[40];
|
|
|
|
ast_devstate_prov_cb_type callback;
|
2007-02-02 00:39:01 +00:00
|
|
|
AST_RWLIST_ENTRY(devstate_prov) list;
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*! \brief A list of providers */
|
2007-02-02 00:39:01 +00:00
|
|
|
static AST_RWLIST_HEAD_STATIC(devstate_provs, devstate_prov);
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
|
2005-07-08 21:15:41 +00:00
|
|
|
struct state_change {
|
|
|
|
AST_LIST_ENTRY(state_change) list;
|
2013-01-02 18:11:59 +00:00
|
|
|
enum ast_devstate_cache cachable;
|
2005-07-08 21:15:41 +00:00
|
|
|
char device[1];
|
|
|
|
};
|
|
|
|
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
/*! \brief The state change queue. State changes are queued
|
|
|
|
for processing by a separate thread */
|
2005-07-08 21:15:41 +00:00
|
|
|
static AST_LIST_HEAD_STATIC(state_changes, state_change);
|
|
|
|
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
/*! \brief The device state change notification thread */
|
2005-07-08 21:15:41 +00:00
|
|
|
static pthread_t change_thread = AST_PTHREADT_NULL;
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
|
|
|
|
/*! \brief Flag for the queue */
|
2005-10-28 16:35:43 +00:00
|
|
|
static ast_cond_t change_pending;
|
2005-07-08 21:15:41 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
struct stasis_subscription *devstate_message_sub;
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
static struct stasis_topic *device_state_topic_all;
|
|
|
|
static struct stasis_caching_topic *device_state_topic_cached;
|
|
|
|
static struct stasis_topic_pool *device_state_topic_pool;
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-05-15 02:37:22 +00:00
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_device_state_message_type);
|
|
|
|
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
/* Forward declarations */
|
|
|
|
static int getproviderstate(const char *provider, const char *address);
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Find devicestate as text message for output */
|
2012-03-22 19:51:16 +00:00
|
|
|
const char *ast_devstate2str(enum ast_device_state devstate)
|
2008-11-04 18:47:20 +00:00
|
|
|
{
|
|
|
|
return devstatestring[devstate][0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Deprecated interface (not prefixed with ast_) */
|
2012-03-22 19:51:16 +00:00
|
|
|
const char *devstate2str(enum ast_device_state devstate)
|
2005-07-20 00:34:01 +00:00
|
|
|
{
|
2008-11-04 18:47:20 +00:00
|
|
|
return devstatestring[devstate][0];
|
2005-07-20 00:34:01 +00:00
|
|
|
}
|
|
|
|
|
2008-07-25 21:20:03 +00:00
|
|
|
enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
chanstate &= 0xFFFF;
|
|
|
|
for (i = 0; chan2dev[i].chan != -100; i++) {
|
|
|
|
if (chan2dev[i].chan == chanstate) {
|
|
|
|
return chan2dev[i].dev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AST_DEVICE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2008-11-04 18:47:20 +00:00
|
|
|
/* Parseable */
|
2007-02-13 22:02:20 +00:00
|
|
|
const char *ast_devstate_str(enum ast_device_state state)
|
|
|
|
{
|
2008-11-04 18:47:20 +00:00
|
|
|
return devstatestring[state][1];
|
2007-02-13 22:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum ast_device_state ast_devstate_val(const char *val)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(val, "NOT_INUSE"))
|
|
|
|
return AST_DEVICE_NOT_INUSE;
|
|
|
|
else if (!strcasecmp(val, "INUSE"))
|
|
|
|
return AST_DEVICE_INUSE;
|
|
|
|
else if (!strcasecmp(val, "BUSY"))
|
|
|
|
return AST_DEVICE_BUSY;
|
|
|
|
else if (!strcasecmp(val, "INVALID"))
|
|
|
|
return AST_DEVICE_INVALID;
|
|
|
|
else if (!strcasecmp(val, "UNAVAILABLE"))
|
|
|
|
return AST_DEVICE_UNAVAILABLE;
|
|
|
|
else if (!strcasecmp(val, "RINGING"))
|
|
|
|
return AST_DEVICE_RINGING;
|
|
|
|
else if (!strcasecmp(val, "RINGINUSE"))
|
|
|
|
return AST_DEVICE_RINGINUSE;
|
|
|
|
else if (!strcasecmp(val, "ONHOLD"))
|
|
|
|
return AST_DEVICE_ONHOLD;
|
|
|
|
|
|
|
|
return AST_DEVICE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
/*! \brief Find out if device is active in a call or not
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
\note find channels with the device's name in it
|
2012-03-22 19:51:16 +00:00
|
|
|
This function is only used for channels that does not implement
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
devicestate natively
|
2006-04-04 18:24:41 +00:00
|
|
|
*/
|
2007-02-13 22:02:20 +00:00
|
|
|
enum ast_device_state ast_parse_device_state(const char *device)
|
2005-07-08 21:15:41 +00:00
|
|
|
{
|
|
|
|
struct ast_channel *chan;
|
|
|
|
char match[AST_CHANNEL_NAME];
|
2007-02-13 22:02:20 +00:00
|
|
|
enum ast_device_state res;
|
2005-07-08 21:15:41 +00:00
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
snprintf(match, sizeof(match), "%s-", device);
|
2005-07-08 21:15:41 +00:00
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
if (!(chan = ast_channel_get_by_name_prefix(match, strlen(match)))) {
|
2005-07-08 21:15:41 +00:00
|
|
|
return AST_DEVICE_UNKNOWN;
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
}
|
2005-07-08 21:15:41 +00:00
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
res = (ast_channel_state(chan) == AST_STATE_RINGING) ? AST_DEVICE_RINGING : AST_DEVICE_INUSE;
|
2012-03-22 19:51:16 +00:00
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
chan = ast_channel_unref(chan);
|
2005-07-08 21:15:41 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2007-08-10 16:24:11 +00:00
|
|
|
static enum ast_device_state devstate_cached(const char *device)
|
|
|
|
{
|
2013-04-16 15:33:59 +00:00
|
|
|
RAII_VAR(struct stasis_message *, cached_msg, NULL, ao2_cleanup);
|
|
|
|
struct ast_device_state_message *device_state;
|
2007-08-10 16:24:11 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
cached_msg = stasis_cache_get(ast_device_state_topic_cached(), ast_device_state_message_type(), device);
|
|
|
|
if (!cached_msg) {
|
|
|
|
return AST_DEVICE_UNKNOWN;
|
|
|
|
}
|
|
|
|
device_state = stasis_message_data(cached_msg);
|
2007-08-10 16:24:11 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
return device_state->state;
|
2007-08-10 16:24:11 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Check device state through channel specific function or generic function */
|
2008-07-26 15:15:14 +00:00
|
|
|
static enum ast_device_state _ast_device_state(const char *device, int check_cache)
|
2005-07-08 21:15:41 +00:00
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
char *number;
|
|
|
|
const struct ast_channel_tech *chan_tech;
|
2007-08-10 16:24:11 +00:00
|
|
|
enum ast_device_state res;
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
/*! \brief Channel driver that provides device state */
|
|
|
|
char *tech;
|
|
|
|
/*! \brief Another provider of device state */
|
|
|
|
char *provider = NULL;
|
2007-08-10 16:24:11 +00:00
|
|
|
|
|
|
|
/* If the last known state is cached, just return that */
|
2008-07-26 15:16:20 +00:00
|
|
|
if (check_cache) {
|
|
|
|
res = devstate_cached(device);
|
|
|
|
if (res != AST_DEVICE_UNKNOWN) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
2007-08-10 16:24:11 +00:00
|
|
|
|
2005-07-08 21:15:41 +00:00
|
|
|
buf = ast_strdupa(device);
|
|
|
|
tech = strsep(&buf, "/");
|
2007-02-02 00:58:09 +00:00
|
|
|
if (!(number = buf)) {
|
2010-05-17 22:08:01 +00:00
|
|
|
provider = strsep(&tech, ":");
|
|
|
|
if (!tech) {
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
return AST_DEVICE_INVALID;
|
2010-05-17 22:08:01 +00:00
|
|
|
}
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
/* We have a provider */
|
|
|
|
number = tech;
|
|
|
|
tech = NULL;
|
|
|
|
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(3, "Checking if I can find provider for \"%s\" - number: %s\n", provider, number);
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
return getproviderstate(provider, number);
|
|
|
|
}
|
2007-02-02 00:58:09 +00:00
|
|
|
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(4, "No provider found, checking channel drivers for %s - %s\n", tech, number);
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
|
2007-02-02 00:58:09 +00:00
|
|
|
if (!(chan_tech = ast_get_channel_tech(tech)))
|
2005-07-08 21:15:41 +00:00
|
|
|
return AST_DEVICE_INVALID;
|
|
|
|
|
2007-02-02 00:58:09 +00:00
|
|
|
if (!(chan_tech->devicestate)) /* Does the channel driver support device state notification? */
|
|
|
|
return ast_parse_device_state(device); /* No, try the generic function */
|
|
|
|
|
|
|
|
res = chan_tech->devicestate(number);
|
|
|
|
|
|
|
|
if (res != AST_DEVICE_UNKNOWN)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
res = ast_parse_device_state(device);
|
|
|
|
|
|
|
|
return res;
|
2005-07-08 21:15:41 +00:00
|
|
|
}
|
|
|
|
|
2008-07-26 15:15:14 +00:00
|
|
|
enum ast_device_state ast_device_state(const char *device)
|
|
|
|
{
|
|
|
|
/* This function is called from elsewhere in the code to find out the
|
|
|
|
* current state of a device. Check the cache, first. */
|
|
|
|
|
|
|
|
return _ast_device_state(device, 1);
|
|
|
|
}
|
|
|
|
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
/*! \brief Add device state provider */
|
|
|
|
int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
|
|
|
|
{
|
|
|
|
struct devstate_prov *devprov;
|
|
|
|
|
|
|
|
if (!callback || !(devprov = ast_calloc(1, sizeof(*devprov))))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
devprov->callback = callback;
|
|
|
|
ast_copy_string(devprov->label, label, sizeof(devprov->label));
|
|
|
|
|
2007-02-02 00:39:01 +00:00
|
|
|
AST_RWLIST_WRLOCK(&devstate_provs);
|
|
|
|
AST_RWLIST_INSERT_HEAD(&devstate_provs, devprov, list);
|
|
|
|
AST_RWLIST_UNLOCK(&devstate_provs);
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Remove device state provider */
|
2007-02-13 22:02:20 +00:00
|
|
|
int ast_devstate_prov_del(const char *label)
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
{
|
|
|
|
struct devstate_prov *devcb;
|
2007-02-13 22:02:20 +00:00
|
|
|
int res = -1;
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
|
2007-02-02 00:39:01 +00:00
|
|
|
AST_RWLIST_WRLOCK(&devstate_provs);
|
|
|
|
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) {
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
if (!strcasecmp(devcb->label, label)) {
|
2007-11-08 05:28:47 +00:00
|
|
|
AST_RWLIST_REMOVE_CURRENT(list);
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(devcb);
|
2007-02-13 22:02:20 +00:00
|
|
|
res = 0;
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-02-02 00:39:01 +00:00
|
|
|
AST_RWLIST_TRAVERSE_SAFE_END;
|
|
|
|
AST_RWLIST_UNLOCK(&devstate_provs);
|
2007-02-13 22:02:20 +00:00
|
|
|
|
|
|
|
return res;
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Get provider device state */
|
|
|
|
static int getproviderstate(const char *provider, const char *address)
|
|
|
|
{
|
|
|
|
struct devstate_prov *devprov;
|
|
|
|
int res = AST_DEVICE_INVALID;
|
|
|
|
|
2007-02-02 00:39:01 +00:00
|
|
|
AST_RWLIST_RDLOCK(&devstate_provs);
|
|
|
|
AST_RWLIST_TRAVERSE(&devstate_provs, devprov, list) {
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(5, "Checking provider %s with %s\n", devprov->label, provider);
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
|
|
|
|
if (!strcasecmp(devprov->label, provider)) {
|
|
|
|
res = devprov->callback(address);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-02-02 00:39:01 +00:00
|
|
|
AST_RWLIST_UNLOCK(&devstate_provs);
|
2008-06-10 15:12:17 +00:00
|
|
|
|
METERMAIDS:
-----------
- Adding devicestate providers, a new architecture to add non-channel related
device state information, like parking lots, queues, meetmes, vending machines
and Windows 98 reboots (lots of blinking on those lights)
- Adding provider for parking lots, so you can subscribe to the status of a
parking lot
- Adding provider for meetme, so you can have a blinking lamp for a meetme
( Example: exten => edvina,hint,meetme:1234 )
- Adding support for directed parking - set the PARKINGEXTEN before you manually
call Park() and you will be parked on that space. If it's occupied, dialplan
execution will continue.
This work was sponsored by Voop A/S - www.voop.com
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@36055 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-06-26 16:43:21 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2007-08-10 16:24:11 +00:00
|
|
|
/*! Called by the state change thread to find out what the state is, and then
|
|
|
|
* to queue up the state change event */
|
2013-04-16 15:33:59 +00:00
|
|
|
static void do_state_change(const char *device, enum ast_devstate_cache cachable)
|
2007-08-10 16:24:11 +00:00
|
|
|
{
|
|
|
|
enum ast_device_state state;
|
|
|
|
|
2008-07-26 15:15:14 +00:00
|
|
|
state = _ast_device_state(device, 0);
|
2007-08-10 16:24:11 +00:00
|
|
|
|
2008-11-04 18:47:20 +00:00
|
|
|
ast_debug(3, "Changing state for %s - state %d (%s)\n", device, state, ast_devstate2str(state));
|
2007-08-10 16:24:11 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
ast_publish_device_state(device, state, cachable);
|
2007-08-10 16:24:11 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 18:11:59 +00:00
|
|
|
int ast_devstate_changed_literal(enum ast_device_state state, enum ast_devstate_cache cachable, const char *device)
|
2005-07-08 21:15:41 +00:00
|
|
|
{
|
2006-02-09 16:59:50 +00:00
|
|
|
struct state_change *change;
|
2005-07-08 21:15:41 +00:00
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
/*
|
2008-07-26 14:57:50 +00:00
|
|
|
* If we know the state change (how nice of the caller of this function!)
|
2012-03-22 19:51:16 +00:00
|
|
|
* then we can just generate a device state event.
|
2008-07-26 14:57:50 +00:00
|
|
|
*
|
|
|
|
* Otherwise, we do the following:
|
|
|
|
* - Queue an event up to another thread that the state has changed
|
|
|
|
* - In the processing thread, it calls the callback provided by the
|
|
|
|
* device state provider (which may or may not be a channel driver)
|
|
|
|
* to determine the state.
|
|
|
|
* - If the device state provider does not know the state, or this is
|
|
|
|
* for a channel and the channel driver does not implement a device
|
|
|
|
* state callback, then we will look through the channel list to
|
|
|
|
* see if we can determine a state based on active calls.
|
|
|
|
* - Once a state has been determined, a device state event is generated.
|
|
|
|
*/
|
2007-05-14 18:39:16 +00:00
|
|
|
|
2007-08-10 16:24:11 +00:00
|
|
|
if (state != AST_DEVICE_UNKNOWN) {
|
2013-04-16 15:33:59 +00:00
|
|
|
ast_publish_device_state(device, state, cachable);
|
2007-08-10 16:24:11 +00:00
|
|
|
} else if (change_thread == AST_PTHREADT_NULL || !(change = ast_calloc(1, sizeof(*change) + strlen(device)))) {
|
2005-07-08 21:15:41 +00:00
|
|
|
/* we could not allocate a change struct, or */
|
|
|
|
/* there is no background thread, so process the change now */
|
2013-01-02 18:11:59 +00:00
|
|
|
do_state_change(device, cachable);
|
2005-07-08 21:15:41 +00:00
|
|
|
} else {
|
|
|
|
/* queue the change */
|
|
|
|
strcpy(change->device, device);
|
2013-01-02 18:11:59 +00:00
|
|
|
change->cachable = cachable;
|
2005-07-08 21:15:41 +00:00
|
|
|
AST_LIST_LOCK(&state_changes);
|
|
|
|
AST_LIST_INSERT_TAIL(&state_changes, change, list);
|
2007-02-02 00:49:14 +00:00
|
|
|
ast_cond_signal(&change_pending);
|
2005-07-10 13:06:54 +00:00
|
|
|
AST_LIST_UNLOCK(&state_changes);
|
2005-07-08 21:15:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-10-17 15:41:55 +00:00
|
|
|
int ast_device_state_changed_literal(const char *dev)
|
|
|
|
{
|
2013-01-02 18:11:59 +00:00
|
|
|
return ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, dev);
|
2007-08-10 16:24:11 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 18:11:59 +00:00
|
|
|
int ast_devstate_changed(enum ast_device_state state, enum ast_devstate_cache cachable, const char *fmt, ...)
|
2007-08-10 16:24:11 +00:00
|
|
|
{
|
|
|
|
char buf[AST_MAX_EXTENSION];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2013-01-02 18:11:59 +00:00
|
|
|
return ast_devstate_changed_literal(state, cachable, buf);
|
2005-10-17 15:41:55 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
int ast_device_state_changed(const char *fmt, ...)
|
2005-10-17 15:41:55 +00:00
|
|
|
{
|
|
|
|
char buf[AST_MAX_EXTENSION];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
|
|
va_end(ap);
|
2007-08-10 16:24:11 +00:00
|
|
|
|
2013-01-02 18:11:59 +00:00
|
|
|
return ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, buf);
|
2005-10-17 15:41:55 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Go through the dev state change queue and update changes in the dev state thread */
|
2005-07-20 00:34:01 +00:00
|
|
|
static void *do_devstate_changes(void *data)
|
2005-07-08 21:15:41 +00:00
|
|
|
{
|
2007-02-02 00:49:14 +00:00
|
|
|
struct state_change *next, *current;
|
2005-07-08 21:15:41 +00:00
|
|
|
|
2007-01-23 00:11:32 +00:00
|
|
|
for (;;) {
|
2007-02-02 00:49:14 +00:00
|
|
|
/* This basically pops off any state change entries, resets the list back to NULL, unlocks, and processes each state change */
|
|
|
|
AST_LIST_LOCK(&state_changes);
|
|
|
|
if (AST_LIST_EMPTY(&state_changes))
|
2005-10-28 16:35:43 +00:00
|
|
|
ast_cond_wait(&change_pending, &state_changes.lock);
|
2007-02-02 00:49:14 +00:00
|
|
|
next = AST_LIST_FIRST(&state_changes);
|
|
|
|
AST_LIST_HEAD_INIT_NOLOCK(&state_changes);
|
|
|
|
AST_LIST_UNLOCK(&state_changes);
|
|
|
|
|
|
|
|
/* Process each state change */
|
|
|
|
while ((current = next)) {
|
|
|
|
next = AST_LIST_NEXT(current, list);
|
2013-01-02 18:11:59 +00:00
|
|
|
do_state_change(current->device, current->cachable);
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(current);
|
2005-07-08 21:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-06-10 15:12:17 +00:00
|
|
|
#define MAX_SERVERS 64
|
2013-04-16 15:33:59 +00:00
|
|
|
static int devstate_change_aggregator_cb(void *obj, void *arg, void *data, int flags)
|
2008-06-10 15:12:17 +00:00
|
|
|
{
|
2013-04-16 15:33:59 +00:00
|
|
|
struct stasis_message *msg = obj;
|
|
|
|
struct ast_devstate_aggregate *aggregate = arg;
|
|
|
|
char *device = data;
|
|
|
|
struct ast_device_state_message *device_state = stasis_message_data(msg);
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
if (!device_state->eid || strcmp(device, device_state->device)) {
|
|
|
|
/* ignore aggregate states and devices that don't match */
|
|
|
|
return 0;
|
2008-06-10 15:12:17 +00:00
|
|
|
}
|
2013-04-16 15:33:59 +00:00
|
|
|
ast_debug(1, "Adding per-server state of '%s' for '%s'\n",
|
|
|
|
ast_devstate2str(device_state->state), device);
|
|
|
|
ast_devstate_aggregate_add(aggregate, device_state->state);
|
|
|
|
return 0;
|
2008-06-10 15:12:17 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
static void device_state_dtor(void *obj)
|
2008-06-10 15:12:17 +00:00
|
|
|
{
|
2013-04-16 15:33:59 +00:00
|
|
|
struct ast_device_state_message *device_state = obj;
|
|
|
|
ast_string_field_free_memory(device_state);
|
|
|
|
ast_free(device_state->eid);
|
|
|
|
}
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
static struct ast_device_state_message *device_state_alloc(const char *device, enum ast_device_state state, enum ast_devstate_cache cachable, const struct ast_eid *eid)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_device_state_message *, new_device_state, ao2_alloc(sizeof(*new_device_state), device_state_dtor), ao2_cleanup);
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
if (!new_device_state || ast_string_field_init(new_device_state, 256)) {
|
|
|
|
return NULL;
|
2008-06-10 15:12:17 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
ast_string_field_set(new_device_state, device, device);
|
|
|
|
new_device_state->state = state;
|
|
|
|
new_device_state->cachable = cachable;
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
if (eid) {
|
|
|
|
char eid_str[20];
|
|
|
|
struct ast_str *cache_id = ast_str_alloca(256);
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
new_device_state->eid = ast_malloc(sizeof(*eid));
|
|
|
|
if (!new_device_state->eid) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
*new_device_state->eid = *eid;
|
|
|
|
ast_eid_to_str(eid_str, sizeof(eid_str), new_device_state->eid);
|
|
|
|
ast_str_set(&cache_id, 0, "%s%s", eid_str, device);
|
|
|
|
ast_string_field_set(new_device_state, cache_id, ast_str_buffer(cache_id));
|
|
|
|
} else {
|
|
|
|
/* no EID makes this an aggregate state */
|
|
|
|
ast_string_field_set(new_device_state, cache_id, device);
|
|
|
|
}
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
ao2_ref(new_device_state, +1);
|
|
|
|
return new_device_state;
|
|
|
|
}
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
static enum ast_device_state get_aggregate_state(char *device)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ao2_container *, cached, NULL, ao2_cleanup);
|
|
|
|
struct ast_devstate_aggregate aggregate;
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
ast_devstate_aggregate_init(&aggregate);
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
cached = stasis_cache_dump(ast_device_state_topic_cached(), NULL);
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
ao2_callback_data(cached, OBJ_NODATA, devstate_change_aggregator_cb, &aggregate, device);
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
return ast_devstate_aggregate_result(&aggregate);
|
2008-06-10 15:12:17 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
static int aggregate_state_changed(char *device, enum ast_device_state new_aggregate_state)
|
2008-06-10 15:12:17 +00:00
|
|
|
{
|
2013-04-16 15:33:59 +00:00
|
|
|
RAII_VAR(struct stasis_message *, cached_aggregate_msg, NULL, ao2_cleanup);
|
|
|
|
struct ast_device_state_message *cached_aggregate_device_state;
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
cached_aggregate_msg = stasis_cache_get(ast_device_state_topic_cached(), ast_device_state_message_type(), device);
|
|
|
|
if (!cached_aggregate_msg) {
|
|
|
|
return 1;
|
2008-06-10 15:12:17 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
cached_aggregate_device_state = stasis_message_data(cached_aggregate_msg);
|
|
|
|
if (cached_aggregate_device_state->state == new_aggregate_state) {
|
|
|
|
return 0;
|
2008-06-10 15:12:17 +00:00
|
|
|
}
|
2013-04-16 15:33:59 +00:00
|
|
|
return 1;
|
2008-06-10 15:12:17 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
static void devstate_change_collector_cb(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
|
2008-06-10 15:12:17 +00:00
|
|
|
{
|
2013-04-16 15:33:59 +00:00
|
|
|
enum ast_device_state aggregate_state;
|
|
|
|
char *device;
|
|
|
|
struct ast_device_state_message *device_state;
|
|
|
|
RAII_VAR(struct stasis_message *, new_aggregate_msg, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct ast_device_state_message *, new_aggregate_state, NULL, ao2_cleanup);
|
|
|
|
|
|
|
|
if (stasis_cache_update_type() == stasis_message_type(msg)) {
|
|
|
|
struct stasis_cache_update *update = stasis_message_data(msg);
|
|
|
|
if (!update->new_snapshot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
msg = update->new_snapshot;
|
|
|
|
}
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
if (ast_device_state_message_type() != stasis_message_type(msg)) {
|
|
|
|
return;
|
|
|
|
}
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
device_state = stasis_message_data(msg);
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
if (!device_state->eid) {
|
|
|
|
/* ignore aggregate messages */
|
|
|
|
return;
|
2008-06-10 15:12:17 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
device = ast_strdupa(device_state->device);
|
|
|
|
ast_debug(1, "Processing device state change for '%s'\n", device);
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
if (device_state->cachable == AST_DEVSTATE_NOT_CACHABLE) {
|
|
|
|
/* if it's not cachable, there will be no aggregate state to get
|
|
|
|
* and this should be passed through */
|
|
|
|
aggregate_state = device_state->state;
|
|
|
|
} else {
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
aggregate_state = get_aggregate_state(device);
|
|
|
|
ast_debug(1, "Aggregate devstate result is '%s' for '%s'\n",
|
|
|
|
ast_devstate2str(aggregate_state), device);
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
if (!aggregate_state_changed(device, aggregate_state)) {
|
|
|
|
/* No change since last reported device state */
|
|
|
|
ast_debug(1, "Aggregate state for device '%s' has not changed from '%s'\n",
|
|
|
|
device, ast_devstate2str(aggregate_state));
|
|
|
|
return;
|
|
|
|
}
|
2008-06-10 15:12:17 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
ast_debug(1, "Aggregate state for device '%s' has changed to '%s'\n",
|
|
|
|
device, ast_devstate2str(aggregate_state));
|
2008-06-10 15:12:17 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
ast_publish_device_state_full(device, aggregate_state, device_state->cachable, NULL);
|
2008-06-10 15:12:17 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Initialize the device state engine in separate thread */
|
2005-07-08 21:15:41 +00:00
|
|
|
int ast_device_state_engine_init(void)
|
|
|
|
{
|
2005-10-28 16:35:43 +00:00
|
|
|
ast_cond_init(&change_pending, NULL);
|
2006-10-04 19:51:38 +00:00
|
|
|
if (ast_pthread_create_background(&change_thread, NULL, do_devstate_changes, NULL) < 0) {
|
2005-07-08 21:15:41 +00:00
|
|
|
ast_log(LOG_ERROR, "Unable to start device state change thread.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-10 14:06:29 +00:00
|
|
|
|
|
|
|
void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg)
|
|
|
|
{
|
|
|
|
memset(agg, 0, sizeof(*agg));
|
2012-03-13 20:06:57 +00:00
|
|
|
agg->state = AST_DEVICE_INVALID;
|
2008-06-10 14:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state)
|
|
|
|
{
|
2012-03-13 20:06:57 +00:00
|
|
|
static enum ast_device_state state_order[] = {
|
|
|
|
1, /* AST_DEVICE_UNKNOWN */
|
|
|
|
3, /* AST_DEVICE_NOT_INUSE */
|
|
|
|
6, /* AST_DEVICE_INUSE */
|
|
|
|
7, /* AST_DEVICE_BUSY */
|
|
|
|
0, /* AST_DEVICE_INVALID */
|
|
|
|
2, /* AST_DEVICE_UNAVAILABLE */
|
|
|
|
5, /* AST_DEVICE_RINGING */
|
|
|
|
8, /* AST_DEVICE_RINGINUSE */
|
|
|
|
4, /* AST_DEVICE_ONHOLD */
|
|
|
|
};
|
|
|
|
|
|
|
|
if (state == AST_DEVICE_RINGING) {
|
|
|
|
agg->ringing = 1;
|
|
|
|
} else if (state == AST_DEVICE_INUSE || state == AST_DEVICE_ONHOLD || state == AST_DEVICE_BUSY) {
|
|
|
|
agg->inuse = 1;
|
2008-06-10 14:06:29 +00:00
|
|
|
}
|
|
|
|
|
2012-03-13 20:06:57 +00:00
|
|
|
if (agg->ringing && agg->inuse) {
|
|
|
|
agg->state = AST_DEVICE_RINGINUSE;
|
|
|
|
} else if (state_order[state] > state_order[agg->state]) {
|
|
|
|
agg->state = state;
|
|
|
|
}
|
|
|
|
}
|
2009-06-05 21:21:22 +00:00
|
|
|
|
2009-07-02 16:03:44 +00:00
|
|
|
enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg)
|
|
|
|
{
|
2012-03-13 20:06:57 +00:00
|
|
|
return agg->state;
|
2008-06-10 14:06:29 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
struct stasis_topic *ast_device_state_topic_all(void)
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
{
|
2013-04-16 15:33:59 +00:00
|
|
|
return device_state_topic_all;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stasis_caching_topic *ast_device_state_topic_cached(void)
|
|
|
|
{
|
|
|
|
return device_state_topic_cached;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stasis_topic *ast_device_state_topic(const char *device)
|
|
|
|
{
|
|
|
|
return stasis_topic_pool_get_topic(device_state_topic_pool, device);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_publish_device_state_full(
|
|
|
|
const char *device,
|
|
|
|
enum ast_device_state state,
|
|
|
|
enum ast_devstate_cache cachable,
|
|
|
|
struct ast_eid *eid)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_device_state_message *, device_state, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
|
|
|
|
struct stasis_topic *device_specific_topic;
|
|
|
|
|
|
|
|
ast_assert(!ast_strlen_zero(device));
|
|
|
|
|
|
|
|
device_state = device_state_alloc(device, state, cachable, eid);
|
|
|
|
if (!device_state) {
|
|
|
|
return -1;
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
message = stasis_message_create(ast_device_state_message_type(), device_state);
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
device_specific_topic = ast_device_state_topic(device);
|
|
|
|
if (!device_specific_topic) {
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
stasis_publish(device_specific_topic, message);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *device_state_get_id(struct stasis_message *message)
|
|
|
|
{
|
|
|
|
struct ast_device_state_message *device_state;
|
|
|
|
if (ast_device_state_message_type() != stasis_message_type(message)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_state = stasis_message_data(message);
|
|
|
|
if (device_state->cachable == AST_DEVSTATE_NOT_CACHABLE) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return device_state->cache_id;
|
|
|
|
}
|
|
|
|
|
Avoid unnecessary cleanups during immediate shutdown
This patch addresses issues during immediate shutdowns, where modules
are not unloaded, but Asterisk atexit handlers are run.
In the typical case, this usually isn't a big deal. But the
introduction of the Stasis message bus makes it much more likely for
asynchronous activity to be happening off in some thread during
shutdown.
During an immediate shutdown, Asterisk skips unloading modules. But
while it is processing the atexit handlers, there is a window of time
where some of the core message types have been cleaned up, but the
message bus is still running. Specifically, it's still running
module subscriptions that might be using the core message types. If a
message is received by that subscription in that window, it will
attempt to use a message type that has been cleaned up.
To solve this problem, this patch introduces ast_register_cleanup().
This function operates identically to ast_register_atexit(), except
that cleanup calls are not invoked on an immediate shutdown. All of
the core message type and topic cleanup was moved from atexit handlers
to cleanup handlers.
This ensures that core type and topic cleanup only happens if the
modules that used them are first unloaded.
This patch also changes the ast_assert() when accessing a cleaned up
or uninitialized message type to an error log message. Message type
functions are actually NULL safe across the board, so the assert was a
bit heavy handed. Especially for anyone with DO_CRASH enabled.
Review: https://reviewboard.asterisk.org/r/2562/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390122 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-30 17:05:53 +00:00
|
|
|
static void devstate_cleanup(void)
|
2013-04-16 15:33:59 +00:00
|
|
|
{
|
2013-06-24 23:56:54 +00:00
|
|
|
devstate_message_sub = stasis_unsubscribe_and_join(devstate_message_sub);
|
2013-04-16 15:33:59 +00:00
|
|
|
ao2_cleanup(device_state_topic_all);
|
|
|
|
device_state_topic_all = NULL;
|
2013-05-17 21:10:32 +00:00
|
|
|
device_state_topic_cached = stasis_caching_unsubscribe_and_join(device_state_topic_cached);
|
2013-05-15 02:37:22 +00:00
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_device_state_message_type);
|
2013-04-16 15:33:59 +00:00
|
|
|
ao2_cleanup(device_state_topic_pool);
|
|
|
|
device_state_topic_pool = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int devstate_init(void)
|
|
|
|
{
|
Avoid unnecessary cleanups during immediate shutdown
This patch addresses issues during immediate shutdowns, where modules
are not unloaded, but Asterisk atexit handlers are run.
In the typical case, this usually isn't a big deal. But the
introduction of the Stasis message bus makes it much more likely for
asynchronous activity to be happening off in some thread during
shutdown.
During an immediate shutdown, Asterisk skips unloading modules. But
while it is processing the atexit handlers, there is a window of time
where some of the core message types have been cleaned up, but the
message bus is still running. Specifically, it's still running
module subscriptions that might be using the core message types. If a
message is received by that subscription in that window, it will
attempt to use a message type that has been cleaned up.
To solve this problem, this patch introduces ast_register_cleanup().
This function operates identically to ast_register_atexit(), except
that cleanup calls are not invoked on an immediate shutdown. All of
the core message type and topic cleanup was moved from atexit handlers
to cleanup handlers.
This ensures that core type and topic cleanup only happens if the
modules that used them are first unloaded.
This patch also changes the ast_assert() when accessing a cleaned up
or uninitialized message type to an error log message. Message type
functions are actually NULL safe across the board, so the assert was a
bit heavy handed. Especially for anyone with DO_CRASH enabled.
Review: https://reviewboard.asterisk.org/r/2562/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390122 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-30 17:05:53 +00:00
|
|
|
ast_register_cleanup(devstate_cleanup);
|
|
|
|
|
2013-05-26 04:47:17 +00:00
|
|
|
if (STASIS_MESSAGE_TYPE_INIT(ast_device_state_message_type) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-04-16 15:33:59 +00:00
|
|
|
device_state_topic_all = stasis_topic_create("ast_device_state_topic");
|
|
|
|
if (!device_state_topic_all) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
device_state_topic_cached = stasis_caching_topic_create(device_state_topic_all, device_state_get_id);
|
|
|
|
if (!device_state_topic_cached) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
device_state_topic_pool = stasis_topic_pool_create(ast_device_state_topic_all());
|
|
|
|
if (!device_state_topic_pool) {
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-16 15:33:59 +00:00
|
|
|
devstate_message_sub = stasis_subscribe(stasis_caching_get_topic(ast_device_state_topic_cached()), devstate_change_collector_cb, NULL);
|
|
|
|
|
|
|
|
if (!devstate_message_sub) {
|
|
|
|
ast_log(LOG_ERROR, "Failed to create subscription for the device state change collector\n");
|
|
|
|
return -1;
|
|
|
|
}
|
Improve performance of the ast_event cache functionality.
This code comes from svn/asterisk/team/russell/event_performance/.
Here is a summary of the changes that have been made, in order of both
invasiveness and performance impact, from smallest to largest.
1) Asterisk 1.6.1 introduces some additional logic to be able to handle
distributed device state. This functionality comes at a cost.
One relatively minor change in this patch is that the extra processing
required for distributed device state is now completely bypassed if
it's not needed.
2) One of the things that I noticed when profiling this code was that a
_lot_ of time was spent doing string comparisons. I changed the way
strings are represented in an event to include a hash value at the front.
So, before doing a string comparison, we do an integer comparison on the
hash.
3) Finally, the code that handles the event cache has been re-written.
I tried to do this in a such a way that it had minimal impact on the API.
I did have to change one API call, though - ast_event_queue_and_cache().
However, the way it works now is nicer, IMO. Each type of event that
can be cached (MWI, device state) has its own hash table and rules for
hashing and comparing objects. This by far made the biggest impact on
performance.
For additional details regarding this code and how it was tested, please see the
review request.
(closes issue #14738)
Reported by: russell
Review: http://reviewboard.digium.com/r/205/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@184339 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-03-25 21:57:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|