diff options
author | Federico Mena Quintero <federico@helixcode.com> | 2000-05-01 12:19:47 +0800 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2000-05-01 12:19:47 +0800 |
commit | d936a5c38a6125548ec44eac981a26d42ce72413 (patch) | |
tree | 3b8b7793b3d25ab602d8e2d5c78b6a9dd68cb70b /addressbook/backend/pas/pas-backend-file.c | |
parent | eb5dc08dc91a593357a6c1b1db98fac8cdb1662e (diff) | |
download | gsoc2013-evolution-d936a5c38a6125548ec44eac981a26d42ce72413.tar gsoc2013-evolution-d936a5c38a6125548ec44eac981a26d42ce72413.tar.gz gsoc2013-evolution-d936a5c38a6125548ec44eac981a26d42ce72413.tar.bz2 gsoc2013-evolution-d936a5c38a6125548ec44eac981a26d42ce72413.tar.lz gsoc2013-evolution-d936a5c38a6125548ec44eac981a26d42ce72413.tar.xz gsoc2013-evolution-d936a5c38a6125548ec44eac981a26d42ce72413.tar.zst gsoc2013-evolution-d936a5c38a6125548ec44eac981a26d42ce72413.zip |
Added new status values for the IDL stuff.
2000-04-30 Federico Mena Quintero <federico@helixcode.com>
* backend/ebook/e-book-types.h (EBookStatus): Added new status
values for the IDL stuff.
* backend/pas/pas-book-factory.h (PASBookFactoryClass): New
"last_book_gone" signal.
* backend/pas/pas-book-factory.c
(pas_book_factory_launch_backend): Better error handling.
(pas_book_factory_process_queue): Let
pas_book_factory_process_request() free the request.
(pas_book_factory_process_request): Free the request here.
Perform better error handling.
(free_active_server_map_entry): Free an active server map entry;
free the URI key and unref the backend value. This function was
renamed; the old one was trying to CORBA_Object_unref() a GTK+
object!
(remove_backends_entry): Free a backend table entry; free the URI
key.
(backend_last_client_gone_cb): Remove the backend from the active
server map and emit the "last_book_gone" signal if appropriate.
(pas_book_factory_get_n_backends): New function to query the
number of running backends in an addressbook factory.
* backend/idl/addressbook.idl (BookListener::CallStatus): Added a
ProtocolNotSupported code. This is for when the addressbook
factory cannot find a provider for the requested URI.
* backend/pas/pas-backend.h (PASBackendClass): New
"last_client_gone" signal.
(PASBackendClass): New get_uri virtual method.
* backend/pas/pas-backend.c (pas_backend_load_uri): Return a
gboolean success code.
(pas_backend_add_client): Return a gboolean success code.
(pas_backend_last_client_gone): New function used by backend
implementations to notify upwards when the backend's last client
is destroyed.
(pas_backend_get_uri): New function to get the URI of a backend.
* backend/pas/pas-backend-file.c (pas_backend_file_add_client):
Pass the backend as the closure data to the "destroy" handler of
the book. We cannot call pas_book_get_backend() in the callback
since the book's private data has already been destroyed when the
callback is invoked. Alternatively, we could move the private
data destruction step to the book's ::finalize() method.
(pas_backend_file_book_destroy_cb): Get the backend from the
callback's data, not from the book.
(pas_backend_file_remove_client): Remove the book from the list of
clients. When all clients go away, call
pas_backend_last_client_gone().
(PASBackendFilePrivate): Added an uri field.
(pas_backend_file_get_uri): Implement the get_uri method.
(pas_backend_file_load_uri): Return a gboolean success code.
Also, store the URI in the private structure.
(pas_backend_file_add_client): Return a gboolean success code.
Also, call pas_backend_last_client_gone() if appropriate.
(pas_backend_file_destroy): Free the bf->priv->uri.
* backend/pas/pas-backend-ldap.c (pas_backend_ldap_add_client):
Pass the backend as the closure data to the "destroy" handler of
the book. See above for rationale.
(pas_backend_ldap_book_destroy_cb): Get the backend from the
callback's data.
(pas_backend_ldap_remove_client): Remove the book from the list of
clients. When all clients go away, call
pas_backend_last_client_gone().
(pas_backend_ldap_load_uri): Return a gboolean success code.
(pas_backend_ldap_add_client): Return a gboolean success code.
Also, call pas_backend_last_client_gone() if appropriate.
(PASBackendLDAPPrivate): New uri field.
(pas_backend_ldap_get_uri): Implement the get_uri method.
(pas_backend_ldap_load_uri): Store the uri in the private
structure.
(pas_backend_ldap_destroy): Free the bl->priv->uri.
svn path=/trunk/; revision=2705
Diffstat (limited to 'addressbook/backend/pas/pas-backend-file.c')
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 93 |
1 files changed, 82 insertions, 11 deletions
diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index 20de42808c..e2ca9a7348 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -33,6 +33,7 @@ typedef struct _PASBackendFileSearchContext PASBackendFileSearchContext; struct _PASBackendFilePrivate { GList *clients; gboolean loaded; + char *uri; DB *file_db; GList *book_views; }; @@ -825,11 +826,11 @@ pas_backend_file_process_client_requests (PASBook *book) } static void -pas_backend_file_book_destroy_cb (PASBook *book) +pas_backend_file_book_destroy_cb (PASBook *book, gpointer data) { PASBackendFile *backend; - backend = PAS_BACKEND_FILE (pas_book_get_backend (book)); + backend = PAS_BACKEND_FILE (data); pas_backend_remove_client (PAS_BACKEND (backend), book); } @@ -924,7 +925,7 @@ pas_backend_file_maybe_upgrade_db (PASBackendFile *bf) return ret_val; } -static void +static gboolean pas_backend_file_load_uri (PASBackend *backend, const char *uri) { @@ -937,18 +938,45 @@ pas_backend_file_load_uri (PASBackend *backend, bf->priv->file_db = dbopen (filename, O_RDWR | O_CREAT, 0666, DB_HASH, NULL); + g_free (filename); + if (bf->priv->file_db != NULL) { if (pas_backend_file_maybe_upgrade_db (bf)) bf->priv->loaded = TRUE; /* XXX what if we fail to upgrade it? */ + + bf->priv->uri = g_strdup (uri); + } else { + GList *l; + + for (l = bf->priv->clients; l; l = l->next) { + PASBook *book; + + book = PAS_BOOK (l->data); + pas_book_respond_open (book, Evolution_BookListener_OtherError); + } + + return FALSE; } - else - g_warning ("pas_backend_file_load_uri failed for '%s'\n", filename); - g_free (filename); + return TRUE; } -static void +/* Get_uri handler for the addressbook file backend */ +static const char * +pas_backend_file_get_uri (PASBackend *backend) +{ + PASBackendFile *bf; + + bf = PAS_BACKEND_FILE (backend); + + g_return_val_if_fail (bf->priv->loaded, NULL); + g_assert (bf->priv->uri != NULL); + + return bf->priv->uri; +} + +static gboolean pas_backend_file_add_client (PASBackend *backend, Evolution_BookListener listener) { @@ -964,10 +992,15 @@ pas_backend_file_add_client (PASBackend *backend, backend, listener, pas_backend_file_get_vcard); - g_assert (book != NULL); + if (!book) { + if (!bf->priv->clients) + pas_backend_last_client_gone (backend); + + return FALSE; + } gtk_signal_connect (GTK_OBJECT (book), "destroy", - pas_backend_file_book_destroy_cb, NULL); + pas_backend_file_book_destroy_cb, backend); gtk_signal_connect (GTK_OBJECT (book), "requests_queued", pas_backend_file_process_client_requests, NULL); @@ -983,18 +1016,46 @@ pas_backend_file_add_client (PASBackend *backend, pas_book_respond_open ( book, Evolution_BookListener_Success); } + + return TRUE; } static void pas_backend_file_remove_client (PASBackend *backend, PASBook *book) { + PASBackendFile *bf; + GList *l; + PASBook *lbook; + g_return_if_fail (backend != NULL); - g_return_if_fail (PAS_IS_BACKEND (backend)); + g_return_if_fail (PAS_IS_BACKEND_FILE (backend)); g_return_if_fail (book != NULL); g_return_if_fail (PAS_IS_BOOK (book)); - g_warning ("pas_backend_file_remove_client: Unimplemented!\n"); + bf = PAS_BACKEND_FILE (backend); + + /* Find the book in the list of clients */ + + for (l = bf->priv->clients; l; l = l->next) { + lbook = PAS_BOOK (l->data); + + if (lbook == book) + break; + } + + g_assert (l != NULL); + + /* Disconnect */ + + bf->priv->clients = g_list_remove_link (bf->priv->clients, l); + g_list_free_1 (l); + + /* When all clients go away, notify the parent factory about it so that + * it may decide whether to kill the backend or not. + */ + if (!bf->priv->clients) + pas_backend_last_client_gone (backend); } static gboolean @@ -1031,6 +1092,15 @@ pas_backend_file_new (void) static void pas_backend_file_destroy (GtkObject *object) { + PASBackendFile *bf; + + bf = PAS_BACKEND_FILE (object); + + if (bf->priv->uri) { + g_free (bf->priv->uri); + bf->priv->uri = NULL; + } + GTK_OBJECT_CLASS (pas_backend_file_parent_class)->destroy (object); } @@ -1046,6 +1116,7 @@ pas_backend_file_class_init (PASBackendFileClass *klass) /* Set the virtual methods. */ parent_class->load_uri = pas_backend_file_load_uri; + parent_class->get_uri = pas_backend_file_get_uri; parent_class->add_client = pas_backend_file_add_client; parent_class->remove_client = pas_backend_file_remove_client; |