GnuCash  5.6-150-g038405b370+
qofbook-p.hpp
1 /********************************************************************\
2  * qof-book-p.h -- private functions for QOF books. *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License*
15  * along with this program; if not, contact: *
16  * *
17  * Free Software Foundation Voice: +1-617-542-5942 *
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19  * Boston, MA 02110-1301, USA gnu@gnu.org *
20  * *
21 \********************************************************************/
29 /*
30  * HISTORY:
31  * Created 2001 by Rob Browning
32  * Copyright (c) 2001 Rob Browning
33  * Copyright (c) 2001,2003 Linas Vepstas <linas@linas.org>
34  */
35 
36 #ifndef QOF_BOOK_P_H
37 #define QOF_BOOK_P_H
38 
39 #include "qofbackend.h"
40 #include "qofbook.h"
41 #include "qofid.h"
42 #include "qofid-p.h"
43 #include "qofinstance-p.h"
44 
45 
46 struct QofBook
47 {
48  QofInstance inst; /* Unique guid for this book. */
49 
50  /* Boolean indicates that the session is dirty -- that is, it has
51  * not yet been written out to disk after the last time the
52  * backend ran commit_edit(). This is distinct from the inherited
53  * QofInstance::dirty, which indicates that some persistent
54  * property of the book object itself has been edited and not
55  * committed. Some backends write data out as part of
56  * commit_edit() and so don't use this flag.
57  */
58  gboolean session_dirty;
59 
60  /* The time when the book was first dirtied. This is a secondary
61  * indicator. It should only be used when session_saved is FALSE. */
62  time64 dirty_time;
63 
64  /* This callback function is called any time the book dirty flag
65  * changes state. Both clean->dirty and dirty->clean transitions
66  * trigger a callback. */
67  QofBookDirtyCB dirty_cb;
68 
69  /* This is the user supplied data that is returned in the dirty
70  * callback function.*/
71  gpointer dirty_data;
72 
73  /* The entity table associates the GUIDs of all the objects
74  * belonging to this book, with their pointers to the respective
75  * objects. This allows a lookup of objects based on their guid.
76  */
77  GHashTable * hash_of_collections;
78 
79  /* In order to store arbitrary data, for extensibility, add a table
80  * that will be used to hold arbitrary pointers.
81  */
82  GHashTable *data_tables;
83 
84  /* Hash table of destroy callbacks for the data table. */
85  GHashTable *data_table_finalizers;
86 
87  /* Boolean indicates whether book is safe to write to (true means
88  * that it isn't). The usual reason will be a database version
89  * mismatch with the running instance of Gnucash.
90  */
91  gboolean read_only;
92 
93  /* state flag: 'y' means 'open for editing',
94  * 'n' means 'book is closed'
95  * xxxxx shouldn't this be replaced by the instance editlevel ???
96  */
97  char book_open;
98 
99  /* a flag denoting whether the book is closing down, used to
100  * help the QOF objects shut down cleanly without maintaining
101  * internal consistency.
102  * XXX shouldn't this be replaced by instance->do_free ???
103  */
104  gboolean shutting_down;
105 
106  /* version number, used for tracking multiuser updates */
107  gint32 version;
108 
109  /* To be technically correct, backends belong to sessions and
110  * not books. So the pointer below "really shouldn't be here",
111  * except that it provides a nice convenience, avoiding a lookup
112  * from the session. Better solutions welcome ... */
113  QofBackend *backend;
114 
115  /* A cached value of the OPTION_NAME_NUM_FIELD_SOURCE option value
116  * because it is queried quite a lot, so we want to avoid a KVP
117  * lookup on each query */
118  gboolean cached_num_field_source;
119  /* Whether the above cached value is valid. */
120  gboolean cached_num_field_source_isvalid;
121 
122  /* A cahed value of the "autoreadonly-days" option value because
123  * it is queried quite a lot, so we want to avoid a KVP lookup on
124  * each query */
125  gint cached_num_days_autoreadonly;
126  /* Whether the above cached value is valid. */
127  gboolean cached_num_days_autoreadonly_isvalid;
128 };
129 
130 
131 /* Structure for accessing static functions for testing */
132 typedef struct
133 {
134  gboolean (*get_session_dirty)(const QofBook*);
135  gboolean (*get_read_only)(const QofBook*);
136  QofBookDirtyCB (*get_dirty_cb)(const QofBook*);
137  void (*set_shutting_down)(QofBook*, gboolean);
138  gpointer (*get_dirty_data)(const QofBook*);
139  GHashTable* (*get_collections)(const QofBook*);
140  GHashTable* (*get_data_tables)(const QofBook*);
141  GHashTable* (*get_data_table_finalizers)(const QofBook*);
142  char (*get_book_open)(const QofBook*);
143  int (*get_version)(const QofBook*);
145 
146 QofBookTestFunctions* _utest_qofbook_fill_functions (void);
147 
148 /*
149  * qof_book_set_backend() is used by backends to
150  * initialize the pointers in the book structure to
151  * something that contains actual data. These routines
152  * should not be used otherwise. (Its somewhat questionable
153  * if the backends should even be doing this much, but for
154  * backwards compatibility, we leave these here.)
155  */
156 void qof_book_set_backend (QofBook *book, QofBackend *be);
157 
158 /* Register books with the engine */
159 gboolean qof_book_register (void);
160 
169 gchar *qof_book_normalize_counter_format_internal(const gchar *p,
170  const gchar* gint64_format, gchar **err_msg);
171 
176 void qof_book_print_dirty (const QofBook *book);
177 
178 /* @} */
179 /* @} */
180 /* @} */
181 
182 #endif /* QOF_BOOK_P_H */
API for data storage Backend.
QOF entity type identification system.
gchar * qof_book_normalize_counter_format_internal(const gchar *p, const gchar *gint64_format, gchar **err_msg)
Validate a counter format string with a given format specifier.
Definition: qofbook.cpp:785
Encapsulate all the information about a dataset.
QofBook reference.
Definition: qofbook-p.hpp:46
void qof_book_print_dirty(const QofBook *book)
This debugging function can be used to traverse the book structure and all subsidiary structures...
Definition: qofbook.cpp:411
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87