Files
evolution/addressbook/backend/pas/pas-backend.c
Federico Mena Quintero d936a5c38a 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
2000-05-01 04:19:47 +00:00

163 lines
3.6 KiB
C

/*
* Author:
* Nat Friedman (nat@helixcode.com)
*
* Copyright 2000, Helix Code, Inc.
*/
#include <config.h>
#include <gtk/gtkobject.h>
#include <gtk/gtksignal.h>
#include "pas-backend.h"
#define CLASS(o) PAS_BACKEND_CLASS (GTK_OBJECT (o)->klass)
/* Signal IDs */
enum {
LAST_CLIENT_GONE,
LAST_SIGNAL
};
static guint pas_backend_signals[LAST_SIGNAL];
gboolean
pas_backend_construct (PASBackend *backend)
{
return TRUE;
}
gboolean
pas_backend_load_uri (PASBackend *backend,
const char *uri)
{
g_return_val_if_fail (backend != NULL, FALSE);
g_return_val_if_fail (PAS_IS_BACKEND (backend), FALSE);
g_return_val_if_fail (uri != NULL, FALSE);
g_assert (CLASS (backend)->load_uri != NULL);
return (* CLASS (backend)->load_uri) (backend, uri);
}
/**
* pas_backend_get_uri:
* @backend: An addressbook backend.
*
* Queries the URI that an addressbook backend is serving.
*
* Return value: URI for the backend.
**/
const char *
pas_backend_get_uri (PASBackend *backend)
{
g_return_val_if_fail (backend != NULL, NULL);
g_return_val_if_fail (PAS_IS_BACKEND (backend), NULL);
g_assert (CLASS (backend)->get_uri != NULL);
return (* CLASS (backend)->get_uri) (backend);
}
/**
* pas_backend_add_client:
* @backend: An addressbook backend.
* @listener: Listener for notification to the client.
*
* Adds a client to an addressbook backend.
*
* Return value: TRUE on success, FALSE on failure to add the client.
*/
gboolean
pas_backend_add_client (PASBackend *backend,
Evolution_BookListener listener)
{
g_return_val_if_fail (backend != NULL, FALSE);
g_return_val_if_fail (PAS_IS_BACKEND (backend), FALSE);
g_return_val_if_fail (listener != CORBA_OBJECT_NIL, FALSE);
g_assert (CLASS (backend)->add_client != NULL);
return CLASS (backend)->add_client (backend, listener);
}
void
pas_backend_remove_client (PASBackend *backend,
PASBook *book)
{
g_return_if_fail (backend != NULL);
g_return_if_fail (PAS_IS_BACKEND (backend));
g_return_if_fail (book != NULL);
g_return_if_fail (PAS_IS_BOOK (book));
g_assert (CLASS (backend)->remove_client != NULL);
CLASS (backend)->remove_client (backend, book);
}
/**
* pas_backend_last_client_gone:
* @backend: An addressbook backend.
*
* Emits the "last_client_gone" signal for the specified backend. Should
* only be called from backend implementations if the backend really does
* not have any more clients.
**/
void
pas_backend_last_client_gone (PASBackend *backend)
{
g_return_if_fail (backend != NULL);
g_return_if_fail (PAS_IS_BACKEND (backend));
gtk_signal_emit (GTK_OBJECT (backend), pas_backend_signals[LAST_CLIENT_GONE]);
}
static void
pas_backend_init (PASBackend *backend)
{
}
static void
pas_backend_class_init (PASBackendClass *klass)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass *) klass;
pas_backend_signals[LAST_CLIENT_GONE] =
gtk_signal_new ("last_client_gone",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET (PASBackendClass, last_client_gone),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
gtk_object_class_add_signals (object_class, pas_backend_signals, LAST_SIGNAL);
}
/**
* pas_backend_get_type:
*/
GtkType
pas_backend_get_type (void)
{
static GtkType type = 0;
if (! type) {
GtkTypeInfo info = {
"PASBackend",
sizeof (PASBackend),
sizeof (PASBackendClass),
(GtkClassInitFunc) pas_backend_class_init,
(GtkObjectInitFunc) pas_backend_init,
NULL, /* reserved 1 */
NULL, /* reserved 2 */
(GtkClassInitFunc) NULL
};
type = gtk_type_unique (gtk_object_get_type (), &info);
}
return type;
}