This class provides several important services:
1) It resolves and loads the appropriate backend, based on the URL.
2) It reports backend errors (e.g. network errors, storage corruption errors) through a single, backend-independent API.
3) It reports non-error events received from the backend.
4) It helps manage global dataset locks. For example, for the file backend, the lock prevents multiple users from editing the same file at the same time, thus avoiding lost data due to race conditions. Thus, an open session implies that the associated file is locked.
5) Misc utilities, such as a search path for the file to be edited, and/or other URL resolution utilities. This should simplify install & maintenance problems for naive users who may not have a good grasp on what a file system is, or where they want to keep their data files.
6) In the future, this class is probably a good place to manage a portion of the user authentication process, and hold user credentials/cookies/keys/tokens. This is because at the coarsest level, authorization can happen at the datastore level: i.e. does this user even have the authority to connect to and open this datastore?
A brief note about books & sessions: A book encapsulates the datasets manipulated by QOF. A book holds the actual data. By contrast, the session mediates the connection between a book (the thing that lives in virtual memory in the local process) and the datastore (the place where book data lives permanently, e.g., file, database).
In the current design, a session may hold multiple books. For now, exactly what this means is somewhat vague, and code in various places makes some implicit assumptions: first, only one book is 'current' and open for editing. Next, its assumed that all of the books in a session are related in some way. i.e. that they are all earlier accounting periods of the currently open book. In particular, the backends probably make that assumption, in order to store the different accounting periods in a clump so that one can be found, given another.
If you want multiple books that are unrelated to each other, use multiple sessions.
The session now calls QofBackendProvider->check_data_type to check that the incoming path contains data that the backend provider can open. The backend provider should also check if it can contact it's storage media (disk, network, server, etc.) and abort if it can't. Malformed file URL's would be handled the same way.
Files | |
file | qofsession.h |
Encapsulates a connection to a backend (persistent store). | |
Copying entities between sessions. | |
Only certain backends can cope with selective copying of entities and only fully defined QOF entities can be copied between sessions - see the QOF Serialisation Format (QSF) documentation (qsf_write_file) for more information. The recommended backend for the new session is QSF or a future SQL backend. Using any of these entity copy functions sets a flag in the backend that this is now a partial QofBook. See Reference: Referring to entities outside a partial book.. When you save a session containing a partial QofBook, the session will check that the backend is able to handle the partial book. If not, the backend will be replaced by one that can handle partial books, preferably one using the same access_method. Currently, this means that a book using the GnuCash XML v2 file backend will be switched to QSF. Copied entities are identical to the source entity, all parameters defined with QofAccessFunc and QofSetterFunc in QOF are copied and the GUID of the original QofEntity is set in the new entity. Sessions containing copied entities are intended for use as mechanisms for data export. It is acceptable to add entities to new_session in batches. Note that any of these calls will fail if an entity already exists in new_session with the same GUID as any entity to be copied.
To merge a whole QofBook or where there is any possibility of collisions or requirement for user intervention, see Merge: Merging QofBook structures | |
gboolean | qof_entity_copy_to_session (QofSession *new_session, QofEntity *original) |
Copy a single QofEntity to another session. | |
gboolean | qof_entity_copy_list (QofSession *new_session, GList *entity_list) |
Copy a GList of entities to another session. | |
gboolean | qof_entity_copy_coll (QofSession *new_session, QofCollection *entity_coll) |
Copy a QofCollection of entities. | |
gboolean | qof_entity_copy_coll_r (QofSession *new_session, QofCollection *coll) |
Recursively copy a collection of entities to a session. | |
gboolean | qof_entity_copy_one_r (QofSession *new_session, QofEntity *ent) |
Recursively copy a single entity to a new session. | |
Event Handling | |
gboolean | qof_session_events_pending (QofSession *session) |
gboolean | qof_session_process_events (QofSession *session) |
Defines | |
#define | QOF_MOD_SESSION "qof-session" |
#define | QOF_STDOUT "file:" |
Allow session data to be printed to stdout. | |
Typedefs | |
typedef _QofSession | QofSession |
typedef void(*) | QofPercentageFunc (const gchar *message, gdouble percent) |
Functions | |
QofSession * | qof_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 gchar *book_id, gboolean ignore_lock, gboolean create_if_nonexistent) |
void | qof_session_load (QofSession *session, QofPercentageFunc percentage_func) |
void | qof_session_add_book (QofSession *session, QofBook *book) |
QofBook * | qof_session_get_book (QofSession *session) |
const gchar * | qof_session_get_file_path (QofSession *session) |
const gchar * | qof_session_get_url (QofSession *session) |
gboolean | qof_session_not_saved (QofSession *session) |
gboolean | qof_session_save_may_clobber_data (QofSession *session) |
void | qof_session_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) |
#define QOF_STDOUT "file:" |
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 386 of file qofsession.h.
typedef void(*) QofPercentageFunc(const gchar *message, gdouble percent) |
The qof_session_load() method causes the QofBook to be made ready to to use with this URL/datastore. When the URL points at a file, then this routine would load the data from the file. With remote backends, e.g. network or SQL, this would load only enough data to make the book actually usable; it would not cause *all* of the data to be loaded.
XXX the current design tries to accomodate multiple calls to 'load' for each session, each time wiping out the old books; this seems wrong to me, and should be restricted to allow only one load per session.
Definition at line 168 of file qofsession.h.
gboolean qof_entity_copy_coll | ( | QofSession * | new_session, | |
QofCollection * | entity_coll | |||
) |
Copy a QofCollection of entities.
The QofBook in the new_session must not contain any entities with the same GUID as any entities in the collection - there is no support for handling collisions - instead, use Merge: Merging QofBook structures
new_session | - the target session | |
entity_coll | - a QofCollection of any QofIdType. |
Definition at line 737 of file qofsession.c.
00737 { 00738 QofSession *session; 00739 gboolean success; 00740 GList *ref_list; 00741 GList *ent_list; 00742 }; 00743 00744 static void 00745 recurse_collection_cb (QofEntity * ent, gpointer user_data) 00746 { 00747 struct recurse_s *store; 00748 00749 if (user_data == NULL) 00750 { 00751 return; 00752 } 00753 store = (struct recurse_s *) user_data; 00754 if (!ent || !store) 00755 { 00756 return; 00757 } 00758 store->success = qof_entity_copy_to_session (store->session, ent); 00759 if (store->success) 00760 { 00761 store->ent_list = g_list_append (store->ent_list, ent);
gboolean qof_entity_copy_coll_r | ( | QofSession * | new_session, | |
QofCollection * | coll | |||
) |
Recursively copy a collection of entities to a session.
Objects can be defined solely in terms of QOF data types or as a mix of data types and other objects, which may in turn include other objects. These references can be copied recursively down to the third level. See QofEntityReference.
coll | A QofCollection of entities that may or may not have references. | |
new_session | The QofSession to receive the copied entities. |
Definition at line 938 of file qofsession.c.
00943 { 00944 const gchar *libdir; 00945 const gchar *filename; 00946 const gchar *init_fcn; 00947 }; 00948 00949 /* All available QOF backends need to be described here 00950 and the last entry must be three NULL's. 00951 Remember: Use the libdir from the current build environment 00952 and use JUST the module name without .so - .so is not portable! */ 00953 struct backend_providers backend_list[] = { 00954 {QOF_LIB_DIR, QSF_BACKEND_LIB, QSF_MODULE_INIT}, 00955 {QOF_LIB_DIR, "libqof-backend-sqlite", "qof_sqlite_provider_init"}, 00956 /* {QOF_LIB_DIR, "libqof-backend-gda", "qof_gda_provider_init"},*/ 00957 #ifdef HAVE_DWI 00958 {QOF_LIB_DIR, "libqof_backend_dwi", "dwiend_provider_init"}, 00959 #endif
gboolean qof_entity_copy_list | ( | QofSession * | new_session, | |
GList * | entity_list | |||
) |
Copy a GList of entities to another session.
The QofBook in the new_session must not contain any entities with the same GUID as any of the source entities - there is no support for handling collisions, instead use Merge: Merging QofBook structures
Note that the GList (e.g. from qof_sql_query_run) can contain QofEntity pointers of any QofIdType, in any sequence. As long as all members of the list are QofEntity*, and all GUID's are unique, the list can be copied.
new_session | - the target session | |
entity_list | - a GList of QofEntity pointers of any type(s). |
Definition at line 715 of file qofsession.c.
00717 { 00718 return FALSE; 00719 } 00720 qof_event_suspend (); 00721 qecd.param_list = NULL; 00722 qecd.new_session = new_session; 00723 qof_book_set_partial (qof_session_get_book (qecd.new_session)); 00724 qof_collection_foreach (entity_coll, qof_entity_coll_foreach, &qecd); 00725 qof_class_param_foreach (qof_collection_get_type (entity_coll), 00726 qof_entity_param_cb, &qecd); 00727 qof_collection_foreach (entity_coll, qof_entity_coll_copy, &qecd); 00728 if (qecd.param_list != NULL) 00729 { 00730 g_slist_free (qecd.param_list); 00731 } 00732 qof_event_resume (); 00733 return TRUE; 00734 }
gboolean qof_entity_copy_one_r | ( | QofSession * | new_session, | |
QofEntity * | ent | |||
) |
Recursively copy a single entity to a new session.
Copy the single entity and all referenced entities to the second level.
Only entities that are directly referenced by the top level entity are copied.
This is a deep copy - all parameters of all referenced entities are copied. If the top level entity has no references, this is identical to qof_entity_copy_to_session.
ent | A single entity that may or may not have references. | |
new_session | The QofSession to receive the copied entities. |
Definition at line 962 of file qofsession.c.
00965 { 00966 GSList *p; 00967 GList *node; 00968 QofBackendProvider *prov; 00969 QofBook *book; 00970 gint num; 00971 gboolean prov_type; 00972 gboolean (*type_check) (const gchar *); 00973 00974 ENTER (" list=%d", g_slist_length (provider_list)); 00975 prov_type = FALSE; 00976 if (NULL == provider_list) 00977 { 00978 for (num = 0; backend_list[num].filename != NULL; num++) 00979 { 00980 if (!qof_load_backend_library (backend_list[num].libdir, 00981 backend_list[num].filename, 00982 backend_list[num].init_fcn)) 00983 { 00984 PWARN (" failed to load %s from %s using %s", 00985 backend_list[num].filename, backend_list[num].libdir, 00986 backend_list[num].init_fcn); 00987 } 00988 }
gboolean qof_entity_copy_to_session | ( | QofSession * | new_session, | |
QofEntity * | original | |||
) |
Copy a single QofEntity to another session.
Checks first that no entity in the session book contains the GUID of the source entity.
new_session | - the target session | |
original | - the QofEntity* to copy |
Definition at line 683 of file qofsession.c.
00689 { 00690 QofEntityCopyData *qecd; 00691 00692 if (!new_session || !entity_list) 00693 return FALSE; 00694 ENTER (" list=%d", g_list_length (entity_list)); 00695 qecd = g_new0 (QofEntityCopyData, 1); 00696 qof_event_suspend (); 00697 qecd->param_list = NULL; 00698 qecd->new_session = new_session; 00699 qof_book_set_partial (qof_session_get_book (new_session)); 00700 g_list_foreach (entity_list, qof_entity_list_foreach, qecd); 00701 qof_event_resume (); 00702 if (qecd->error) 00703 PWARN (" some/all entities in the list could not be copied."); 00704 g_free (qecd); 00705 LEAVE (" "); 00706 return TRUE; 00707 } 00708 00709 gboolean 00710 qof_entity_copy_coll (QofSession * new_session, 00711 QofCollection * entity_coll) 00712 {
void qof_session_add_book | ( | QofSession * | session, | |
QofBook * | book | |||
) |
The qof_session_add_book() allows additional books to be added to a session. XXX Under construction, clarify the following when done: XXX There must already be an open book in the session already!? XXX Only one open book at a time per session is allowed!? XXX each book gets its own unique backend ???
Definition at line 148 of file qofsession.c.
00149 { 00150 GList *node; 00151 if (!session) 00152 return; 00153 00154 ENTER (" sess=%p book=%p", session, addbook); 00155 00156 /* See if this book is already there ... */ 00157 for (node = session->books; node; node = node->next) 00158 { 00159 QofBook *book = node->data; 00160 if (addbook == book) 00161 return; 00162 } 00163 00164 if ('y' == addbook->book_open) 00165 { 00166 /* hack alert -- someone should free all the books in the list, 00167 * but it should probably not be us ... since the books backends 00168 * should be shutdown first, etc */ 00169 /* XXX this should probably be an error XXX */ 00170 g_list_free (session->books); 00171 session->books = g_list_append (NULL, addbook); 00172 } 00173 else 00174 { 00175 /* XXX Need to tell the backend to add a book as well */ 00176 session->books = g_list_append (session->books, addbook); 00177 } 00178 00179 qof_book_set_backend (addbook, session->backend); 00180 LEAVE (" "); 00181 }
void qof_session_add_close_hook | ( | GFunc | fn, | |
gpointer | data | |||
) |
Register a function to be called just before a session is closed.
fn | The function to be called. The function definition must be func(gpointer session, gpointer user_data); | |
data | The data to be passed to the function. |
Definition at line 69 of file qofsession.c.
00070 { 00071 GHook *hook; 00072 00073 if (session_closed_hooks == NULL) 00074 { 00075 session_closed_hooks = malloc (sizeof (GHookList)); /* LEAKED */ 00076 g_hook_list_init (session_closed_hooks, sizeof (GHook)); 00077 } 00078 00079 hook = g_hook_alloc (session_closed_hooks); 00080 if (!hook) 00081 return; 00082 00083 hook->func = (GHookFunc) fn; 00084 hook->data = data; 00085 g_hook_append (session_closed_hooks, hook); 00086 }
void qof_session_begin | ( | QofSession * | session, | |
const gchar * | book_id, | |||
gboolean | ignore_lock, | |||
gboolean | create_if_nonexistent | |||
) |
The qof_session_begin () method begins a new session. It takes as an argument the book id. The book id must be a string in the form of a URI/URL. The access method specified depends on the loaded backends. In the absence of a customised backend, only QSF XML would be accepted). Paths may be relative or absolute. If the path is relative; that is, if the argument is "file:somefile.xml" then the current working directory is assumed. Customised backends can choose to search other, application-specific, directories as well.
The 'ignore_lock' argument, if set to TRUE, will cause this routine to ignore any global-datastore locks (e.g. file locks) that it finds. If set to FALSE, then file/database-global locks will be tested and obeyed.
If the datastore exists, can be reached (e.g over the net), connected to, opened and read, and a lock can be obtained then a lock will be obtained. Note that multi-user datastores (e.g. the SQL backend) typically will not need to get a global lock, and thus, the user will not be locked out. That's the whole point of 'multi-user'.
If the file/database doesn't exist, and the create_if_nonexistent flag is set to TRUE, then the database is created.
If an error occurs, it will be pushed onto the session error stack, and that is where it should be examined.
Definition at line 1109 of file qofsession.c.
01111 { 01112 gchar * msg; 01113 01114 msg = g_strdup_printf (_("Unable to locate a " 01115 "suitable backend for '%s' - please check " 01116 "you have specified an access method " 01117 "like file: or sqlite:"), book_id); 01118 qof_error_set (session, qof_error_register 01119 (msg, FALSE)); 01120 DEBUG (" msg=%s", msg); 01121 LEAVE (" BAD: no backend: sess=%p book-id=%s", 01122 session, book_id ? book_id : "(null)"); 01123 g_free (msg); 01124 return; 01125 } 01126 01127 /* If there's a begin method, call that. */ 01128 if (session->backend->session_begin) 01129 { 01130 (session->backend->session_begin) (session->backend, session, 01131 session->book_id, ignore_lock, create_if_nonexistent); 01132 PINFO (" Done running session_begin on backend"); 01133 if (qof_error_check(session) != QOF_SUCCESS) 01134 { 01135 g_free (session->book_id); 01136 session->book_id = NULL; 01137 LEAVE (" backend error "); 01138 return; 01139 } 01140 } 01141 qof_error_clear (session); 01142 LEAVE (" sess=%p book-id=%s", session, book_id ? book_id : "(null)"); 01143 } 01144 01145 /* ============================================================== */ 01146 01147 void 01148 qof_session_load (QofSession * session, QofPercentageFunc percentage_func) 01149 { 01150 QofBook *newbook, *ob; 01151 QofBookList *oldbooks, *node; 01152 QofBackend *be; 01153 01154 if (!session) 01155 return; 01156 if ((!session->book_id) || 01157 (0 == safe_strcasecmp(session->book_id, QOF_STDOUT))) 01158 return; 01159 01160 ENTER (" sess=%p book_id=%s", session, session->book_id 01161 ? session->book_id : "(null)"); 01162 01163 /* At this point, we should are supposed to have a valid book 01164 * id and a lock on the file. */ 01165 01166 oldbooks = session->books; 01167 01168 /* XXX why are we creating a book here? I think the books 01169 * need to be handled by the backend ... especially since 01170 * the backend may need to load multiple books ... XXX. FIXME. 01171 */ 01172 newbook = qof_book_new (); 01173 session->books = g_list_append (NULL, newbook); 01174 PINFO (" new book=%p", newbook); 01175 01176 qof_error_clear (session); 01177 01178 /* This code should be sufficient to initialize *any* backend, 01179 * whether http, postgres, or anything else that might come along. 01180 * Basically, the idea is that by now, a backend has already been 01181 * created & set up. At this point, we only need to get the 01182 * top-level account group out of the backend, and that is a 01183 * generic, backend-independent operation. 01184 */ 01185 be = session->backend; 01186 qof_book_set_backend (newbook, be); 01187 01188 /* Starting the session should result in a bunch of accounts 01189 * and currencies being downloaded, but probably no transactions; 01190 * The GUI will need to do a query for that. 01191 */ 01192 if (be) 01193 { 01194 be->percentage = percentage_func; 01195 01196 if (be->load) 01197 {
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.
session | A pointer to the session being closed. |
Definition at line 89 of file qofsession.c.
00090 { 00091 GHook *hook; 00092 GFunc fn; 00093 00094 if (session_closed_hooks == NULL) 00095 return; 00096 00097 hook = g_hook_first_valid (session_closed_hooks, FALSE); 00098 while (hook) 00099 { 00100 fn = (GFunc) hook->func; 00101 fn (session, hook->data); 00102 hook = g_hook_next_valid (session_closed_hooks, hook, FALSE); 00103 } 00104 }
void qof_session_end | ( | QofSession * | session | ) |
The qof_session_end() method will release the session lock. For the file backend, it will *not* save the data to a file. Thus, this method acts as an "abort" or "rollback" primitive. However, for other backends, such as the sql backend, the data would have been written out before this, and so this routines wouldn't roll-back anything; it would just shut the connection.
Definition at line 1451 of file qofsession.c.
01457 { 01458 GList *books_1, *books_2, *node; 01459 01460 if (session_1 == session_2) 01461 return; 01462 if (!session_1 || !session_2) 01463 return; 01464 01465 ENTER (" sess1=%p sess2=%p", session_1, session_2); 01466 01467 books_1 = session_1->books; 01468 books_2 = session_2->books; 01469 01470 session_1->books = books_2; 01471 session_2->books = books_1; 01472
gboolean qof_session_events_pending | ( | 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 1544 of file qofsession.c.
const gchar* qof_session_get_file_path | ( | QofSession * | session | ) |
The qof_session_get_file_path() routine returns the fully-qualified file path for the session. That is, if a relative or partial filename was for the session, then it had to have been fully resolved to open the session. This routine returns the result of this resolution. The path is always guaranteed to reside in the local file system, even if the session itself was opened as a URL. (currently, the filepath is derived from the url by substituting commas for slashes).
The qof_session_get_url() routine returns the url that was opened. URL's for local files take the form of file:/some/where/some/file.gml
Definition at line 192 of file qofsession.c.
00193 { 00194 if (!session) 00195 return NULL; 00196 if (!session->backend) 00197 return NULL; 00198 return session->backend->fullpath; 00199 }
gboolean qof_session_not_saved | ( | QofSession * | session | ) |
The qof_session_not_saved() subroutine will return TRUE if any data in the session hasn't been saved to long-term storage.
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 1557 of file qofsession.c.
void qof_session_save | ( | QofSession * | session, | |
QofPercentageFunc | percentage_func | |||
) |
The qof_session_save() method will commit all changes that have been made to the session. For the file backend, this is nothing more than a write to the file of the current AccountGroup & etc. For the SQL backend, this is typically a no-op (since all data has already been written out to the database.
Definition at line 1297 of file qofsession.c.
01302 { 01303 prov = p->data; 01304 if (TRUE == prov->partial_book_supported) 01305 { 01307 /* if((TRUE == prov->partial_book_supported) && 01308 (0 == strcasecmp (access_method, prov->access_method))) 01309 { */ 01310 if (NULL == prov->backend_new) 01311 continue; 01312 /* Use the providers creation callback */ 01313 session->backend = (*(prov->backend_new)) (); 01314 session->backend->provider = prov; 01315 if (session->backend->session_begin) 01316 { 01317 /* Call begin - backend has been changed, 01318 so make sure a file can be written, 01319 use ignore_lock and create_if_nonexistent */ 01320 g_free (session->book_id); 01321 session->book_id = NULL; 01322 (session->backend->session_begin) (session->backend, 01323 session, book_id, TRUE, TRUE); 01324 PINFO 01325 (" Done running session_begin on changed backend"); 01326 if (qof_error_check (session) != QOF_SUCCESS) 01327 { 01328 g_free (session->book_id); 01329 session->book_id = NULL; 01330 LEAVE (" changed backend error"); 01331 return; 01332 } 01333 } 01334 /* Tell the books about the backend that they'll be using. */ 01335 for (node = session->books; node; node = node->next) 01336 { 01337 book = node->data; 01338 qof_book_set_backend (book, session->backend); 01339 } 01340 p = NULL; 01341 } 01342 if (p) 01343 { 01344 p = p->next; 01345 } 01346 } 01347 if (!session->backend) 01348 { 01349 msg = g_strdup_printf (" failed to load backend"); 01350 qof_error_set (session, qof_error_register 01351 (_("Failed to load backend, no suitable handler."), 01352 FALSE)); 01353 return; 01354 } 01355 } 01356 /* If there is a backend, and the backend is reachable 01357 * (i.e. we can communicate with it), then synchronize with 01358 * the backend. If we cannot contact the backend (e.g. 01359 * because we've gone offline, the network has crashed, etc.) 01360 * then give the user the option to save to the local disk. 01361 * 01362 * hack alert -- FIXME -- XXX the code below no longer 01363 * does what the words above say. This needs fixing. 01364 */ 01365 be = session->backend; 01366 if (be) 01367 { 01368 for (node = session->books; node; node = node->next) 01369 { 01370 abook = node->data; 01371 /* if invoked as SaveAs(), then backend not yet set */ 01372 qof_book_set_backend (abook, be); 01373 be->percentage = percentage_func; 01374 if (be->sync) 01375 (be->sync) (be, abook); 01376 } 01377 /* If we got to here, then the backend saved everything 01378 * just fine, and we are done. So return. */ 01379 /* Return the book_id to previous value. */ 01380 qof_error_clear (session); 01381 LEAVE (" Success"); 01382 return; 01383 } 01384 else 01385 { 01386 msg = g_strdup_printf (" failed to load backend"); 01387 qof_error_set (session, qof_error_register 01388 (_("Failed to load backend, no suitable handler."), 01389 FALSE)); 01390 } 01391 LEAVE (" error -- No backend!"); 01392 } 01393 01394 /* ============================================================= */ 01395 01396 void 01397 qof_session_end (QofSession * session) 01398 { 01399 if (!session) 01400 return; 01401 01402 ENTER (" sess=%p book_id=%s", session, session->book_id 01403 ? session->book_id : "(null)"); 01404 01405 /* close down the backend first */ 01406 if (session->backend && session->backend->session_end) 01407 { 01408 (session->backend->session_end) (session->backend); 01409 } 01410 01411 qof_error_clear (session); 01412 01413 g_free (session->book_id); 01414 session->book_id = NULL; 01415 01416 LEAVE (" sess=%p book_id=%s", session, session->book_id 01417 ? session->book_id : "(null)"); 01418 } 01419 01420 void 01421 qof_session_destroy (QofSession * session) 01422 { 01423 GList *node; 01424 if (!session) 01425 return; 01426 01427 ENTER (" sess=%p book_id=%s", session, session->book_id 01428 ? session->book_id : "(null)"); 01429 01430 qof_session_end (session); 01431 01432 /* destroy the backend */ 01433 qof_session_destroy_backend (session); 01434 01435 for (node = session->books; node; node = node->next) 01436 { 01437 QofBook *book = node->data; 01438 qof_book_set_backend (book, NULL); 01439 qof_book_destroy (book); 01440 } 01441 01442 session->books = NULL; 01443 #ifndef QOF_DISABLE_DEPRECATED 01444 if (session == qof_session_get_current_session()) 01445 qof_session_clear_current_session(); 01446 #endif
gboolean qof_session_save_may_clobber_data | ( | QofSession * | session | ) |
Allows the backend to warn the user if a dataset already exists.
Definition at line 1284 of file qofsession.c.
01284 { 01285 change_backend = TRUE; 01286 } 01287 } 01288 if (change_backend == TRUE) 01289 { 01290 qof_session_destroy_backend (session); 01291 if (NULL == provider_list) 01292 { 01293 for (num = 0; backend_list[num].filename != NULL; num++) 01294 {
void qof_session_swap_data | ( | QofSession * | session_1, | |
QofSession * | session_2 | |||
) |
The qof_session_swap_data () method swaps the book of the two given sessions. It is useful for 'Save As' type functionality.
Definition at line 1510 of file qofsession.c.