rendered paste body/*
* Asterisk -- A telephony toolkit for Linux.
*
* GetChannelState application, returns status of channel.
*
* Mike Tkachuk <mike@ukr.net>
*
* This program is free software, distributed under the terms of
* the GNU General Public License
*
* Mark Spencer have original rights
*/
#include <asterisk/lock.h>
#include <asterisk/file.h>
#include <asterisk/logger.h>
#include <asterisk/channel.h>
#include <asterisk/pbx.h>
#include <asterisk/module.h>
#include <asterisk/translate.h>
#include <asterisk/image.h>
#include <asterisk/callerid.h>
#include <asterisk/utils.h>
#include <string.h>
#include <stdlib.h>
static char *synopsis = "Gets channel state";
static char *tdesc = "This application returns originating channel state of current channel";
static char *desc = " GetChannelState()\n"
"Returns originating channel state. Returns -1 if failure, 2 if DOWN, 3 if UP\n";
static char *app = "GetChannelState";
STANDARD_LOCAL_USER;
LOCAL_USER_DECL;
static int get_channel_state(struct ast_channel *chan, void *data)
{
struct localuser *u;
LOCAL_USER_ADD(u);
int res = -1;
if (chan) {
if (chan->_softhangup){
// Channel DOWN
ast_log(LOG_NOTICE, "Channel DOWN");
res = 2;
} else {
// Channel UP
ast_log(LOG_NOTICE, "Channel UP");
res = 3;
}
}
LOCAL_USER_REMOVE(u);
return res;
}
int unload_module(void)
{
STANDARD_HANGUP_LOCALUSERS;
return ast_unregister_application(app);
}
int load_module(void)
{
return ast_register_application(app, get_channel_state, synopsis, desc);
}
char *description(void)
{
return tdesc;
}
int usecount(void)
{
int res;
STANDARD_USECOUNT(res);
return res;
}
char *key()
{
return ASTERISK_GPL_KEY;
}