Skip to content

Commit

Permalink
gnc-hooks - factor out scm calls into a separate source file
Browse files Browse the repository at this point in the history
This required the addition of an extra parameter to gnc_hook_add_dangler
to allow the scm hooks to unprotect the scm data on hook destruction.
  • Loading branch information
gjanssens committed Dec 6, 2019
1 parent 49bf27f commit b1ba16c
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 107 deletions.
4 changes: 2 additions & 2 deletions gnucash/gnome-utils/gnc-main-window.c
Expand Up @@ -2542,9 +2542,9 @@ gnc_main_window_class_init (GncMainWindowClass *klass)
NULL);

gnc_hook_add_dangler(HOOK_BOOK_SAVED,
(GFunc)gnc_main_window_update_all_titles, NULL);
(GFunc)gnc_main_window_update_all_titles, NULL, NULL);
gnc_hook_add_dangler(HOOK_BOOK_OPENED,
(GFunc)gnc_main_window_attach_to_book, NULL);
(GFunc)gnc_main_window_attach_to_book, NULL, NULL);

}

Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome-utils/gnc-plugin-manager.c
Expand Up @@ -67,7 +67,7 @@ gnc_plugin_manager_get (void)
singleton = g_object_new (GNC_TYPE_PLUGIN_MANAGER,
NULL);
gnc_hook_add_dangler (HOOK_SHUTDOWN,
gnc_plugin_manager_shutdown, NULL);
gnc_plugin_manager_shutdown, NULL, NULL);
}

return singleton;
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome-utils/gnc-tree-view-account.c
Expand Up @@ -138,7 +138,7 @@ gnc_tree_view_account_class_init (GncTreeViewAccountClass *klass)
o_class->finalize = gnc_tree_view_account_finalize;

gnc_hook_add_dangler(HOOK_CURRENCY_CHANGED,
(GFunc)gtva_currency_changed_cb, NULL);
(GFunc)gtva_currency_changed_cb, NULL, NULL);
}

/********************************************************************\
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome-utils/gnc-tree-view-owner.c
Expand Up @@ -110,7 +110,7 @@ gnc_tree_view_owner_class_init (GncTreeViewOwnerClass *klass)
o_class->finalize = gnc_tree_view_owner_finalize;

gnc_hook_add_dangler(HOOK_CURRENCY_CHANGED,
(GFunc)gtvo_currency_changed_cb, NULL);
(GFunc)gtvo_currency_changed_cb, NULL, NULL);
}

/********************************************************************\
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome/assistant-hierarchy.c
Expand Up @@ -1366,5 +1366,5 @@ void
gnc_ui_hierarchy_assistant_initialize (void)
{
gnc_hook_add_dangler(HOOK_NEW_BOOK,
(GFunc)gnc_ui_hierarchy_assistant_hook, NULL);
(GFunc)gnc_ui_hierarchy_assistant_hook, NULL, NULL);
}
2 changes: 1 addition & 1 deletion gnucash/gnome/dialog-sx-editor.c
Expand Up @@ -1822,7 +1822,7 @@ gnc_ui_sx_initialize (void)
_sx_engine_event_handler_id = qof_event_register_handler(_sx_engine_event_handler, NULL);

gnc_hook_add_dangler(HOOK_BOOK_OPENED,
(GFunc)gnc_sx_sxsincelast_book_opened, NULL);
(GFunc)gnc_sx_sxsincelast_book_opened, NULL, NULL);

/* Add page to preferences page for Scheduled Transactions */
/* The parameters are; glade file, items to add from glade file - last being the dialog, preference tab name */
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome/dialog-sx-editor2.c
Expand Up @@ -1771,7 +1771,7 @@ gnc_ui_sx_initialize2 (void) //FIXME need to remove the 2 when live
_sx_engine_event_handler_id = qof_event_register_handler (_sx_engine_event_handler, NULL);

gnc_hook_add_dangler (HOOK_BOOK_OPENED,
(GFunc)gnc_sx_sxsincelast_book_opened, NULL);
(GFunc)gnc_sx_sxsincelast_book_opened, NULL, NULL);

/* Add page to preferences page for Scheduled Transactions */
/* The parameters are; glade file, items to add from glade file - last being the dialog, preference tab name */
Expand Down
10 changes: 5 additions & 5 deletions gnucash/gnome/top-level.c
Expand Up @@ -411,15 +411,15 @@ gnc_main_gui_init (void)
gnc_hook_run(HOOK_UI_STARTUP, NULL);

