GnuCash 2.3.0
Defines | Typedefs | Functions
qofsession.h File Reference

Encapsulates a connection to a backend (persistent store) More...

#include "qofbackend.h"
#include "qofbook.h"
#include "qofclass.h"
#include "qofobject.h"

Go to the source code of this file.

Defines

#define QOF_MOD_SESSION   "qof.session"
#define QOF_STDOUT   ">"
 Allow session data to be printed to stdout.

Typedefs

typedef struct _QofSession QofSession
typedef void(* QofPercentageFunc )(const char *message, double percent)

Functions

QofSessionqof_session_new (void)
void qof_session_destroy (QofSession *session)
void qof_session_swap_data (QofSession *session_1, QofSession *session_2)
void qof_session_begin (QofSession *session, const char *book_id, gboolean ignore_lock, gboolean create, gboolean force)
void qof_session_load (QofSession *session, QofPercentageFunc percentage_func)
QofBookqof_session_get_book (const QofSession *session)
const char * qof_session_get_file_path (const QofSession *session)
const char * qof_session_get_url (const QofSession *session)
gboolean qof_session_save_in_progress (const QofSession *session)
void qof_session_save (QofSession *session, QofPercentageFunc percentage_func)
void qof_session_safe_save (QofSession *session, QofPercentageFunc percentage_func)
void qof_session_end (QofSession *session)
void qof_session_add_close_hook (GFunc fn, gpointer data)
void qof_session_call_close_hooks (QofSession *session)
gboolean qof_session_export (QofSession *tmp_session, QofSession *real_session, QofPercentageFunc percentage_func)
GList * qof_backend_get_registered_access_method_list (void)
void qof_session_ensure_all_data_loaded (QofSession *session)
Session Errors
QofBackendError qof_session_get_error (QofSession *session)
const char * qof_session_get_error_message (const QofSession *session)
QofBackendError qof_session_pop_error (QofSession *session)
Event Handling
gboolean qof_session_events_pending (const QofSession *session)
gboolean qof_session_process_events (QofSession *session)

Detailed Description

Encapsulates a connection to a backend (persistent store)

Author:
Copyright (c) 1998, 1999, 2001, 2002 Linas Vepstas <linas@linas.org>
Copyright (c) 2000 Dave Peticolas
Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>

Definition in file qofsession.h.


Define Documentation

#define QOF_STDOUT   ">"

Allow session data to be printed to stdout.

book_id can't be NULL and we do need to have an access_method, so use one to solve the other.

To print a session to stdout, use qof_session_begin. Example:

qof_session_begin(session,QOF_STDOUT,TRUE,FALSE);

When you call qof_session_save(session, NULL), the output will appear on stdout and can be piped or redirected to other processes.

Currently, only the QSF backend supports writing to stdout, other backends may return a QofBackendError.

Definition at line 269 of file qofsession.h.


Function Documentation

GList* qof_backend_get_registered_access_method_list ( void  )

Return a list of strings for the registered access methods. The owner is responsible for freeing the list but not the strings.

Definition at line 99 of file qofsession.c.

{
    GList* list = NULL;
    GSList* node;

    for ( node = provider_list; node != NULL; node = node->next )
    {
        QofBackendProvider *prov = node->data;
        list = g_list_append( list, (gchar*)prov->access_method );
    }

    return list;
}
void qof_session_add_close_hook ( GFunc  fn,
gpointer  data 
)

Register a function to be called just before a session is closed.

Parameters:
fnThe function to be called. The function definition must be func(gpointer session, gpointer user_data);
dataThe data to be passed to the function.

Definition at line 118 of file qofsession.c.

{
    GHook *hook;

    if (session_closed_hooks == NULL)
    {
        session_closed_hooks = malloc(sizeof(GHookList)); /* LEAKED */
        g_hook_list_init (session_closed_hooks, sizeof(GHook));
    }

    hook = g_hook_alloc(session_closed_hooks);
    if (!hook)
        return;

    hook->func = (GHookFunc)fn;
    hook->data = data;
    g_hook_append(session_closed_hooks, hook);
}
void qof_session_call_close_hooks ( QofSession session)

Call all registered session close hooks, informing them that the specified session is about to be closed.

Parameters:
sessionA pointer to the session being closed.

Definition at line 138 of file qofsession.c.

{
    GHook *hook;
    GFunc fn;

    if (session_closed_hooks == NULL)
        return;

    hook = g_hook_first_valid (session_closed_hooks, FALSE);
    while (hook)
    {
        fn = (GFunc)hook->func;
        fn(session, hook->data);
        hook = g_hook_next_valid (session_closed_hooks, hook, FALSE);
    }
}
void qof_session_ensure_all_data_loaded ( QofSession session)

Ensure all of the data is loaded from the session.

Definition at line 303 of file qofsession.c.

{
    QofBackend* backend;

    if (session == NULL) return;
    backend = qof_session_get_backend(session);
    if (backend == NULL) return;

    if (backend->load == NULL) return;
    backend->load(backend, qof_session_get_book(session), LOAD_TYPE_LOAD_ALL);
    qof_session_push_error (session, qof_backend_get_error(backend), NULL);
}
gboolean qof_session_events_pending ( const QofSession session)

The qof_session_events_pending() method will return TRUE if the backend has pending events which must be processed to bring the engine up to date with the backend.

Definition at line 1558 of file qofsession.c.

{
    if (!session) return FALSE;
    if (!session->backend) return FALSE;
    if (!session->backend->events_pending) return FALSE;

    return session->backend->events_pending (session->backend);
}
gboolean qof_session_process_events ( QofSession session)

The qof_session_process_events() method will process any events indicated by the qof_session_events_pending() method. It returns TRUE if the engine was modified while engine events were suspended.

Definition at line 1568 of file qofsession.c.

{
    if (!session) return FALSE;
    if (!session->backend) return FALSE;
    if (!session->backend->process_events) return FALSE;

    return session->backend->process_events (session->backend);
}
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines