aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEttore Perazzoli <ettore@src.gnome.org>2000-10-02 20:52:22 +0800
committerEttore Perazzoli <ettore@src.gnome.org>2000-10-02 20:52:22 +0800
commitee5decd2ffb8693396d27b6c0eed24991d676934 (patch)
tree63be38a87db54da4a529e52f89eb31fe7b9943b2
parent7936f1411f1737fb408eb2132bee8ee508a80233 (diff)
downloadgsoc2013-evolution-ee5decd2ffb8693396d27b6c0eed24991d676934.tar.gz
gsoc2013-evolution-ee5decd2ffb8693396d27b6c0eed24991d676934.tar.zst
gsoc2013-evolution-ee5decd2ffb8693396d27b6c0eed24991d676934.zip
Add a `::remove_listener' method to Evolution::Storage.
svn path=/trunk/; revision=5655
-rw-r--r--shell/ChangeLog18
-rw-r--r--shell/Evolution-Storage.idl9
-rw-r--r--shell/evolution-storage.c81
3 files changed, 101 insertions, 7 deletions
diff --git a/shell/ChangeLog b/shell/ChangeLog
index 10af81fa5d..6a5bda5196 100644
--- a/shell/ChangeLog
+++ b/shell/ChangeLog
@@ -1,3 +1,21 @@
+2000-10-02 Ettore Perazzoli <ettore@helixcode.com>
+
+ * evolution-storage.c (find_listener_in_list): New helper
+ function.
+ (impl_Storage_remove_listener): New, implementation for
+ `Storage::remove_listener'.
+ (remove_listener): Helper function for
+ `impl_Storage_remove_listener'.
+ (evolution_storage_get_epv): Install the implementation for
+ `::remove_listener'.
+ (add_listener): Return a boolean indicating success or failure.
+ Reject multiple additions of the same listener.
+ (impl_Storage_add_listener): Updated accordingly: raise an
+ exception if `add_listener' fails.
+
+ * Evolution-Storage.idl: Added `Storage::remove_listener'. Added
+ exception `AlreadyListening' for `::add_listener'.
+
2000-09-29 Ettore Perazzoli <ettore@helixcode.com>
* e-shell-view.c (popup_storage_set_view_button_clicked): Renamed
diff --git a/shell/Evolution-Storage.idl b/shell/Evolution-Storage.idl
index 0a2402a773..42fc043047 100644
--- a/shell/Evolution-Storage.idl
+++ b/shell/Evolution-Storage.idl
@@ -22,11 +22,16 @@ module Evolution {
interface StorageListener;
interface Storage : Bonobo::Unknown {
+ exception AlreadyListening {};
+ exception NotFound {};
+
attribute string name;
- void add_listener (in StorageListener listener);
+ void add_listener (in StorageListener listener)
+ raises (AlreadyListening);
- /* FIXME remove_listener? */
+ void remove_listener (in StorageListener listener)
+ raises (NotFound);
};
interface StorageListener {
diff --git a/shell/evolution-storage.c b/shell/evolution-storage.c
index 1561c48242..4d271cefa8 100644
--- a/shell/evolution-storage.c
+++ b/shell/evolution-storage.c
@@ -86,7 +86,30 @@ list_through_listener (EvolutionStorage *storage,
listener);
}
-static void
+static GList *
+find_listener_in_list (const Evolution_StorageListener listener,
+ GList *list)
+{
+ CORBA_Environment ev;
+ GList *p;
+
+ CORBA_exception_init (&ev);
+
+ for (p = list; p != NULL; p = p->next) {
+ Evolution_StorageListener listener_item;
+
+ listener_item = (Evolution_StorageListener) p->data;
+
+ if (CORBA_Object_is_equivalent (listener_item, listener, &ev) && ev._major == CORBA_NO_EXCEPTION)
+ return p;
+ }
+
+ CORBA_exception_free (&ev);
+
+ return NULL;
+}
+
+static gboolean
add_listener (EvolutionStorage *storage,
const Evolution_StorageListener listener)
{
@@ -96,6 +119,9 @@ add_listener (EvolutionStorage *storage,
priv = storage->priv;
+ if (find_listener_in_list (listener, priv->corba_storage_listeners) != NULL)
+ return FALSE;
+
CORBA_exception_init (&ev);
listener_copy = CORBA_Object_duplicate (listener, &ev);
@@ -103,7 +129,10 @@ add_listener (EvolutionStorage *storage,
/* Panic. */
g_warning ("EvolutionStorage -- Cannot duplicate listener.");
CORBA_exception_free (&ev);
- return;
+
+ /* FIXME this will cause the ::add_listener implementation to
+ incorrectly raise `AlreadyListening' */
+ return FALSE;
}
priv->corba_storage_listeners = g_list_prepend (priv->corba_storage_listeners,
@@ -112,6 +141,31 @@ add_listener (EvolutionStorage *storage,
list_through_listener (storage, listener_copy, &ev);
CORBA_exception_free (&ev);
+
+ return TRUE;
+}
+
+static gboolean
+remove_listener (EvolutionStorage *storage,
+ const Evolution_StorageListener listener)
+{
+ EvolutionStoragePrivate *priv;
+ CORBA_Environment ev;
+ GList *p;
+
+ priv = storage->priv;
+
+ p = find_listener_in_list (listener, priv->corba_storage_listeners);
+ if (p == NULL)
+ return FALSE;
+
+ CORBA_exception_init (&ev);
+ CORBA_Object_release ((CORBA_Object) p->data, &ev);
+ CORBA_exception_free (&ev);
+
+ priv->corba_storage_listeners = g_list_remove_link (priv->corba_storage_listeners, p);
+
+ return TRUE;
}
@@ -183,7 +237,23 @@ impl_Storage_add_listener (PortableServer_Servant servant,
bonobo_object = bonobo_object_from_servant (servant);
storage = EVOLUTION_STORAGE (bonobo_object);
- add_listener (storage, listener);
+ if (! add_listener (storage, listener))
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_Evolution_Storage_AlreadyListening, NULL);
+}
+
+static void
+impl_Storage_remove_listener (PortableServer_Servant servant,
+ const Evolution_StorageListener listener,
+ CORBA_Environment *ev)
+{
+ BonoboObject *bonobo_object;
+ EvolutionStorage *storage;
+
+ bonobo_object = bonobo_object_from_servant (servant);
+ storage = EVOLUTION_STORAGE (bonobo_object);
+
+ if (! remove_listener (storage, listener))
+ CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_Evolution_Storage_NotFound, NULL);
}
@@ -278,8 +348,9 @@ evolution_storage_get_epv (void)
POA_Evolution_Storage__epv *epv;
epv = g_new0 (POA_Evolution_Storage__epv, 1);
- epv->_get_name = impl_Storage__get_name;
- epv->add_listener = impl_Storage_add_listener;
+ epv->_get_name = impl_Storage__get_name;
+ epv->add_listener = impl_Storage_add_listener;
+ epv->remove_listener = impl_Storage_remove_listener;
return epv;
}