[svn-commits] russell: branch russell/func_devstate r54220 - in
/team/russell/func_devstate...
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Tue Feb 13 14:10:46 MST 2007
Author: russell
Date: Tue Feb 13 15:10:46 2007
New Revision: 54220
URL: http://svn.digium.com/view/asterisk?view=rev&rev=54220
Log:
- Implement a CLI command to list the current state of all known custom
device states.
- Make ast_cli_(un)register_multiple return success or failure
- Make ast_devstate_prov_del() return success or failure
Modified:
team/russell/func_devstate/funcs/func_devstate.c
team/russell/func_devstate/include/asterisk/cli.h
team/russell/func_devstate/include/asterisk/devicestate.h
team/russell/func_devstate/main/cli.c
team/russell/func_devstate/main/devicestate.c
Modified: team/russell/func_devstate/funcs/func_devstate.c
URL: http://svn.digium.com/view/asterisk/team/russell/func_devstate/funcs/func_devstate.c?view=diff&rev=54220&r1=54219&r2=54220
==============================================================================
--- team/russell/func_devstate/funcs/func_devstate.c (original)
+++ team/russell/func_devstate/funcs/func_devstate.c Tue Feb 13 15:10:46 2007
@@ -40,6 +40,7 @@
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
#include "asterisk/devicestate.h"
+#include "asterisk/cli.h"
struct custom_device {
int state;
@@ -106,6 +107,48 @@
return state;
}
+static char *cli_funcdevstate_list(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct custom_device *dev;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "funcdevstate list";
+ e->usage =
+ "Usage: funcdevstate list\n"
+ " List all custom device states that have been set by using\n"
+ " the DEVSTATE dialplan function.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != e->args)
+ return CLI_SHOWUSAGE;
+
+ ast_cli(a->fd, "\n"
+ "---------------------------------------------------------------------\n"
+ "--- Custom Device States --------------------------------------------\n"
+ "---------------------------------------------------------------------\n"
+ "---\n");
+ AST_RWLIST_RDLOCK(&custom_devices);
+ AST_RWLIST_TRAVERSE(&custom_devices, dev, entry) {
+ ast_cli(a->fd, "--- Name: 'Custom:%s' State: '%s'\n"
+ "---\n", dev->name, ast_devstate_str(dev->state));
+ }
+ AST_RWLIST_UNLOCK(&custom_devices);
+ ast_cli(a->fd,
+ "---------------------------------------------------------------------\n"
+ "---------------------------------------------------------------------\n"
+ "\n");
+
+ return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry cli_funcdevstate[] = {
+ NEW_CLI(cli_funcdevstate_list, "List currently known custom device states"),
+};
+
static struct ast_custom_function devstate_function = {
.name = "DEVSTATE",
.synopsis = "Get or Set a device state",
@@ -120,7 +163,8 @@
int res = 0;
res |= ast_custom_function_unregister(&devstate_function);
- ast_devstate_prov_del("Custom");
+ res |= ast_devstate_prov_del("Custom");
+ res |= ast_cli_unregister_multiple(cli_funcdevstate, ARRAY_LEN(cli_funcdevstate));
AST_RWLIST_WRLOCK(&custom_devices);
while ((dev = AST_RWLIST_REMOVE_HEAD(&custom_devices, entry)))
@@ -136,6 +180,7 @@
res |= ast_custom_function_register(&devstate_function);
res |= ast_devstate_prov_add("Custom", custom_devstate_callback);
+ res |= ast_cli_register_multiple(cli_funcdevstate, ARRAY_LEN(cli_funcdevstate));
return res;
}
Modified: team/russell/func_devstate/include/asterisk/cli.h
URL: http://svn.digium.com/view/asterisk/team/russell/func_devstate/include/asterisk/cli.h?view=diff&rev=54220&r1=54219&r2=54220
==============================================================================
--- team/russell/func_devstate/include/asterisk/cli.h (original)
+++ team/russell/func_devstate/include/asterisk/cli.h Tue Feb 13 15:10:46 2007
@@ -235,7 +235,7 @@
* \param e pointer to first cli entry to register
* \param len number of entries to register
*/
-void ast_cli_register_multiple(struct ast_cli_entry *e, int len);
+int ast_cli_register_multiple(struct ast_cli_entry *e, int len);
/*! \brief Unregisters a command or an array of commands
*
@@ -250,7 +250,7 @@
* \param e pointer to first cli entry to unregister
* \param len number of entries to unregister
*/
-void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len);
+int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len);
/*! \brief Readline madness
* Useful for readline, that's about it
Modified: team/russell/func_devstate/include/asterisk/devicestate.h
URL: http://svn.digium.com/view/asterisk/team/russell/func_devstate/include/asterisk/devicestate.h?view=diff&rev=54220&r1=54219&r2=54220
==============================================================================
--- team/russell/func_devstate/include/asterisk/devicestate.h (original)
+++ team/russell/func_devstate/include/asterisk/devicestate.h Tue Feb 13 15:10:46 2007
@@ -127,9 +127,9 @@
/*! \brief Remove device state provider
* \param label to use in hint, like label:object
- * Return -1 on failure, ID on success
+ * Return -1 on failure, 0 on success
*/
-void ast_devstate_prov_del(const char *label);
+int ast_devstate_prov_del(const char *label);
int ast_device_state_engine_init(void);
Modified: team/russell/func_devstate/main/cli.c
URL: http://svn.digium.com/view/asterisk/team/russell/func_devstate/main/cli.c?view=diff&rev=54220&r1=54219&r2=54220
==============================================================================
--- team/russell/func_devstate/main/cli.c (original)
+++ team/russell/func_devstate/main/cli.c Tue Feb 13 15:10:46 2007
@@ -1354,20 +1354,24 @@
/*
* register/unregister an array of entries.
*/
-void ast_cli_register_multiple(struct ast_cli_entry *e, int len)
-{
- int i;
+int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
+{
+ int i, res = 0;
for (i = 0; i < len; i++)
- ast_cli_register(e + i);
-}
-
-void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
-{
- int i;
+ res |= ast_cli_register(e + i);
+
+ return res;
+}
+
+int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
+{
+ int i, res = 0;
for (i = 0; i < len; i++)
- ast_cli_unregister(e + i);
+ res |= ast_cli_unregister(e + i);
+
+ return res;
}
Modified: team/russell/func_devstate/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/team/russell/func_devstate/main/devicestate.c?view=diff&rev=54220&r1=54219&r2=54220
==============================================================================
--- team/russell/func_devstate/main/devicestate.c (original)
+++ team/russell/func_devstate/main/devicestate.c Tue Feb 13 15:10:46 2007
@@ -339,20 +339,24 @@
}
/*! \brief Remove device state provider */
-void ast_devstate_prov_del(const char *label)
+int ast_devstate_prov_del(const char *label)
{
struct devstate_prov *devcb;
+ int res = -1;
AST_RWLIST_WRLOCK(&devstate_provs);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&devstate_provs, devcb, list) {
if (!strcasecmp(devcb->label, label)) {
AST_RWLIST_REMOVE_CURRENT(&devstate_provs, list);
free(devcb);
+ res = 0;
break;
}
}
AST_RWLIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&devstate_provs);
+
+ return res;
}
/*! \brief Get provider device state */
More information about the svn-commits
mailing list