m_desktop.h

Go to the documentation of this file.
00001 ///
00002 /// \file       m_desktop.h
00003 ///             Mode class for the Desktop mode
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2007, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #ifndef __BARRY_M_DESKTOP_H__
00023 #define __BARRY_M_DESKTOP_H__
00024 
00025 #include "dll.h"
00026 #include "socket.h"
00027 #include "record.h"
00028 
00029 namespace Barry {
00030 
00031 // forward declarations
00032 class Parser;
00033 class Builder;
00034 class Controller;
00035 
00036 namespace Mode {
00037 
00038 //
00039 // Desktop class
00040 //
00041 /// The main interface class to the device databases.
00042 ///
00043 /// To use this class, use the following steps:
00044 ///
00045 ///     - Create a Controller object (see Controller class for more details)
00046 ///     - Create this Mode::Desktop object, passing in the Controller
00047 ///             object during construction
00048 ///     - Call Open() to open database socket and finish constructing.
00049 ///     - Call GetDBDB() to get the device's database database
00050 ///     - Call GetDBID() to get a database ID by name
00051 ///     - Call LoadDatabase() to retrieve and store a database
00052 ///
00053 class BXEXPORT Desktop
00054 {
00055 public:
00056         enum CommandType { Unknown, DatabaseAccess };
00057 
00058 private:
00059         Controller &m_con;
00060 
00061         SocketHandle m_socket;
00062 
00063         CommandTable m_commandTable;
00064         DatabaseDatabase m_dbdb;
00065 
00066         uint16_t m_ModeSocket;                  // socket recommended by device
00067                                                 // when mode was selected
00068 
00069 protected:
00070         void LoadCommandTable();
00071         void LoadDBDB();
00072 
00073 public:
00074         Desktop(Controller &con);
00075         ~Desktop();
00076 
00077         //////////////////////////////////
00078         // primary operations - required before anything else
00079 
00080         void Open(const char *password = 0);
00081         void RetryPassword(const char *password);
00082 
00083         //////////////////////////////////
00084         // meta access
00085 
00086         /// Returns DatabaseDatabase object for this connection.
00087         /// Must call Open() first, which loads the DBDB.
00088         const DatabaseDatabase& GetDBDB() const { return m_dbdb; }
00089         unsigned int GetDBID(const std::string &name) const;
00090         unsigned int GetDBCommand(CommandType ct);
00091 
00092         //////////////////////////////////
00093         // Desktop mode - database specific
00094 
00095         // dirty flag related functions, for sync operations
00096         void GetRecordStateTable(unsigned int dbId, RecordStateTable &result);
00097         void AddRecord(unsigned int dbId, Builder &build); // RecordId is
00098                 // retrieved from build, and duplicate IDs are allowed,
00099                 // but *not* recommended!
00100         void GetRecord(unsigned int dbId, unsigned int stateTableIndex, Parser &parser);
00101         void SetRecord(unsigned int dbId, unsigned int stateTableIndex, Builder &build);
00102         void ClearDirty(unsigned int dbId, unsigned int stateTableIndex);
00103         void DeleteRecord(unsigned int dbId, unsigned int stateTableIndex);
00104 
00105         // pure load/save operations
00106         void LoadDatabase(unsigned int dbId, Parser &parser);
00107         void SaveDatabase(unsigned int dbId, Builder &builder);
00108 
00109         template <class RecordT, class StorageT> void LoadDatabaseByType(StorageT &store);
00110         template <class RecordT, class StorageT> void SaveDatabaseByType(StorageT &store);
00111 
00112         template <class StorageT> void LoadDatabaseByName(const std::string &name, StorageT &store);
00113         template <class StorageT> void SaveDatabaseByName(const std::string &name, StorageT &store);
00114 
00115         template <class RecordT> void AddRecordByType(uint32_t recordId, const RecordT &rec);
00116 
00117 };
00118 
00119 }} // namespace Barry::Mode
00120 
00121 #endif
00122 

Generated on Wed Sep 24 21:27:32 2008 for Barry by  doxygen 1.5.1