[asterisk-commits] jrose: branch jrose/bridge_projects r383499 - /team/jrose/bridge_projects/res...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 20 17:12:26 CDT 2013


Author: jrose
Date: Wed Mar 20 17:12:22 2013
New Revision: 383499

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383499
Log:
remove parking_tools, add parking_ui

Added:
    team/jrose/bridge_projects/res/parking/parking_ui.c   (with props)
Removed:
    team/jrose/bridge_projects/res/parking/parking_tools.c

Added: team/jrose/bridge_projects/res/parking/parking_ui.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_ui.c?view=auto&rev=383499
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_ui.c (added)
+++ team/jrose/bridge_projects/res/parking/parking_ui.c Wed Mar 20 17:12:22 2013
@@ -1,0 +1,279 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Jonathan Rose <jrose at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Call Parking CLI commands and Manager Actions
+ *
+ * \author Jonathan Rose <jrose at digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "res_parking.h"
+#include "asterisk/config.h"
+#include "asterisk/config_options.h"
+#include "asterisk/event.h"
+#include "asterisk/utils.h"
+#include "asterisk/module.h"
+#include "asterisk/cli.h"
+#include "asterisk/astobj2.h"
+#include "asterisk/features.h"
+#include "asterisk/manager.h"
+
+/*** DOCUMENTATION
+	<manager name="Parkinglots" language="en_US">
+		<synopsis>
+			Get a list of parking lots
+		</synopsis>
+		<syntax>
+			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+		</syntax>
+		<description>
+			<para>List all parking lots as a series of AMI events</para>
+		</description>
+	</manager>
+	<manager name="ParkedCalls" language="en_US">
+		<synopsis>
+			List parked calls.
+		</synopsis>
+		<syntax>
+			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+		</syntax>
+		<description>
+			<para>List parked calls.</para>
+		</description>
+	</manager>
+ ***/
+
+static void cli_display_parking_lot(int fd, const char *name)
+{
+	RAII_VAR(struct parking_lot *, lot, NULL, ao2_cleanup);
+	struct ao2_iterator i;
+	struct parked_user *user;
+	int total = 0;
+
+	lot = parking_lot_get(name);
+
+	/* If the parking lot couldn't be found with the search, also abort. */
+	if (!lot) {
+		return;
+	}
+
+	ast_cli(fd, "\nParking Lot: %s\n------------------------------------------------------------------------\n", name);
+	ast_cli(fd, "Parking Extension      :      %s\n", lot->parkext);
+	ast_cli(fd, "Parking Context        :      %s\n", lot->parking_con);
+	ast_cli(fd, "Parked Call Extensions :      %d-%d\n", lot->parking_start, lot->parking_stop);
+	ast_cli(fd, "Parking Time           :      %u sec\n", lot->parkingtime);
+	ast_cli(fd, "Comeback to Origin     :      %s\n", lot->comebacktoorigin ? "yes" : "no");
+	ast_cli(fd, "Comeback Context       :      %s%s\n", lot->comebackcontext, lot->comebacktoorigin ? " (comebacktoorigin=yes, not used)" : "");
+	ast_cli(fd, "Comeback Dial Time     :      %u sec\n", lot->comebackdialtime);
+	ast_cli(fd, "MusicOnHold Class      :      %s\n", lot->mohclass);
+	ast_cli(fd, "Enabled                :      %s\n", lot->disabled ? "no" : "yes");
+	ast_cli(fd, "\n");
+	ast_cli(fd, "Parked Calls\n------------\n");
+
+	i = ao2_iterator_init(lot->parked_user_list, 0);
+	while ((user = ao2_iterator_next(&i))) {
+		ast_cli(fd, "  Space: %d\n", user->parking_space);
+		ast_cli(fd, "  Channel: %s\n", ast_channel_name(user->chan));
+		ast_cli(fd, "\n");
+		ao2_ref(user, -1);
+		total++;
+	}
+	ao2_iterator_destroy(&i);
+
+	if (!total) {
+		ast_cli(fd, "  (none)\n");
+		ast_cli(fd, "\n");
+	}
+
+	ast_cli(fd, "\n");
+}
+
+static void cli_display_parking_lot_list(int fd)
+{
+	struct ao2_iterator *i;
+	void *o;
+
+	i = parking_lot_iterator_create();
+
+	if (!i) {
+		ast_cli(fd, "Parking Lot configuration is unavailable.\n");
+		return;
+	}
+
+	while ((o = ao2_iterator_next(i))) {
+		struct parking_lot *lot = o;
+		ast_cli(fd, "\n");
+		ast_cli(fd, "Parking lot: %s\n", lot->name);
+		ast_cli(fd, "------------\n");
+		ast_cli(fd, "Parking Extension      :      %s\n", lot->parkext);
+		ast_cli(fd, "Parking Context        :      %s\n", lot->parking_con);
+		ast_cli(fd, "Parked Call Extensions :      %d-%d\n", lot->parking_start, lot->parking_stop);
+		ast_cli(fd, "Parking Time           :      %u sec\n", lot->parkingtime);
+		ast_cli(fd, "Comeback to Origin     :      %s\n", lot->comebacktoorigin ? "yes" : "no");
+		ast_cli(fd, "Comeback Context       :      %s%s\n", lot->comebackcontext, lot->comebacktoorigin ? "(comebacktoorigin=yes, not used)" : "");
+		ast_cli(fd, "Comeback Dial Time     :      %u sec\n", lot->comebackdialtime);
+		ast_cli(fd, "MusicOnHold Class      :      %s\n", lot->mohclass);
+		ast_cli(fd, "Enabled                :      %s\n", lot->disabled ? "no" : "yes");
+		ast_cli(fd, "\n");
+		ao2_ref(o, -1);
+	}
+
+	parking_lot_iterator_destroy(i);
+}
+
+/* \brief Parkinglots command show <name> */
+static char *handle_show_parking_lot_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int length;
+	int which;
+	struct ao2_iterator *i;
+	struct parking_lot *lot;
+	char *match = NULL;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "parking show";
+		e->usage =
+			"Usage: parking show [name]\n"
+			"	Shows a list of parking lots or details of a specific parking lot.";
+		return NULL;
+	case CLI_GENERATE:
+		length = strlen(a->word);
+		which = 0;
+		i = parking_lot_iterator_create();
+		while ((lot = ao2_iterator_next(i))) {
+			if (!strncasecmp(a->word, lot->name, length) && ++which > a->n) {
+				match = ast_strdup(lot->name);
+				ao2_ref(lot, -1);
+				break;
+			}
+			ao2_ref(lot, -1);
+		}
+		parking_lot_iterator_destroy(i);
+		return match;
+		return NULL;
+	}
+
+	if (a->argc == 2) {
+		cli_display_parking_lot_list(a->fd);
+		return CLI_SUCCESS;
+	}
+
+	if (a->argc == 3) {
+		cli_display_parking_lot(a->fd, a->argv[2]);
+		return CLI_SUCCESS;
+	}
+
+	return CLI_SHOWUSAGE;
+}
+
+static int manager_parkinglot_list(struct mansession *s, const struct message *m)
+{
+	const char *id = astman_get_header(m, "ActionID");
+	char id_text[256] = "";
+	struct ao2_iterator *iter;
+	struct parking_lot *curlot;
+
+	if (!ast_strlen_zero(id)) {
+		snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id);
+	}
+
+	iter = parking_lot_iterator_create();
+
+	if (!iter) {
+		ast_log(LOG_ERROR, "Failed to create parking lot iterator. Action canceled.\n");
+		astman_send_error(s, m, "Could not create parking lot list");
+		return -1;
+	}
+
+	astman_send_ack(s, m, "Parking lots will follow");
+
+	while ((curlot = ao2_iterator_next(iter))) {
+		publish_parking_lot(curlot);
+		ao2_ref(curlot, -1);
+	}
+
+	parking_lot_iterator_destroy(iter);
+
+	return RESULT_SUCCESS;
+}
+
+static int manager_parking_status(struct mansession *s, const struct message *m)
+{
+	struct parked_user *curuser;
+	const char *id = astman_get_header(m, "ActionID");
+	char id_text[256] = "";
+	struct ao2_iterator *iter_lots;
+	struct ao2_iterator iter_users;
+	struct parking_lot *curlot;
+
+	if (!ast_strlen_zero(id)) {
+		snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id);
+	}
+
+	iter_lots = parking_lot_iterator_create();
+
+	if (!iter_lots) {
+		ast_log(LOG_ERROR, "Failed to create parking lot iterator. Action canceled.\n");
+		astman_send_error(s, m, "Could not create parking lot list");
+		return -1;
+	}
+
+	astman_send_ack(s, m, "Parked calls will follow");
+
+	while ((curlot = ao2_iterator_next(iter_lots))) {
+		iter_users = ao2_iterator_init(curlot->parked_user_list, 0);
+		while ((curuser = ao2_iterator_next(&iter_users))) {
+			publish_parked_call(curuser, PARKED_CALL);
+			ao2_ref(curuser, -1);
+		}
+		ao2_iterator_destroy(&iter_users);
+		ao2_ref(curlot, -1);
+	}
+
+	parking_lot_iterator_destroy(iter_lots);
+
+	return RESULT_SUCCESS;
+}
+
+static struct ast_cli_entry cli_parking_lot[] = {
+	AST_CLI_DEFINE(handle_show_parking_lot_cmd, "Show a parking lot or a list of all parking lots."),
+};
+
+int load_tools(void)
+{
+	int res;
+
+	ast_cli_register_multiple(cli_parking_lot, ARRAY_LEN(cli_parking_lot));
+	res = ast_manager_register_xml_core("Parkinglots", 0, manager_parkinglot_list);
+	res |= ast_manager_register_xml_core("ParkedCalls", 0, manager_parking_status);
+
+	return res ? -1 : 0;
+}
+
+void unload_tools(void)
+{
+	ast_cli_unregister_multiple(cli_parking_lot, ARRAY_LEN(cli_parking_lot));
+	ast_manager_unregister("Parkinglots");
+	ast_manager_unregister("ParkedCalls");
+}

Propchange: team/jrose/bridge_projects/res/parking/parking_ui.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/jrose/bridge_projects/res/parking/parking_ui.c
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Rev URL"

Propchange: team/jrose/bridge_projects/res/parking/parking_ui.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list