Index: CHANGES =================================================================== --- CHANGES (revision 244040) +++ CHANGES (working copy) @@ -57,6 +57,12 @@ if available Reason: Q.850;cause= header. It is implemented in some gateways for better passing PRI/SS7 cause codes via SIP. +Device State Changes +----------- + * Added AMI commands to set and get device_state information in func_devicestate. + * DeviceStates are now sent directly as events to Asterisk Manager Interface as + 'DeviceStateChanged' events in a new devicestate event class. + IAX2 Changes ----------- * Added rtsavesysname option into iax.conf to allow the systname to be saved @@ -324,6 +330,7 @@ * The redirect command now has new parameters ExtraContext, ExtraExtension, and ExtraPriority to allow redirecting the second channel to a different location than the first. + * A new class, devicestate, is introduced for devicestate operations and events. Channel Event Logging --------------------- Index: funcs/func_devstate.c =================================================================== --- funcs/func_devstate.c (revision 244040) +++ funcs/func_devstate.c (working copy) @@ -42,6 +42,7 @@ #include "asterisk/devicestate.h" #include "asterisk/cli.h" #include "asterisk/astdb.h" +#include "asterisk/manager.h" #include "asterisk/app.h" /*** DOCUMENTATION @@ -92,6 +93,37 @@ NoOp(Hint for Extension 1234 is ${HINT(1234)}) + + + Get DeviceState information. + + + + + + + The DeviceStateGet command can be used to get custom device states. + Possible DeviceState return values are: + UNKNOWN | NOT_INUSE | INUSE | BUSY | INVALID | UNAVAILABLE | RINGING | + RINGINUSE | ONHOLD + + + + + Set DeviceState information. + + + + + + + + The DeviceStateSet command can be used to set custom device states. + The possible DeviceState values for this function are: + UNKNOWN | NOT_INUSE | INUSE | BUSY | INVALID | UNAVAILABLE | RINGING | + RINGINUSE | ONHOLD + + ***/ @@ -295,6 +327,66 @@ return CLI_SUCCESS; } +static int manager_devicestateget(struct mansession *s, const struct message *m) +{ + const char *id = astman_get_header(m,"ActionID"); + char idText[256] = ""; + const char *device = astman_get_header(m, "DeviceName"); + + if (ast_strlen_zero(device)) { + astman_send_error(s, m, "No DeviceName specified"); + return 0; + } + + if (!ast_strlen_zero(id)) { + snprintf(idText, sizeof(idText) ,"ActionID: %s\r\n", id); + } + + astman_append(s, "Response: Success\r\n" + "DeviceName: %s\r\n" + "DeviceState: %s\r\n" + "%s" + "\r\n", + device, ast_devstate_str(ast_device_state(device)), idText); + + return 0; +} + +static int manager_devicestateset(struct mansession *s, const struct message *m) +{ + size_t len = strlen("Custom:"); + enum ast_device_state state_val; + const char *device = astman_get_header(m, "DeviceName"); + const char *value = astman_get_header(m, "DeviceState"); + + if (ast_strlen_zero(device)) { + astman_send_error(s, m, "No DeviceName specified"); + return 0; + } + + if (ast_strlen_zero(value)) { + astman_send_error(s, m, "No DeviceState specified"); + return 0; + } + + if (strncasecmp(device, "Custom:", len)) { + astman_send_error(s, m, "DeviceName must be prefixed with Custom:"); + return 0; + } + + state_val = ast_devstate_val(value); + + if (state_val == AST_DEVICE_UNKNOWN) { + astman_send_error(s, m, "Invalid state value"); + return 0; + } + + ast_db_put(astdb_family, device + len, value); + ast_devstate_changed_literal(state_val, device); + astman_send_ack(s, m, "Device state was successfully set"); + return 0; +} + static struct ast_cli_entry cli_funcdevstate[] = { AST_CLI_DEFINE(handle_cli_devstate_list, "List currently known custom device states"), AST_CLI_DEFINE(handle_cli_devstate_change, "Change a custom device state"), @@ -320,6 +412,9 @@ res |= ast_devstate_prov_del("Custom"); res |= ast_cli_unregister_multiple(cli_funcdevstate, ARRAY_LEN(cli_funcdevstate)); + ast_manager_unregister("DeviceStateSet"); + ast_manager_unregister("DeviceStateGet"); + return res; } @@ -346,6 +441,9 @@ res |= ast_devstate_prov_add("Custom", custom_devstate_callback); res |= ast_cli_register_multiple(cli_funcdevstate, ARRAY_LEN(cli_funcdevstate)); + ast_manager_register("DeviceStateSet", EVENT_FLAG_DEVICESTATE, manager_devicestateset, "Set a ${DEVICE_STATE(Custom:devicename)} state"); + ast_manager_register("DeviceStateGet", EVENT_FLAG_DEVICESTATE, manager_devicestateget, "Get a ${DEVICE_STATE(devicename)} state"); + return res; } Index: include/asterisk/manager.h =================================================================== --- include/asterisk/manager.h (revision 244040) +++ include/asterisk/manager.h (working copy) @@ -74,6 +74,7 @@ #define EVENT_FLAG_ORIGINATE (1 << 12) /* Originate a call to an extension */ #define EVENT_FLAG_AGI (1 << 13) /* AGI events */ #define EVENT_FLAG_HOOKRESPONSE (1 << 14) /* Hook Response */ +#define EVENT_FLAG_DEVICESTATE (1 << 15) /* Devicestate events and commands */ /*@} */ /*! \brief Export manager structures */ Index: main/manager.c =================================================================== --- main/manager.c (revision 244040) +++ main/manager.c (working copy) @@ -980,6 +980,7 @@ { EVENT_FLAG_DIALPLAN, "dialplan" }, { EVENT_FLAG_ORIGINATE, "originate" }, { EVENT_FLAG_AGI, "agi" }, + { EVENT_FLAG_DEVICESTATE, "devicestate" }, { INT_MAX, "all" }, { 0, "none" }, }; Index: main/devicestate.c =================================================================== --- main/devicestate.c (revision 244040) +++ main/devicestate.c (working copy) @@ -126,6 +126,7 @@ #include "asterisk/pbx.h" #include "asterisk/app.h" #include "asterisk/event.h" +#include "asterisk/manager.h" /*! \brief Device state strings for printing */ static const char * const devstatestring[][2] = { @@ -455,6 +456,12 @@ ast_debug(3, "Changing state for %s - state %d (%s)\n", device, state, ast_devstate2str(state)); + manager_event(EVENT_FLAG_DEVICESTATE, "DeviceStateChanged", + "DeviceName: %s\r\n" + "DeviceState: %s\r\n", + device, + ast_devstate_str(state)); + devstate_event(device, state); } Index: configs/manager.conf.sample =================================================================== --- configs/manager.conf.sample (revision 244040) +++ configs/manager.conf.sample (working copy) @@ -84,23 +84,24 @@ ; Write authorization permits you to send commands and get back responses. The ; following classes exist: ; -; system - General information about the system and ability to run system -; management commands, such as Shutdown, Restart, and Reload. -; call - Information about channels and ability to set information in a -; running channel. -; log - Logging information. Read-only. -; verbose - Verbose information. Read-only. -; agent - Information about queues and agents and ability to add queue -; members to a queue. -; user - Permission to send and receive UserEvent. -; config - Ability to read and write configuration files. -; command - Permission to run CLI commands. Write-only. -; dtmf - Receive DTMF events. Read-only. -; reporting - Ability to get information about the system. -; cdr - Output of cdr_manager, if loaded. Read-only. -; dialplan - Receive NewExten and VarSet events. Read-only. -; originate - Permission to originate new calls. Write-only. +; system - General information about the system and ability to run system +; management commands, such as Shutdown, Restart, and Reload. +; call - Information about channels and ability to set information in a +; running channel. +; log - Logging information. Read-only. +; verbose - Verbose information. Read-only. +; agent - Information about queues and agents and ability to add queue +; members to a queue. +; user - Permission to send and receive UserEvent. +; config - Ability to read and write configuration files. +; command - Permission to run CLI commands. Write-only. +; dtmf - Receive DTMF events. Read-only. +; reporting - Ability to get information about the system. +; cdr - Output of cdr_manager, if loaded. Read-only. +; dialplan - Receive NewExten and VarSet events. Read-only. +; originate - Permission to originate new calls. Write-only. +; devicestate - Devicestate getting/setting and events. ; -;read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan -;write = system,call,agent,user,config,command,reporting,originate +;read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan,devicestate +;write = system,call,agent,user,config,command,reporting,originate,devicestate