[Asterisk-code-review] res parking: Add dialplan function for lot channel (asterisk[master])

George Joseph asteriskteam at digium.com
Thu Jul 12 17:14:32 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/9375 )

Change subject: res_parking: Add dialplan function for lot channel
......................................................................

res_parking: Add dialplan function for lot channel

This commit adds a new function to res_parking.

This function, PARK_GET_CHANNEL allows the retrieval
of the channel name of the channel occupying the parking slot.

ASTERISK-22825 #close

Change-Id: Idba6ae55b8a53f734238cb3d995cedb95c0e7b74
---
M res/parking/parking_bridge_features.c
M res/parking/parking_controller.c
M res/parking/res_parking.h
3 files changed, 107 insertions(+), 0 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Richard Mudgett: Looks good to me, approved
  George Joseph: Approved for Submit



diff --git a/res/parking/parking_bridge_features.c b/res/parking/parking_bridge_features.c
index 2770233..cbc23fa 100644
--- a/res/parking/parking_bridge_features.c
+++ b/res/parking/parking_bridge_features.c
@@ -30,10 +30,12 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/logger.h"
 #include "asterisk/pbx.h"
+#include "asterisk/app.h"
 #include "asterisk/bridge.h"
 #include "asterisk/bridge_internal.h"
 #include "asterisk/bridge_channel.h"
 #include "asterisk/bridge_features.h"
+#include "asterisk/conversions.h"
 #include "asterisk/features.h"
 #include "asterisk/say.h"
 #include "asterisk/datastore.h"
@@ -42,6 +44,24 @@
 #include "asterisk/core_local.h"
 #include "asterisk/causes.h"
 
+/*** DOCUMENTATION
+	<function name="PARK_GET_CHANNEL" language="en_US">
+		<synopsis>
+			Get the channel name of an occupied parking space in a parking lot.
+		</synopsis>
+			<syntax>
+				<parameter name="parking_space" required="true">
+				</parameter>
+				<parameter name="parking_lot" required="true">
+				</parameter>
+			</syntax>
+		<description>
+			<para>This function returns the channel of the specified parking space
+				if the parking lot space is occupied.</para>
+			</description>
+	</function>
+***/
+
 struct parked_subscription_datastore {
 	struct stasis_subscription *parked_subscription;
 };
@@ -704,6 +724,60 @@
 	}
 }
 
+/*! \brief  Dial plan function to get the parking lot channel of an occupied parking lot */
+static int func_get_parkingslot_channel(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
+{
+	RAII_VAR(struct parked_user *, pu, NULL, ao2_cleanup);
+	RAII_VAR(struct parking_lot *, lot, NULL, ao2_cleanup);
+	unsigned int space = 0;
+	const char *content = NULL;
+
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(parking_space);
+		AST_APP_ARG(parking_lot);
+		AST_APP_ARG(other);
+	);
+
+	/* Parse the arguments. */
+	AST_STANDARD_APP_ARGS(args, data);
+
+	if (args.argc < 2) {
+		/* Didn't receive enough arguments to do anything */
+		ast_log(LOG_ERROR, "Usage: %s(<parking_space>,<parking_lot>)\n",
+			function);
+		return -1;
+	}
+
+	lot = parking_lot_find_by_name(args.parking_lot);
+	if (!lot) {
+		ast_log(LOG_ERROR, "Could not find parking lot: '%s'\n", args.parking_lot);
+		return -1;
+	}
+
+	if (!ast_strlen_zero(args.parking_space)) {
+		if (ast_str_to_uint(args.parking_space, &space) != 0) {
+			ast_log(LOG_ERROR, "value '%s' for parking_space argument is invalid. Must be an integer greater than 0.\n",
+				args.parking_space);
+			return -1;
+		}
+	}
+
+	pu = parking_lot_inspect_parked_user(lot, space);
+	if (!pu) {
+		return -1;
+	}
+
+	content = ast_channel_name(pu->chan);
+	ast_copy_string(buf, content, len);
+
+	return 0;
+}
+
+static struct ast_custom_function getparkingslotchannel_function = {
+	.name = "PARK_GET_CHANNEL",
+	.read = func_get_parkingslot_channel,
+};
+
 struct ast_parking_bridge_feature_fn_table parking_provider = {
 	.module_version = PARKING_MODULE_VERSION,
 	.module_name = __FILE__,
@@ -717,12 +791,15 @@
 {
 	ast_bridge_features_unregister(AST_BRIDGE_BUILTIN_PARKCALL);
 	ast_parking_unregister_bridge_features(parking_provider.module_name);
+	ast_custom_function_unregister(&getparkingslotchannel_function);
 }
 
 int load_parking_bridge_features(void)
 {
 	parking_provider.module = AST_MODULE_SELF;
 
+	ast_custom_function_register(&getparkingslotchannel_function);
+
 	if (ast_parking_register_bridge_features(&parking_provider)) {
 		return -1;
 	}
diff --git a/res/parking/parking_controller.c b/res/parking/parking_controller.c
index 9e9e540..365acdd 100644
--- a/res/parking/parking_controller.c
+++ b/res/parking/parking_controller.c
@@ -163,6 +163,23 @@
 	return 0;
 }
 
+struct parked_user *parking_lot_inspect_parked_user(struct parking_lot *lot, int target)
+{
+	struct parked_user *user;
+
+	if (target < 0) {
+		user = ao2_callback(lot->parked_users, 0, NULL, NULL);
+	} else {
+		user = ao2_callback(lot->parked_users, 0, retrieve_parked_user_targeted, &target);
+	}
+
+	if (!user) {
+		return NULL;
+	}
+
+	return user;
+}
+
 struct parked_user *parking_lot_retrieve_parked_user(struct parking_lot *lot, int target)
 {
 	RAII_VAR(struct parked_user *, user, NULL, ao2_cleanup);
diff --git a/res/parking/res_parking.h b/res/parking/res_parking.h
index 3c34e5c..79fb97f 100644
--- a/res/parking/res_parking.h
+++ b/res/parking/res_parking.h
@@ -196,6 +196,19 @@
 int parking_lot_get_space(struct parking_lot *lot, int target_override);
 
 /*!
+ * \brief Determine if there is a parked user in a parking space and return it if there is.
+ *
+ * \param lot Parking lot being pulled from
+ * \param target If < 0   search for the first occupied space in the parking lot
+ *               If >= 0  Only pull from the indicated target
+ *
+ * \retval NULL if no parked user could be pulled from the requested parking lot at the requested parking space
+ * \retval reference to the requested parked user
+ *
+ */
+struct parked_user *parking_lot_inspect_parked_user(struct parking_lot *lot, int target);
+
+/*!
  * \since 12.0.0
  * \brief Determine if there is a parked user in a parking space and pull it from the parking lot if there is.
  *

-- 
To view, visit https://gerrit.asterisk.org/9375
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Idba6ae55b8a53f734238cb3d995cedb95c0e7b74
Gerrit-Change-Number: 9375
Gerrit-PatchSet: 6
Gerrit-Owner: Joshua Elson <joshelson at gmail.com>
Gerrit-Reviewer: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Elson <joshelson at gmail.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180712/349529c9/attachment-0001.html>


More information about the asterisk-code-review mailing list