#include <asterisk.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <stdio.h>#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 <asterisk/devicestate.h>

Go to the source code of this file.
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | action_devstate (struct mansession *s, struct message *m) |
| static int | devstate_cli (int fd, int argc, char *argv[]) |
| static int | devstate_exec (struct ast_channel *chan, void *data) |
| static int | ds_devicestate (void *data) |
| int | load_module (void) |
| int | unload_module (void) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Control SNOM LED Device State" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } |
| static char | app [] = "DevState" |
| static const struct ast_module_info * | ast_module_info = &__mod_info |
| 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 } |
| 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 [] |
| static struct ast_channel_tech | devstate_tech |
| static char | mandescr_devstate [] = "Description: Put a value into astdb\n" "Variables: \n" " Family: ...\n" " Key: ...\n" " Value: ...\n" |
| static char | synopsis [] = "Generate a device state change event given the input parameters" |
| static char | tdesc [] = "Application for sending device state messages" |
| static char | type [] = "DS" |
| static void __reg_module | ( | void | ) | [static] |
Definition at line 175 of file app_devstate.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 175 of file app_devstate.c.
| static int action_devstate | ( | struct mansession * | s, | |
| struct message * | m | |||
| ) | [static] |
Definition at line 130 of file app_devstate.c.
References ast_db_put(), ast_device_state_changed(), ast_log(), astman_get_header(), astman_send_error(), and LOG_DEBUG.
Referenced by load_module().
00131 { 00132 char *devstate = (char *) astman_get_header(m, "DevState"); 00133 char *value = (char *) astman_get_header(m, "Value"); 00134 char devName[128]; 00135 00136 if (!strlen(devstate)) { 00137 astman_send_error(s, m, "No DevState specified"); 00138 return 0; 00139 } 00140 if (!strlen(value)) { 00141 astman_send_error(s, m, "No Value specified"); 00142 return 0; 00143 } 00144 00145 if (!ast_db_put("DEVSTATES", devstate, value)) { 00146 snprintf(devName, sizeof(devName), "DS/%s", devstate); 00147 ast_device_state_changed(devName); 00148 } else { 00149 ast_log(LOG_DEBUG, "ast_db_put failed\n"); 00150 } 00151 return 0; 00152 }
| static int devstate_cli | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 44 of file app_devstate.c.
References ast_db_put(), ast_device_state_changed_literal(), ast_log(), LOG_DEBUG, LOG_NOTICE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00045 { 00046 char devName[128]; 00047 if ((argc != 3) && (argc != 4)) 00048 return RESULT_SHOWUSAGE; 00049 00050 if (ast_db_put("DEVSTATES", argv[1], argv[2])) { 00051 ast_log(LOG_DEBUG, "ast_db_put failed\n"); 00052 } 00053 snprintf(devName, sizeof(devName), "DS/%s", argv[1]); 00054 if (argc == 4) { 00055 ast_log(LOG_NOTICE, "devname %s cid %s\n", devName, argv[3]); 00056 ast_device_state_changed_literal(devName); 00057 } else { 00058 ast_device_state_changed_literal(devName); 00059 } 00060 return RESULT_SUCCESS; 00061 }
| static int devstate_exec | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Definition at line 63 of file app_devstate.c.
References ast_db_put(), ast_device_state_changed_literal(), ast_log(), ast_strdupa, LOG_DEBUG, and LOG_WARNING.
Referenced by load_module().
00064 { 00065 struct localuser *u; 00066 char *device, *state, *info; 00067 char devName[128]; 00068 if (!(info = ast_strdupa(data))) { 00069 ast_log(LOG_WARNING, "Unable to dupe data :(\n"); 00070 return -1; 00071 } 00072 00073 device = info; 00074 state = strchr(info, '|'); 00075 if (state) { 00076 *state = '\0'; 00077 state++; 00078 } else { 00079 ast_log(LOG_DEBUG, "No state argument supplied\n"); 00080 return -1; 00081 } 00082 00083 if (ast_db_put("DEVSTATES", device, state)) { 00084 ast_log(LOG_DEBUG, "ast_db_put failed\n"); 00085 } 00086 00087 snprintf(devName, sizeof(devName), "DS/%s", device); 00088 ast_device_state_changed_literal(devName); 00089 00090 return 0; 00091 }
| static int ds_devicestate | ( | void * | data | ) | [static] |
Definition at line 94 of file app_devstate.c.
References ast_db_get(), ast_log(), and LOG_DEBUG.
00095 { 00096 char *dest = data; 00097 char stateStr[16]; 00098 if (ast_db_get("DEVSTATES", dest, stateStr, sizeof(stateStr))) { 00099 ast_log(LOG_DEBUG, "ds_devicestate couldnt get state in astdb\n"); 00100 return 0; 00101 } else { 00102 ast_log(LOG_DEBUG, "ds_devicestate dev=%s returning state %d\n", dest, atoi(stateStr)); 00103 return (atoi(stateStr)); 00104 } 00105 }
| int load_module | ( | void | ) |
Definition at line 154 of file app_devstate.c.
References action_devstate(), app, ast_channel_register(), ast_cli_register(), ast_log(), ast_manager_register2(), ast_register_application(), descrip, devstate_exec(), EVENT_FLAG_CALL, LOG_DEBUG, mandescr_devstate, synopsis, and type.
00155 { 00156 if (ast_channel_register(&devstate_tech)) { 00157 ast_log(LOG_DEBUG, "Unable to register channel class %s\n", type); 00158 return -1; 00159 } 00160 ast_cli_register(&cli_dev_state); 00161 ast_manager_register2("DevState", EVENT_FLAG_CALL, (void *) action_devstate, "Change a device state", mandescr_devstate); 00162 return ast_register_application(app, devstate_exec, synopsis, descrip); 00163 }
| int unload_module | ( | void | ) |
Definition at line 165 of file app_devstate.c.
References app, ast_channel_unregister(), ast_cli_unregister(), ast_manager_unregister(), and ast_unregister_application().
00166 { 00167 int res = 0; 00168 ast_manager_unregister("DevState"); 00169 ast_cli_unregister(&cli_dev_state); 00170 res = ast_unregister_application(app); 00171 ast_channel_unregister(&devstate_tech); 00172 return res; 00173 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Control SNOM LED Device State" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static] |
Definition at line 175 of file app_devstate.c.
char app[] = "DevState" [static] |
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 175 of file app_devstate.c.
struct ast_cli_entry cli_dev_state = { {"DevState", NULL}, devstate_cli, "Set the device state on one of the \"pseudo devices\".", devstate_cli_usage } [static] |
Definition at line 41 of file app_devstate.c.
char devstate_cli_usage[] [static] |
Initial value:
"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"
Definition at line 36 of file app_devstate.c.
struct ast_channel_tech devstate_tech [static] |
Definition at line 107 of file app_devstate.c.
char mandescr_devstate[] = "Description: Put a value into astdb\n" "Variables: \n" " Family: ...\n" " Key: ...\n" " Value: ...\n" [static] |
Definition at line 31 of file app_devstate.c.
char type[] = "DS" [static] |
Definition at line 30 of file app_devstate.c.
1.5.9