[asterisk-commits] twilson: branch twilson/calendaring r166952 - in /team/twilson/calendaring: i...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 31 13:02:13 CST 2008


Author: twilson
Date: Wed Dec 31 13:02:13 2008
New Revision: 166952

URL: http://svn.digium.com/view/asterisk?view=rev&rev=166952
Log:
Baby steps towards reworking loading, start by making the config a global and getting rid of the load_data struct

Modified:
    team/twilson/calendaring/include/asterisk/calendar.h
    team/twilson/calendaring/main/calendar.c
    team/twilson/calendaring/res/res_caldav.c
    team/twilson/calendaring/res/res_exchangecal.c
    team/twilson/calendaring/res/res_icalendar.c

Modified: team/twilson/calendaring/include/asterisk/calendar.h
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/include/asterisk/calendar.h?view=diff&rev=166952&r1=166951&r2=166952
==============================================================================
--- team/twilson/calendaring/include/asterisk/calendar.h (original)
+++ team/twilson/calendaring/include/asterisk/calendar.h Wed Dec 31 13:02:13 2008
@@ -60,14 +60,10 @@
  * to unregister that module's calendar type (usually done in module_unload())
  */
 
+struct ast_config *calendar_config;
+
 struct ast_calendar;
 struct ast_calendar_event;
