[svn-commits] kmoore: branch kmoore/cel_cleanup r392722 - in /team/kmoore/cel_cleanup: incl...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jun 24 10:39:10 CDT 2013


Author: kmoore
Date: Mon Jun 24 10:39:09 2013
New Revision: 392722

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392722
Log:
Enable CEL config to be swapped for easier unit testing

Modified:
    team/kmoore/cel_cleanup/include/asterisk/cel.h
    team/kmoore/cel_cleanup/main/cel.c

Modified: team/kmoore/cel_cleanup/include/asterisk/cel.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_cleanup/include/asterisk/cel.h?view=diff&rev=392722&r1=392721&r2=392722
==============================================================================
--- team/kmoore/cel_cleanup/include/asterisk/cel.h (original)
+++ team/kmoore/cel_cleanup/include/asterisk/cel.h Mon Jun 24 10:39:09 2013
@@ -263,6 +263,44 @@
  */
 struct stasis_topic *ast_cel_topic(void);
 
+/*! \brief A structure to hold CEL global configuration options */
+struct ast_cel_config {
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(date_format); /*!< The desired date format for logging */
+	);
+	int enable;			/*!< Whether CEL is enabled */
+	int64_t events;			/*!< The events to be logged */
+	struct ao2_container *apps;	/*!< The apps for which to log app start and end events */
+};
+
+/*!
+ * \brief Allocate a CEL configuration object
+ *
+ * \retval NULL on error
+ * \retval The new CEL configuration object
+ */
+void *ast_cel_config_alloc(void);
+
+/*!
+ * \since 12
+ * \brief Obtain the current CEL configuration
+ *
+ * The configuration is a ref counted object. The caller of this function must
+ * decrement the ref count when finished with the configuration.
+ *
+ * \retval NULL on error
+ * \retval The current CEL configuration
+ */
+struct ast_cel_config *ast_cel_get_config(void);
+
+/*!
+ * \since 12
+ * \brief Set the current CEL configuration
+ *
+ * \param config The new CEL configuration
+ */
+void ast_cel_set_config(struct ast_cel_config *config);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/kmoore/cel_cleanup/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_cleanup/main/cel.c?view=diff&rev=392722&r1=392721&r2=392722
==============================================================================
--- team/kmoore/cel_cleanup/main/cel.c (original)
+++ team/kmoore/cel_cleanup/main/cel.c Mon Jun 24 10:39:09 2013
@@ -180,30 +180,20 @@
  */
 static struct ao2_container *linkedids;
 
-/*! \brief A structure to hold global configuration-related options */
-struct cel_general_config {
-	AST_DECLARE_STRING_FIELDS(
-		AST_STRING_FIELD(date_format); /*!< The desired date format for logging */
-	);
-	int enable;			/*!< Whether CEL is enabled */
-	int64_t events;			/*!< The events to be logged */
-	struct ao2_container *apps;	/*!< The apps for which to log app start and end events */
-};
-
 /*! \brief Destructor for cel_config */
-static void cel_general_config_dtor(void *obj)
-{
-	struct cel_general_config *cfg = obj;
+static void ast_cel_config_dtor(void *obj)
+{
+	struct ast_cel_config *cfg = obj;
 	ast_string_field_free_memory(cfg);
 	ao2_cleanup(cfg->apps);
 	cfg->apps = NULL;
 }
 
-static void *cel_general_config_alloc(void)
-{
-	RAII_VAR(struct cel_general_config *, cfg, NULL, ao2_cleanup);
-
-	if (!(cfg = ao2_alloc(sizeof(*cfg), cel_general_config_dtor))) {
+void *ast_cel_config_alloc(void)
+{
+	RAII_VAR(struct ast_cel_config *, cfg, NULL, ao2_cleanup);
+
+	if (!(cfg = ao2_alloc(sizeof(*cfg), ast_cel_config_dtor))) {
 		return NULL;
 	}
 
@@ -221,7 +211,7 @@
 
 /*! \brief A container that holds all config-related information */
 struct cel_config {
-	struct cel_general_config *general;
+	struct ast_cel_config *general;
 };
 
 
@@ -243,7 +233,7 @@
 		return NULL;
 	}
 
-	if (!(cfg->general = cel_general_config_alloc())) {
+	if (!(cfg->general = ast_cel_config_alloc())) {
 		return NULL;
 	}
 
@@ -251,7 +241,7 @@
 	return cfg;
 }
 
-/*! \brief An aco_type structure to link the "general" category to the cel_general_config type */
+/*! \brief An aco_type structure to link the "general" category to the ast_cel_config type */
 static struct aco_type general_option = {
 	.type = ACO_GLOBAL,
 	.name = "general",
@@ -559,7 +549,7 @@
 
 static int events_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
-	struct cel_general_config *cfg = obj;
+	struct ast_cel_config *cfg = obj;
 	char *events = ast_strdupa(var->value);
 	char *cur_event;
 
@@ -589,7 +579,7 @@
 
 static int apps_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
-	struct cel_general_config *cfg = obj;
+	struct ast_cel_config *cfg = obj;
 	char *apps = ast_strdupa(var->value);
 	char *cur_app;
 
@@ -1578,8 +1568,8 @@
 		return -1;
 	}
 
-	aco_option_register(&cel_cfg_info, "enable", ACO_EXACT, general_options, "no", OPT_BOOL_T, 1, FLDSET(struct cel_general_config, enable));
-	aco_option_register(&cel_cfg_info, "dateformat", ACO_EXACT, general_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct cel_general_config, date_format));
+	aco_option_register(&cel_cfg_info, "enable", ACO_EXACT, general_options, "no", OPT_BOOL_T, 1, FLDSET(struct ast_cel_config, enable));
+	aco_option_register(&cel_cfg_info, "dateformat", ACO_EXACT, general_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_cel_config, date_format));
 	aco_option_register_custom(&cel_cfg_info, "apps", ACO_EXACT, general_options, "", apps_handler, 0);
 	aco_option_register_custom(&cel_cfg_info, "events", ACO_EXACT, general_options, "", events_handler, 0);
 
@@ -1616,3 +1606,19 @@
 {
 	return cel_topic;
 }
+
+struct ast_cel_config *ast_cel_get_config(void)
+{
+	RAII_VAR(struct cel_config *, mod_cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
+	ao2_ref(mod_cfg->general, +1);
+	return mod_cfg->general;
+}
+
+void ast_cel_set_config(struct ast_cel_config *config)
+{
+	RAII_VAR(struct cel_config *, mod_cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
+	ao2_cleanup(mod_cfg->general);
+	mod_cfg->general = config;
+	ao2_ref(mod_cfg->general, +1);
+}
+




More information about the svn-commits mailing list