From 32c4df4977b1c6fae62497de544b8e1538ca80d2 Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Thu, 27 Sep 2001 11:08:03 +0000 Subject: added InvalidURI and UnsupportedMethod exceptions to the CalFactory 2001-09-27 Rodrigo Moya * idl/evolution-calendar.idl: added InvalidURI and UnsupportedMethod exceptions to the CalFactory interface * pcs/cal-factory.c (impl_CalFactory_open): raise InvalidURI exception on URI errors and UnsupportedMethod when we don't support the method for a given URI 2001-09-26 Rodrigo Moya * cal-client/cal-client.c: added support for using multiple calendar factories (cal_client_uri_list): use the list of factories loaded for this CalClient svn path=/trunk/; revision=13189 --- calendar/ChangeLog | 16 +++++ calendar/cal-client/cal-client.c | 129 +++++++++++++++++++++++------------- calendar/idl/evolution-calendar.idl | 2 + calendar/pcs/cal-factory.c | 35 +++++++++- 4 files changed, 133 insertions(+), 49 deletions(-) diff --git a/calendar/ChangeLog b/calendar/ChangeLog index e57b7d107f..fef66bcf9f 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,19 @@ +2001-09-27 Rodrigo Moya + + * idl/evolution-calendar.idl: added InvalidURI and UnsupportedMethod + exceptions to the CalFactory interface + + * pcs/cal-factory.c (impl_CalFactory_open): raise InvalidURI exception on + URI errors and UnsupportedMethod when we don't support the method for + a given URI + +2001-09-26 Rodrigo Moya + + * cal-client/cal-client.c: added support for using multiple calendar + factories + (cal_client_uri_list): use the list of factories loaded for this + CalClient + 2001-09-26 Damon Chaplin * gui/e-calendar-table.c (date_compare_cb): diff --git a/calendar/cal-client/cal-client.c b/calendar/cal-client/cal-client.c index 27c827cbac..60e8ae7840 100644 --- a/calendar/cal-client/cal-client.c +++ b/calendar/cal-client/cal-client.c @@ -44,8 +44,8 @@ struct _CalClientPrivate { */ char *uri; - /* The calendar factory we are contacting */ - GNOME_Evolution_Calendar_CalFactory factory; + /* The calendar factories we are contacting */ + GList *factories; /* Our calendar listener implementation */ CalListener *listener; @@ -213,7 +213,7 @@ cal_client_init (CalClient *client) priv->load_state = CAL_CLIENT_LOAD_NOT_LOADED; priv->uri = NULL; - priv->factory = CORBA_OBJECT_NIL; + priv->factories = NULL; priv->timezones = g_hash_table_new (g_str_hash, g_str_equal); /* create the WombatClient */ @@ -241,36 +241,43 @@ destroy_wombat_client (CalClient *client) priv->w_client = NULL; } -/* Gets rid of the factory that a client knows about */ +/* Gets rid of the factories that a client knows about */ static void -destroy_factory (CalClient *client) +destroy_factories (CalClient *client) { CalClientPrivate *priv; + CORBA_Object factory; CORBA_Environment ev; int result; + GList *f; priv = client->priv; CORBA_exception_init (&ev); - result = CORBA_Object_is_nil (priv->factory, &ev); - if (BONOBO_EX (&ev)) { - g_message ("destroy_factory(): could not see if the factory was nil"); - priv->factory = CORBA_OBJECT_NIL; - CORBA_exception_free (&ev); - return; - } - CORBA_exception_free (&ev); - if (result) - return; + for (f = priv->factories; f; f = f->next) { + factory = f->data; - CORBA_exception_init (&ev); - CORBA_Object_release (priv->factory, &ev); - if (BONOBO_EX (&ev)) - g_message ("destroy_factory(): could not release the factory"); + result = CORBA_Object_is_nil (factory, &ev); + if (BONOBO_EX (&ev)) { + g_message ("destroy_factories(): could not see if a factory was nil"); + CORBA_exception_free (&ev); - CORBA_exception_free (&ev); - priv->factory = CORBA_OBJECT_NIL; + continue; + } + + if (result) + continue; + + CORBA_Object_release (factory, &ev); + if (BONOBO_EX (&ev)) { + g_message ("destroy_factories(): could not release a factory"); + CORBA_exception_free (&ev); + } + } + + g_list_free (priv->factories); + priv->factories = NULL; } /* Gets rid of the calendar client interface object that a client knows about */ @@ -342,7 +349,7 @@ cal_client_destroy (GtkObject *object) } destroy_wombat_client (client); - destroy_factory (client); + destroy_factories (client); destroy_cal (client); priv->load_state = CAL_CLIENT_LOAD_NOT_LOADED; @@ -585,8 +592,8 @@ client_forget_password_cb (WombatClient *w_client, * cal_client_construct: * @client: A calendar client. * - * Constructs a calendar client object by contacting the calendar factory of the - * calendar server. + * Constructs a calendar client object by contacting all available + * calendar factories. * * Return value: The same object as the @client argument, or NULL if the * calendar factory could not be contacted. @@ -595,8 +602,10 @@ CalClient * cal_client_construct (CalClient *client) { CalClientPrivate *priv; - GNOME_Evolution_Calendar_CalFactory factory, factory_copy; + GNOME_Evolution_Calendar_CalFactory factory; + OAF_ServerInfoList *servers; CORBA_Environment ev; + int i; CORBA_exception_init (&ev); g_return_val_if_fail (client != NULL, NULL); @@ -605,27 +614,37 @@ cal_client_construct (CalClient *client) priv = client->priv; CORBA_exception_init (&ev); - factory = (GNOME_Evolution_Calendar_CalFactory) oaf_activate_from_id ( - "OAFIID:GNOME_Evolution_Wombat_CalendarFactory", - 0, NULL, &ev); - if (BONOBO_EX (&ev)) { - g_message ("cal_client_construct(): Could not activate the calendar factory"); + servers = oaf_query ("repo_ids.has ('IDL:GNOME/Evolution/Calendar/CalFactory:1.0')", NULL, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_message ("Cannot perform OAF query for Calendar servers."); CORBA_exception_free (&ev); return NULL; } - CORBA_exception_init (&ev); - factory_copy = CORBA_Object_duplicate (factory, &ev); + if (servers->_length == 0) + g_warning ("No Calendar servers installed."); - if (BONOBO_EX (&ev)) { - g_message ("cal_client_construct(): could not duplicate the calendar factory"); - CORBA_exception_free (&ev); - return NULL; + for (i = 0; i < servers->_length; i++) { + const OAF_ServerInfo *info; + + info = servers->_buffer + i; + + factory = (GNOME_Evolution_Calendar_CalFactory) + oaf_activate_from_id (info->iid, 0, NULL, &ev); + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("cal_client_construct: Could not activate calendar server %s", info->iid); + CORBA_free (servers); + CORBA_exception_free (&ev); + return NULL; + } + + priv->factories = g_list_prepend (priv->factories, factory); } - CORBA_exception_free (&ev); - priv->factory = factory_copy; + CORBA_free (servers); + + CORBA_exception_free (&ev); return client; } @@ -703,6 +722,7 @@ cal_client_open_calendar (CalClient *client, const char *str_uri, gboolean only_ CalClientPrivate *priv; GNOME_Evolution_Calendar_Listener corba_listener; CORBA_Environment ev; + GList *f; g_return_val_if_fail (client != NULL, FALSE); g_return_val_if_fail (IS_CAL_CLIENT (client), FALSE); @@ -734,8 +754,14 @@ cal_client_open_calendar (CalClient *client, const char *str_uri, gboolean only_ priv->load_state = CAL_CLIENT_LOAD_LOADING; priv->uri = g_strdup (str_uri); - GNOME_Evolution_Calendar_CalFactory_open (priv->factory, str_uri, only_if_exists, - corba_listener, &ev); + for (f = priv->factories; f; f = f->next) { + CORBA_exception_free (&ev); + GNOME_Evolution_Calendar_CalFactory_open (f->data, str_uri, + only_if_exists, + corba_listener, &ev); + if (ev._major == CORBA_NO_EXCEPTION) + break; + } if (BONOBO_EX (&ev)) { CORBA_exception_free (&ev); @@ -782,22 +808,31 @@ cal_client_uri_list (CalClient *client, CalMode mode) GNOME_Evolution_Calendar_StringSeq *uri_seq; GList *uris = NULL; CORBA_Environment ev; + GList *f; g_return_val_if_fail (client != NULL, FALSE); g_return_val_if_fail (IS_CAL_CLIENT (client), FALSE); priv = client->priv; - CORBA_exception_init (&ev); + for (f = priv->factories; f; f = f->next) { + CORBA_exception_init (&ev); + uri_seq = GNOME_Evolution_Calendar_CalFactory_uriList (f->data, mode, &ev); - uri_seq = GNOME_Evolution_Calendar_CalFactory_uriList (priv->factory, mode, &ev); + if (BONOBO_EX (&ev)) { + g_message ("cal_client_uri_list(): request failed"); - if (BONOBO_EX (&ev)) - g_message ("cal_client_uri_list(): request failed"); - else - uris = build_uri_list (uri_seq); + /* free memory and return */ + g_list_foreach (uris, (GFunc) g_free, NULL); + g_list_free (uris); + uris = NULL; + break; + } + else + uris = g_list_concat (uris, build_uri_list (uri_seq)); - CORBA_exception_free (&ev); + CORBA_exception_free (&ev); + } return uris; } diff --git a/calendar/idl/evolution-calendar.idl b/calendar/idl/evolution-calendar.idl index df9b7ecf57..fe3c710cbc 100644 --- a/calendar/idl/evolution-calendar.idl +++ b/calendar/idl/evolution-calendar.idl @@ -283,6 +283,8 @@ module Calendar { /* A calendar factory, can load and create calendars */ interface CalFactory : Bonobo::Unknown { exception NilListener {}; + exception InvalidURI {}; + exception UnsupportedMethod {}; /* Open a calendar from an URI */ void open (in string uri, in boolean only_if_exists, in Listener listener) diff --git a/calendar/pcs/cal-factory.c b/calendar/pcs/cal-factory.c index b2b718f861..e7a7316193 100644 --- a/calendar/pcs/cal-factory.c +++ b/calendar/pcs/cal-factory.c @@ -417,7 +417,7 @@ open_fn (gpointer data) static void impl_CalFactory_open (PortableServer_Servant servant, - const CORBA_char *uri, + const CORBA_char *str_uri, CORBA_boolean only_if_exists, GNOME_Evolution_Calendar_Listener listener, CORBA_Environment *ev) @@ -428,10 +428,40 @@ impl_CalFactory_open (PortableServer_Servant servant, gboolean result; OpenJobData *jd; GNOME_Evolution_Calendar_Listener listener_copy; + GnomeVFSURI *uri; + const char *method_str; + GtkType type; factory = CAL_FACTORY (bonobo_object_from_servant (servant)); priv = factory->priv; + /* check URI to see if we support it */ + CORBA_exception_init (&ev2); + + uri = gnome_vfs_uri_new_private (str_uri, TRUE, TRUE, TRUE); + if (!uri) { + CORBA_exception_set (ev, CORBA_USER_EXCEPTION, + ex_GNOME_Evolution_Calendar_CalFactory_InvalidURI, + NULL); + CORBA_exception_free (&ev2); + return; + } + + method_str = gnome_vfs_uri_get_scheme (uri); + type = g_hash_table_lookup (priv->methods, method_str); + + gnome_vfs_uri_unref (uri); + if (!type) { + CORBA_exception_set (ev, CORBA_USER_EXCEPTION, + ex_GNOME_Evolution_Calendar_CalFactory_UnsupportedMethod, + NULL); + CORBA_exception_free (&ev2); + return; + } + + CORBA_exception_free (&ev2); + + /* duplicate the listener object */ CORBA_exception_init (&ev2); result = CORBA_Object_is_nil (listener, &ev2); @@ -459,9 +489,10 @@ impl_CalFactory_open (PortableServer_Servant servant, CORBA_exception_free (&ev2); + /* add new asynchronous job */ jd = g_new (OpenJobData, 1); jd->factory = factory; - jd->uri = g_strdup (uri); + jd->uri = g_strdup (str_uri); jd->only_if_exists = only_if_exists; jd->listener = listener_copy; -- cgit v1.2.3