Backends are used to save and restore Entities in a Book.
Files | |
file | qofbackend.h |
API for data storage Backend. | |
Modules | |
Session: Backend connections. | |
QOF Serialisation Format | |
qof-backend-gda outline | |
QOF-backend-SQLite support | |
Data Structures | |
struct | QofBackendOption_s |
Backend Configuration using KVP | |
The backend uses qof_backend_get_config to pass back a KvpFrame of QofBackendOption that includes the translated strings that serve as description and tooltip for that option. qof_backend_prepare_frame, qof_backend_prepare_option and qof_backend_complete_frame are intended to be used by the backend itself to create the options. qof_backend_get_config, qof_backend_option_foreach and qof_backend_load_config are intended for either the backend or the frontend to retrieve the option data from the frame or set new data.
Backends are loaded using QofBackendProvider via the function specified in prov->backend_new. Before backend_new returns, you should ensure that your backend is fully configured and ready for use. | |
typedef struct QofBackendOption_s | QofBackendOption |
typedef void(* | QofBackendOptionCB )(QofBackendOption *, gpointer data) |
void | qof_backend_prepare_frame (QofBackend *be) |
void | qof_backend_prepare_option (QofBackend *be, QofBackendOption *option) |
KvpFrame * | qof_backend_complete_frame (QofBackend *be) |
void | qof_backend_option_foreach (KvpFrame *config, QofBackendOptionCB cb, gpointer data) |
void | qof_backend_load_config (QofBackend *be, KvpFrame *config) |
Load configuration options specific to this backend. | |
KvpFrame * | qof_backend_get_config (QofBackend *be) |
Get the available configuration options. | |
Allow access to the begin routine for this backend. | |
QOF_BEGIN_EDIT and QOF_COMMIT_EDIT_PART1 and part2 rely on calling QofBackend *be->begin and be->commit. This means the QofBackend struct becomes part of the public API. These function replaces those calls to allow the macros to be used when QOF is built as a library. | |
void | qof_backend_run_begin (QofBackend *be, QofInstance *inst) |
gboolean | qof_backend_begin_exists (QofBackend *be) |
void | qof_backend_run_commit (QofBackend *be, QofInstance *inst) |
gboolean | qof_backend_commit_exists (QofBackend *be) |
Defines | |
#define | QOF_MOD_BACKEND "qof-backend" |
Typedefs | |
typedef gint32 | QofErrorId |
The ID of this error. | |
typedef struct QofBackendProvider_s | QofBackendProvider |
typedef struct QofBackend_s | QofBackend |
Pseudo-object providing an interface between the framework and a persistant data store (e.g. a server, a database, or a file). | |
typedef void(* | QofBePercentageFunc )(const gchar *message, double percent) |
DOCUMENT ME! | |
Functions | |
gboolean | qof_load_backend_library (const gchar *directory, const gchar *filename, const gchar *init_fcn) |
Load a QOF-compatible backend shared library. | |
QofBackend * | qof_book_get_backend (QofBook *book) |
Retrieve the backend used by this book. | |
void | qof_book_set_backend (QofBook *book, QofBackend *) |
Set the backend used by this book. |
typedef struct QofBackend_s QofBackend |
Pseudo-object providing an interface between the framework and a persistant data store (e.g. a server, a database, or a file).
There are no backend functions that are 'public' to users of the framework. The backend can, however, report errors to the GUI & other front-end users.
Definition at line 69 of file qofbackend.h.
typedef void(* QofBackendOptionCB)(QofBackendOption *, gpointer data) |
Backend configuration option foreach callback prototype.
Definition at line 134 of file qofbackend.h.
typedef struct QofBackendProvider_s QofBackendProvider |
A structure that declares backend services that can be gotten. The Provider specifies a URL access method, and specifies the function to create a backend that can handle that URL access function.
Definition at line 60 of file qofbackend.h.
typedef gint32 QofErrorId |
The ID of this error.
0 == QOF_SUCCESS (equivalent to ERR_BACKEND_NO_ERR )
Definition at line 54 of file qofbackend.h.
KvpFrame* qof_backend_complete_frame | ( | QofBackend * | be | ) |
Complete the backend_configuration and return the frame.
Definition at line 200 of file qofbackend.c.
00201 { 00202 g_return_val_if_fail (be, NULL); 00203 be->config_count = 0; 00204 return be->backend_configuration; 00205 }
KvpFrame* qof_backend_get_config | ( | QofBackend * | be | ) |
Get the available configuration options.
To retrieve the options from the returned KvpFrame, the caller needs to parse the XML file that documents the option names and data types. The XML file itself is part of the backend and is installed in a directory determined by the backend. Therefore, loading a new backend requires two paths: the path to the .la file and the path to the xml. Both paths are available by including a generated header file, e.g. gncla-dir.h defines GNC_LIB_DIR for the location of the .la file and GNC_XML_DIR for the xml.
be | The QofBackend to be configured. |
Definition at line 410 of file qofbackend.c.
00411 { 00412 if (!be) 00413 return NULL; 00414 if (!be->get_config) 00415 return NULL; 00416 return (be->get_config) (be); 00417 }
void qof_backend_load_config | ( | QofBackend * | be, | |
KvpFrame * | config | |||
) |
Load configuration options specific to this backend.
be | The backend to configure. | |
config | A KvpFrame of QofBackendOptions that this backend will recognise. Each backend needs to document their own config types and acceptable values. |
Definition at line 400 of file qofbackend.c.
00401 { 00402 if (!be || !config) 00403 return; 00404 if (!be->load_config) 00405 return; 00406 (be->load_config) (be, config); 00407 }
void qof_backend_option_foreach | ( | KvpFrame * | config, | |
QofBackendOptionCB | cb, | |||
gpointer | data | |||
) |
Iterate over the frame and process each option.
Definition at line 383 of file qofbackend.c.
00385 { 00386 struct config_iterate helper; 00387 00388 if (!config || !cb) 00389 return; 00390 ENTER (" "); 00391 helper.fcn = cb; 00392 helper.count = 1; 00393 helper.data = data; 00394 helper.recursive = config; 00395 kvp_frame_for_each_slot (config, config_foreach_cb, &helper); 00396 LEAVE (" "); 00397 }
void qof_backend_prepare_frame | ( | QofBackend * | be | ) |
Initialise the backend_configuration
Definition at line 99 of file qofbackend.c.
00100 { 00101 g_return_if_fail (be); 00102 if (!kvp_frame_is_empty (be->backend_configuration)) 00103 { 00104 kvp_frame_delete (be->backend_configuration); 00105 be->backend_configuration = kvp_frame_new (); 00106 } 00107 be->config_count = 0; 00108 }
void qof_backend_prepare_option | ( | QofBackend * | be, | |
QofBackendOption * | option | |||
) |
Add an option to the backend_configuration. Repeat for more.
Definition at line 111 of file qofbackend.c.
00113 { 00114 KvpValue *value; 00115 gchar *temp; 00116 gint count; 00117 00118 g_return_if_fail (be || option); 00119 count = be->config_count; 00120 count++; 00121 value = NULL; 00122 switch (option->type) 00123 { 00124 case KVP_TYPE_GINT64: 00125 { 00126 value = kvp_value_new_gint64 (*(gint64 *) option->value); 00127 break; 00128 } 00129 case KVP_TYPE_DOUBLE: 00130 { 00131 value = kvp_value_new_double (*(gdouble *) option->value); 00132 break; 00133 } 00134 case KVP_TYPE_NUMERIC: 00135 { 00136 value = kvp_value_new_numeric (*(QofNumeric *) option->value); 00137 break; 00138 } 00139 case KVP_TYPE_STRING: 00140 { 00141 value = kvp_value_new_string ((const gchar *) option->value); 00142 break; 00143 } 00144 case KVP_TYPE_BOOLEAN: 00145 { 00146 break; 00147 } 00148 case KVP_TYPE_GUID: 00149 { 00150 break; 00151 } /* unsupported */ 00152 case KVP_TYPE_TIME : 00153 { 00154 value = kvp_value_new_time ((QofTime*) option->value); 00155 break; 00156 } 00157 #ifndef QOF_DISABLE_DEPRECATED 00158 case KVP_TYPE_TIMESPEC: 00159 { 00160 value = kvp_value_new_timespec (*(Timespec *) option->value); 00161 break; 00162 } 00163 #endif 00164 case KVP_TYPE_BINARY: 00165 { 00166 break; 00167 } /* unsupported */ 00168 case KVP_TYPE_GLIST: 00169 { 00170 break; 00171 } /* unsupported */ 00172 case KVP_TYPE_FRAME: 00173 { 00174 break; 00175 } /* unsupported */ 00176 } 00177 if (value) 00178 { 00179 temp = g_strdup_printf ("/%s", option->option_name); 00180 kvp_frame_set_value (be->backend_configuration, temp, value); 00181 g_free (temp); 00182 temp = 00183 g_strdup_printf ("/%s/%s", QOF_CONFIG_DESC, 00184 option->option_name); 00185 kvp_frame_set_string (be->backend_configuration, temp, 00186 option->description); 00187 g_free (temp); 00188 temp = 00189 g_strdup_printf ("/%s/%s", QOF_CONFIG_TIP, 00190 option->option_name); 00191 kvp_frame_set_string (be->backend_configuration, temp, 00192 option->tooltip); 00193 g_free (temp); 00194 /* only increment the counter if successful */ 00195 be->config_count = count; 00196 } 00197 }
void qof_book_set_backend | ( | QofBook * | book, | |
QofBackend * | ||||
) |
gboolean qof_load_backend_library | ( | const gchar * | directory, | |
const gchar * | filename, | |||
const gchar * | init_fcn | |||
) |
Load a QOF-compatible backend shared library.
directory | Can be NULL if filename is a complete path. | |
filename | Name of the .la file that describes the shared library. This provides platform independence, courtesy of libtool. | |
init_fcn | The QofBackendProvider init function. |
Definition at line 431 of file qofbackend.c.
00433 { 00434 gchar *fullpath; 00435 typedef void (*backend_init) (void); 00436 GModule *backend; 00437 backend_init gmod_init; 00438 gpointer g; 00439 00440 g_return_val_if_fail (g_module_supported (), FALSE); 00441 fullpath = g_module_build_path (directory, filename); 00442 backend = g_module_open (fullpath, G_MODULE_BIND_LAZY); 00443 if (!backend) 00444 { 00445 PERR (" No backend found. %s", g_module_error ()); 00446 return FALSE; 00447 } 00448 g = &gmod_init; 00449 if (!g_module_symbol (backend, init_fcn, g)) 00450 { 00451 PERR (" Backend did not initialise. %s", g_module_error ()); 00452 return FALSE; 00453 } 00454 g_module_make_resident (backend); 00455 gmod_init (); 00456 g_free (fullpath); 00457 return TRUE; 00458 }