aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/pcs/cal-factory.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@helixcode.com>2000-02-11 19:08:08 +0800
committerArturo Espinosa <unammx@src.gnome.org>2000-02-11 19:08:08 +0800
commitd8fbc4fc0c01d174f04e8f2370131a5240764f4b (patch)
treed530001f5c312790457e2cd55585dd46eac32085 /calendar/pcs/cal-factory.c
parentdb6312e2549c63372546af84fce3ce41b7c3f48d (diff)
downloadgsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.tar.gz
gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.tar.zst
gsoc2013-evolution-d8fbc4fc0c01d174f04e8f2370131a5240764f4b.zip
Connect to the Cal's destroy signal. (cal_backend_remove_cal): Killed
2000-02-10 Federico Mena Quintero <federico@helixcode.com> * cal-backend.c (cal_backend_add_cal): Connect to the Cal's destroy signal. (cal_backend_remove_cal): Killed function now that removal of Cal objects is done in their destroy callback. (cal_destroy_cb): New callback to remove a Cal from the backend's list of clients. Also, the backend destroys itself when there are no more clients connected to it. (save): New placeholder function to save a backend. (destroy): New function to destroy a backend's data. (cal_backend_destroy): Save the calendar and destroy it. * cal.c (cal_destroy): Reset the priv->backend to NULL. * cal-factory.c (add_calendar_client): There is no need to call cal_backend_remove_cal(); we can now just destroy the Cal object. (create_fn): Make sure we always unref the URI. (load_fn): Move the URI unref to the end of the function for safety. * cal-factory.c (add_calendar_client): Unref the Cal only if notification of the listener was unsuccessful. Otherwise, the calendar user agent (Listener side) keeps the reference. * tl-test.c (list_uids): Free the calobj. * cal-client.c (cal_loaded_cb): Use bonobo_object_unref() to get rid of the listener. (load_or_create): Likewise. (destroy_factory): New function to get rid of the factory. (destroy_listener): New function to get rid of the listener. (destroy_cal): New function to get rid of the calendar client interface object. (cal_client_destroy): Free all resources. (cal_client_get_object): CORBA_free() the calobj string. Boy, I love memprof. * cal-listener.c (cal_listener_destroy): Reset the priv->cal to CORBA_OBJECT_NIL. * cal-backend.c (cal_backend_remove_cal): Do not unref the Cal, since the calendar user agent owns it. (cal_backend_add_cal): Do not ref the Cal, since the calendar user agent owns it. * cal-factory.c (add_calendar_client): Use bonobo_object_unref() to get rid of the calendar client interface object. * calobj.c (ical_object_create_from_vobject): Duplicate the default "PUBLIC" string. 2000-02-09 Federico Mena Quintero <federico@helixcode.com> * cal-factory.c (cal_factory_load): Added documentation comment. (load_fn): Do not print a message if the backend could not be loaded due to a non-fatal error. (queue_load_create_job): Moved the stuff from cal_factory_load() to here. Now this function serves to queue load or create requests. (cal_factory_load): Use queue_load_create_job(). (cal_factory_create): Implemented; use queue_load_create_job(). (create_fn): New job handler for creating new calendars. (create_backend): New function to create a new backend with a new calendar. (add_backend): New helper function to add backends to the factory's hash table. (load_backend): Use add_backend() instead of adding the backend by ourselves. * cal-client.c (load_or_create): Moved the functionality from cal_client_load_calendar() to here, and added an option to create a new calendar instead of loading an existing one. (cal_client_load_calendar): Use load_or_create(). (cal_client_create_calendar): Implemented. * cal-backend.c (cal_backend_create): Implemented. * evolution-calendar.idl (LoadStatus): Added an IN_USE error for create requests. * cal-listener.h (CalListenerLoadStatus): Added CAL_LISTENER_LOAD_IN_USE. * cal-listener.c (Listener_cal_loaded): Convert the IN_USE error. * cal-client.h (CalClientLoadStatus): Added CAL_CLIENT_LOAD_IN_USE. * cal-client.c (cal_loaded_cb): Handle CAL_LISTENER_LOAD_IN_USE. * tl-test.c: New test program for the calendar client side; it also exercises the server side by sending commands to it. * Makefile.am: Added the tl-test program. * tlacuache.gnorba: Updated. * tlacuache.c (create_cal_factory): Use the right GOAD id. * cal-client.c (cal_client_construct): Use the right GOAD id. svn path=/trunk/; revision=1732
Diffstat (limited to 'calendar/pcs/cal-factory.c')
-rw-r--r--calendar/pcs/cal-factory.c159
1 files changed, 141 insertions, 18 deletions
diff --git a/calendar/pcs/cal-factory.c b/calendar/pcs/cal-factory.c
index d5b79ef423..14b7ac9cb6 100644
--- a/calendar/pcs/cal-factory.c
+++ b/calendar/pcs/cal-factory.c
@@ -244,9 +244,24 @@ lookup_backend (CalFactory *factory, GnomeVFSURI *uri)
return backend;
}
+/* Adds a backend to the calendar factory's hash table */
+static void
+add_backend (CalFactory *factory, GnomeVFSURI *uri, CalBackend *backend)
+{
+ CalFactoryPrivate *priv;
+
+ priv = factory->priv;
+
+ gnome_vfs_uri_ref (uri);
+ g_hash_table_insert (priv->backends, uri, backend);
+ /* FIXME: connect to destroy on the backend and remove it from
+ * the hash table when it dies.
+ */
+}
+
/* Loads a calendar backend and puts it in the factory's backend hash table */
static CalBackend *
-load_backend (CalFactory *factory, GnomeVFSURI *uri, Evolution_Calendar_Listener listener)
+load_backend (CalFactory *factory, GnomeVFSURI *uri)
{
CalFactoryPrivate *priv;
CalBackend *backend;
@@ -264,9 +279,7 @@ load_backend (CalFactory *factory, GnomeVFSURI *uri, Evolution_Calendar_Listener
switch (status) {
case CAL_BACKEND_LOAD_SUCCESS:
- gnome_vfs_uri_ref (uri);
- g_hash_table_insert (priv->backends, uri, backend);
-
+ add_backend (factory, uri, backend);
return backend;
case CAL_BACKEND_LOAD_ERROR:
@@ -279,6 +292,27 @@ load_backend (CalFactory *factory, GnomeVFSURI *uri, Evolution_Calendar_Listener
}
}
+/* Creates a calendar backend and puts it in the factory's backend hash table */
+static CalBackend *
+create_backend (CalFactory *factory, GnomeVFSURI *uri)
+{
+ CalFactoryPrivate *priv;
+ CalBackend *backend;
+
+ priv = factory->priv;
+
+ backend = cal_backend_new ();
+ if (!backend) {
+ g_message ("create_backend(): could not create the backend");
+ return NULL;
+ }
+
+ cal_backend_create (backend, uri);
+ add_backend (factory, uri, backend);
+
+ return backend;
+}
+
/* Adds a listener to a calendar backend by creating a calendar client interface
* object.
*/
@@ -314,10 +348,8 @@ add_calendar_client (CalFactory *factory, CalBackend *backend, Evolution_Calenda
if (ev._major != CORBA_NO_EXCEPTION) {
g_message ("add_calendar_client(): could not notify the listener");
- cal_backend_remove_cal (backend, cal);
+ bonobo_object_unref (BONOBO_OBJECT (cal));
}
-
- gtk_object_unref (GTK_OBJECT (cal));
}
/* Job handler for the load calendar command */
@@ -342,15 +374,14 @@ load_fn (gpointer data)
listener = jd->listener;
g_free (jd);
+ /* Look up the backend and create it if needed */
+
backend = lookup_backend (factory, uri);
if (!backend)
- backend = load_backend (factory, uri, listener);
-
- gnome_vfs_uri_unref (uri);
+ backend = load_backend (factory, uri);
if (!backend) {
- g_message ("load_fn(): could not load the backend");
CORBA_exception_init (&ev);
Evolution_Calendar_Listener_cal_loaded (listener,
Evolution_Calendar_Listener_ERROR,
@@ -368,6 +399,8 @@ load_fn (gpointer data)
out:
+ gnome_vfs_uri_unref (uri);
+
CORBA_exception_init (&ev);
CORBA_Object_release (listener, &ev);
@@ -377,6 +410,78 @@ load_fn (gpointer data)
CORBA_exception_free (&ev);
}
+/* Job handler for the create calendar command */
+static void
+create_fn (gpointer data)
+{
+ LoadCreateJobData *jd;
+ CalFactory *factory;
+ GnomeVFSURI *uri;
+ Evolution_Calendar_Listener listener;
+ CalBackend *backend;
+ CORBA_Environment ev;
+
+ jd = data;
+ factory = jd->factory;
+
+ uri = gnome_vfs_uri_new (jd->uri);
+ g_free (jd->uri);
+
+ factory = jd->factory;
+ listener = jd->listener;
+ g_free (jd);
+
+ /* Check that the backend is not in use */
+
+ backend = lookup_backend (factory, uri);
+
+ if (backend) {
+ CORBA_exception_init (&ev);
+ Evolution_Calendar_Listener_cal_loaded (listener,
+ Evolution_Calendar_Listener_IN_USE,
+ CORBA_OBJECT_NIL,
+ &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION)
+ g_message ("create_fn(): could not notify the listener");
+
+ CORBA_exception_free (&ev);
+ goto out;
+ }
+
+ /* Create the backend */
+
+ backend = create_backend (factory, uri);
+
+ if (!backend) {
+ CORBA_exception_init (&ev);
+ Evolution_Calendar_Listener_cal_loaded (listener,
+ Evolution_Calendar_Listener_ERROR,
+ CORBA_OBJECT_NIL,
+ &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION)
+ g_message ("create_fn(): could not notify the listener");
+
+ CORBA_exception_free (&ev);
+ goto out;
+ }
+
+ add_calendar_client (factory, backend, listener);
+
+ out:
+
+ gnome_vfs_uri_unref (uri);
+
+ CORBA_exception_init (&ev);
+ CORBA_Object_release (listener, &ev);
+
+ if (ev._major != CORBA_NO_EXCEPTION)
+ g_message ("create_fn(): could not release the listener");
+
+ CORBA_exception_free (&ev);
+}
+
/**
@@ -470,8 +575,10 @@ cal_factory_new (void)
return cal_factory_construct (factory, corba_factory);
}
-void
-cal_factory_load (CalFactory *factory, const char *uri, Evolution_Calendar_Listener listener)
+/* Queues a load or create request */
+static void
+queue_load_create_job (CalFactory *factory, const char *uri, Evolution_Calendar_Listener listener,
+ JobFunc func)
{
LoadCreateJobData *jd;
CORBA_Environment ev;
@@ -481,21 +588,21 @@ cal_factory_load (CalFactory *factory, const char *uri, Evolution_Calendar_Liste
CORBA_exception_init (&ev);
result = CORBA_Object_is_nil (listener, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
- g_message ("cal_factory_load(): could not see if the listener was NIL");
+ g_message ("queue_load_create_job(): could not see if the listener was NIL");
CORBA_exception_free (&ev);
return;
}
CORBA_exception_free (&ev);
if (result) {
- g_message ("cal_factory_load(): cannot operate on a NIL listener!");
+ g_message ("queue_load_create_job(): cannot operate on a NIL listener!");
return;
}
listener_copy = CORBA_Object_duplicate (listener, &ev);
if (ev._major != CORBA_NO_EXCEPTION) {
- g_message ("cal_factory_load(): could not duplicate the listener");
+ g_message ("queue_load_create_job(): could not duplicate the listener");
CORBA_exception_free (&ev);
return;
}
@@ -507,11 +614,27 @@ cal_factory_load (CalFactory *factory, const char *uri, Evolution_Calendar_Liste
jd->uri = g_strdup (uri);
jd->listener = listener_copy;
- job_add (load_fn, jd);
+ job_add (func, jd);
+}
+
+/**
+ * cal_factory_load:
+ * @factory: A calendar factory.
+ * @uri: URI of calendar to load.
+ * @listener: Listener for notification of the load result.
+ *
+ * Initiates a load request in a calendar factory. A calendar will be loaded
+ * asynchronously and the result code will be reported to the specified
+ * listener.
+ **/
+void
+cal_factory_load (CalFactory *factory, const char *uri, Evolution_Calendar_Listener listener)
+{
+ queue_load_create_job (factory, uri, listener, load_fn);
}
void
cal_factory_create (CalFactory *factory, const char *uri, Evolution_Calendar_Listener listener)
{
- /* FIXME */
+ queue_load_create_job (factory, uri, listener, create_fn);
}