[asterisk-commits] rmudgett: branch rmudgett/parking r329098 - /team/rmudgett/parking/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 20 18:50:07 CDT 2011


Author: rmudgett
Date: Wed Jul 20 18:50:03 2011
New Revision: 329098

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=329098
Log:
Outline for config reload.

Modified:
    team/rmudgett/parking/main/features.c

Modified: team/rmudgett/parking/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/parking/main/features.c?view=diff&rev=329098&r1=329097&r2=329098
==============================================================================
--- team/rmudgett/parking/main/features.c (original)
+++ team/rmudgett/parking/main/features.c Wed Jul 20 18:50:03 2011
@@ -488,9 +488,13 @@
 
 /*! \brief The list of parking lots configured. Always at least one  - the default parking lot */
 static struct ao2_container *parkinglots;
- 
+
+/*!
+ * \brief Default parking lot.
+ * \note Holds a parkinglot reference.
+ * \note Will not be NULL while running. (BUGBUG can I guarantee this? The code already expects it.)
+ */
 static struct ast_parkinglot *default_parkinglot;
-char parking_ext[AST_MAX_EXTENSION];            /*!< Extension you type to park the call */
 
 static char courtesytone[256];                             /*!< Courtesy tone */
 static int parkedplay = 0;                                 /*!< Who to play the courtesy tone to */
@@ -5061,14 +5065,12 @@
 	return parkinglot;
 }
 
-static int load_config(void) 
+static int process_config(struct ast_config *cfg)
 {
 	int i;
 	struct ast_context *con = NULL;
-	struct ast_config *cfg = NULL;
 	struct ast_variable *var = NULL;
 	struct feature_group *fg = NULL;
-	struct ast_flags config_flags = { 0 };
 	char *ctg; 
 	static const char * const categories[] = { 
 		/* Categories in features.conf that are not
@@ -5093,23 +5095,6 @@
 	}
 #endif
 	
-	if (!default_parkinglot) {
-		/* Must create the default parking lot */
-		default_parkinglot = build_parkinglot(DEFAULT_PARKINGLOT, NULL);
-		if (!default_parkinglot) {
-			ast_log(LOG_ERROR, "Configuration of default parkinglot failed.\n");
-			return -1;
-		}
-		ast_debug(1, "Configuration of default default parkinglot done.\n");
-	}
-
-	cfg = ast_config_load2("features.conf", "features", config_flags);
-	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
-		ast_log(LOG_WARNING,"Could not load features.conf\n");
-/* BUGBUG need to clear all parkinglot->the_mark flags. */
-		return 0;
-	}
-
 	/* Reset to defaults */
 	strcpy(pickup_ext, "*8");
 	courtesytone[0] = '\0';
@@ -5212,7 +5197,7 @@
 		}
 	}
 
