[asterisk-commits] jrose: branch jrose/bridge_projects r384819 - in /team/jrose/bridge_projects:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 5 14:18:52 CDT 2013


Author: jrose
Date: Fri Apr  5 14:18:48 2013
New Revision: 384819

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384819
Log:
Stuff related to Kinsey's Review

Modified:
    team/jrose/bridge_projects/include/asterisk/parking.h
    team/jrose/bridge_projects/res/parking/parking_manager.c
    team/jrose/bridge_projects/res/parking/parking_ui.c
    team/jrose/bridge_projects/res/res_parking.c

Modified: team/jrose/bridge_projects/include/asterisk/parking.h
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/include/asterisk/parking.h?view=diff&rev=384819&r1=384818&r2=384819
==============================================================================
--- team/jrose/bridge_projects/include/asterisk/parking.h (original)
+++ team/jrose/bridge_projects/include/asterisk/parking.h Fri Apr  5 14:18:48 2013
@@ -43,14 +43,14 @@
  * \since 12
  */
 struct ast_parked_call_payload {
-	struct ast_channel_snapshot *parkee;
-	struct ast_channel_snapshot *parker;
-	enum ast_parked_call_event_type event_type;
-	long unsigned int timeout;
-	long unsigned int duration;
-	unsigned int parkingspace;
+	struct ast_channel_snapshot *parkee;             /*!< Snapshot of the channel that is parked */
+	struct ast_channel_snapshot *parker;             /*!< Snapshot of the channel that parked the call */
+	enum ast_parked_call_event_type event_type;      /*!< Reason for issuing the parked call message */
+	long unsigned int timeout;                       /*!< Time remaining before the call times out (seconds ) */
+	long unsigned int duration;                      /*!< How long the parkee has been parked (seconds) */
+	unsigned int parkingspace;                       /*!< Which Parking Space the parkee occupies */
 	AST_DECLARE_STRING_FIELDS(
-		AST_STRING_FIELD(parkinglot);
+		AST_STRING_FIELD(parkinglot);                /*!< Name of the parking lot used to park the parkee */
 	);
 };
 

Modified: team/jrose/bridge_projects/res/parking/parking_manager.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_manager.c?view=diff&rev=384819&r1=384818&r2=384819
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_manager.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_manager.c Fri Apr  5 14:18:48 2013
@@ -190,8 +190,12 @@
 	return RESULT_SUCCESS;
 }
 
