Actually, this was a bit tougher in HEAD due to the new ast_channel_tech & register methods. I've re-written/patched the app_devstate.c file to allow the toggle of any parameter in order to make the light go on/off with the SNOM phones.
This works as of HEAD today (08/09/2005):

Thanks for the info Klaus!

--Dustin




Klaus-Peter Junghanns wrote:

hmm..extracting it from:
http://www.junghanns.net/asterisk/downloads/bristuff-0.2.0-RC8f-CVS.tar.gz
shouldnt be rocket science. ;-)

good luck,

Klaus

On Tue, 2005-08-09 at 09:36 -0400, Dustin Wildes wrote:
I had noticed the 'devicestate.c' in HEAD and was looking over both the custom-bristuff version and the HEAD to see how involved it would be. Not to be pushy or anything, but do you have an ETA of the new version? I have a client that I can get off my back if I make some of their buttons light-up! (not extensions - but settings related to astdb) *hahah*

I'll be more than happy to test it out.
Thanks for your help!!

--Dustin


/*
 * Devstate application
 * 
 * Since we like the snom leds so much, a little app to
 * light the lights on the snom on demand ....
 *
 * Copyright (C) 2005, Druid Software
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License
 */

#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/astdb.h>
#include <asterisk/utils.h>
#include <asterisk/cli.h>
#include <asterisk/manager.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

static int ds_devicestate(void *data);
static char *type = "DS";
static char *tdesc = "Application for sending device state messages";

static char *app = "Devstate";

static char *synopsis = "Generate a device state change event given the input parameters";

static char *descrip = 
"  Devstate(device|state):  Generate a device state change event given the input parameters. Returns 0. State values match the asterisk device states. They are 0 = unknown, 1 = not inuse, 2 = inuse, 3 = busy, 4 = invalid, 5 = unavailable, 6 = ringing\n";

static char devstate_cli_usage[] = 
"Usage: devstate device state\n" 
"       Generate a device state change event given the input parameters.\n Mainly used for lighting the LEDs on the snoms.\n";

static int devstate_cli(int fd, int argc, char *argv[]);
static struct ast_cli_entry  cli_dev_state =
        { { "devstate", NULL }, devstate_cli, "Set the device state on one of the \"pseudo devices\".", devstate_cli_usage };

STANDARD_LOCAL_USER;

LOCAL_USER_DECL;

static struct ast_channel *ds_request(const char *type, int format, void *data, int *cause);

static const struct ast_channel_tech ds_tech = {
        .type = "DS",
        .description = "Devstate",
	.requester = ds_request,
	.devicestate = ds_devicestate,

};


static int devstate_cli(int fd, int argc, char *argv[])
{
    char devName[128];
    if (argc != 3)
        return RESULT_SHOWUSAGE;

    if (ast_db_put("DEVSTATES", argv[1], argv[2]))
    {
        ast_log(LOG_DEBUG, "ast_db_put failed\n");
    }

    snprintf(devName, sizeof(devName), "DS/%s", argv[1]);
    ast_device_state_changed(devName);
    return RESULT_SUCCESS;
}

static int devstate_exec(struct ast_channel *chan, void *data)
{
    struct localuser *u;
    char *device, *state, *info;
    char devName[128];
    if (!(info = ast_strdupa(data))) {
            ast_log(LOG_WARNING, "Unable to dupe data :(\n");
            return -1;
    }
    LOCAL_USER_ADD(u);
    
    device = info;
    state = strchr(info, '|');
    if (state) {
        *state = '\0';
        state++;
    }
    else
    {
        ast_log(LOG_DEBUG, "No state argument supplied\n");
        return -1;
    }

    if (ast_db_put("DEVSTATES", device, state))
    {
        ast_log(LOG_DEBUG, "ast_db_put failed\n");
    }

    snprintf(devName, sizeof(devName), "DS/%s", device);
    ast_device_state_changed(devName);

    LOCAL_USER_REMOVE(u);
    return 0;
}


static int ds_devicestate(void *data)
{
    char *dest = data;
    char stateStr[16];
    if (ast_db_get("DEVSTATES", dest, stateStr, sizeof(stateStr)))
    {
        ast_log(LOG_DEBUG, "ds_devicestate couldnt get state in astdb\n");
        return 0;
    }
    else
    {
        ast_log(LOG_DEBUG, "ds_devicestate dev=%s returning state %d\n",
               dest, atoi(stateStr));
        return (atoi(stateStr));
    }
}

static char mandescr_devstate[] = 
"Description: Put a value into astdb\n"
"Variables: \n"
"	Family: ...\n"
"	Key: ...\n"
"	Value: ...\n";

static int action_devstate(struct mansession *s, struct message *m)
{
        char *devstate = astman_get_header(m, "Devstate");
        char *value = astman_get_header(m, "Value");
	char *id = astman_get_header(m,"ActionID");
	char devName[128];

	if (!strlen(devstate)) {
		astman_send_error(s, m, "No Devstate specified");
		return 0;
	}
	if (!strlen(value)) {
		astman_send_error(s, m, "No Value specified");
		return 0;
	}

	ast_mutex_lock(&s->lock);

        if (!ast_db_put("DEVSTATES", devstate, value)) {
	    snprintf(devName, sizeof(devName), "DS/%s", devstate);
	    ast_device_state_changed(devName);
	    ast_cli(s->fd, "Response: Success\r\n");
	} else {
	    ast_log(LOG_DEBUG, "ast_db_put failed\n");
	    ast_cli(s->fd, "Response: Failed\r\n");
	}
	if (id && !ast_strlen_zero(id))
		ast_cli(s->fd, "ActionID: %s\r\n",id);
	ast_cli(s->fd, "\r\n");
	ast_mutex_unlock(&s->lock);
	return 0;
}

static struct ast_channel *ds_request(const char *type, int format, void *data, int *cause)
{
        char *exten = NULL;
        struct ast_channel *peer;

        if(!data || !(exten = ast_strdupa(data))) {
        ast_log(LOG_WARNING,"No Memory!\n");
        return NULL;
    }
        if((peer = devstate_exec(NULL, exten))) {
                ast_setstate(peer, AST_STATE_RESERVED);
        }

        return peer;
}


int load_module(void)
{
    if (ast_channel_register(&ds_tech)) {
        ast_log(LOG_DEBUG, "Unable to register channel class %s\n", type);
        return -1;
    }
    ast_cli_register(&cli_dev_state);  
    ast_manager_register2( "Devstate", EVENT_FLAG_CALL, action_devstate, "Change a device state", mandescr_devstate );
    return ast_register_application(app, devstate_exec, synopsis, descrip);
}

int unload_module(void)
{
    int res = 0;
    STANDARD_HANGUP_LOCALUSERS;
    ast_manager_unregister( "Devstate");
    ast_cli_unregister(&cli_dev_state);
    res = ast_unregister_application(app);
    ast_channel_unregister(type);    
    return res;
}

char *description(void)
{
    return tdesc;
}

int usecount(void)
{
    int res;
    STANDARD_USECOUNT(res);
    return res;
}

char *key()
{
    return ASTERISK_GPL_KEY;
}
_______________________________________________
Asterisk-Users mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to