[asterisk-commits] jpeeler: branch group/multiparking r114066 - /team/group/multiparking/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 11 14:52:25 CDT 2008


Author: jpeeler
Date: Fri Apr 11 14:52:24 2008
New Revision: 114066

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114066
Log:
converted astobj1 to astobj2, still need to clean up and look over carefully

Modified:
    team/group/multiparking/main/features.c

Modified: team/group/multiparking/main/features.c
URL: http://svn.digium.com/view/asterisk/team/group/multiparking/main/features.c?view=diff&rev=114066&r1=114065&r2=114066
==============================================================================
--- team/group/multiparking/main/features.c (original)
+++ team/group/multiparking/main/features.c Fri Apr 11 14:52:24 2008
@@ -57,7 +57,7 @@
 #include "asterisk/monitor.h"
 #include "asterisk/audiohook.h"
 #include "asterisk/global_datastores.h"
-#include "asterisk/astobj.h"
+#include "asterisk/astobj2.h"
 
 #define DEFAULT_PARK_TIME 45000
 #define DEFAULT_TRANSFER_DIGIT_TIMEOUT 3000
@@ -120,7 +120,8 @@
 
 /*! \brief Structure for parking lots in a linked list. */
 struct ast_parkinglot {
-	ASTOBJ_COMPONENTS(struct ast_parkinglot);	/*!< various object stuff, including ->name */
+	//ASTOBJ_COMPONENTS(struct ast_parkinglot);	/*!< various object stuff, including ->name */
+	char name[80];
 	char parking_con[AST_MAX_EXTENSION];		/*!< Context for which parking is made accessible */
 	char parking_con_dial[AST_MAX_EXTENSION];	/*!< Context for dialback for parking (KLUDGE) */
 	int parking_start;				/*!< First available extension for parking */
@@ -132,10 +133,14 @@
 	struct parkinglot_parklist parkings;		/*!< List of active parkings in this parkinglot */
 };
 
-/*! \brief The list of parking lots configured. Always at least one  - the default parking lot */
+/*! \brief The list of parking lots configured. Always at least one  - the default parking lot jpeeler:astobj1*/
+/*
 struct ast_parkinglot_list {
 	ASTOBJ_CONTAINER_COMPONENTS(struct ast_parkinglot);
 } parkinglots;
+*/
+
+static struct ao2_container *parkinglots;
  
 struct ast_parkinglot *default_parkinglot;
 char parking_ext[AST_MAX_EXTENSION];            /*!< Extension you type to park the call */
@@ -197,7 +202,7 @@
 /* Forward declarations */
 static struct ast_parkinglot *parkinglot_addref(struct ast_parkinglot *parkinglot);
 static void parkinglot_unref(struct ast_parkinglot *parkinglot);
-static void parkinglot_destroy(struct ast_parkinglot *ruin);
+static void parkinglot_destroy(void *obj);
 int manage_parkinglot(struct ast_parkinglot *curlot, fd_set *rfds, fd_set *efds, fd_set *nrfds, fd_set *nefds, int *fs, int *max);
 int ast_park_call_full(struct ast_channel *chan, struct ast_channel *peer, int timeout, int *extout, struct ast_parkinglot *parkinglot); /* TODO: this wasn't defined anywhere */
 struct ast_parkinglot *find_parkinglot(const char *name);
@@ -222,6 +227,17 @@
 	unsigned int return_to_pbx:1;
 };
 
+static int parkinglot_hash_cb(const void *obj, const int flags)
+{
+	const struct ast_parkinglot *parkinglot = obj;
+	return ast_str_hash(parkinglot->name);
+}
+
+static int parkinglot_cmp_cb(void *obj, void *arg, int flags)
+{
+	struct ast_parkinglot *parkinglot = obj, *parkinglot2 = arg;
+	return !strcasecmp(parkinglot->name, parkinglot2->name) ? CMP_MATCH : 0;
+}
 
 /*!
  * \brief store context, extension and priority 
@@ -452,7 +468,8 @@
 		return -1;
 	}
 
-	ASTOBJ_WRLOCK(parkinglot);
+	//ASTOBJ_WRLOCK(parkinglot);
+	ao2_lock(parkinglot);
 
 	/* Lock parking list */
 	AST_LIST_LOCK(&parkinglot->parkings);
