[asterisk-commits] eliel: branch eliel/data_api_providers_gsoc2010 r281434 - in /team/eliel/data...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Aug 9 16:02:47 CDT 2010
Author: eliel
Date: Mon Aug 9 16:02:43 2010
New Revision: 281434
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=281434
Log:
Implements the /asterisk/core/uptime AstData API node.
Modified:
team/eliel/data_api_providers_gsoc2010/include/asterisk/_private.h
team/eliel/data_api_providers_gsoc2010/main/asterisk.c
team/eliel/data_api_providers_gsoc2010/main/cli.c
Modified: team/eliel/data_api_providers_gsoc2010/include/asterisk/_private.h
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/include/asterisk/_private.h?view=diff&rev=281434&r1=281433&r2=281434
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/include/asterisk/_private.h (original)
+++ team/eliel/data_api_providers_gsoc2010/include/asterisk/_private.h Mon Aug 9 16:02:43 2010
@@ -24,6 +24,7 @@
int astdb_init(void); /*!< Provided by db.c */
void ast_channels_init(void); /*!< Provided by channel.c */
void ast_builtins_init(void); /*!< Provided by cli.c */
+void ast_builtins_cli_data_init(void); /*!< Provided by cli.c */
int ast_cli_perms_init(int reload); /*!< Provided by cli.c */
int dnsmgr_init(void); /*!< Provided by dnsmgr.c */
void dnsmgr_start_refresh(void); /*!< Provided by dnsmgr.c */
Modified: team/eliel/data_api_providers_gsoc2010/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/main/asterisk.c?view=diff&rev=281434&r1=281433&r2=281434
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/main/asterisk.c (original)
+++ team/eliel/data_api_providers_gsoc2010/main/asterisk.c Mon Aug 9 16:02:43 2010
@@ -3671,6 +3671,7 @@
printf ("%s", term_quit());
exit(1);
}
+ ast_builtins_cli_data_init();
ast_channels_init();
Modified: team/eliel/data_api_providers_gsoc2010/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/main/cli.c?view=diff&rev=281434&r1=281433&r2=281434
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/main/cli.c (original)
+++ team/eliel/data_api_providers_gsoc2010/main/cli.c Mon Aug 9 16:02:43 2010
@@ -46,6 +46,7 @@
#include "asterisk/lock.h"
#include "editline/readline/readline.h"
#include "asterisk/threadstorage.h"
+#include "asterisk/data.h"
/*!
* \brief List of restrictions per user.
@@ -1792,10 +1793,50 @@
return 0;
}
+/*!
+ * \internal
+ * \brief Callback used to generate the uptime tree.
+ * \param[in] search The search pattern tree.
+ * \retval <0 on error.
+ * \retval 0 The generated tree.
+ */
+static int uptime_data_provider_get(const struct ast_data_search *search,
+ struct ast_data *data_root)
+{
+ struct timeval curtime = ast_tvnow(), last_reload, current_uptime;
+
+ if (ast_startuptime.tv_sec) {
+ current_uptime = ast_tvsub(curtime, ast_startuptime);
+ ast_data_add_seconds(data_root, "uptime", (u_long)current_uptime.tv_sec);
+ }
+
+ if (ast_lastreloadtime.tv_sec) {
+ last_reload = ast_tvsub(curtime, ast_lastreloadtime);
+ ast_data_add_seconds(data_root, "reload", (u_long)last_reload.tv_sec);
+ }
+
+ return 0;
+}
+
+static const struct ast_data_handler uptime_data_provider = {
+ .version = AST_DATA_HANDLER_VERSION,
+ .get = uptime_data_provider_get
+};
+
+static const struct ast_data_entry cli_data_providers[] = {
+ AST_DATA_ENTRY("/asterisk/core/uptime", &uptime_data_provider),
+};
+
/*! \brief initialize the _full_cmd string in * each of the builtins. */
void ast_builtins_init(void)
{
ast_cli_register_multiple(cli_cli, ARRAY_LEN(cli_cli));
+}
+
+/*! \brief Initialize cli data providers */
+void ast_builtins_cli_data_init(void)
+{
+ ast_data_register_multiple_core(cli_data_providers, ARRAY_LEN(cli_data_providers));
}
/*!
More information about the asterisk-commits
mailing list