gnc_hook_add_dangler(HOOK_BOOK_OPENED,
gnc_restore_all_state, NULL);
gnc_restore_all_state, NULL, NULL);
gnc_hook_add_dangler(HOOK_BOOK_CLOSED,
gnc_save_all_state, NULL);
gnc_save_all_state, NULL, NULL);
gnc_hook_add_dangler(HOOK_BOOK_CLOSED,
(GFunc)gnc_reports_flush_global, NULL);
(GFunc)gnc_reports_flush_global, NULL, NULL);
gnc_hook_add_dangler(HOOK_BOOK_OPENED,
(GFunc)gnc_invoice_remind_bills_due_cb, NULL);
(GFunc)gnc_invoice_remind_bills_due_cb, NULL, NULL);
gnc_hook_add_dangler(HOOK_BOOK_OPENED,
(GFunc)gnc_invoice_remind_invoices_due_cb, NULL);
(GFunc)gnc_invoice_remind_invoices_due_cb, NULL, NULL);

gnc_ui_sx_initialize();

Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnucash-bin.c
Expand Up @@ -636,7 +636,7 @@ inner_main (void *closure, int argc, char **argv)
before booting guile. */
gnc_main_gui_init();

gnc_hook_add_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit, NULL);
gnc_hook_add_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit, NULL, NULL);

/* Install Price Quote Sources */
gnc_update_splash_screen(_("Checking Finance::Quote..."), GNC_SPLASH_PERCENTAGE_UNKNOWN);
Expand Down
2 changes: 1 addition & 1 deletion gnucash/report/html-style-sheet.scm
Expand Up @@ -122,7 +122,7 @@
(define gnc:current-saved-stylesheets
(gnc-build-userdata-path "stylesheets-2.0"))

(define (gnc:save-style-sheet-options)
(define (gnc:save-style-sheet-options)
(let ((port (false-if-exception
(open gnc:current-saved-stylesheets
(logior O_WRONLY O_CREAT O_TRUNC)))))
Expand Down
4 changes: 2 additions & 2 deletions libgnucash/app-utils/gncmod-app-utils.c
Expand Up @@ -95,8 +95,8 @@ libgncmod_app_utils_gnc_module_init(int refcount)
if (refcount == 0)
{
gnc_component_manager_init ();
gnc_hook_add_dangler(HOOK_STARTUP, (GFunc)gnc_exp_parser_init, NULL);
gnc_hook_add_dangler(HOOK_SHUTDOWN, (GFunc)app_utils_shutdown, NULL);
gnc_hook_add_dangler(HOOK_STARTUP, (GFunc)gnc_exp_parser_init, NULL, NULL);
gnc_hook_add_dangler(HOOK_SHUTDOWN, (GFunc)app_utils_shutdown, NULL, NULL);
}

return TRUE;
Expand Down
1 change: 1 addition & 0 deletions libgnucash/engine/CMakeLists.txt
Expand Up @@ -160,6 +160,7 @@ set (engine_SOURCES
gnc-event.c
gnc-features.c
gnc-hooks.c
gnc-hooks-scm.c
gnc-int128.cpp
gnc-lot.c
gnc-numeric.cpp
Expand Down
86 changes: 86 additions & 0 deletions libgnucash/engine/gnc-hooks-scm.c
@@ -0,0 +1,86 @@
/*
* gnc-hooks-scm.c -- helpers for using Glib hook functions in guile
* Copyright (C) 2005 David Hampton <hampton@employees.org>
* Derek Atkins <derek@ihtfp.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
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
* Boston, MA 02110-1301, USA gnu@gnu.org
*/

#include <config.h>

#include <glib.h>
#include <stdio.h>
#include "gnc-hooks.h"
#include "gnc-hooks-scm.h"
#include "gnc-engine.h"
#include <libguile.h>
#include "swig-runtime.h"
#include <guile-mappings.h>

static QofLogModule log_module = GNC_MOD_ENGINE;

typedef struct
{
SCM proc;
int num_args;
} GncScmDangler;


static void
delete_scm_hook (gpointer data)
{
GncScmDangler *scm = data;
scm_gc_unprotect_object(scm->proc);
g_free(scm);
}

static void
scm_hook_cb (gpointer data, GncScmDangler *scm)
{
ENTER("data %p, cbarg %p", data, scm);

if (scm->num_args == 0)
scm_call_0 (scm->proc);
else
{
// XXX: FIXME: We really should make sure this is a session!!! */
scm_call_1 (scm->proc,
SWIG_NewPointerObj(data, SWIG_TypeQuery("_p_QofSession"), 0));
}

LEAVE("");
}

void
gnc_hook_add_scm_dangler (const gchar *name, SCM proc)
{
GHook *hook;
GncScmDangler *scm;
int num_args;

ENTER("list %s, proc ???", name);
num_args = gnc_hook_num_args(name);
g_return_if_fail(num_args >= 0);
scm = g_new0(GncScmDangler, 1);
scm_gc_protect_object(proc);
scm->proc = proc;
scm->num_args = num_args;
gnc_hook_add_dangler(name, (GFunc)scm_hook_cb,
(GDestroyNotify) delete_scm_hook, scm);
LEAVE("");
}

0 comments on commit b1ba16c

Please sign in to comment.