00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00015 #include "nvsgcommon.h"
00016
00017 #include <vector>
00018 #include <map>
00019 #include "nvutil/Singleton.h"
00020
00021 namespace nvsg
00022 {
00023 class DALServer;
00024 class DALData;
00025
00026 typedef unsigned long HDAL;
00027 extern const HDAL HDAL_INVALID;
00028
00030
00032 class DALHost
00033 {
00034 public:
00036
00044 NVSG_API HDAL storeDeviceAbstractionLinkData(unsigned int dataID, DALData * data) const;
00045
00047
00048 NVSG_API void releaseDeviceAbstractionLinkData();
00049
00051
00054 NVSG_API bool getDeviceAbstractionLinkData(unsigned int dataID, std::vector<DALData*>& data) const;
00055
00057
00060 NVSG_API DALData * getLastRecentlyUsedDeviceAbstractionLinkData() const;
00061
00063
00065 NVSG_API void setLastRecentlyUsedDeviceAbstractionLinkData(DALData * lastRecentlyUsed) const;
00066
00067 #if !defined(DOXYGEN_IGNORE)
00068 public:
00069 DALHost();
00070 DALHost(const DALHost&);
00071 ~DALHost();
00072 private:
00073 mutable HDAL m_hDAL;
00074 mutable DALData * m_lastRecentlyUsed;
00075 #endif
00076 };
00077
00079 class DALDataCreator
00080 {
00081 public:
00082 #if !defined(DOXYGEN_IGNORE)
00083 virtual ~DALDataCreator() {}
00084 #endif
00085
00086
00093 virtual void onReleaseDAL(HDAL hDAL) {}
00094
00095 protected:
00097 DALDataCreator() {}
00098
00100
00106 NVSG_API void releaseDeviceAbstractionLinkData(HDAL hDAL, unsigned int dataID);
00107 };
00108
00110
00115 class DALData
00116 {
00117 #if !defined(DOXYGEN_IGNORE)
00118 friend class DALServer;
00119 friend class DALDataCreator;
00120 protected:
00121 virtual ~DALData();
00122 #endif
00123
00124 protected:
00126 DALData(
00127 DALDataCreator * creator
00128 , const DALHost * host
00129 );
00130
00132
00140 virtual void deleteThis() { delete this; }
00141
00142 #if !defined(DOXYGEN_IGNORE)
00143 private:
00144 DALDataCreator * m_creator;
00145 const DALHost * m_host;
00146 #endif
00147 };
00148
00150 class DALServer
00151 {
00152 friend class DALDataCreator;
00153 friend class DALHost;
00154
00155 #if !defined(DOXYGEN_IGNORE)
00156 public:
00157
00158 DALServer();
00159
00160 ~DALServer();
00161 private:
00162
00163
00164
00165
00166 HDAL storeDALData(HDAL hDAL, unsigned int dataID, DALData* data);
00167
00168
00169
00170
00171
00172
00173 void releaseDALData(HDAL hDAL, DALDataCreator * creator=NULL, unsigned int dataID=0xFFFFFFFF);
00174
00175
00176
00177 bool getDALData(HDAL hDAL, unsigned int dataID, std::vector<DALData*>& data) const;
00178 private:
00179 std::map<HDAL, std::multimap<unsigned int, DALData*> > m_DALMap;
00180 std::vector<HDAL> m_freeHDALs;
00181 HDAL m_hDALNext;
00182 #endif
00183 };
00184
00185 #if !defined(DOXYGEN_IGNORE)
00186 typedef nvutil::Singleton<DALServer> DALS;
00187 #endif
00188
00189 inline HDAL DALHost::storeDeviceAbstractionLinkData(unsigned int dataID, DALData * data) const
00190 {
00191 m_hDAL = DALS::instance()->storeDALData(m_hDAL, dataID, data);
00192 return m_hDAL;
00193 }
00194
00195 inline void DALHost::releaseDeviceAbstractionLinkData()
00196 {
00197 if ( m_hDAL != HDAL_INVALID )
00198 {
00199 DALS::instance()->releaseDALData(m_hDAL);
00200 m_hDAL = HDAL_INVALID;
00201 m_lastRecentlyUsed = NULL;
00202 }
00203 }
00204
00205 inline bool DALHost::getDeviceAbstractionLinkData(unsigned int dataID, std::vector<DALData*>& data) const
00206 {
00207 return DALS::instance()->getDALData(m_hDAL, dataID, data);
00208 }
00209
00210 inline DALData * DALHost::getLastRecentlyUsedDeviceAbstractionLinkData() const
00211 {
00212 return m_lastRecentlyUsed;
00213 }
00214
00215 inline void DALHost::setLastRecentlyUsedDeviceAbstractionLinkData(DALData * lastRecentlyUsed) const
00216 {
00217 m_lastRecentlyUsed = lastRecentlyUsed;
00218 }
00219
00220 inline void DALDataCreator::releaseDeviceAbstractionLinkData(HDAL hDAL, unsigned int dataID)
00221 {
00222 __ASSERT(hDAL != HDAL_INVALID);
00223 DALS::instance()->releaseDALData(hDAL, this, dataID);
00224 }
00225
00226 }