-static void manager_append_event_parking_lot(struct mansession *s, struct parking_lot_state *curlot, char *id_text)
-{
+static int manager_append_event_parking_lot_data_cb(void *obj, void *arg, void *data, int flags)
+{
+	struct parking_lot_state *curlot = obj;
+	struct mansession *s = arg;
+	char *id_text = data;
+
 	astman_append(s, "Event: Parkinglot\r\n"
 		"Name: %s\r\n"
 		"StartSpace: %d\r\n"
@@ -204,20 +208,7 @@
 		curlot->parking_stop,
 		curlot->parkingtime,
 		id_text);
-}
-
-struct manager_append_event_cb_data {
-	struct mansession *s;
-	char *id_text;
-};
-
-static int manager_append_event_parking_lot_cb(void *obj, void *arg, int flags)
-{
-	struct parking_lot_state *lot = obj;
-	struct manager_append_event_cb_data *data = arg;
-	struct mansession *s = data->s;
-	char *id_text = data->id_text;
-	manager_append_event_parking_lot(s, lot, id_text);
+
 	return 0;
 }
 
@@ -226,10 +217,6 @@
 	const char *id = astman_get_header(m, "ActionID");
 	char id_text[256] = "";
 	struct ao2_container *lot_container;
-	struct manager_append_event_cb_data cb_data = {
-		.s = s,
-		.id_text = id_text,
-	};
 
 	if (!ast_strlen_zero(id)) {
 		snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", id);
@@ -245,7 +232,7 @@
 
 	astman_send_ack(s, m, "Parking lots will follow");
 
-	ao2_callback(lot_container, OBJ_MULTIPLE | OBJ_NODATA, manager_append_event_parking_lot_cb, &cb_data);
+	ao2_callback_data(lot_container, OBJ_MULTIPLE | OBJ_NODATA, manager_append_event_parking_lot_data_cb, s, id_text);
 
 	astman_append(s,
 		"Event: ParkinglotsComplete\r\n"

Modified: 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=diff&rev=384819&r1=384818&r2=384819
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_ui.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_ui.c Fri Apr  5 14:18:48 2013
@@ -116,16 +116,44 @@
 	ast_cli(fd, "\n");
 }
 
+struct parking_lot_complete {
+	int seeking;    /*! Nth match to return. */
+	int which;      /*! Which match currently on. */
+};
+
+static int complete_parking_lot_search(void *obj, void *arg, void *data, int flags)
+{
+	struct parking_lot_complete *search = data;
+	if (++search->which > search->seeking) {
+		return CMP_MATCH;
+	}
+	return 0;
+}
+
+static char *complete_parking_lot(const char *word, int seeking)
+{
+	char *ret = NULL;
+	struct parking_lot_state *lot;
+	struct ao2_container *global_lots = get_parking_lot_state_container();
+	struct parking_lot_complete search = {
+		.seeking = seeking,
+		};
+
+	lot = ao2_callback_data(global_lots, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY,
+		complete_parking_lot_search, (char *) word, &search);
+
+	if (!lot) {
+		return NULL;
+	}
+
+	ret = ast_strdup(lot->name);
+	ao2_ref(lot, -1);
+	return ret;
+}
+
 /* \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_container *lot_container;
-	struct ao2_iterator iter;
-	struct parking_lot_state *lot;
-	char *match = NULL;
-
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "parking show";
@@ -134,28 +162,10 @@
 			"	Shows a list of parking lots or details of a specific parking lot.";
 		return NULL;
 	case CLI_GENERATE:
-		length = strlen(a->word);
-		which = 0;
-
-		lot_container = get_parking_lot_state_container();
-
-		if (!lot_container) {
-			/* This should never be possible, but if it is, there certainly aren't any parking lots to look at */
-			return NULL;
+		if (a->pos == 2) {
+			return complete_parking_lot(a->word, a->n);
 		}
-
-		iter = ao2_iterator_init(lot_container, 0);
-		while ((lot = ao2_iterator_next(&iter))) {
-			if (!strncasecmp(a->word, lot->name, length) && ++which > a->n) {
-				match = ast_strdup(lot->name);
-				ao2_ref(lot, -1);
-				break;
-			}
-			ao2_ref(lot, -1);
-		}
-		ao2_iterator_destroy(&iter);
-
-		return match;
+		return NULL;
 	}
 
 	ast_cli(a->fd, "\n");

Modified: team/jrose/bridge_projects/res/res_parking.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/res_parking.c?view=diff&rev=384819&r1=384818&r2=384819
==============================================================================
--- team/jrose/bridge_projects/res/res_parking.c (original)
+++ team/jrose/bridge_projects/res/res_parking.c Fri Apr  5 14:18:48 2013
@@ -189,21 +189,25 @@
 
 #define PARKED_CALL_APPLICATION "ParkedCall"
 
-static int parking_lot_state_hash_fn(const void *obj, const int flags)
-{
-	const struct parking_lot_state *entry;
-	const char *key;
-
-	switch (flags & (OBJ_POINTER | OBJ_KEY)) {
+static int parking_lot_state_sort_fn(const void *obj_left, const void *obj_right, int flags)
+{
+	const struct parking_lot_state *left = obj_left;
+	const struct parking_lot_state *right = obj_right;
+	const char *right_key = obj_right;
+	int cmp;
+
+	switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
+	default:
+	case OBJ_POINTER:
+		right_key = right->name;
+		/* Fall through */
 	case OBJ_KEY:
-		key = obj;
-		return ast_str_hash(key);
-	case OBJ_POINTER:
-		entry = obj;
-		return ast_str_hash(entry->name);
-	default:
-		return 0;
-	}
+		cmp = strcmp(left->name, right_key);
+		break;
+	case OBJ_PARTIAL_KEY:
+		cmp = strncmp(left->name, right_key, strlen(right_key));
+	}
+	return cmp;
 }
 
 static int parking_lot_state_cmp_fn(void *obj, void *arg, const int flags)
@@ -678,7 +682,12 @@
 		goto error;
 	}
 
-	if (!(parking_lot_state_container = ao2_container_alloc(37, parking_lot_state_hash_fn, parking_lot_state_cmp_fn))) {
+	parking_lot_state_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_RWLOCK,
+		AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT,
+		parking_lot_state_sort_fn,
+		parking_lot_state_cmp_fn);
+
+	if (!parking_lot_state_container) {
 		goto error;
 	}
 




More information about the asterisk-commits mailing list