From ab4e1534a83c999d2b95327822cd91da3442bcb2 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Thu, 7 Dec 2000 11:28:30 +0000 Subject: [PATCH] Add engine event interface files and stub .c file. guid.[ch]: cleanup git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3259 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Makefile.am | 11 ++++-- src/engine/gnc-event-p.h | 45 ++++++++++++++++++++++ src/engine/gnc-event.c | 26 +++++++++++++ src/engine/gnc-event.h | 81 ++++++++++++++++++++++++++++++++++++++++ src/engine/guid.c | 47 ++++++++++++++--------- src/engine/guid.h | 5 ++- 6 files changed, 191 insertions(+), 24 deletions(-) create mode 100644 src/engine/gnc-event-p.h create mode 100644 src/engine/gnc-event.c create mode 100644 src/engine/gnc-event.h diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index ac17177c2d..9e38f1e610 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -26,9 +26,10 @@ libgncengine_la_SOURCES = \ kvp_frame.c \ gnc-book.c \ gnc-commodity.c \ - gnc-numeric.c \ gnc-engine.c \ - gnc-engine-util.c + gnc-engine-util.c \ + gnc-event.c \ + gnc-numeric.c libgncengine_la_LDFLAGS = -version-info 2:1:1 @@ -57,9 +58,11 @@ noinst_HEADERS = \ kvp_frame.h \ gnc-book.h \ gnc-commodity.h \ - gnc-numeric.h \ gnc-engine.h \ - gnc-engine-util.h + gnc-engine-util.h \ + gnc-event.h \ + gnc-event-p.h \ + gnc-numeric.h EXTRA_DIST = \ .cvsignore \ diff --git a/src/engine/gnc-event-p.h b/src/engine/gnc-event-p.h new file mode 100644 index 0000000000..68e970a8ca --- /dev/null +++ b/src/engine/gnc-event-p.h @@ -0,0 +1,45 @@ +/******************************************************************** + * gnc-event-p.h -- private engine event handling interface * + * Copyright 2000 Dave Peticolas * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * + ********************************************************************/ + +#ifndef __GNC_EVENT_P_H__ +#define __GNC_EVENT_P_H__ + +#include "gnc-event.h" + +/* gnc_engine_generate_event + * Invoke all registered event handlers using the given arguments. + * + * GNC_EVENT_CREATE events should be generated after the object + * has been created and registered in the engine entity table. + * GNC_EVENT_MODIFY events should be generated whenever any data + * member or submember (i.e., splits) is changed. + * GNC_EVENT_DESTROY events should be called before the object + * has been destroyed or removed from the entity table. + * + * entity: the GUID of the entity generating the event + * event_type: the type of event -- this should be one of the + * GNCEngineEventType values, not a combination. + */ +void gnc_engine_generate_event (GUID *entity, GNCEngineEventType event_type); + +#endif diff --git a/src/engine/gnc-event.c b/src/engine/gnc-event.c new file mode 100644 index 0000000000..7ea2390cf5 --- /dev/null +++ b/src/engine/gnc-event.c @@ -0,0 +1,26 @@ +/******************************************************************** + * gnc-event.c -- engine event handling implementation * + * Copyright 2000 Dave Peticolas * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * + ********************************************************************/ + +#include "config.h" + +#include "gnc-event-p.h" diff --git a/src/engine/gnc-event.h b/src/engine/gnc-event.h new file mode 100644 index 0000000000..8db7e95f39 --- /dev/null +++ b/src/engine/gnc-event.h @@ -0,0 +1,81 @@ +/******************************************************************** + * gnc-event.h -- engine event handling interface * + * Copyright 2000 Dave Peticolas * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * + ********************************************************************/ + +#ifndef __GNC_EVENT_H__ +#define __GNC_EVENT_H__ + +#include + +#include "guid.h" + + +typedef enum +{ + GNC_EVENT_CREATE = 1 << 0, + GNC_EVENT_MODIFY = 1 << 1, + GNC_EVENT_DESTROY = 1 << 2 +} GNCEngineEventType; + +/* GNCEngineEventCallback + * Callback invoked when an engine event occurs. + * + * entity: GUID of entity generating event + * event_type: one of GNCEngineEventType, not a combination + * user_data: user_data supplied when callback was registered. + */ +typedef void (*GNCEngineEventHandler) (GUID *entity, + GNCEngineEventType event_type, + gpointer user_data); + +/* gnc_engine_register_event_handler + * Register a handler for engine events. + * + * handler: handler to register + * user_data: data provided in future callbacks + * + * Returns: id identifying callback + */ +gint gnc_engine_register_event_handler (GNCEngineEventHandler handler, + gpointer user_data); + +/* gnc_engine_unregister_event_handler + * Unregister an engine event handler. + * + * handler_id: the id of the handler to unregister + */ +void gnc_engine_unregister_event_handler (gint handler_id); + +/* gnc_engine_suspend_events + * Suspend all engine events. This function may be + * called multiple times. To resume event generation, + * an equal number of calls to gnc_engine_resume_events + * must be made. + */ +void gnc_engine_suspend_events (void); + +/* gnc_engine_resume_events + * Resume engine event generation. + */ +void gnc_engine_resume_events (void); + +#endif diff --git a/src/engine/guid.c b/src/engine/guid.c index 3ef1cf6177..9ecdcb2060 100644 --- a/src/engine/guid.c +++ b/src/engine/guid.c @@ -455,28 +455,38 @@ guid_equal(const GUID *guid_1, const GUID *guid_2) } gint -guid_compare(const GUID *guid_1, const GUID *guid_2) { - if(guid_1 == guid_2) return 0; - /* nothing is always less than something */ - if(!guid_1 && guid_2) return -1; - if(guid_1 && !guid_2) return 1; +guid_compare(const GUID *guid_1, const GUID *guid_2) +{ + if (guid_1 == guid_2) + return 0; - return(memcmp(guid_1, guid_2, sizeof(GUID))); + /* nothing is always less than something */ + if (!guid_1 && guid_2) + return -1; + + if (guid_1 && !guid_2) + return 1; + + return memcmp (guid_1, guid_2, sizeof (GUID)); } guint -guid_hash_to_guint(gconstpointer ptr) +guid_hash_to_guint (gconstpointer ptr) { - GUID *guid = (GUID *) ptr; + const GUID *guid = ptr; - if(!guid) { + if (!guid) + { fprintf(stderr, "guid_g_hash_table_hash: received NULL guid pointer."); - return(0); + return 0; } - if (sizeof(guint) <= sizeof(guid->data)) { - return(*((guint *) guid->data)); - } else { + if (sizeof(guint) <= sizeof(guid->data)) + { + return (*((guint *) guid->data)); + } + else + { guint hash = 0; int i, j; @@ -487,17 +497,18 @@ guid_hash_to_guint(gconstpointer ptr) hash |= guid->data[j]; } - return(hash); + return hash; } } static gint -guid_g_hash_table_equal(gconstpointer guid_a, gconstpointer guid_b) +guid_g_hash_table_equal (gconstpointer guid_a, gconstpointer guid_b) { - return((gint) guid_equal((GUID *) guid_a, (GUID *) guid_b)); + return guid_equal (guid_a, guid_b); } GHashTable * -guid_hash_table_new() { - return(g_hash_table_new(guid_hash_to_guint, guid_g_hash_table_equal)); +guid_hash_table_new (void) +{ + return g_hash_table_new (guid_hash_to_guint, guid_g_hash_table_equal); } diff --git a/src/engine/guid.h b/src/engine/guid.h index 69cea03e85..37cff17c9e 100644 --- a/src/engine/guid.h +++ b/src/engine/guid.h @@ -25,9 +25,10 @@ #define __GUID_H__ #ifdef HAVE_CONFIG_H -# include +# include "config.h" #endif +#include #include /* This file defines an API for using globally unique identifiers. */ @@ -96,6 +97,6 @@ gint guid_compare(const GUID *g1, const GUID *g2); /* Given a GUID *, hash it to a guint */ guint guid_hash_to_guint(gconstpointer ptr); -GHashTable *guid_hash_table_new(); +GHashTable *guid_hash_table_new(void); #endif