[asterisk-commits] twilson: branch twilson/config_work r361910 - in /team/twilson/config_work: a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 11 13:17:08 CDT 2012


Author: twilson
Date: Wed Apr 11 13:17:04 2012
New Revision: 361910

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=361910
Log:
Do some RAII-ification and demo pvt non-config-related state

Modified:
    team/twilson/config_work/apps/app_skel.c
    team/twilson/config_work/include/asterisk/config_options.h

Modified: team/twilson/config_work/apps/app_skel.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/apps/app_skel.c?view=diff&rev=361910&r1=361909&r2=361910
==============================================================================
--- team/twilson/config_work/apps/app_skel.c (original)
+++ team/twilson/config_work/apps/app_skel.c Wed Apr 11 13:17:04 2012
@@ -341,13 +341,19 @@
 	/* It is ok if pvt_container is NULL, it just means this is our first load */
 
 	while ((cat = ast_category_browse(cfg, cat))) {
-		struct skel_pvt *tmppvt;
-		struct skel_pvt_config *tmpcfg;
+		RAII_VAR(struct skel_pvt *, tmppvt, NULL, ao2_cleanup);
+		RAII_VAR(struct skel_pvt_config *, tmpcfg, NULL, ao2_cleanup);
 
 		if (!strcasecmp(cat, "general")) {
 			continue;
 		}
 
+		/* If we've already linked a private for cat in newpvts, don't add a second one with the same name */
+		if ((tmppvt = ao2_find(newpvts, cat, OBJ_KEY))) {
+			return -1;
+		}
+
+		/* Get a ref to the existing private, or create a new one */
 		if (!(pvt_container && (tmppvt = ao2_find(pvt_container, cat, OBJ_KEY))) && !(tmppvt = new_pvt(cat))) {
 			/* Since we will be replacing the whole private container, bail out on errors instead of just
 			 * skipping privates with config errors */
@@ -356,14 +362,11 @@
 		}
 
 		if (!(tmpcfg = new_pvt_cfg(cfg, cat))) {
-			ao2_ref(tmppvt, -1);
 			return -1;
 		}
 		/* We have a valid pvt/cfg, link 'em */
 		ao2_link(newpvts, tmppvt);
-		ao2_ref(tmppvt, -1);
 		ao2_link(newcfgs, tmpcfg);
-		ao2_ref(tmpcfg, -1);
 	}
 
 	return 0;
@@ -431,6 +434,13 @@
 		return -1;
 	}
 