@@ -464,7 +481,8 @@
 			parkinglot_unref(parkinglot);
 			ast_free(pu);
 			ast_log(LOG_WARNING, "Requested parking extension already exists: %s@%s\n", parkingexten, parkinglot->parking_con);
-			ASTOBJ_UNLOCK(parkinglot);
+			//ASTOBJ_UNLOCK(parkinglot);
+			ao2_unlock(parkinglot);
 			return 1;	/* Continue execution if possible */
 		}
 		ast_copy_string(pu->parkingexten, parkingexten, sizeof(pu->parkingexten));
@@ -487,7 +505,8 @@
 			ast_free(pu);
 			AST_LIST_UNLOCK(&parkinglot->parkings);
 			parkinglot_unref(parkinglot);
-			ASTOBJ_UNLOCK(parkinglot);
+			//ASTOBJ_UNLOCK(parkinglot);
+			ao2_unlock(parkinglot);
 			return -1;
 		}
 		/* Set pointer for next parking */
@@ -529,7 +548,8 @@
 		pu->notquiteyet = 1;
 	AST_LIST_UNLOCK(&parkinglot->parkings);
 
-	ASTOBJ_UNLOCK(parkinglot);
+	//ASTOBJ_UNLOCK(parkinglot)
+	ao2_unlock(parkinglot);
 	/* Wake up the (presumably select()ing) thread */
 	pthread_kill(parking_thread, SIGURG);
 	ast_verb(2, "Parked %s on %d (lot %s). Will timeout back to extension [%s] %s, %d in %d seconds\n", pu->chan->name, pu->parkingnum, parkinglot->name, pu->context, pu->exten, pu->priority, (pu->parkingtime/1000));
@@ -2248,7 +2268,8 @@
 
 	/* jpeeler: this either needs to be moved or is not necessary: */
 	/*parkinglot_addref(curlot);*/
-	ASTOBJ_WRLOCK(curlot);
+	//ASTOBJ_WRLOCK(curlot);
+	ao2_lock(curlot);
 	/* Lock parking list */
 	AST_LIST_LOCK(&curlot->parkings);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&curlot->parkings, pu, list) {
@@ -2400,7 +2421,8 @@
 	AST_LIST_TRAVERSE_SAFE_END;
 	AST_LIST_UNLOCK(&curlot->parkings);
 
-	ASTOBJ_UNLOCK(curlot);
+	//ASTOBJ_UNLOCK(curlot);
+	ao2_unlock(curlot);
 	return res;
 }
 
@@ -2423,11 +2445,21 @@
 		int res = 0;
 		int ms = -1;	/* select timeout, uninitialized */
 		int max = -1;	/* max fd, none there yet */
+		/*
 		ASTOBJ_CONTAINER_TRAVERSE(&parkinglots, 1, do {
 			ASTOBJ_WRLOCK(iterator);
 			res = manage_parkinglot(iterator, &rfds, &efds, &nrfds, &nefds, &ms, &max);
 			ASTOBJ_UNLOCK(iterator);
 		} while (0) );
+		*/
+		struct ao2_iterator iter;
+		struct ast_parkinglot *curlot;
+		iter = ao2_iterator_init(parkinglots, 0);
+
+		while ((curlot = ao2_iterator_next(&iter))) {
+			res = manage_parkinglot(curlot, &rfds, &efds, &nrfds, &nefds, &ms, &max);
+			ao2_ref(curlot, -1);
+		}
 
 		rfds = nrfds;
 		efds = nefds;
