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-2009, 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 class IConverter;
00036 
00037 namespace Mode {
00038 
00039 //
00040 // Desktop class
00041 //
00042 /// The main interface class to the device databases.
00043 ///
00044 /// To use this class, use the following steps:
00045 ///
00046 ///     - Create a Controller object (see Controller class for more details)
00047 ///     - Create this Mode::Desktop object, passing in the Controller
00048 ///             object during construction
00049 ///     - Call Open() to open database socket and finish constructing.
00050 ///     - Call GetDBDB() to get the device's database database
00051 ///     - Call GetDBID() to get a database ID by name
00052 ///     - Call LoadDatabase() to retrieve and store a database
00053 ///
00054 class BXEXPORT Desktop
00055 {
00056 public:
00057         enum CommandType { Unknown, DatabaseAccess };
00058 
00059 private:
00060         Controller &m_con;
00061 
00062         SocketHandle m_socket;
00063 
00064         CommandTable m_commandTable;
00065         DatabaseDatabase m_dbdb;
00066 
00067         uint16_t m_ModeSocket;                  // socket recommended by device
00068                                                 // when mode was selected
00069 
00070         // external objects (optional, can be null)
00071         const IConverter *m_ic;
00072 
00073 protected:
00074         void LoadCommandTable();
00075         void LoadDBDB();
00076 
00077 public:
00078         Desktop(Controller &con);
00079         Desktop(Controller &con, const IConverter &ic);
00080         ~Desktop();
00081 
00082         //////////////////////////////////
00083         // primary operations - required before anything else
00084 
00085         void Open(const char *password = 0);
00086         void RetryPassword(const char *password);
00087 
00088         //////////////////////////////////
00089         // meta access
00090 
00091         /// Returns DatabaseDatabase object for this connection.
00092         /// Must call Open() first, which loads the DBDB.
00093         const DatabaseDatabase& GetDBDB() const { return m_dbdb; }
00094         unsigned int GetDBID(const std::string &name) const;
00095         unsigned int GetDBCommand(CommandType ct);
00096 
00097         void SetIConverter(const IConverter &ic);
00098 
00099         //////////////////////////////////
00100         // Desktop mode - database specific
00101 
00102         // dirty flag related functions, for sync operations
00103         void GetRecordStateTable(unsigned int dbId, RecordStateTable &result);
00104         void AddRecord(unsigned int dbId, Builder &build); // RecordId is
00105                 // retrieved from build, and duplicate IDs are allowed,
00106                 // but *not* recommended!
00107         void GetRecord(unsigned int dbId, unsigned int stateTableIndex, Parser &parser);
00108         void SetRecord(unsigned int dbId, unsigned int stateTableIndex, Builder &build);
00109         void ClearDirty(unsigned int dbId, unsigned int stateTableIndex);
00110         void DeleteRecord(unsigned int dbId, unsigned int stateTableIndex);
00111 
00112         // pure load/save operations
00113         void LoadDatabase(unsigned int dbId, Parser &parser);
00114         void SaveDatabase(unsigned int dbId, Builder &builder);
00115 
00116         template <class RecordT, class StorageT> void LoadDatabaseByType(StorageT &store);
00117         template <class RecordT, class StorageT> void SaveDatabaseByType(StorageT &store);
00118 
00119         template <class StorageT> void LoadDatabaseByName(const std::string &name, StorageT &store);
00120         template <class StorageT> void SaveDatabaseByName(const std::string &name, StorageT &store);
00121 
00122         template <class RecordT> void AddRecordByType(uint32_t recordId, const RecordT &rec);
00123 
00124 };
00125 
00126 }} // namespace Barry::Mode
00127 
00128 #endif
00129 

Generated on Mon Jan 12 10:51:13 2009 for Barry by  doxygen 1.5.7.1