Add Browser Bookmark reverse documentation.
[barry.git] / src / m_desktop.h
blob6d38a27acf48780a4c1fc0c17815de05b671c9d4
1 ///
2 /// \file m_desktop.h
3 /// Mode class for the Desktop mode
4 ///
6 /*
7 Copyright (C) 2005-2009, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_M_DESKTOP_H__
23 #define __BARRY_M_DESKTOP_H__
25 #include "dll.h"
26 #include "m_mode_base.h"
27 #include "socket.h"
28 #include "record.h"
30 namespace Barry {
32 // forward declarations
33 class Parser;
34 class Builder;
35 class IConverter;
37 namespace Mode {
40 // Desktop class
42 /// The main interface class to the device databases.
43 ///
44 /// To use this class, use the following steps:
45 ///
46 /// - Create a Controller object (see Controller class for more details)
47 /// - Create this Mode::Desktop object, passing in the Controller
48 /// object during construction
49 /// - Call Open() to open database socket and finish constructing.
50 /// - Call GetDBDB() to get the device's database database
51 /// - Call GetDBID() to get a database ID by name
52 /// - Call LoadDatabase() to retrieve and store a database
53 ///
54 class BXEXPORT Desktop : public Mode
56 public:
57 enum CommandType { Unknown, DatabaseAccess };
59 private:
60 CommandTable m_commandTable;
61 DatabaseDatabase m_dbdb;
63 // external objects (optional, can be null)
64 const IConverter *m_ic;
66 protected:
67 void LoadCommandTable();
68 void LoadDBDB();
70 //////////////////////////////////
71 // overrides
73 virtual void OnOpen();
75 public:
76 Desktop(Controller &con);
77 Desktop(Controller &con, const IConverter &ic);
78 ~Desktop();
80 //////////////////////////////////
81 // meta access
83 /// Returns DatabaseDatabase object for this connection.
84 /// Must call Open() first, which loads the DBDB.
85 const DatabaseDatabase& GetDBDB() const { return m_dbdb; }
86 unsigned int GetDBID(const std::string &name) const;
87 unsigned int GetDBCommand(CommandType ct);
89 void SetIConverter(const IConverter &ic);
91 //////////////////////////////////
92 // Desktop mode - database specific
94 // dirty flag related functions, for sync operations
95 void GetRecordStateTable(unsigned int dbId, RecordStateTable &result);
96 void AddRecord(unsigned int dbId, Builder &build); // RecordId is
97 // retrieved from build, and duplicate IDs are allowed,
98 // but *not* recommended!
99 void GetRecord(unsigned int dbId, unsigned int stateTableIndex, Parser &parser);
100 void SetRecord(unsigned int dbId, unsigned int stateTableIndex, Builder &build);
101 void ClearDirty(unsigned int dbId, unsigned int stateTableIndex);
102 void DeleteRecord(unsigned int dbId, unsigned int stateTableIndex);
104 // pure load/save operations
105 void LoadDatabase(unsigned int dbId, Parser &parser);
106 void ClearDatabase(unsigned int dbId);
107 void SaveDatabase(unsigned int dbId, Builder &builder);
109 template <class RecordT, class StorageT> void LoadDatabaseByType(StorageT &store);
110 template <class RecordT, class StorageT> void SaveDatabaseByType(StorageT &store);
112 template <class StorageT> void LoadDatabaseByName(const std::string &name, StorageT &store);
113 template <class StorageT> void SaveDatabaseByName(const std::string &name, StorageT &store);
115 template <class RecordT> void AddRecordByType(uint32_t recordId, const RecordT &rec);
119 }} // namespace Barry::Mode
121 #endif