3 /// Mode class for the Desktop mode
7 Copyright (C) 2005-2007, 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__
31 // forward declarations
41 /// The main interface class to the device databases.
43 /// To use this class, use the following steps:
45 /// - Create a Controller object (see Controller class for more details)
46 /// - Create this Mode::Desktop object, passing in the Controller
47 /// object during construction
48 /// - Call Open() to open database socket and finish constructing.
49 /// - Call GetDBDB() to get the device's database database
50 /// - Call GetDBID() to get a database ID by name
51 /// - Call LoadDatabase() to retrieve and store a database
53 class BXEXPORT Desktop
56 enum CommandType
{ Unknown
, DatabaseAccess
};
61 SocketHandle m_socket
;
63 CommandTable m_commandTable
;
64 DatabaseDatabase m_dbdb
;
66 uint16_t m_ModeSocket
; // socket recommended by device
67 // when mode was selected
70 void LoadCommandTable();
74 Desktop(Controller
&con
);
77 //////////////////////////////////
78 // primary operations - required before anything else
80 void Open(const char *password
= 0);
81 void RetryPassword(const char *password
);
83 //////////////////////////////////
86 /// Returns DatabaseDatabase object for this connection.
87 /// Must call Open() first, which loads the DBDB.
88 const DatabaseDatabase
& GetDBDB() const { return m_dbdb
; }
89 unsigned int GetDBID(const std::string
&name
) const;
90 unsigned int GetDBCommand(CommandType ct
);
92 //////////////////////////////////
93 // Desktop mode - database specific
95 // dirty flag related functions, for sync operations
96 void GetRecordStateTable(unsigned int dbId
, RecordStateTable
&result
);
97 void AddRecord(unsigned int dbId
, Builder
&build
); // RecordId is
98 // retrieved from build, and duplicate IDs are allowed,
99 // but *not* recommended!
100 void GetRecord(unsigned int dbId
, unsigned int stateTableIndex
, Parser
&parser
);
101 void SetRecord(unsigned int dbId
, unsigned int stateTableIndex
, Builder
&build
);
102 void ClearDirty(unsigned int dbId
, unsigned int stateTableIndex
);
103 void DeleteRecord(unsigned int dbId
, unsigned int stateTableIndex
);
105 // pure load/save operations
106 void LoadDatabase(unsigned int dbId
, Parser
&parser
);
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