[svn-commits] twilson: branch twilson/calendaring r151411 - /team/twilson/calendaring/main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Oct 21 11:18:00 CDT 2008


Author: twilson
Date: Tue Oct 21 11:17:59 2008
New Revision: 151411

URL: http://svn.digium.com/view/asterisk?view=rev&rev=151411
Log:
Get rid of event masquerading by making merging slightly less efficient

Modified:
    team/twilson/calendaring/main/calendar.c

Modified: team/twilson/calendaring/main/calendar.c
URL: http://svn.digium.com/view/asterisk/team/twilson/calendaring/main/calendar.c?view=diff&rev=151411&r1=151410&r2=151411
==============================================================================
--- team/twilson/calendaring/main/calendar.c (original)
+++ team/twilson/calendaring/main/calendar.c Tue Oct 21 11:17:59 2008
@@ -309,39 +309,17 @@
 
 }
 
-static void event_masquerade(struct ast_calendar_event *dst, struct ast_calendar_event *src)
-{
-	ast_string_field_init(dst, 0);
-	ast_string_field_set(dst, summary, src->summary);
-	ast_string_field_set(dst, description, src->description);
-	ast_string_field_set(dst, organizer, src->organizer);
-	ast_string_field_set(dst, location, src->location);
-	ast_string_field_set(dst, uid, src->uid);
-
-	dst->start = src->start;
-	dst->end = src->end;
-	dst->alarm = src->alarm;
-	dst->alarm_tries = src->alarm_tries;
-	dst->busy_state = src->busy_state;
-	dst->owner = src->owner;
-}
-
 static void *event_notification_duplicate(void *data)
 {
-	struct ast_calendar_event *old = data;
-	struct ast_calendar_event *new;
-
-	if (!old) {
+	struct ast_calendar_event *event = data;
+
+	if (!event) {
 		return NULL;
 	}
 
-	if (!(new = ast_calendar_event_alloc(old->owner))) {
-		return NULL;
-	}
-
-	event_masquerade(new, old);
-
-	return new;
+	ao2_ref(event, +1);
+
+	return event;
 }
 
 static int calendar_event_notify(const void *data)
@@ -492,51 +470,49 @@
 
 int ast_calendar_merge_events(struct ast_calendar *cal, struct ao2_container *new_events)
 {
-
 	struct ao2_iterator i;
-	struct ast_calendar_event *event, *new_event;
-
-	/* Loop through existing events, deleting ones that aren't in the passed events
-	 * and merging the changes, updating our notification if the times have changed
-	 * and removing the events from the passed list that are merged, so we can add
-	 * new events from that list without having to iterate over the ones we merged */
-	i = ao2_iterator_init(cal->events, 0);
-	while ((event = ao2_iterator_next(&i))) {
+	struct ast_calendar_event *old_event, *new_event;
+
+	i = ao2_iterator_init(new_events, 0);
+	while ((new_event = ao2_iterator_next(&i))) {
 		int needs_rescheduled = 0;
 
-		if (!(new_event = find_event(new_events, event->uid))) {
-			ao2_unlink(cal->events, event);
-			event = ast_calendar_unref_event(event);
+		/* Completely new eent */
+		if (!(old_event = find_event(cal->events, new_event->uid))) {
+			schedule_calendar_event(cal, new_event);
+			new_event = ast_calendar_unref_event(new_event);
 			continue;
 		}
 
-		if (!(event->start == new_event->start && event->alarm == new_event->alarm && event->end == new_event->end)) {
+		/* Event exists in old events, and may need to be rescheduled */
+		if (!(old_event->start == new_event->start && old_event->alarm == new_event->alarm && old_event->end == new_event->end)) {
 			needs_rescheduled = 1;
 		}
 
-		event_masquerade(event, new_event);
-		ao2_unlink(new_events, new_event);
+		ao2_unlink(cal->events, old_event);
+		old_event = ast_calendar_unref_event(old_event);
 
 		if (needs_rescheduled) {
-			schedule_calendar_event(cal, event);
-
-			/* If an event is moved forward in time, we need to make sure the busy state is updated */
-			if (!calendar_is_busy(event->owner)) {
-				ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Calendar/%s", event->owner->name);
+			schedule_calendar_event(cal, new_event);
+
+			/* if an event is moved forward in time, we need to make sure the busy state is updated */
+			if (!calendar_is_busy(new_event->owner)) {
+				ast_devstate_changed(AST_DEVICE_NOT_INUSE, "calendar/%s", new_event->owner->name);
 			}
 		}
 		new_event = ast_calendar_unref_event(new_event);
-		event = ast_calendar_unref_event(event);
-	}
-
-	/* Now new_events should only contain completely new events. Add them to cal->events */
+	}
+
+	/* Delete stale events in calendar */
+	if (ao2_container_count(cal->events)) {
+		ast_calendar_clear_events(cal);
+	}
+
+	/* It doesn't feel right to just point cal->events to new_events */
 	i = ao2_iterator_init(new_events, 0);
 	while ((new_event = ao2_iterator_next(&i))) {
 		ao2_link(cal->events, new_event);
 		ao2_unlink(new_events, new_event);
-
-		schedule_calendar_event(cal, new_event);
-
 		new_event = ast_calendar_unref_event(new_event);
 	}
 




More information about the svn-commits mailing list