GnuCash  5.6-150-g038405b370+
gnc-xml-backend.hpp
1 /********************************************************************
2  * gnc-xml-backend.hpp: Declare XML file backend. *
3  * Copyright 2016 John Ralls <jralls@ceridwen.us> *
4  * *
5  * This program is distributed in the hope that it will be useful, *
6  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
7  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
8  * GNU General Public License for more details. *
9  * *
10  * You should have received a copy of the GNU General Public License*
11  * along with this program; if not, contact: *
12  * *
13  * Free Software Foundation Voice: +1-617-542-5942 *
14  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
15  * Boston, MA 02110-1301, USA gnu@gnu.org *
16 \********************************************************************/
17 
18 #ifndef __GNC_XML_BACKEND_HPP__
19 #define __GNC_XML_BACKEND_HPP__
20 
21 #include <qof.h>
22 
23 #include <string>
24 #include <qof-backend.hpp>
25 
26 class GncXmlBackend : public QofBackend
27 {
28 public:
29  GncXmlBackend() = default;
30  GncXmlBackend(const GncXmlBackend&) = delete;
31  GncXmlBackend operator=(const GncXmlBackend&) = delete;
32  GncXmlBackend(const GncXmlBackend&&) = delete;
33  GncXmlBackend operator=(const GncXmlBackend&&) = delete;
34  ~GncXmlBackend();
35  void session_begin(QofSession* session, const char* new_uri,
36  SessionOpenMode mode) override;
37  void session_end() override;
38  void load(QofBook* book, QofBackendLoadType loadType) override;
39  /* The XML backend isn't able to do anything with individual instances. */
40  void export_coa(QofBook*) override;
41  void sync(QofBook* book) override;
42  void safe_sync(QofBook* book) override { sync(book); } // XML sync is inherently safe.
43  void commit(QofInstance* instance) override;
44  const char * get_filename() { return m_fullpath.c_str(); }
45  QofBook* get_book() { return m_book; }
46 
47 private:
48  bool save_may_clobber_data();
49  void get_file_lock(SessionOpenMode);
50  bool link_or_make_backup(const std::string& orig, const std::string& bkup);
51  bool backup_file();
52  bool write_to_file(bool make_backup);
53  void remove_old_files();
54  void write_accounts(QofBook* book);
55  bool check_path(const char* fullpath, bool create);
56 
57  std::string m_dirname;
58  std::string m_lockfile;
59  std::string m_linkfile;
60  int m_lockfd = -1;
61 
62  QofBook* m_book = nullptr; /* The primary, main open book */
63 };
64 #endif // __GNC_XML_BACKEND_HPP__
void sync(QofBook *book) override
Synchronizes the engine contents to the backend.
void export_coa(QofBook *) override
Extract the chart of accounts from the current database and create a new database with it...
void load(QofBook *book, QofBackendLoadType loadType) override
Load the minimal set of application data needed for the application to be operable at initial startup...
void safe_sync(QofBook *book) override
Perform a sync in a way that prevents data loss on a DBI backend.
void commit(QofInstance *instance) override
Commits the changes from the engine to the backend data storage.
std::string m_fullpath
Each backend resolves a fully-qualified file path.
void session_begin(QofSession *session, const char *new_uri, SessionOpenMode mode) override
Open the file or connect to the server.
SessionOpenMode
Mode for opening sessions.
Definition: qofsession.h:120