mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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
This commit is contained in:
parent
522f3e20cb
commit
ab4e1534a8
@ -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 \
|
||||
|
45
src/engine/gnc-event-p.h
Normal file
45
src/engine/gnc-event-p.h
Normal file
@ -0,0 +1,45 @@
|
||||
/********************************************************************
|
||||
* gnc-event-p.h -- private engine event handling interface *
|
||||
* Copyright 2000 Dave Peticolas <dave@krondo.com> *
|
||||
* *
|
||||
* 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
|
26
src/engine/gnc-event.c
Normal file
26
src/engine/gnc-event.c
Normal file
@ -0,0 +1,26 @@
|
||||
/********************************************************************
|
||||
* gnc-event.c -- engine event handling implementation *
|
||||
* Copyright 2000 Dave Peticolas <dave@krondo.com> *
|
||||
* *
|
||||
* 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"
|
81
src/engine/gnc-event.h
Normal file
81
src/engine/gnc-event.h
Normal file
@ -0,0 +1,81 @@
|
||||
/********************************************************************
|
||||
* gnc-event.h -- engine event handling interface *
|
||||
* Copyright 2000 Dave Peticolas <dave@krondo.com> *
|
||||
* *
|
||||
* 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 <glib.h>
|
||||
|
||||
#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
|
@ -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);
|
||||
}
|
||||
|
@ -25,9 +25,10 @@
|
||||
#define __GUID_H__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <glib.h>
|
||||
|
||||
/* 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
|
||||
|
Loading…
Reference in New Issue
Block a user