-
-/*! \brief The structure to pass to the load_calendar callback */
-struct ast_calendar_load_data {
-	struct ast_config *cfg;
-	struct ast_calendar *cal;
-};
 
 /*! \brief Individual calendaring technology data */
 struct ast_calendar_tech {

Modified: team/twilson/calendaring/main/calendar.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/main/calendar.c?view=diff&rev=166952&r1=166951&r2=166952
==============================================================================
--- team/twilson/calendaring/main/calendar.c (original)
+++ team/twilson/calendaring/main/calendar.c Wed Dec 31 13:02:13 2008
@@ -687,7 +687,6 @@
 
 static int load_config(void *data)
 {
-	struct ast_config *cfg;
 	const char *cat = NULL;
 	struct ast_flags config_flags = { 0 };
 	const char *val;
@@ -696,16 +695,16 @@
 		sleep(1);
 	}
 
-	if (!(cfg = ast_config_load2("calendar.conf", "calendar", config_flags))) {
+	if (!(calendar_config = ast_config_load2("calendar.conf", "calendar", config_flags))) {
 		ast_log(LOG_ERROR, "Unable to load config calendar.conf\n");
 		return -1;
 	}
 
-	while ((cat = ast_category_browse(cfg, cat))) {
+	while ((cat = ast_category_browse(calendar_config, cat))) {
 		if (!strcasecmp(cat, "general")) {
-			if (!(val = ast_variable_retrieve(cfg, cat, "enabled")) || !ast_true(val)) {
+			if (!(val = ast_variable_retrieve(calendar_config, cat, "enabled")) || !ast_true(val)) {
 				ast_debug(1, "Disabling calendar support\n");
-				ast_config_destroy(cfg);
+				ast_config_destroy(calendar_config);
 				return 0;
 			} else {
 				ast_debug(1, "Enabling calendar support\n");
@@ -713,10 +712,9 @@
 		} else {
 			struct ast_calendar *cal;
 			const struct ast_calendar_tech *tech;
-			struct ast_calendar_load_data *load_data;
 			const char *val;
 
-			if (!(val = ast_variable_retrieve(cfg, cat, "type"))) {
+			if (!(val = ast_variable_retrieve(calendar_config, cat, "type"))) {
 				ast_log(LOG_WARNING, "Calendar '%s' has no type, skipping!\n", cat);
 				continue;
 			}
@@ -726,30 +724,21 @@
 				continue;
 			}
 
-			if (!(cal = build_calendar(cfg, cat, tech))) {
-				ast_config_destroy(cfg);
+			if (!(cal = build_calendar(calendar_config, cat, tech))) {
+				ast_config_destroy(calendar_config);
 				return -1;
 			}
 
 			ao2_link(calendars, cal);
 
-			if (!(load_data = ast_malloc(sizeof(*load_data)))) {
-				ast_log(LOG_ERROR, "Could not allocate memory for two measly pointers? Right...\n");
-				cal = unref_calendar(cal);
-				ast_config_destroy(cfg);
-				return -1;
-			}
-			load_data->cfg = cfg;
-			load_data->cal = cal;
-
 			/* Respsonsible for freeing load_data */
-			ast_pthread_create(&cal->thread, NULL, cal->tech->load_calendar, load_data);
+			ast_pthread_create(&cal->thread, NULL, cal->tech->load_calendar, cal);
 
 			cal = unref_calendar(cal);
 		}
 	}
 
-	ast_config_destroy(cfg);
+	ast_config_destroy(calendar_config);
 
 	return 0;
 }

Modified: team/twilson/calendaring/res/res_caldav.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/res/res_caldav.c?view=diff&rev=166952&r1=166951&r2=166952
==============================================================================
--- team/twilson/calendaring/res/res_caldav.c (original)
+++ team/twilson/calendaring/res/res_caldav.c Wed Dec 31 13:02:13 2008
@@ -517,12 +517,10 @@
 {
 	struct caldav_pvt *pvt;
 	struct ast_variable *v;
-	struct ast_calendar_load_data *data = void_data;
-	struct ast_config *cfg = data->cfg;
-	struct ast_calendar *cal = data->cal;
+	struct ast_calendar *cal = void_data;
 	ast_mutex_t refreshlock;
 
-	if (!(cal && cfg)) {
+	if (!(cal && calendar_config)) {
 		ast_log(LOG_ERROR, "Required parameters not provided\n");
 		return NULL;
 	}
@@ -550,7 +548,7 @@
 		return NULL;
 	}
 
-	for (v = ast_variable_browse(cfg, cal->name); v; v = v->next) {
+	for (v = ast_variable_browse(calendar_config, cal->name); v; v = v->next) {
 		if (!strcasecmp(v->name, "url")) {
 			ast_string_field_set(pvt, url, v->value);
 		} else if (!strcasecmp(v->name, "user")) {
@@ -597,10 +595,6 @@
 
 	ao2_unlock(cal);
 
-	cfg = NULL;
-	cal = NULL;
-	ast_free(data);
-
 	/* The only writing from another thread will be if unload is true */
 	for (;;) {
 		struct timeval tv = ast_tvnow();

Modified: team/twilson/calendaring/res/res_exchangecal.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/res/res_exchangecal.c?view=diff&rev=166952&r1=166951&r2=166952
==============================================================================
--- team/twilson/calendaring/res/res_exchangecal.c (original)
+++ team/twilson/calendaring/res/res_exchangecal.c Wed Dec 31 13:02:13 2008
@@ -616,12 +616,10 @@
 {
 	struct exchangecal_pvt *pvt;
 	struct ast_variable *v;
-	struct ast_calendar_load_data *data = void_data;
-	struct ast_config *cfg = data->cfg;
-	struct ast_calendar *cal = data->cal;
+	struct ast_calendar *cal = void_data;
 	ast_mutex_t refreshlock;
 
-	if (!(cal && cfg)) {
+	if (!(cal && calendar_config)) {
 		ast_log(LOG_ERROR, "Required parameters not provided\n");
 		return NULL;
 	}
@@ -649,7 +647,7 @@
 		return NULL;
 	}
 
-	for (v = ast_variable_browse(cfg, cal->name); v; v = v->next) {
+	for (v = ast_variable_browse(calendar_config, cal->name); v; v = v->next) {
 		if (!strcasecmp(v->name, "url")) {
 			ast_string_field_set(pvt, url, v->value);
 		} else if (!strcasecmp(v->name, "user")) {
@@ -696,10 +694,6 @@
 
 	ao2_unlock(cal);
 
-	cfg = NULL;
-	cal = NULL;
-	ast_free(data);
-
 	/* The only writing from another thread will be if unload is true */
 	for (;;) {
 		struct timeval tv = ast_tvnow();

Modified: team/twilson/calendaring/res/res_icalendar.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/res/res_icalendar.c?view=diff&rev=166952&r1=166951&r2=166952
==============================================================================
--- team/twilson/calendaring/res/res_icalendar.c (original)
+++ team/twilson/calendaring/res/res_icalendar.c Wed Dec 31 13:02:13 2008
@@ -312,12 +312,10 @@
 {
 	struct icalendar_pvt *pvt;
 	struct ast_variable *v;
-	struct ast_calendar_load_data *data = void_data;
-	struct ast_config *cfg = data->cfg;
-	struct ast_calendar *cal = data->cal;
+	struct ast_calendar *cal = void_data;
 	ast_mutex_t refreshlock;
 
-	if (!(cal && cfg)) {
+	if (!(cal && calendar_config)) {
 		ast_log(LOG_ERROR, "Required parameters not provided\n");
 		return NULL;
 	}
@@ -345,7 +343,7 @@
 		return NULL;
 	}
 
-	for (v = ast_variable_browse(cfg, cal->name); v; v = v->next) {
+	for (v = ast_variable_browse(calendar_config, cal->name); v; v = v->next) {
 		if (!strcasecmp(v->name, "url")) {
 			ast_string_field_set(pvt, url, v->value);
 		} else if (!strcasecmp(v->name, "user")) {
@@ -396,10 +394,6 @@
 
 	ao2_unlock(cal);
 
-	cfg = NULL;
-	cal = NULL;
-	ast_free(data);
-
 	/* The only writing from another thread will be if unload is true */
 	for(;;) {
 		struct timeval tv = ast_tvnow();




More information about the asterisk-commits mailing list