qofbook.h

Go to the documentation of this file.
00001 /********************************************************************\
00002  * qofbook.h -- Encapsulate all the information about a dataset.    *
00003  * This program is free software; you can redistribute it and/or    *
00004  * modify it under the terms of the GNU General Public License as   *
00005  * published by the Free Software Foundation; either version 2 of   *
00006  * the License, or (at your option) any later version.              *
00007  *                                                                  *
00008  * This program is distributed in the hope that it will be useful,  *
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00011  * GNU General Public License for more details.                     *
00012  *                                                                  *
00013  * You should have received a copy of the GNU General Public License*
00014  * along with this program; if not, contact:                        *
00015  *                                                                  *
00016  * Free Software Foundation           Voice:  +1-617-542-5942       *
00017  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00018  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00019  *                                                                  *
00020 \********************************************************************/
00040 #ifndef QOF_BOOK_H
00041 #define QOF_BOOK_H
00042 
00043 typedef struct _QofBookClass  QofBookClass;
00044 
00045 #include "qofid.h"
00046 #include "kvp_frame.h"
00047 #include "qofinstance.h"
00048 
00049 /* --- type macros --- */
00050 #define QOF_TYPE_BOOK            (qof_book_get_type ())
00051 #define QOF_BOOK(o)              \
00052      (G_TYPE_CHECK_INSTANCE_CAST ((o), QOF_TYPE_BOOK, QofBook))
00053 #define QOF_BOOK_CLASS(k)        \
00054      (G_TYPE_CHECK_CLASS_CAST((k), QOF_TYPE_BOOK, QofBookClass))
00055 #define QOF_IS_BOOK(o)           \
00056      (G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_BOOK))
00057 #define QOF_IS_BOOK_CLASS(k)     \
00058      (G_TYPE_CHECK_CLASS_TYPE ((k), QOF_TYPE_BOOK))
00059 #define QOF_BOOK_GET_CLASS(o)    \
00060      (G_TYPE_INSTANCE_GET_CLASS ((o), QOF_TYPE_BOOK, QofBookClass))
00061 
00062 typedef void (*QofBookDirtyCB) (QofBook *, gboolean dirty, gpointer user_data);
00063 
00064 /* Book structure */
00065 struct _QofBook
00066 {
00067   QofInstance   inst;     /* Unique guid for this book. */
00068 
00069   /* The time when the book was first dirtied.  This is a secondary
00070    * indicator. It should only be used when inst.dirty is TRUE. */
00071   time_t dirty_time;
00072 
00073   /* This callback function is called any time the book dirty flag
00074    * changes state. Both clean->dirty and dirty->clean transitions
00075    * trigger a callback. */
00076   QofBookDirtyCB dirty_cb;
00077 
00078   /* This is the user supplied data that is returned in the dirty
00079    * callback function.*/
00080   gpointer dirty_data;
00081 
00082   /* The entity table associates the GUIDs of all the objects
00083    * belonging to this book, with their pointers to the respective
00084    * objects.  This allows a lookup of objects based on thier guid.
00085    */
00086   GHashTable * hash_of_collections;
00087 
00088   /* In order to store arbitrary data, for extensibility, add a table
00089    * that will be used to hold arbitrary pointers.
00090    */
00091   GHashTable *data_tables;
00092 
00093   /* Hash table of destroy callbacks for the data table. */
00094   GHashTable *data_table_finalizers;
00095 
00096   /* state flag: 'y' means 'open for editing',
00097    * 'n' means 'book is closed'
00098    * xxxxx shouldn't this be replaced by the instance editlevel ???
00099    */
00100   char book_open;
00101 
00102   /* a flag denoting whether the book is closing down, used to
00103    * help the QOF objects shut down cleanly without maintaining
00104    * internal consistency.
00105    * XXX shouldn't this be replaced by instance->do_free ???
00106    */
00107   gboolean shutting_down;
00108 
00109   /* version number, used for tracking multiuser updates */
00110   gint32  version;
00111 
00112   /* To be technically correct, backends belong to sessions and
00113    * not books.  So the pointer below "really shouldn't be here",
00114    * except that it provides a nice convenience, avoiding a lookup
00115    * from the session.  Better solutions welcome ... */
00116   QofBackend *backend;
00117 };
00118 
00119 struct _QofBookClass
00120 {
00121    QofInstanceClass parent_class;
00122 };
00123 
00124 GType qof_book_get_type(void);
00125 
00132 #define QOF_BOOK_LOOKUP_ENTITY(book,guid,e_type,c_type) ({  \
00133   QofInstance *val = NULL;                                    \
00134   if (guid && book) {                                       \
00135     QofCollection *col;                                     \
00136     col = qof_book_get_collection (book, e_type);           \
00137     val = qof_collection_lookup_entity (col, guid);         \
00138   }                                                         \
00139   (c_type *) val;                                           \
00140 })
00141 
00143 typedef GList                 QofBookList;
00144 
00145 typedef void (*QofBookFinalCB) (QofBook *, gpointer key, gpointer user_data);
00146 
00148 gboolean qof_book_register (void);
00149 
00152 QofBook * qof_book_new (void);
00153 
00156 void      qof_book_destroy (QofBook *book);
00157 
00163 void qof_book_mark_closed (QofBook *book);
00164 
00178 QofCollection  * qof_book_get_collection (const QofBook *, QofIdType);
00179 
00181 typedef void (*QofCollectionForeachCB) (QofCollection *, gpointer user_data);
00182 void qof_book_foreach_collection (const QofBook *, QofCollectionForeachCB, gpointer);
00183 
00191 #define qof_book_get_slots(book) qof_instance_get_slots(QOF_INSTANCE(book))
00192 
00203 void qof_book_set_data (QofBook *book, const gchar *key, gpointer data);
00204 
00209 void qof_book_set_data_fin (QofBook *book, const gchar *key, gpointer data, 
00210                             QofBookFinalCB);
00211 
00213 gpointer qof_book_get_data (const QofBook *book, const gchar *key);
00214 
00216 gboolean qof_book_shutting_down (const QofBook *book);
00217 
00226 gboolean qof_book_not_saved (const QofBook *book);
00227 
00233 void qof_book_mark_saved(QofBook *book);
00234 
00239 void qof_book_mark_dirty(QofBook *book);
00240 
00245 void qof_book_print_dirty (const QofBook *book);
00246 
00248 time_t qof_book_get_dirty_time(const QofBook *book);
00249 
00253 void qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data);
00254 
00257 void qof_book_kvp_changed (QofBook *book);
00258 
00262 gboolean qof_book_equal (const QofBook *book_1, const QofBook *book_2);
00263 
00267 gint64 qof_book_get_counter (const QofBook *book, const char *counter_name);
00268 
00270 #define qof_book_get_guid(X) qof_entity_get_guid (QOF_INSTANCE(X))
00271 
00272 #endif /* QOF_BOOK_H */
00273 

Generated on Mon Sep 8 05:04:19 2008 for GnuCash by  doxygen 1.5.2