+	if (!(new_pvt_container = ao2_container_alloc(17, skel_pvt_hash, skel_pvt_cmp))) {
+		goto error;
+	}
+	if (!(new_cfg_container = ao2_container_alloc(17, skel_pvt_config_hash, skel_pvt_config_cmp))) {
+		goto error;
+	}
+
 	/* If either [general] or individual parsing fails, refuse to load or make any changes.
 	 * If no settings from [general] filter down into settings for individual private
 	 * structures, then treating the two settings as separate cases would be fine. Note
@@ -441,13 +451,6 @@
 		goto error;
 	}
 
-	if (!(new_pvt_container = ao2_container_alloc(17, skel_pvt_hash, skel_pvt_cmp))) {
-		goto error;
-	}
-	if (!(new_cfg_container = ao2_container_alloc(17, skel_pvt_config_hash, skel_pvt_config_cmp))) {
-		goto error;
-	}
-
 	if (process_pvt_config_options(cfg, new_pvt_container, new_cfg_container)) {
 		goto error;
 	}
@@ -476,7 +479,7 @@
 
 static char *handle_skel_show_config(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	struct skel_global_config *cfg;
+	RAII_VAR(struct skel_global_config *, cfg, NULL, ao2_cleanup);
 
 	switch(cmd) {
 	case CLI_INIT:
@@ -499,15 +502,14 @@
 	ast_cli(a->fd, "blah:     %s\n", AST_CLI_YESNO(cfg->blah));
 	ast_cli(a->fd, "bindaddr: %s\n", ast_sockaddr_stringify(&cfg->bindaddr));
 
-	ao2_ref(cfg, -1);
-
 	return CLI_SUCCESS;
 }
 
 static char *handle_skel_show_pvts(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	struct ao2_container *pvts, *cfgs;
-	struct ao2_iterator iter;
+	RAII_VAR(struct ao2_container *, pvts, NULL, ao2_cleanup);
+	RAII_VAR(struct ao2_container *, cfgs, NULL, ao2_cleanup);
+	struct ao2_iterator iter __attribute__((cleanup(ao2_iterator_destroy)));
 	struct skel_pvt *pvt;
 	char codec_buf[128];
 
@@ -530,26 +532,25 @@
 		return NULL;
 	}
 
-#define SKEL_FORMAT "%-15.15s %-25.25s %-20.20s %-5.5s %-5.5s %-5.5s\n"
-	ast_cli(a->fd, SKEL_FORMAT, "Name", "Description", "Codecs", "ACL", "Bit1", "Bit2");
+#define SKEL_FORMAT "%-15.15s %-25.25s %-20.20s %-5.5s %-5.5s %-5.5s %-2.2s\n"
+#define SKEL_FORMAT1 "%-15.15s %-25.25s %-20.20s %-5.5s %-5.5s %-5.5s %-2.2zu\n"
+	ast_cli(a->fd, SKEL_FORMAT, "Name", "Description", "Codecs", "ACL", "Bit1", "Bit2", "N");
 	iter = ao2_iterator_init(pvts, 0);
 	while ((pvt = ao2_iterator_next(&iter))) {
-		struct skel_pvt_config *cfg;
+		RAII_VAR(struct skel_pvt_config *, cfg, NULL, ao2_cleanup);
 		if (!(cfg = ao2_find(cfgs, pvt->name, OBJ_KEY))) {
 			ast_log(LOG_NOTICE, "Could not find config info for %s\n", pvt->name);
 			ao2_ref(pvt, -1);
 			continue;
 		}
+		/* As an example of non-config-related state remaining between reloads */
+		++pvt->non_config_state;
 		ast_getformatname_multiple(codec_buf, sizeof(codec_buf) - 1, cfg->caps);
-		ast_cli(a->fd, SKEL_FORMAT, pvt->name, cfg->description, codec_buf, AST_CLI_YESNO(cfg->permit != NULL), AST_CLI_YESNO(cfg->bit1), AST_CLI_YESNO(cfg->bit2));
+		ast_cli(a->fd, SKEL_FORMAT1, pvt->name, cfg->description, codec_buf, AST_CLI_YESNO(cfg->permit != NULL), AST_CLI_YESNO(cfg->bit1), AST_CLI_YESNO(cfg->bit2), pvt->non_config_state);
 		ao2_ref(pvt, -1);
-		ao2_ref(cfg, -1);
-	}
-	ao2_iterator_destroy(&iter);
+	}
 #undef SKEL_FORMAT
-
-	ao2_ref(pvts, -1);
-	ao2_ref(cfgs, -1);
+#undef SKEL_FORAMT1
 
 	return CLI_SUCCESS;
 }

Modified: team/twilson/config_work/include/asterisk/config_options.h
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/include/asterisk/config_options.h?view=diff&rev=361910&r1=361909&r2=361910
==============================================================================
--- team/twilson/config_work/include/asterisk/config_options.h (original)
+++ team/twilson/config_work/include/asterisk/config_options.h Wed Apr 11 13:17:04 2012
@@ -39,7 +39,9 @@
  * to look up the handler for that type. Each type requires field
  * names for specific types in the struct being configured. Each
  * option below is commented with the field types, *in the order
- * they must be passed* to ast_config_option_register.
+ * they must be passed* to ast_config_option_register. The fields
+ * are located in the args array in the ast_config_option passed to
+ * the default handler function.
  * */
 enum ast_config_option_type {
 	OPT_ACL_T,         /*!< fields: struct ast_ha * */
@@ -182,7 +184,7 @@
  *     ARGMAP(offsetof, struct foo, a, c)
  * produces the string:
  *     2, offsetof(struct foo, a), offsetof(struct foo, b) 
- * which can be passed as the varargs of some other function
+ * which can be passed as the varargs to some other function
  * 
  * The macro isn't limited to offsetof, but that is the only purpose for
  * which it has been tested.




More information about the asterisk-commits mailing list