@@ -2445,11 +2477,15 @@
 struct ast_parkinglot *find_parkinglot(const char *name)
 {
 	struct ast_parkinglot *parkinglot = NULL;
+	struct ast_parkinglot tmp_parkinglot;
 	
 	if (ast_strlen_zero(name))
 		return NULL;
 
-	parkinglot = ASTOBJ_CONTAINER_FIND(&parkinglots, name);
+	ast_copy_string(tmp_parkinglot.name, name, sizeof(tmp_parkinglot.name));
+
+	//parkinglot = ASTOBJ_CONTAINER_FIND(&parkinglots, name);
+	parkinglot = ao2_find(parkinglots, &tmp_parkinglot, OBJ_POINTER);
 
 	if (parkinglot && option_debug)
 		ast_log(LOG_DEBUG, "Found Parkinglot: %s\n", parkinglot->name);
@@ -2649,16 +2685,24 @@
 	then go ahead and delete it */
 static void parkinglot_unref(struct ast_parkinglot *parkinglot) 
 {
+	/*
 	if (option_debug > 2)
 		ast_log(LOG_DEBUG, "Multiparking: %s refcount now %d\n", parkinglot->name, parkinglot->refcount - 1);
-	ASTOBJ_UNREF(parkinglot, parkinglot_destroy);
+	*/
+	//ASTOBJ_UNREF(parkinglot, parkinglot_destroy);
+	ao2_ref(parkinglot, -1);
 }
 
 static struct ast_parkinglot *parkinglot_addref(struct ast_parkinglot *parkinglot)
 {
+	// doesn't look like astobj2 makes the refcount accessible
+	/*
 	if (option_debug > 2)
 		ast_log(LOG_DEBUG, "Multiparking: %s refcount now %d\n", parkinglot->name, parkinglot->refcount + 1);
-	return ASTOBJ_REF(parkinglot);
+	*/
+	//return ASTOBJ_REF(parkinglot);
+	ao2_ref(parkinglot, +1);
+	return parkinglot;
 }
 
 /*! \brief Allocate parking lot structure */
@@ -2669,25 +2713,29 @@
 	if (!name)
 		return NULL;
 
-	newlot = ast_calloc(1, sizeof(*newlot));
+	//newlot = ast_calloc(1, sizeof(*newlot));
+	newlot = ao2_alloc(sizeof(*newlot), parkinglot_destroy);
 	if (!newlot)
 		return NULL;
 
-	ASTOBJ_INIT(newlot);
+	//ASTOBJ_INIT(newlot);
+	
 	ast_copy_string(newlot->name, name, sizeof(newlot->name));
 
 	return newlot;
 }
 
 /*! \brief Destroy a parking lot */
