diff options
author | Christopher James Lahey <clahey@helixcode.com> | 2000-03-28 11:52:46 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2000-03-28 11:52:46 +0800 |
commit | 21e60e238477edd1ad157bd17024d5ea6395e048 (patch) | |
tree | 4f251e318f085aecc387c49f052a14f7874c1a1a /addressbook/backend/pas | |
parent | bd46ea2926e3f244d6d875195363d261f53a4e07 (diff) | |
download | gsoc2013-evolution-21e60e238477edd1ad157bd17024d5ea6395e048.tar.gz gsoc2013-evolution-21e60e238477edd1ad157bd17024d5ea6395e048.tar.zst gsoc2013-evolution-21e60e238477edd1ad157bd17024d5ea6395e048.zip |
Fixed some warnings.
2000-03-27 Christopher James Lahey <clahey@helixcode.com>
* addressbook/backend/ebook/test-card.c: Fixed some warnings.
* addressbook/backend/ebook/test-client.c: Added a section to test
cursors and returning an id when adding.
* addressbook/backend/ebook/e-card-pairs.h: Removed the address
pairs since they were added to e-card.c.
* addressbook/backend/ebook/e-card.c,
addressbook/backend/ebook/e-card.h: Made the set_id function take
a const char *.
* addressbook/backend/ebook/e-book-listener.c,
addressbook/backend/ebook/e-book-listener.h,
addressbook/backend/ebook/e-book.c,
addressbook/backend/ebook/e-book.h,
addressbook/backend/idl/addressbook.idl,
addressbook/backend/pas/pas-backend-file.c,
addressbook/backend/pas/pas-book.c,
addressbook/backend/pas/pas-book.h: Added a get_all_cards function
and made the response to the create_card function include the card
id.
* addressbook/backend/ebook/Makefile.am: Added e-card-cursor.c and
e-card-cursor.h.
* addressbook/backend/ebook/e-card-cursor.c,
addressbook/backend/ebook/e-card-cursor.h: New class for proxying
to an Evolution_CardCursor.
* addressbook/backend/pas/Makefile.am: Added pas-card-cursor.c and
pas-card-cursor.h.
* addressbook/backend/pas/pas-card-cursor.c,
addressbook/backend/pas/pas-card-cursor.h: New bonobo class for
making an Evolution_CardCursor server.
svn path=/trunk/; revision=2205
Diffstat (limited to 'addressbook/backend/pas')
-rw-r--r-- | addressbook/backend/pas/Makefile.am | 6 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 106 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book.c | 53 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book.h | 9 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-card-cursor.c | 224 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-card-cursor.h | 58 |
6 files changed, 449 insertions, 7 deletions
diff --git a/addressbook/backend/pas/Makefile.am b/addressbook/backend/pas/Makefile.am index 36eeab0782..20b2d85531 100644 --- a/addressbook/backend/pas/Makefile.am +++ b/addressbook/backend/pas/Makefile.am @@ -43,7 +43,8 @@ libpas_la_SOURCES = \ pas-book.c \ pas-book-factory.c \ pas-backend.c \ - pas-backend-file.c + pas-backend-file.c \ + pas-card-cursor.c libpasincludedir = $(includedir)/backend @@ -51,7 +52,8 @@ libpasinclude_HEADERS = \ pas-book.h \ pas-book-factory.h \ pas-backend.h \ - pas-backend-file.h + pas-backend-file.h \ + pas-card-cursor.h wombat_SOURCES = \ pas.c diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index bf5ef55c2f..04f59d40f8 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -17,11 +17,13 @@ #include <pas-backend-file.h> #include <pas-book.h> +#include <pas-card-cursor.h> #define PAS_BACKEND_FILE_VERSION_NAME "PAS-DB-VERSION" #define PAS_BACKEND_FILE_VERSION "0.1" static PASBackendClass *pas_backend_file_parent_class; +typedef struct _PASBackendFileCursorPrivate PASBackendFileCursorPrivate; struct _PASBackendFilePrivate { GList *clients; @@ -29,6 +31,52 @@ struct _PASBackendFilePrivate { DB *file_db; }; +struct _PASBackendFileCursorPrivate { + PASBackend *backend; + PASBook *book; +}; + +static long +get_length(PASCardCursor *cursor, gpointer data) +{ +#if 0 + PASBackendFileCursorPrivate *cursor_data = (PASBackendFileCursorPrivate *) data; +#endif + return 0; +} + +static char * +get_nth(PASCardCursor *cursor, long n, gpointer data) +{ +#if 0 + PASBackendFileCursorPrivate *cursor_data = (PASBackendFileCursorPrivate *) data; +#endif + return ""; +} + +static void +cursor_destroy(GtkObject *object, gpointer data) +{ + CORBA_Environment ev; + Evolution_Book corba_book; + PASBackendFileCursorPrivate *cursor_data = (PASBackendFileCursorPrivate *) data; + + corba_book = bonobo_object_corba_objref(cursor_data->book); + + CORBA_exception_init(&ev); + + Evolution_Book_unref(corba_book, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning("cursor_destroy: Exception unreffing " + "corba book.\n"); + } + + CORBA_exception_free(&ev); + + g_free(cursor_data); +} + static void string_to_dbt(const char *str, DBT *dbt) { @@ -65,7 +113,8 @@ pas_backend_file_process_create_card (PASBackend *backend, pas_book_respond_create ( book, - Evolution_BookListener_Success); + Evolution_BookListener_Success, + id); db_error = db->sync (db, 0); if (db_error != 0) @@ -76,7 +125,8 @@ pas_backend_file_process_create_card (PASBackend *backend, think */ pas_book_respond_create ( book, - Evolution_BookListener_CardNotFound); + Evolution_BookListener_CardNotFound, + ""); } g_free (id); @@ -154,6 +204,54 @@ pas_backend_file_process_modify_card (PASBackend *backend, } static void +pas_backend_file_process_get_all_cards (PASBackend *backend, + PASBook *book, + PASRequest *req) +{ + /* + PASBackendFile *bf = PAS_BACKEND_FILE (backend); + DB *db = bf->priv->file_db; + DBT id_dbt, vcard_dbt; + */ + CORBA_Environment ev; + int db_error = 0; + PASBackendFileCursorPrivate *cursor_data; + PASCardCursor *cursor; + Evolution_Book corba_book; + + cursor_data = g_new(PASBackendFileCursorPrivate, 1); + cursor_data->backend = backend; + cursor_data->book = book; + + corba_book = bonobo_object_corba_objref(book); + + CORBA_exception_init(&ev); + + Evolution_Book_ref(corba_book, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning("pas_backend_file_process_get_all_cards: Exception reffing " + "corba book.\n"); + } + + CORBA_exception_free(&ev); + + cursor = pas_card_cursor_new(get_length, + get_nth, + cursor_data); + + gtk_signal_connect(GTK_OBJECT(cursor), "destroy", + GTK_SIGNAL_FUNC(cursor_destroy), cursor_data); + + pas_book_respond_get_cursor ( + book, + (db_error == 0 + ? Evolution_BookListener_Success + : Evolution_BookListener_CardNotFound), + cursor); +} + +static void pas_backend_file_process_check_connection (PASBackend *backend, PASBook *book, PASRequest *req) @@ -191,6 +289,10 @@ pas_backend_file_process_client_requests (PASBook *book) case CheckConnection: pas_backend_file_process_check_connection (backend, book, req); break; + + case GetAllCards: + pas_backend_file_process_get_all_cards (backend, book, req); + break; } g_free (req); diff --git a/addressbook/backend/pas/pas-book.c b/addressbook/backend/pas/pas-book.c index 907ff6482a..f571bc4044 100644 --- a/addressbook/backend/pas/pas-book.c +++ b/addressbook/backend/pas/pas-book.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * pas-book.c * @@ -90,6 +91,17 @@ pas_book_queue_modify_card (PASBook *book, const char *vcard) } static void +pas_book_queue_get_all_cards (PASBook *book) +{ + PASRequest *req; + + req = g_new0 (PASRequest, 1); + req->op = GetAllCards; + + pas_book_queue_request (book, req); +} + +static void pas_book_queue_check_connection (PASBook *book) { PASRequest *req; @@ -147,6 +159,15 @@ impl_Evolution_Book_modify_card (PortableServer_Servant servant, } static void +impl_Evolution_Book_get_all_cards (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); + + pas_book_queue_get_all_cards (book); +} + +static void impl_Evolution_Book_check_connection (PortableServer_Servant servant, CORBA_Environment *ev) { @@ -253,14 +274,15 @@ pas_book_respond_open (PASBook *book, */ void pas_book_respond_create (PASBook *book, - Evolution_BookListener_CallStatus status) + Evolution_BookListener_CallStatus status, + const char *id) { CORBA_Environment ev; CORBA_exception_init (&ev); Evolution_BookListener_respond_create_card ( - book->priv->listener, status, &ev); + book->priv->listener, status, (char *)id, &ev); if (ev._major != CORBA_NO_EXCEPTION) { g_warning ("pas_book_respond_create: Exception " @@ -315,6 +337,32 @@ pas_book_respond_modify (PASBook *book, } /** + * pas_book_respond_get_cursor: + */ +void +pas_book_respond_get_cursor (PASBook *book, + Evolution_BookListener_CallStatus status, + PASCardCursor *cursor) +{ + CORBA_Environment ev; + CORBA_Object object; + + CORBA_exception_init (&ev); + + object = bonobo_object_corba_objref(BONOBO_OBJECT(cursor)); + + Evolution_BookListener_respond_get_cursor ( + book->priv->listener, status, object, &ev); + + if (ev._major != CORBA_NO_EXCEPTION) { + g_warning ("pas_book_respond_get_cursor: Exception " + "responding to BookListener!\n"); + } + + CORBA_exception_free (&ev); +} + +/** * pas_book_report_connection: */ void @@ -502,6 +550,7 @@ pas_book_get_epv (void) epv->remove_card = impl_Evolution_Book_remove_card; epv->modify_card = impl_Evolution_Book_modify_card; epv->check_connection = impl_Evolution_Book_check_connection; + epv->get_all_cards = impl_Evolution_Book_get_all_cards; return epv; diff --git a/addressbook/backend/pas/pas-book.h b/addressbook/backend/pas/pas-book.h index c4763d1654..ab0dced4e4 100644 --- a/addressbook/backend/pas/pas-book.h +++ b/addressbook/backend/pas/pas-book.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * A wrapper object which exports the Evolution_Book CORBA interface * and which maintains a request queue. @@ -19,11 +20,13 @@ typedef struct _PASBook PASBook; typedef struct _PASBookPrivate PASBookPrivate; #include <pas-backend.h> +#include <pas-card-cursor.h> typedef enum { CreateCard, RemoveCard, ModifyCard, + GetAllCards, CheckConnection } PASOperation; @@ -58,11 +61,15 @@ PASRequest *pas_book_pop_request (PASBook void pas_book_respond_open (PASBook *book, Evolution_BookListener_CallStatus status); void pas_book_respond_create (PASBook *book, - Evolution_BookListener_CallStatus status); + Evolution_BookListener_CallStatus status, + const char *id); void pas_book_respond_remove (PASBook *book, Evolution_BookListener_CallStatus status); void pas_book_respond_modify (PASBook *book, Evolution_BookListener_CallStatus status); +void pas_book_respond_get_cursor (PASBook *book, + Evolution_BookListener_CallStatus status, + PASCardCursor *cursor); void pas_book_report_connection (PASBook *book, gboolean connected); diff --git a/addressbook/backend/pas/pas-card-cursor.c b/addressbook/backend/pas/pas-card-cursor.c new file mode 100644 index 0000000000..b6ef91f41c --- /dev/null +++ b/addressbook/backend/pas/pas-card-cursor.c @@ -0,0 +1,224 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * pas-card-cursor.c: Implements card cursors. + * + * Author: + * Christopher James Lahey <clahey@helixcode.com. + */ + +#include <config.h> +#include <bonobo.h> +#include "addressbook.h" +#include "pas-card-cursor.h" + +struct _PASCardCursorPrivate { + long (*get_length) (PASCardCursor *cursor, gpointer data); + char * (*get_nth) (PASCardCursor *cursor, long n, gpointer data); + gpointer data; +}; + +/* + * A pointer to our parent object class + */ +static BonoboObjectClass *parent_class; + +/* + * The VEPV for the CardCursor object + */ +static POA_Evolution_CardCursor__vepv cursor_vepv; + +/* + * Implemented GtkObject::destroy + */ +static void +pas_card_cursor_destroy (GtkObject *object) +{ + PASCardCursor *cursor = PAS_CARD_CURSOR (object); + + if ( cursor->priv ) + g_free ( cursor->priv ); + + GTK_OBJECT_CLASS (parent_class)->destroy (object); +} + +/* + * CORBA Demo::Echo::echo method implementation + */ +static CORBA_long +impl_pas_card_cursor_get_length (PortableServer_Servant servant, + CORBA_Environment *ev) +{ + PASCardCursor *cursor = PAS_CARD_CURSOR (bonobo_object_from_servant (servant)); + if ( cursor->priv->get_length ) + return cursor->priv->get_length( cursor, cursor->priv->data ); + else + return 0; +} + +/* + * CORBA Demo::Echo::echo method implementation + */ +static char * +impl_pas_card_cursor_get_nth (PortableServer_Servant servant, + const CORBA_long n, + CORBA_Environment *ev) +{ + PASCardCursor *cursor = PAS_CARD_CURSOR (bonobo_object_from_servant (servant)); + if ( cursor->priv->get_nth ) + return cursor->priv->get_nth( cursor, n, cursor->priv->data ); + else + return ""; +} + +/* + * If you want users to derive classes from your implementation + * you need to support this method. + */ +POA_Evolution_CardCursor__epv * +pas_card_cursor_get_epv (void) +{ + POA_Evolution_CardCursor__epv *epv; + + epv = g_new0 (POA_Evolution_CardCursor__epv, 1); + + /* + * This is the method invoked by CORBA + */ + epv->get_length = impl_pas_card_cursor_get_length; + epv->get_nth = impl_pas_card_cursor_get_nth; + + return epv; +} + +static void +init_pas_card_cursor_corba_class (void) +{ + cursor_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); + cursor_vepv.Evolution_CardCursor_epv = pas_card_cursor_get_epv (); +} + +static void +pas_card_cursor_class_init (PASCardCursorClass *klass) +{ + GtkObjectClass *object_class = (GtkObjectClass *) klass; + + parent_class = gtk_type_class (bonobo_object_get_type ()); + + object_class->destroy = pas_card_cursor_destroy; + + init_pas_card_cursor_corba_class (); +} + +static void +pas_card_cursor_init (PASCardCursor *cursor) +{ + cursor->priv = g_new(PASCardCursorPrivate, 1); + cursor->priv->get_length = NULL; + cursor->priv->get_nth = NULL; + cursor->priv->data = NULL; +} + +GtkType +pas_card_cursor_get_type (void) +{ + static GtkType type = 0; + + if (!type){ + GtkTypeInfo info = { + "PASCardCursor", + sizeof (PASCardCursor), + sizeof (PASCardCursorClass), + (GtkClassInitFunc) pas_card_cursor_class_init, + (GtkObjectInitFunc) pas_card_cursor_init, + NULL, /* reserved 1 */ + NULL, /* reserved 2 */ + (GtkClassInitFunc) NULL + }; + + type = gtk_type_unique (bonobo_object_get_type (), &info); + } + + return type; +} + +PASCardCursor * +pas_card_cursor_construct (PASCardCursor *cursor, + Evolution_CardCursor corba_cursor, + PASCardCursorLengthFunc get_length, + PASCardCursorNthFunc get_nth, + gpointer data) +{ + g_return_val_if_fail (cursor != NULL, NULL); + g_return_val_if_fail (PAS_IS_CARD_CURSOR (cursor), NULL); + g_return_val_if_fail (corba_cursor != CORBA_OBJECT_NIL, NULL); + + /* + * Call parent constructor + */ + if (!bonobo_object_construct (BONOBO_OBJECT (cursor), (CORBA_Object) corba_cursor)) + return NULL; + + /* + * Initialize cursor + */ + cursor->priv->get_length = get_length; + cursor->priv->get_nth = get_nth; + cursor->priv->data = data; + + /* + * Success: return the GtkType we were given + */ + return cursor; +} + +/* + * This routine creates the ORBit CORBA server and initializes the + * CORBA side of things + */ +static Evolution_CardCursor +create_cursor (BonoboObject *cursor) +{ + POA_Evolution_CardCursor *servant; + CORBA_Environment ev; + + servant = (POA_Evolution_CardCursor *) g_new (BonoboObjectServant, 1); + servant->vepv = &cursor_vepv; + + CORBA_exception_init (&ev); + POA_Evolution_CardCursor__init ((PortableServer_Servant) servant, &ev); + if (ev._major != CORBA_NO_EXCEPTION){ + g_free (servant); + CORBA_exception_free (&ev); + return CORBA_OBJECT_NIL; + } + + CORBA_exception_free (&ev); + + /* + * Activates the CORBA object. + */ + return (Evolution_CardCursor) bonobo_object_activate_servant (cursor, servant); +} + +PASCardCursor * +pas_card_cursor_new (PASCardCursorLengthFunc get_length, + PASCardCursorNthFunc get_nth, + gpointer data) +{ + PASCardCursor *cursor; + Evolution_CardCursor corba_cursor; + + cursor = gtk_type_new (pas_card_cursor_get_type ()); + corba_cursor = create_cursor (BONOBO_OBJECT (cursor)); + + if (corba_cursor == CORBA_OBJECT_NIL){ + gtk_object_destroy (GTK_OBJECT (cursor)); + return NULL; + } + + return pas_card_cursor_construct (cursor, + corba_cursor, + get_length, + get_nth, + data); +} diff --git a/addressbook/backend/pas/pas-card-cursor.h b/addressbook/backend/pas/pas-card-cursor.h new file mode 100644 index 0000000000..a829d2c838 --- /dev/null +++ b/addressbook/backend/pas/pas-card-cursor.h @@ -0,0 +1,58 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * + * Author: + * Nat Friedman (nat@helixcode.com) + * + * Copyright 2000, Helix Code, Inc. + */ + +#ifndef __PAS_CARD_CURSOR_H__ +#define __PAS_CARD_CURSOR_H__ + +#include <libgnome/gnome-defs.h> +#include <bonobo/bonobo-object.h> +#include "addressbook.h" + +BEGIN_GNOME_DECLS + +typedef struct _PASCardCursor PASCardCursor; +typedef struct _PASCardCursorPrivate PASCardCursorPrivate; +typedef struct _PASCardCursorClass PASCardCursorClass; + +typedef long (*PASCardCursorLengthFunc) (PASCardCursor *cursor, gpointer data); +typedef char * (*PASCardCursorNthFunc) (PASCardCursor *cursor, long n, gpointer data); + +struct _PASCardCursor { + BonoboObject parent; + PASCardCursorPrivate *priv; +}; + +struct _PASCardCursorClass { + BonoboObjectClass parent; +}; + +/* Creating a new addressbook. */ +PASCardCursor *pas_card_cursor_new (PASCardCursorLengthFunc get_length, + PASCardCursorNthFunc get_nth, + gpointer data); +PASCardCursor *pas_card_cursor_construct (PASCardCursor *cursor, + Evolution_CardCursor corba_cursor, + PASCardCursorLengthFunc get_length, + PASCardCursorNthFunc get_nth, + gpointer data); + +GtkType pas_card_cursor_get_type (void); +POA_Evolution_CardCursor__epv * + pas_card_cursor_get_epv (void); + +/* Fetching cards. */ +#define PAS_CARD_CURSOR_TYPE (pas_card_cursor_get_type ()) +#define PAS_CARD_CURSOR(o) (GTK_CHECK_CAST ((o), PAS_CARD_CURSOR_TYPE, PASCardCursor)) +#define PAS_CARD_CURSOR_CLASS(k) (GTK_CHECK_CLASS_CAST((k), PAS_CARD_CURSOR_TYPE, PASCardCursorClass)) +#define PAS_IS_CARD_CURSOR(o) (GTK_CHECK_TYPE ((o), PAS_CARD_CURSOR_TYPE)) +#define PAS_IS_CARD_CURSOR_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), PAS_CARD_CURSOR_TYPE)) + +END_GNOME_DECLS + +#endif /* ! __PAS_CARD_CURSOR_H__ */ |