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-2010, 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 "m_mode_base.h"
00027 #include "socket.h"
00028 #include "record.h"
00029 
00030 namespace Barry {
00031 
00032 // forward declarations
00033 class Parser;
00034 class Builder;
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 : public Mode
00055 {
00056 public:
00057         enum CommandType { Unknown, DatabaseAccess };
00058 
00059 private:
00060         CommandTable m_commandTable;
00061         DatabaseDatabase m_dbdb;
00062 
00063         // external objects (optional, can be null)
00064         const IConverter *m_ic;
00065 
00066 protected:
00067         void LoadCommandTable();
00068         void LoadDBDB();
00069 
00070         //////////////////////////////////
00071         // overrides
00072 
00073         virtual void OnOpen();
00074 
00075 public:
00076         Desktop(Controller &con);
00077         Desktop(Controller &con, const IConverter &ic);
00078         ~Desktop();
00079 
00080         //////////////////////////////////
00081         // meta access
00082 
00083         /// Returns DatabaseDatabase object for this connection.
00084         /// Must call Open() first, which loads the DBDB.
00085         const DatabaseDatabase& GetDBDB() const { return m_dbdb; }
00086         unsigned int GetDBID(const std::string &name) const;
00087         unsigned int GetDBCommand(CommandType ct);
00088 
00089         void SetIConverter(const IConverter &ic);
00090 
00091         //////////////////////////////////
00092         // Desktop mode - database specific
00093 
00094         // dirty flag related functions, for sync operations
00095         void GetRecordStateTable(unsigned int dbId, RecordStateTable &result);
00096         void AddRecord(unsigned int dbId, Builder &build); // RecordId is
00097                 // retrieved from build, and duplicate IDs are allowed,
00098                 // but *not* recommended!
00099         void GetRecord(unsigned int dbId, unsigned int stateTableIndex, Parser &parser);
00100         void SetRecord(unsigned int dbId, unsigned int stateTableIndex, Builder &build);
00101         void ClearDirty(unsigned int dbId, unsigned int stateTableIndex);
00102         void DeleteRecord(unsigned int dbId, unsigned int stateTableIndex);
00103 
00104         // pure load/save operations
00105         void LoadDatabase(unsigned int dbId, Parser &parser);
00106         void ClearDatabase(unsigned int dbId);
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 29 Mar 2010 for Barry by  doxygen 1.6.1