GnuCash c935c2f+
Loading...
Searching...
No Matches
qofsession.hpp
1/********************************************************************\
2 * qofsession.hpp -- declarations for QOF sessions. *
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\********************************************************************/
22
23/*
24 * HISTORY:
25 * Copyright (c) 2001 Linux Developers Group
26 * Copyright (c) 1998-2003 Linas Vepstas <linas@linas.org>
27 */
28
29#ifndef QOF_SESSION_P_H
30#define QOF_SESSION_P_H
31
32#include "qofbook.h"
33#include "qofsession.h"
34#include <utility>
35#include <string>
36
38{
39 QofSessionImpl (QofBook* book = nullptr) noexcept;
40 /* Ends the current session, destroys the backend, and destroys the book. */
41 ~QofSessionImpl () noexcept;
42
44 void begin (const char* new_uri, SessionOpenMode mode) noexcept;
45
47 void swap_books (QofSessionImpl &) noexcept;
48 void ensure_all_data_loaded () noexcept;
49 void load (QofPercentageFunc) noexcept;
50 void save (QofPercentageFunc) noexcept;
51 void safe_save (QofPercentageFunc) noexcept;
52 bool save_in_progress () const noexcept;
53 bool export_session (QofSessionImpl & real_session, QofPercentageFunc) noexcept;
54
55 bool events_pending () const noexcept;
56 bool process_events () const noexcept;
57
58 void clear_error () noexcept;
59 QofBackendError pop_error () noexcept;
60
65 std::string const & get_uri () const noexcept;
70 QofBackendError get_error () noexcept;
71 const std::string& get_error_message () const noexcept;
72 QofBook * get_book () const noexcept;
73 QofBackend * get_backend () const noexcept;
74 const std::string& get_file_path () const noexcept;
75 bool is_saving () const noexcept;
76
80 void end () noexcept;
81 void destroy_backend () noexcept;
82
83private:
84 void push_error (QofBackendError const err, std::string message) noexcept;
85
86 void load_backend (std::string access_method) noexcept;
87
88 /* The backend. We store this during startup to avoid having to create a
89 * book just to hold it.
90 */
91 QofBackend* m_backend;
92 /* A book holds pointers to the various types of datasets.
93 * A session has exactly one book. */
94 QofBook * m_book;
95 /* The requested URI, such as
96 * file://some/where, or sql:server.host.com:555
97 */
98 std::string m_uri;
99
100 bool m_saving;
101 bool m_creating;
102
103 /* If any book subroutine failed, this records the failure reason
104 * (file not found, etc).
105 * This is a 'stack' that is one deep. (Should be deeper ??)
106 * FIXME: Each backend has its own error stack. The session
107 * and the backends should all be using (or making it look like)
108 * there is only one stack.
109 */
110 QofBackendError m_last_err;
111 std::string m_error_message;
112
113 /* These functions support the old testing infrastructure and should
114 * be removed when they are no longer necessary.*/
115 friend void qof_session_load_backend (QofSession *, const char *);
116 friend char const * qof_session_get_uri (QofSession *);
117 friend void qof_session_set_uri (QofSession *, char const *);
118};
119
120typedef struct qof_instance_copy_data
121{
122 QofInstance *from;
123 QofInstance *to;
124 QofParam *param;
125 GList *referenceList;
126 GSList *param_list;
127 QofSession *new_session;
128 gboolean error;
130
131#ifdef __cplusplus
132extern "C"
133{
134#endif
135
136QofBackend * qof_session_get_backend (const QofSession *session);
137
138#ifdef __cplusplus
139}
140#endif
141
142#endif
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition qofbackend.h:58
QofBackend * qof_session_get_backend(const QofSession *session)
Returns the qof session's backend.
SessionOpenMode
Mode for opening sessions.
Definition qofsession.h:121
void(* QofPercentageFunc)(const char *message, double percent)
The qof_session_load() method causes the QofBook to be made ready to to use with this URL/datastore.
Definition qofsession.h:199
Encapsulate all the information about a dataset.
Encapsulates a connection to a backend (persistent store)
QofBook reference.
Definition qofbook-p.hpp:47
void swap_books(QofSessionImpl &) noexcept
Swap books with another session.
void begin(const char *new_uri, SessionOpenMode mode) noexcept
Begin this session.
QofBackendError get_error() noexcept
Returns and clears the local cached error.
std::string const & get_uri() const noexcept
We return by reference so that a pointer to the data of the string lives long enough to make it back ...
void end() noexcept
Terminates the current backend.