/
qofsession.c
906 lines (774 loc) · 25.6 KB
/
qofsession.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
/********************************************************************\
* qofsesssion.c -- session access (connection to backend) *
* *
* 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 *
\********************************************************************/
/**
* @file qofsession.c
* @brief Encapsulate a connection to a storage backend.
*
* HISTORY:
* Created by Linas Vepstas December 1998
@author Copyright (c) 1998-2004 Linas Vepstas <linas@linas.org>
@author Copyright (c) 2000 Dave Peticolas
@author Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#else
# ifdef __GNUC__
# warning "<unistd.h> required."
# endif
#endif
#include <glib.h>
#include "qof.h"
#include "qofbackend-p.h"
#include "qofbook-p.h"
#include "qofsession-p.h"
#include "qofobject-p.h"
static GHookList * session_closed_hooks = NULL;
static QofLogModule log_module = QOF_MOD_SESSION;
static GSList *provider_list = NULL;
static gboolean qof_providers_initialized = FALSE;
/* ====================================================================== */
void
qof_backend_register_provider (QofBackendProvider *prov)
{
provider_list = g_slist_append (provider_list, prov);
}
GList*
qof_backend_get_registered_access_method_list(void)
{
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;
}
/* ====================================================================== */
/* hook routines */
void
qof_session_add_close_hook (GFunc fn, gpointer data)
{
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)
{
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);
}
}
/* ====================================================================== */
/* error handling routines */
static void
qof_session_clear_error (QofSession *session)
{
QofBackendError err;
session->last_err = ERR_BACKEND_NO_ERR;
g_free(session->error_message);
session->error_message = NULL;
/* pop the stack on the backend as well. */
if (session->backend)
{
do
{
err = qof_backend_get_error (session->backend);
}
while (ERR_BACKEND_NO_ERR != err);
}
}
void
qof_session_push_error (QofSession *session, QofBackendError err,
const char *message)
{
if (!session) return;
g_free (session->error_message);
session->last_err = err;
session->error_message = g_strdup (message);
}
QofBackendError
qof_session_get_error (QofSession * session)
{
QofBackendError err;
if (!session) return ERR_BACKEND_NO_BACKEND;
/* if we have a local error, return that. */
if (ERR_BACKEND_NO_ERR != session->last_err)
{
return session->last_err;
}
/* maybe we should return a no-backend error ??? */
if (! session->backend) return ERR_BACKEND_NO_ERR;
err = qof_backend_get_error (session->backend);
session->last_err = err;
return err;
}
static const char *
get_default_error_message(QofBackendError err)
{
return "";
}
const char *
qof_session_get_error_message(const QofSession *session)
{
if (!session) return "";
if (!session->error_message)
return get_default_error_message(session->last_err);
return session->error_message;
}
QofBackendError
qof_session_pop_error (QofSession * session)
{
QofBackendError err;
if (!session) return ERR_BACKEND_NO_BACKEND;
err = qof_session_get_error(session);
qof_session_clear_error(session);
return err;
}
/* ====================================================================== */
static void
qof_session_init (QofSession *session)
{
if (!session) return;
session->entity.e_type = QOF_ID_SESSION;
session->book = qof_book_new ();
session->book_id = NULL;
session->backend = NULL;
session->lock = 1;
qof_session_clear_error (session);
}
QofSession *
qof_session_new (void)
{
QofSession *session = g_new0(QofSession, 1);
qof_session_init(session);
return session;
}
QofBook *
qof_session_get_book (const QofSession *session)
{
GList *node;
if (!session) return NULL;
if (!session->book) return NULL;
if ('y' == session->book->book_open)
{
return session->book;
}
else
{
return NULL;
}
}
QofBackend *
qof_session_get_backend (const QofSession *session)
{
if (!session) return NULL;
return session->backend;
}
const char *
qof_session_get_file_path (const QofSession *session)
{
if (!session) return NULL;
if (!session->backend) return NULL;
return session->backend->fullpath;
}
const char *
qof_session_get_url (const QofSession *session)
{
if (!session) return NULL;
return session->book_id;
}
void
qof_session_ensure_all_data_loaded (QofSession *session)
{
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);
}
/* ====================================================================== */
/** Programs that use their own backends also need to call
the default QOF ones. The backends specified here are
loaded only by applications that do not have their own. */
struct backend_providers
{
const char *libdir;
const char *filename;
};
static void
qof_session_load_backend(QofSession * session, const char * access_method)
{
GSList *p;
QofBackendProvider *prov;
char *msg;
gboolean prov_type;
gboolean (*type_check) (const char*);
ENTER (" list=%d, initted=%s", g_slist_length(provider_list),
qof_providers_initialized ? "true" : "false");
prov_type = FALSE;
if (!qof_providers_initialized)
{
qof_providers_initialized = TRUE;
}
p = provider_list;
while (p != NULL)
{
prov = p->data;
/* Does this provider handle the desired access method? */
if (0 == g_ascii_strcasecmp (access_method, prov->access_method))
{
/* More than one backend could provide this
access method, check file type compatibility. */
type_check = (gboolean (*)(const char*)) prov->check_data_type;
if (type_check)
{
prov_type = (type_check)(session->book_id);
if (!prov_type)
{
PINFO(" %s not usable", prov->provider_name);
p = p->next;
continue;
}
}
PINFO (" selected %s", prov->provider_name);
if (NULL == prov->backend_new)
{
p = p->next;
continue;
}
/* Use the providers creation callback */
session->backend = (*(prov->backend_new))();
session->backend->provider = prov;
/* Tell the book about the backend that they'll be using. */
qof_book_set_backend (session->book, session->backend);
LEAVE (" ");
return;
}
p = p->next;
}
msg = g_strdup_printf("failed to load '%s' using access_method", access_method);
qof_session_push_error (session, ERR_BACKEND_NO_HANDLER, msg);
LEAVE (" ");
}
/* ====================================================================== */
static void
qof_session_destroy_backend (QofSession *session)
{
g_return_if_fail (session);
if (session->backend)
{
/* clear any error message */
char * msg = qof_backend_get_message (session->backend);
g_free (msg);
/* Then destroy the backend */
if (session->backend->destroy_backend)
{
session->backend->destroy_backend(session->backend);
}
else
{
g_free(session->backend);
}
}
session->backend = NULL;
}
void
qof_session_begin (QofSession *session, const char * book_id,
gboolean ignore_lock, gboolean create, gboolean force)
{
gchar *scheme = NULL, *filename = NULL;
if (!session) return;
ENTER (" sess=%p ignore_lock=%d, book-id=%s",
session, ignore_lock,
book_id ? book_id : "(null)");
/* Clear the error condition of previous errors */
qof_session_clear_error (session);
/* Check to see if this session is already open */
if (session->book_id)
{
if (ERR_BACKEND_NO_ERR != qof_session_get_error(session))
qof_session_push_error (session, ERR_BACKEND_LOCKED, NULL);
LEAVE("push error book is already open ");
return;
}
/* seriously invalid */
if (!book_id)
{
if (ERR_BACKEND_NO_ERR != qof_session_get_error(session))
qof_session_push_error (session, ERR_BACKEND_BAD_URL, NULL);
LEAVE("push error missing book_id");
return;
}
scheme = g_uri_parse_scheme (book_id);
if (g_strcmp0 (scheme, "file") == 0)
filename = g_filename_from_uri (book_id, NULL, NULL);
else if (!scheme)
filename = g_strdup (book_id);
if (filename && g_file_test (filename, G_FILE_TEST_IS_DIR))
{
if (ERR_BACKEND_NO_ERR == qof_session_get_error(session))
qof_session_push_error (session, ERR_BACKEND_BAD_URL, NULL);
g_free (filename);
g_free (scheme);
LEAVE("Can't open a directory");
return;
}
/* destroy the old backend */
qof_session_destroy_backend(session);
/* Store the session URL */
session->book_id = g_strdup (book_id);
if (filename)
qof_session_load_backend(session, "file");
else /* access method found, load appropriate backend */
qof_session_load_backend(session, scheme);
g_free (filename);
g_free (scheme);
/* No backend was found. That's bad. */
if (NULL == session->backend)
{
g_free(session->book_id);
session->book_id = NULL;
if (ERR_BACKEND_NO_ERR == qof_session_get_error(session))
qof_session_push_error (session, ERR_BACKEND_BAD_URL, NULL);
LEAVE (" BAD: no backend: sess=%p book-id=%s",
session, book_id ? book_id : "(null)");
return;
}
/* If there's a begin method, call that. */
if (session->backend->session_begin)
{
char *msg;
int err;
(session->backend->session_begin)(session->backend, session,
session->book_id, ignore_lock,
create, force);
PINFO("Done running session_begin on backend");
err = qof_backend_get_error(session->backend);
msg = qof_backend_get_message(session->backend);
if (err != ERR_BACKEND_NO_ERR)
{
g_free(session->book_id);
session->book_id = NULL;
qof_session_push_error (session, err, msg);
LEAVE(" backend error %d %s", err, msg ? msg : "(null)");
return;
}
if (msg != NULL)
{
PWARN("%s", msg);
g_free(msg);
}
}
LEAVE (" sess=%p book-id=%s",
session, book_id ? book_id : "(null)");
}
/* ====================================================================== */
void
qof_session_load (QofSession *session,
QofPercentageFunc percentage_func)
{
QofBook *newbook, *oldbook;
QofBackend *be;
QofBackendError err;
if (!session) return;
if (!session->book_id) return;
ENTER ("sess=%p book_id=%s", session, session->book_id
? session->book_id : "(null)");
/* At this point, we should are supposed to have a valid book
* id and a lock on the file. */
oldbook = session->book;
/* XXX why are we creating a book here? I think the books
* need to be handled by the backend ... especially since
* the backend may need to load multiple books ... XXX. FIXME.
*/
newbook = qof_book_new();
session->book = newbook;
PINFO ("new book=%p", newbook);
qof_session_clear_error (session);
/* This code should be sufficient to initialize *any* backend,
* whether http, postgres, or anything else that might come along.
* Basically, the idea is that by now, a backend has already been
* created & set up. At this point, we only need to get the
* top-level account group out of the backend, and that is a
* generic, backend-independent operation.
*/
be = session->backend;
qof_book_set_backend(newbook, be);
/* Starting the session should result in a bunch of accounts
* and currencies being downloaded, but probably no transactions;
* The GUI will need to do a query for that.
*/
if (be)
{
be->percentage = percentage_func;
if (be->load)
{
be->load (be, newbook, LOAD_TYPE_INITIAL_LOAD);
qof_session_push_error (session, qof_backend_get_error(be), NULL);
}
}
/* XXX if the load fails, then we try to restore the old set of books;
* however, we don't undo the session id (the URL). Thus if the
* user attempts to save after a failed load, they weill be trying to
* save to some bogus URL. This is wrong. XXX FIXME.
*/
err = qof_session_get_error(session);
if ((err != ERR_BACKEND_NO_ERR) &&
(err != ERR_FILEIO_FILE_TOO_OLD) &&
(err != ERR_FILEIO_NO_ENCODING) &&
(err != ERR_SQL_DB_TOO_OLD) &&
(err != ERR_SQL_DB_TOO_NEW))
{
/* Something broke, put back the old stuff */
qof_book_set_backend (newbook, NULL);
qof_book_destroy (newbook);
session->book = oldbook;
LEAVE("error from backend %d", qof_session_get_error(session));
return;
}
qof_book_set_backend (oldbook, NULL);
qof_book_destroy (oldbook);
LEAVE ("sess = %p, book_id=%s", session, session->book_id
? session->book_id : "(null)");
}
/* ====================================================================== */
static gboolean
save_error_handler(QofBackend *be, QofSession *session)
{
int err;
err = qof_backend_get_error(be);
if (ERR_BACKEND_NO_ERR != err)
{
qof_session_push_error (session, err, NULL);
return TRUE;
}
return FALSE;
}
void
qof_session_save (QofSession *session,
QofPercentageFunc percentage_func)
{
QofBackend *be;
gboolean partial, change_backend;
QofBackendProvider *prov;
GSList *p;
QofBook *book;
int err;
gint num;
char *msg = NULL;
char *book_id;
if (!session) return;
if (!g_atomic_int_dec_and_test(&session->lock))
goto leave;
ENTER ("sess=%p book_id=%s",
session, session->book_id ? session->book_id : "(null)");
/* Partial book handling. */
book = qof_session_get_book(session);
partial = (gboolean)GPOINTER_TO_INT(qof_book_get_data(book, PARTIAL_QOFBOOK));
change_backend = FALSE;
msg = g_strdup_printf(" ");
book_id = g_strdup(session->book_id);
if (partial == TRUE)
{
if (session->backend && session->backend->provider)
{
prov = session->backend->provider;
if (TRUE == prov->partial_book_supported)
{
/* if current backend supports partial, leave alone. */
change_backend = FALSE;
}
else
{
change_backend = TRUE;
}
}
/* If provider is undefined, assume partial not supported. */
else
{
change_backend = TRUE;
}
}
if (change_backend == TRUE)
{
qof_session_destroy_backend(session);
if (!qof_providers_initialized)
{
qof_providers_initialized = TRUE;
}
p = provider_list;
while (p != NULL)
{
prov = p->data;
if (TRUE == prov->partial_book_supported)
{
/** \todo check the access_method too, not in scope here, yet. */
/* if((TRUE == prov->partial_book_supported) &&
(0 == g_ascii_strcasecmp (access_method, prov->access_method)))
{*/
if (NULL == prov->backend_new) continue;
/* Use the providers creation callback */
session->backend = (*(prov->backend_new))();
session->backend->provider = prov;
if (session->backend->session_begin)
{
/* Call begin - backend has been changed,
so make sure a file can be written,
use ignore_lock and force create */
g_free(session->book_id);
session->book_id = NULL;
(session->backend->session_begin)(session->backend, session,
book_id, TRUE, TRUE, TRUE);
PINFO("Done running session_begin on changed backend");
err = qof_backend_get_error(session->backend);
msg = qof_backend_get_message(session->backend);
if (err != ERR_BACKEND_NO_ERR)
{
g_free(session->book_id);
session->book_id = NULL;
qof_session_push_error (session, err, msg);
LEAVE("changed backend error %d", err);
goto leave;
}
if (msg != NULL)
{
PWARN("%s", msg);
g_free(msg);
msg = NULL;
}
}
/* Tell the book about the backend that they'll be using. */
qof_book_set_backend (session->book, session->backend);
p = NULL;
}
if (p)
{
p = p->next;
}
}
if (!session->backend)
{
if (ERR_BACKEND_NO_ERR != qof_session_get_error(session))
{
msg = g_strdup_printf("failed to load backend");
qof_session_push_error(session, ERR_BACKEND_NO_HANDLER, msg);
}
goto leave;
}
}
/* If there is a backend, and the backend is reachable
* (i.e. we can communicate with it), then synchronize with
* the backend. If we cannot contact the backend (e.g.
* because we've gone offline, the network has crashed, etc.)
* then give the user the option to save to the local disk.
*
* hack alert -- FIXME -- XXX the code below no longer
* does what the words above say. This needs fixing.
*/
be = session->backend;
if (be)
{
/* if invoked as SaveAs(), then backend not yet set */
qof_book_set_backend (session->book, be);
be->percentage = percentage_func;
if (be->sync)
{
(be->sync)(be, session->book);
if (save_error_handler(be, session))
goto leave;
}
/* If we got to here, then the backend saved everything
* just fine, and we are done. So return. */
/* Return the book_id to previous value. */
qof_session_clear_error (session);
LEAVE("Success");
goto leave;
}
else
{
if (ERR_BACKEND_NO_ERR != qof_session_get_error(session))
{
msg = g_strdup_printf("failed to load backend");
qof_session_push_error(session, ERR_BACKEND_NO_HANDLER, msg);
}
}
LEAVE("error -- No backend!");
leave:
if (msg != NULL) g_free(msg);
g_atomic_int_inc(&session->lock);
return;
}
void
qof_session_safe_save(QofSession *session, QofPercentageFunc percentage_func)
{
QofBackend *be = session->backend;
gint err;
char *msg = NULL;
g_return_if_fail( be != NULL );
g_return_if_fail( be->safe_sync != NULL );
be->percentage = percentage_func;
(be->safe_sync)( be, qof_session_get_book( session ));
err = qof_backend_get_error(session->backend);
msg = qof_backend_get_message(session->backend);
if (err != ERR_BACKEND_NO_ERR)
{
g_free(session->book_id);
session->book_id = NULL;
qof_session_push_error (session, err, msg);
}
}
/* ====================================================================== */
gboolean
qof_session_save_in_progress(const QofSession *session)
{
return (session && g_atomic_int_get(&session->lock) != 1);
}
void
qof_session_end (QofSession *session)
{
if (!session) return;
ENTER ("sess=%p book_id=%s", session, session->book_id
? session->book_id : "(null)");
/* close down the backend first */
if (session->backend && session->backend->session_end)
{
(session->backend->session_end)(session->backend);
}
qof_session_clear_error (session);
g_free (session->book_id);
session->book_id = NULL;
LEAVE ("sess=%p book_id=%s", session, session->book_id
? session->book_id : "(null)");
}
void
qof_session_destroy (QofSession *session)
{
if (!session) return;
ENTER ("sess=%p book_id=%s", session, session->book_id
? session->book_id : "(null)");
qof_session_end (session);
/* destroy the backend */
qof_session_destroy_backend(session);
qof_book_set_backend (session->book, NULL);
qof_book_destroy (session->book);
session->book = NULL;
g_free (session);
LEAVE ("sess=%p", session);
}
/* ====================================================================== */
/* this call is weird. */
void
qof_session_swap_data (QofSession *session_1, QofSession *session_2)
{
QofBook *book_1, *book_2;
if (session_1 == session_2) return;
if (!session_1 || !session_2) return;
ENTER ("sess1=%p sess2=%p", session_1, session_2);
book_1 = session_1->book;
book_2 = session_2->book;
session_1->book = book_2;
session_2->book = book_1;
qof_book_set_backend (book_1, session_2->backend);
qof_book_set_backend (book_2, session_1->backend);
LEAVE (" ");
}
/* ====================================================================== */
gboolean
qof_session_events_pending (const QofSession *session)
{
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)
{
if (!session) return FALSE;
if (!session->backend) return FALSE;
if (!session->backend->process_events) return FALSE;
return session->backend->process_events (session->backend);
}
/* XXX This exports the list of accounts to a file. It does not
* export any transactions. It's a place-holder until full
* book-closing is implemented.
*/
gboolean
qof_session_export (QofSession *tmp_session,
QofSession *real_session,
QofPercentageFunc percentage_func)
{
QofBook *book, *book2;
QofBackend *be;
if ((!tmp_session) || (!real_session)) return FALSE;
book = qof_session_get_book (real_session);
ENTER ("tmp_session=%p real_session=%p book=%p book_id=%s",
tmp_session, real_session, book,
qof_session_get_url(tmp_session)
? qof_session_get_url(tmp_session) : "(null)");
/* There must be a backend or else. (It should always be the file
* backend too.)
*/
book2 = qof_session_get_book(tmp_session);
be = qof_book_get_backend(book2);
if (!be)
return FALSE;
be->percentage = percentage_func;
if (be->export_fn)
{
int err;
(be->export_fn)(be, book);
err = qof_backend_get_error(be);
if (ERR_BACKEND_NO_ERR != err)
{
return FALSE;
}
}
return TRUE;
}
/* =================== END OF FILE ====================================== */