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
|
|
|
*
|
2006-02-10 20:40:00 +00:00
|
|
|
* Copyright (C) 1999 - 2006, Digium, Inc.
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
|
|
|
* Mark Spencer <markster@digium.com>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2005-07-08 21:15:41 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-07-08 21:15:41 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2005-11-01 22:11:55 +00:00
|
|
|
#include <stdio.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/logger.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"
|
2005-07-08 21:15:41 +00:00
|
|
|
#include "asterisk/options.h"
|
|
|
|
|
2006-04-04 18:24:41 +00:00
|
|
|
/*! \brief Device state strings for printing */
|
2005-07-20 00:34:01 +00:00
|
|
|
static const char *devstatestring[] = {
|
2006-04-04 18:24:41 +00:00
|
|
|
/* 0 AST_DEVICE_UNKNOWN */ "Unknown", /*!< Valid, but unknown state */
|
|
|
|
/* 1 AST_DEVICE_NOT_INUSE */ "Not in use", /*!< Not used */
|
|
|
|
/* 2 AST_DEVICE IN USE */ "In use", /*!< In use */
|
|
|
|
/* 3 AST_DEVICE_BUSY */ "Busy", /*!< Busy */
|
|
|
|
/* 4 AST_DEVICE_INVALID */ "Invalid", /*!< Invalid - not known to Asterisk */
|
|
|
|
/* 5 AST_DEVICE_UNAVAILABLE */ "Unavailable", /*!< Unavailable (not registred) */
|
|
|
|
/* 6 AST_DEVICE_RINGING */ "Ringing" /*!< Ring, ring, ring */
|
2005-07-20 00:34: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
|
|
|
/*! \brief A device state provider (not a channel) */
|
|
|
|
struct devstate_prov {
|
|
|
|
char label[40];
|
|
|
|
ast_devstate_prov_cb_type callback;
|
|
|
|
AST_LIST_ENTRY(devstate_prov) list;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*! \brief A list of providers */
|
|
|
|
static AST_LIST_HEAD_STATIC(devstate_provs, devstate_prov);
|
|
|
|
|
2006-04-04 18:24:41 +00:00
|
|
|
/*! \brief A device state watcher (callback) */
|
2005-07-08 21:15:41 +00:00
|
|
|
struct devstate_cb {
|
|
|
|
void *data;
|
|
|
|
ast_devstate_cb_type callback;
|
|
|
|
AST_LIST_ENTRY(devstate_cb) 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 device state watcher list */
|
2005-07-08 21:15:41 +00:00
|
|
|
static AST_LIST_HEAD_STATIC(devstate_cbs, devstate_cb);
|
|
|
|
|
|
|
|
struct state_change {
|
|
|
|
AST_LIST_ENTRY(state_change) list;
|
|
|
|
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
|
|
|
|
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 */
|
2005-07-20 00:34:01 +00:00
|
|
|
const char *devstate2str(int devstate)
|
|
|
|
{
|
|
|
|
return devstatestring[devstate];
|
|
|
|
}
|
|
|
|
|
2006-04-04 18:24:41 +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
|
|
|
|
This function is only used for channels that does not implement
|
|
|
|
devicestate natively
|
2006-04-04 18:24:41 +00:00
|
|
|
*/
|
2005-07-08 21:15:41 +00:00
|
|
|
int ast_parse_device_state(const char *device)
|
|
|
|
{
|
|
|
|
struct ast_channel *chan;
|
|
|
|
char match[AST_CHANNEL_NAME];
|
|
|
|
int res;
|
|
|
|
|
|
|
|
ast_copy_string(match, device, sizeof(match)-1);
|
|
|
|
strcat(match, "-");
|
|
|
|
chan = ast_get_channel_by_name_prefix_locked(match, strlen(match));
|
|
|
|
|
|
|
|
if (!chan)
|
|
|
|
return AST_DEVICE_UNKNOWN;
|
|
|
|
|
|
|
|
if (chan->_state == AST_STATE_RINGING)
|
|
|
|
res = AST_DEVICE_RINGING;
|
|
|
|
else
|
|
|
|
res = AST_DEVICE_INUSE;
|
|
|
|
|
2006-04-29 14:50:18 +00:00
|
|
|
ast_channel_unlock(chan);
|
2005-07-08 21:15:41 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Check device state through channel specific function or generic function */
|
2005-07-08 21:15:41 +00:00
|
|
|
int ast_device_state(const char *device)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
char *number;
|
|
|
|
const struct ast_channel_tech *chan_tech;
|
|
|
|
int 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
|
|
|
/*! \brief Channel driver that provides device state */
|
|
|
|
char *tech;
|
|
|
|
/*! \brief Another provider of device state */
|
|
|
|
char *provider = NULL;
|
2005-07-08 21:15:41 +00:00
|
|
|
|
|
|
|
buf = ast_strdupa(device);
|
|
|
|
tech = strsep(&buf, "/");
|
|
|
|
number = buf;
|
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 (!number) {
|
|
|
|
provider = strsep(&tech, ":");
|
|
|
|
if (!provider)
|
|
|
|
return AST_DEVICE_INVALID;
|
|
|
|
/* We have a provider */
|
|
|
|
number = tech;
|
|
|
|
tech = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (provider) {
|
|
|
|
if(option_debug > 2)
|
|
|
|
ast_log(LOG_DEBUG, "Checking if I can find provider for \"%s\" - number: %s\n", provider, number);
|
|
|
|
return getproviderstate(provider, number);
|
|
|
|
}
|
|
|
|
if (option_debug > 3)
|
|
|
|
ast_log(LOG_DEBUG, "No provider found, checking channel drivers for %s - %s\n", tech, number);
|
|
|
|
|
2005-07-08 21:15:41 +00:00
|
|
|
chan_tech = ast_get_channel_tech(tech);
|
|
|
|
if (!chan_tech)
|
|
|
|
return AST_DEVICE_INVALID;
|
|
|
|
|
2005-07-20 00:34:01 +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 */
|
2005-07-08 21:15:41 +00:00
|
|
|
else {
|
2005-07-20 00:34:01 +00:00
|
|
|
res = chan_tech->devicestate(number); /* Ask the channel driver for device state */
|
2005-09-01 22:28:33 +00:00
|
|
|
if (res == AST_DEVICE_UNKNOWN) {
|
|
|
|
res = ast_parse_device_state(device);
|
|
|
|
/* at this point we know the device exists, but the channel driver
|
|
|
|
could not give us a state; if there is no channel state available,
|
|
|
|
it must be 'not in use'
|
|
|
|
*/
|
|
|
|
if (res == AST_DEVICE_UNKNOWN)
|
|
|
|
res = AST_DEVICE_NOT_INUSE;
|
|
|
|
return res;
|
|
|
|
} else
|
2005-07-08 21:15:41 +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 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));
|
|
|
|
|
|
|
|
AST_LIST_LOCK(&devstate_provs);
|
|
|
|
AST_LIST_INSERT_HEAD(&devstate_provs, devprov, list);
|
|
|
|
AST_LIST_UNLOCK(&devstate_provs);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Remove device state provider */
|
|
|
|
void ast_devstate_prov_del(const char *label)
|
|
|
|
{
|
|
|
|
struct devstate_prov *devcb;
|
|
|
|
|
|
|
|
AST_LIST_LOCK(&devstate_provs);
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) {
|
|
|
|
if (!strcasecmp(devcb->label, label)) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(&devstate_provs, list);
|
|
|
|
free(devcb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
|
|
|
AST_LIST_UNLOCK(&devstate_provs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Get provider device state */
|
|
|
|
static int getproviderstate(const char *provider, const char *address)
|
|
|
|
{
|
|
|
|
struct devstate_prov *devprov;
|
|
|
|
int res = AST_DEVICE_INVALID;
|
|
|
|
|
|
|
|
|
|
|
|
AST_LIST_LOCK(&devstate_provs);
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devprov, list) {
|
|
|
|
if(option_debug > 4)
|
|
|
|
ast_log(LOG_DEBUG, "Checking provider %s with %s\n", devprov->label, provider);
|
|
|
|
|
|
|
|
if (!strcasecmp(devprov->label, provider)) {
|
|
|
|
res = devprov->callback(address);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
|
|
|
AST_LIST_UNLOCK(&devstate_provs);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Add device state watcher */
|
2005-07-08 21:15:41 +00:00
|
|
|
int ast_devstate_add(ast_devstate_cb_type callback, void *data)
|
|
|
|
{
|
|
|
|
struct devstate_cb *devcb;
|
|
|
|
|
2006-02-09 16:59:50 +00:00
|
|
|
if (!callback || !(devcb = ast_calloc(1, sizeof(*devcb))))
|
2005-07-08 21:15:41 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
devcb->data = data;
|
|
|
|
devcb->callback = callback;
|
|
|
|
|
|
|
|
AST_LIST_LOCK(&devstate_cbs);
|
|
|
|
AST_LIST_INSERT_HEAD(&devstate_cbs, devcb, list);
|
|
|
|
AST_LIST_UNLOCK(&devstate_cbs);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Remove device state watcher */
|
2005-07-08 21:15:41 +00:00
|
|
|
void ast_devstate_del(ast_devstate_cb_type callback, void *data)
|
|
|
|
{
|
|
|
|
struct devstate_cb *devcb;
|
|
|
|
|
|
|
|
AST_LIST_LOCK(&devstate_cbs);
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&devstate_cbs, devcb, list) {
|
|
|
|
if ((devcb->callback == callback) && (devcb->data == data)) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(&devstate_cbs, list);
|
|
|
|
free(devcb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
|
|
|
AST_LIST_UNLOCK(&devstate_cbs);
|
|
|
|
}
|
|
|
|
|
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 Notify callback watchers of change, and notify PBX core for hint updates
|
|
|
|
Normally executed within a separate thread
|
|
|
|
*/
|
2005-07-08 21:15:41 +00:00
|
|
|
static void do_state_change(const char *device)
|
|
|
|
{
|
|
|
|
int state;
|
|
|
|
struct devstate_cb *devcb;
|
|
|
|
|
|
|
|
state = ast_device_state(device);
|
|
|
|
if (option_debug > 2)
|
2005-07-20 00:34:01 +00:00
|
|
|
ast_log(LOG_DEBUG, "Changing state for %s - state %d (%s)\n", device, state, devstate2str(state));
|
2005-07-08 21:15:41 +00:00
|
|
|
|
|
|
|
AST_LIST_LOCK(&devstate_cbs);
|
|
|
|
AST_LIST_TRAVERSE(&devstate_cbs, devcb, list)
|
|
|
|
devcb->callback(device, state, devcb->data);
|
|
|
|
AST_LIST_UNLOCK(&devstate_cbs);
|
|
|
|
|
|
|
|
ast_hint_state_changed(device);
|
|
|
|
}
|
|
|
|
|
2005-10-17 15:41:55 +00:00
|
|
|
static int __ast_device_state_changed_literal(char *buf)
|
2005-07-08 21:15:41 +00:00
|
|
|
{
|
2005-10-26 15:34:34 +00:00
|
|
|
char *device, *tmp;
|
2006-02-09 16:59:50 +00:00
|
|
|
struct state_change *change;
|
2005-07-08 21:15:41 +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
|
|
|
if (option_debug > 2)
|
|
|
|
ast_log(LOG_DEBUG, "Notification of state change to be queued on device/channel %s\n", buf);
|
|
|
|
|
2005-10-26 15:34:34 +00:00
|
|
|
device = buf;
|
2006-02-09 16:59:50 +00:00
|
|
|
if ((tmp = strrchr(device, '-')))
|
2005-10-26 15:34:34 +00:00
|
|
|
*tmp = '\0';
|
2005-07-08 21:15:41 +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
|
|
|
|
|
|
|
|
2006-02-09 16:59:50 +00:00
|
|
|
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 */
|
|
|
|
do_state_change(device);
|
|
|
|
} else {
|
|
|
|
/* queue the change */
|
|
|
|
strcpy(change->device, device);
|
|
|
|
AST_LIST_LOCK(&state_changes);
|
|
|
|
AST_LIST_INSERT_TAIL(&state_changes, change, list);
|
2005-07-10 13:06:54 +00:00
|
|
|
if (AST_LIST_FIRST(&state_changes) == change)
|
2005-07-08 21:15:41 +00:00
|
|
|
/* the list was empty, signal the thread */
|
2005-10-28 16:35:43 +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)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
buf = ast_strdupa(dev);
|
|
|
|
return __ast_device_state_changed_literal(buf);
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Accept change notification, add it to change queue */
|
2005-10-17 15:41:55 +00:00
|
|
|
int ast_device_state_changed(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buf[AST_MAX_EXTENSION];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return __ast_device_state_changed_literal(buf);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
struct state_change *cur;
|
|
|
|
|
2005-07-10 13:06:54 +00:00
|
|
|
AST_LIST_LOCK(&state_changes);
|
2005-07-08 21:15:41 +00:00
|
|
|
for(;;) {
|
2005-07-10 13:06:54 +00:00
|
|
|
/* the list lock will _always_ be held at this point in the loop */
|
|
|
|
cur = AST_LIST_REMOVE_HEAD(&state_changes, list);
|
|
|
|
if (cur) {
|
|
|
|
/* we got an entry, so unlock the list while we process it */
|
2005-07-08 21:15:41 +00:00
|
|
|
AST_LIST_UNLOCK(&state_changes);
|
|
|
|
do_state_change(cur->device);
|
|
|
|
free(cur);
|
2005-07-10 13:06:54 +00:00
|
|
|
AST_LIST_LOCK(&state_changes);
|
|
|
|
} else {
|
|
|
|
/* there was no entry, so atomically unlock the list and wait for
|
|
|
|
the condition to be signalled (returns with the lock held) */
|
2005-10-28 16:35:43 +00:00
|
|
|
ast_cond_wait(&change_pending, &state_changes.lock);
|
2005-07-08 21:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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-02-10 20:40:00 +00:00
|
|
|
if (ast_pthread_create(&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;
|
|
|
|
}
|