-	/* Map a key combination to an application*/
+	/* Map a key combination to an application */
 	ast_unregister_features();
 	for (var = ast_variable_browse(cfg, "applicationmap"); var; var = var->next) {
 /* BUGBUG alloca in a loop */
@@ -5353,8 +5338,6 @@
 
 	AST_RWLIST_UNLOCK(&feature_groups);
 
-	ast_config_destroy(cfg);
-
 #if 0	//BUGBUG should no longer need this code after redesign.
 	if (!(con = ast_context_find_or_create(NULL, NULL, default_parkinglot->cfg.parking_con, registrar))) {
 		ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", default_parkinglot->cfg.parking_con);
@@ -5370,7 +5353,79 @@
 	notify_metermaids(default_parkinglot->cfg.parkext, default_parkinglot->cfg.parking_con, AST_DEVICE_INUSE); 
 
 	return 0;
-
+}
+
+static int parkinglot_markall_cb(void *obj, void *arg, int flags)
+{
+	struct ast_parkinglot *parkinglot = obj;
+
+	parkinglot->the_mark = 1;
+	return 0;
+}
+
+static int parkinglot_is_marked_cb(void *obj, void *arg, int flags)
+{
+	struct ast_parkinglot *parkinglot = obj;
+
+	if (parkinglot->the_mark) {
+		if (AST_LIST_EMPTY(&parkinglot->parkings)) {
+			return CMP_MATCH;
+		}
+		/* Try reloading later when parking lot is empty. */
+		ast_log(LOG_WARNING,
+			"Parking lot %s has parked calls.  Could not remove.\n",
+			parkinglot->name);
+	}
+
+	return 0;
+}
+
+static int load_config(int reload)
+{
+#ifdef BUGBUG
+	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
+#else
+	struct ast_flags config_flags = { 0 };
+#endif
+	struct ast_config *cfg;
+	int res;
+
+	if (!default_parkinglot) {
+		/* Must create the default parking lot */
+		default_parkinglot = build_parkinglot(DEFAULT_PARKINGLOT, NULL);
+		if (!default_parkinglot) {
+			ast_log(LOG_ERROR, "Configuration of default parkinglot failed.\n");
+			return -1;
+		}
+		ast_debug(1, "Configuration of default default parkinglot done.\n");
+		parkinglot_addref(default_parkinglot);
+	}
+
+	cfg = ast_config_load2("features.conf", "features", config_flags);
+	if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
+		/* No sense in asking for reload trouble if nothing changed. */
+		ast_debug(1, "features.conf did not change.\n");
+		return 0;
+	}
+	if (cfg == CONFIG_STATUS_FILEMISSING
+		|| cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_WARNING, "Could not load features.conf\n");
+		return 0;
+	}
+
+/* BUGBUG build old contexts and extens usage list. */
+
+	ao2_t_callback(parkinglots, OBJ_NODATA, parkinglot_markall_cb, NULL, "callback to mark all parkinglots");
+	res = process_config(cfg);
+	ast_config_destroy(cfg);
+	ao2_t_callback(parkinglots, OBJ_NODATA | OBJ_UNLINK, parkinglot_is_marked_cb, NULL, "callback to remove marked parkinglots");
+
+/* BUGBUG build new contexts and extens usage list. */
+/* BUGBUG Remove dead contexts and extens */
+/* BUGBUG Destroy old and new contexts and extens usage lists. */
+/* BUGBUG Populate dialplan with new contexts and extens. */
+
+	return res;
 }
 
 /*!
@@ -5461,40 +5516,9 @@
 	return CLI_SUCCESS;
 }
 
-static int parkinglot_markall_cb(void *obj, void *arg, int flags)
-{
-	struct ast_parkinglot *parkinglot = obj;
-
-	parkinglot->the_mark = 1;
-	return 0;
-}
-
-static int parkinglot_is_marked_cb(void *obj, void *arg, int flags)
-{
-	struct ast_parkinglot *parkinglot = obj;
-
-	if (parkinglot->the_mark) {
-		if (AST_LIST_EMPTY(&parkinglot->parkings)) {
-			return CMP_MATCH;
-		}
-		/* Try reloading later when parking lot is empty. */
-		ast_log(LOG_WARNING,
-			"Parking lot %s has parked calls.  Could not remove.\n",
-			parkinglot->name);
-	}
-
-	return 0;
-}
-
 int ast_features_reload(void)
 {
-	int res;
-
-	ao2_t_callback(parkinglots, OBJ_NODATA, parkinglot_markall_cb, NULL, "callback to mark all parkinglots");
-	res = load_config(); /* Reload configuration */
-	ao2_t_callback(parkinglots, OBJ_NODATA | OBJ_UNLINK, parkinglot_is_marked_cb, NULL, "callback to remove all marked parkinglots");
-	
-	return res;
+	return load_config(1);
 }
 
 static char *handle_features_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -6349,8 +6373,10 @@
 		return -1;
 	}
 
-	if ((res = load_config()))
+	res = load_config(0);
+	if (res) {
 		return res;
+	}
 	ast_cli_register_multiple(cli_features, ARRAY_LEN(cli_features));
 	ast_pthread_create(&parking_thread, NULL, do_parking_thread, NULL);
 	ast_register_application2(app_bridge, bridge_exec, NULL, NULL, NULL);




More information about the asterisk-commits mailing list