-static void parkinglot_destroy(struct ast_parkinglot *ruin)
-{
+static void parkinglot_destroy(void *obj)
+{
+	struct ast_parkinglot *ruin = obj;
 	struct ast_context *con;
 	con = ast_context_find(ruin->parking_con);
 	if (con)
 		ast_context_destroy(con, registrar);
-	ASTOBJ_CONTAINER_UNLINK(&parkinglots, ruin);	/* Remove from parkinglot list */
-	free(ruin);
+	//ASTOBJ_CONTAINER_UNLINK(&parkinglots, ruin);	/* Remove from parkinglot list */
+	ao2_unlink(parkinglots, ruin);
+	//free(ruin);
 }
 
 /*! \brief Build parkinglot from configuration and chain it in */
@@ -2701,15 +2749,20 @@
 	int start = 0, end = 0;
 
 	parkinglot = find_parkinglot(name);
+	/*
 	if (parkinglot)
 		ASTOBJ_UNMARK(parkinglot);
 	else
 		parkinglot = create_parkinglot(name);
+	*/
+	if (!parkinglot)
+		parkinglot = create_parkinglot(name);
 
 	if (!parkinglot)
 		return NULL;
 
-	ASTOBJ_WRLOCK(parkinglot);
+	//ASTOBJ_WRLOCK(parkinglot);
+	ao2_lock(parkinglot);
 
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Building parking lot %s\n", name);
@@ -2764,7 +2817,8 @@
 	if (ast_add_extension2(con, 1, ast_parking_ext(), 1, NULL, NULL, parkcall, strdup(""), ast_free, registrar) == -1)
 		error = 1;
 
-	ASTOBJ_UNLOCK(parkinglot);
+	//ASTOBJ_UNLOCK(parkinglot);
+	ao2_unlock(parkinglot);
 
 	if (error) {
 		ast_log(LOG_WARNING, "Parking %s not open for business. Configuration error.\n", name);
@@ -2776,11 +2830,11 @@
 
 
 	/* Move it into the list */
-	ASTOBJ_CONTAINER_LINK(&parkinglots, parkinglot);
+	//ASTOBJ_CONTAINER_LINK(&parkinglots, parkinglot);
+	ao2_link(parkinglots, parkinglot);
 	parkinglot_unref(parkinglot);
 
 	return parkinglot;
-	
 }
 
 
@@ -2830,13 +2884,15 @@
 	} else {
 		default_parkinglot = build_parkinglot(DEFAULT_PARKINGLOT, NULL);
 		if (default_parkinglot) {
-			ASTOBJ_WRLOCK(default_parkinglot);
+			//ASTOBJ_WRLOCK(default_parkinglot);
+			ao2_lock(default_parkinglot);
 			default_parkinglot->parking_start = 701;
 			default_parkinglot->parking_stop = 750;
 			default_parkinglot->parking_offset = 0;
 			default_parkinglot->parkfindnext = 0;
 			default_parkinglot->parkingtime = 0;
-			ASTOBJ_UNLOCK(default_parkinglot);
+			//ASTOBJ_UNLOCK(default_parkinglot);
+			ao2_unlock(default_parkinglot);
 		}
 	}
 	if (default_parkinglot) {
@@ -3131,6 +3187,8 @@
 {
 	int i;
 	struct ast_call_feature *feature;
+	struct ao2_iterator iter;
+	struct ast_parkinglot *curlot;
 #define HFS_FORMAT "%-25s %-7s %-7s\n"
 
 	switch (cmd) {
@@ -3168,6 +3226,7 @@
 	}
 
 	// loop throug all the parking lots
+	/*
 	ASTOBJ_CONTAINER_TRAVERSE(&parkinglots, 1, do {
 		ASTOBJ_RDLOCK(iterator);
 		ast_cli(a->fd, "\nCall parking (Parking lot: %s)\n", iterator->name);
@@ -3178,6 +3237,19 @@
 		ast_cli(a->fd,"\n");
 		ASTOBJ_UNLOCK(iterator);
 	} while (0) );
+	*/
+	iter = ao2_iterator_init(parkinglots, 0);
+
+	while ((curlot = ao2_iterator_next(&iter))) {
+		ast_cli(a->fd, "\nCall parking (Parking lot: %s)\n", curlot->name);
+		ast_cli(a->fd, "------------\n");
+		ast_cli(a->fd,"%-22s:      %s\n", "Parking extension", parking_ext);
+		ast_cli(a->fd,"%-22s:      %s\n", "Parking context", curlot->parking_con);
+		ast_cli(a->fd,"%-22s:      %d-%d\n", "Parked call extensions", curlot->parking_start, curlot->parking_stop);
+		ast_cli(a->fd,"\n");
+		ao2_ref(curlot, -1);
+	}
+
 
 	return CLI_SUCCESS;
 }
@@ -3185,13 +3257,20 @@
 int ast_features_reload(void)
 {
 	int res;
+	struct ast_parkinglot *curlot;
+	struct ao2_iterator iter;
 	/* Release parking lot list */
-	ASTOBJ_CONTAINER_MARKALL(&parkinglots);
+	//ASTOBJ_CONTAINER_MARKALL(&parkinglots);
+	iter = ao2_iterator_init(parkinglots, 0);
+	while ((curlot = ao2_iterator_next(&iter))) {
+		parkinglot_unref(curlot);
+		//ao2_unlink(parkinglots, curlot);
+	}
 
 	/* Reload configuration */
 	res = load_config();
 	
-	ASTOBJ_CONTAINER_PRUNE_MARKED(&parkinglots, parkinglot_destroy);
+	//ASTOBJ_CONTAINER_PRUNE_MARKED(&parkinglots, parkinglot_destroy);
 	return res;
 }
 
@@ -3368,6 +3447,8 @@
 {
 	struct parkeduser *cur;
 	int numparked = 0;
+	struct ao2_iterator iter;
+	struct ast_parkinglot *curlot;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -3386,6 +3467,7 @@
 	ast_cli(a->fd, "%4s %25s (%-15s %-12s %-4s) %-6s \n", "Num", "Channel"
 		, "Context", "Extension", "Pri", "Timeout");
 
+	/*
 	ASTOBJ_CONTAINER_TRAVERSE(&parkinglots, 1, do {
 		int lotparked = 0;
 		ASTOBJ_RDLOCK(iterator);
@@ -3405,6 +3487,28 @@
 
 		ASTOBJ_UNLOCK(iterator);
 	} while (0) );
+	*/
+
+	iter = ao2_iterator_init(parkinglots, 0);
+	while ((curlot = ao2_iterator_next(&iter))) {
+		int lotparked = 0;
+		ast_cli(a->fd, "*** Parking lot: %s\n", curlot->name);
+
+		AST_LIST_LOCK(&curlot->parkings);
+		AST_LIST_TRAVERSE(&curlot->parkings, cur, list) {
+			ast_cli(a->fd, "%-10.10s %25s (%-15s %-12s %-4d) %6lds\n"
+				,cur->parkingexten, cur->chan->name, cur->context, cur->exten
+				,cur->priority, cur->start.tv_sec + (cur->parkingtime/1000) - time(NULL));
+			numparked++;
+			numparked += lotparked;
+		}
+		AST_LIST_UNLOCK(&curlot->parkings);
+		if (lotparked)
+			ast_cli(a->fd, "   %d parked call%s in parking lot %s\n", lotparked, ESS(lotparked), curlot->name);
+
+		ao2_ref(curlot, -1);
+	}
+
 	ast_cli(a->fd, "---\n%d parked call%s in total.\n", numparked, ESS(numparked));
 
 	return CLI_SUCCESS;
@@ -3439,17 +3543,22 @@
 	struct parkeduser *cur;
 	const char *id = astman_get_header(m, "ActionID");
 	char idText[256] = "";
+	struct ao2_iterator iter;
+	struct ast_parkinglot *curlot;
 
 	if (!ast_strlen_zero(id))
 		snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
 
 	astman_send_ack(s, m, "Parked calls will follow");
 
-	ASTOBJ_CONTAINER_TRAVERSE(&parkinglots, 1, do {
-		ASTOBJ_RDLOCK(iterator);
-
-		AST_LIST_LOCK(&iterator->parkings);
-		AST_LIST_TRAVERSE(&iterator->parkings, cur, list) {
+	//ASTOBJ_CONTAINER_TRAVERSE(&parkinglots, 1, do {
+	//	ASTOBJ_RDLOCK(iterator);
+	//
+	iter = ao2_iterator_init(parkinglots, 0);
+	while ((curlot = ao2_iterator_next(&iter))) {
+
+		AST_LIST_LOCK(&curlot->parkings);
+		AST_LIST_TRAVERSE(&curlot->parkings, cur, list) {
 			astman_append(s, "Event: ParkedCall\r\n"
 				"Exten: %d\r\n"
 				"Channel: %s\r\n"
@@ -3465,10 +3574,11 @@
 				S_OR(cur->chan->cid.cid_name, ""),
 				idText);
 		}
-		AST_LIST_UNLOCK(&iterator->parkings);
-
-		ASTOBJ_UNLOCK(iterator);
-	} while (0) );
+		AST_LIST_UNLOCK(&curlot->parkings);
+
+		//ASTOBJ_UNLOCK(iterator);
+		ao2_ref(curlot, -1);
+	} //while (0) );
 
 	astman_append(s,
 		"Event: ParkedCallsComplete\r\n"
@@ -3744,7 +3854,8 @@
 	ast_register_application2(app_bridge, bridge_exec, bridge_synopsis, bridge_descrip, NULL);
 
 
-	ASTOBJ_CONTAINER_INIT(&parkinglots);
+	//ASTOBJ_CONTAINER_INIT(&parkinglots);
+	parkinglots = ao2_container_alloc(7, parkinglot_hash_cb, parkinglot_cmp_cb);
 
 	if ((res = load_config()))
 		return res;




More information about the asterisk-commits mailing list