00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if defined(_MSC_VER)
00023 #pragma warning ( disable : 4786 )
00024 #endif
00025
00026 #include "freSessionAccessor.h"
00027 #include "freExceptions.h"
00028 #include "freSessionInfo.h"
00029 #include "freControllerCentral.h"
00030 #include "freIDPath.h"
00031
00032 namespace FREE
00033 {
00034
00036
00037 ValidityTag::Pointer
00038 SessionAccessor::
00039 GetValidityTag(const IDPath& path, SessionComponentCache* pComponentCache)
00040 {
00041 if (!(path.IsMediaSelection()||path.IsParameterSelection()))
00042 throwStaticExceptionMacro("IDPath selects no media or parameter: "<<path.ToStr()<<". Cannot retrieve validity tag.");
00043 if (!pComponentCache) throwStaticExceptionMacro("Passed component cache is NULL.");
00044
00045 SessionComponentCache* pSpecifiedCache = pComponentCache->GetCacheByIDPath(path);
00046
00047 if (!pSpecifiedCache) throwStaticExceptionMacro("Unable to retrieve component cache specified by ID path ("<<path.ToStr()<<").");
00048
00049 if (!pSpecifiedCache->ControllerIsAssigned()) throwStaticExceptionMacro("Unable to retrieve validity tag, no controller assigned for component cache (ID path: "<<path.ToStr()<<").");
00050
00051 if (path.IsMediaSelection()) return pSpecifiedCache->Controller()->GetMediaValidityTag(path.GetMediaID(),pSpecifiedCache);
00052 else return pSpecifiedCache->Controller()->GetParameterValidityTag(path.GetParameterName(),pSpecifiedCache);
00053 };
00054
00055 ValidityTag::Pointer
00056 SessionAccessor::
00057 GetValidityTagRequirement(const IDPath& path, SessionComponentCache* pComponentCache)
00058 {
00059 if (!(path.IsMediaSelection()||path.IsParameterSelection()))
00060 throwStaticExceptionMacro("IDPath selects no media or parameter: "<<path.ToStr()<<". Cannot retrieve validity tag requirement.");
00061 if (!pComponentCache) throwStaticExceptionMacro("Passed component cache is NULL.");
00062
00063 SessionComponentCache* pSpecifiedCache = pComponentCache->GetCacheByIDPath(path);
00064
00065 if (!pSpecifiedCache) throwStaticExceptionMacro("Unable to retrieve component cache specified by ID path ("<<path.ToStr()<<").");
00066
00067 if (!pSpecifiedCache->ControllerIsAssigned()) throwStaticExceptionMacro("Unable to retrieve validity tag requirement, no controller assigned for component cache (ID path: "<<path.ToStr()<<").");
00068
00069 if (path.IsMediaSelection()) return pSpecifiedCache->Controller()->GetMediaValidityTagRequirement(path.GetMediaID(),pSpecifiedCache);
00070 else return pSpecifiedCache->Controller()->GetParameterValidityTagRequirement(path.GetParameterName(),pSpecifiedCache);
00071 };
00072
00073
00074
00076
00077 SessionAccessor::GenericMediaPointer
00078 SessionAccessor::
00079 GetMedia(const IDPath& mediaID, SessionInfo* pInfo)
00080 {
00081 if (!mediaID.IsMediaSelection()) throwStaticExceptionMacro("IDPath selects no media: "<<mediaID.ToStr());
00082 if (!pInfo) throwStaticExceptionMacro("Passed session info is NULL.");
00083
00084 IDPath componentPath = mediaID.GetParentComponentIDPath();
00085
00086 SessionComponentCache* pCache = pInfo->GetCacheByIDPath(componentPath);
00087
00088 if (!pCache) throwStaticExceptionMacro("Component cache does not exist, unable to get media at "<<componentPath.ToStr());
00089 if (!pCache->IsActive()) throwStaticExceptionMacro("Component cache is not active, unable to get media at "<<mediaID.ToStr());
00090
00091 return pCache->Controller()->GetMedia(mediaID.GetMediaID(), pCache, pInfo);
00092 };
00093
00094 SessionAccessor::GenericMediaPointer
00095 SessionAccessor::
00096 GetLinkedMedia(const std::string& sMediaID, SessionComponentCache* pComponentCache, SessionInfo* pInfo, bool bMissingLinkException )
00097 {
00098 if (!pComponentCache) throwStaticExceptionMacro("Passed component cache is NULL. Cannot get media "<<sMediaID);
00099 if (!pInfo) throwStaticExceptionMacro("Passed session info is NULL. Cannot get media. MediaID: "<< sMediaID <<"; Component: "<<pComponentCache->GetIDPath().ToStr());
00100
00101 GenericMediaType::Pointer smpMedia = 0;
00102
00103 ComponentMediaLink::Pointer smpLink = pComponentCache->Setup()->MediaLinks().GetElement(sMediaID);
00104 if (smpLink.IsNull())
00105 {
00106 if (bMissingLinkException) throwStaticExceptionMacro("No link for the specified media exists for the passed component cache. MediaID: "<< sMediaID <<"; Component: "<<pComponentCache->GetIDPath().ToStr());
00107 }
00108 else
00109 {
00110
00111 IDPath mediaPath = smpLink->GetSourceIDPath().TransformIDPath(pComponentCache->GetIDPath());
00112
00113 smpMedia = SessionAccessor::GetMedia(mediaPath,pInfo);
00114 }
00115
00116 return smpMedia;
00117 };
00118
00119 void
00120 SessionAccessor::
00121 SetMedia(const IDPath& mediaID, GenericMediaPointer& rMedia, SessionInfo* pInfo)
00122 {
00123 if (!mediaID.IsMediaSelection()) throwStaticExceptionMacro("IDPath selects no media: "<<mediaID.ToStr());
00124 if (!pInfo) throwStaticExceptionMacro("Passed session info is NULL.");
00125
00126 IDPath componentPath = mediaID.GetParentComponentIDPath();
00127
00128 SessionComponentCache* pCache = pInfo->GetCacheByIDPath(componentPath);
00129
00130 if (!pCache) throwStaticExceptionMacro("Component cache does not exist, unable to set media at "<<mediaID.ToStr());
00131 if (!pCache->IsActive()) throwStaticExceptionMacro("Component cache is not active, unable to set media at "<<mediaID.ToStr());
00132
00133 pCache->Controller()->SetMedia(mediaID.GetMediaID(), rMedia.GetPointer(), pCache, pInfo);
00134 };
00135
00136 std::string
00137 SessionAccessor::
00138 GetMediaControllerID(const IDPath& mediaID, SessionComponentCache* pComponentCache)
00139 {
00140 if (!mediaID.IsMediaSelection()) throwStaticExceptionMacro("IDPath selects no media: "<<mediaID.ToStr()<<". Cannot retrieve media controller id.");
00141 if (!pComponentCache) throwStaticExceptionMacro("Passed component cache is NULL.");
00142
00143 SessionComponentCache* pMediaCache = pComponentCache->GetCacheByIDPath(mediaID);
00144
00145 if (!pMediaCache) throwStaticExceptionMacro("Unable to retrieve component cache specified by media ID path ("<<mediaID.ToStr()<<").");
00146
00147 if (!pMediaCache->ControllerIsAssigned()) throwStaticExceptionMacro("Unable to retrieve media controller id, no controller assigned for component cache (ID path: "<<mediaID.ToStr()<<").");
00148
00149 return pMediaCache->Controller()->GetMediaControllerID(mediaID.GetMediaID(),pMediaCache);
00150 };
00151
00152
00154
00155 void
00156 SessionAccessor::
00157 GetParameterValueByIDPath(const SessionComponentCache* pComponentCache, const IDPath& parameterID, std::string& value, bool bGetLastValidLayer)
00158 {
00159 if (!pComponentCache) throwStaticExceptionMacro("Cannot get parameter, passed component cache is NULL.");
00160
00161 std::string sParameterName;
00162 Parameter::ValueCountType iItemPos = 0;
00163 Parameter::LayerCountType iLayer = 0;
00164
00165 DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00166
00167 Parameter::Pointer smpParameter = SessionAccessor::GetParameterByIDPath(const_cast<SessionComponentCache*>(pComponentCache), parameterID);
00168
00169
00170 if (smpParameter.IsNull()) throwStaticExceptionMacro("Cannot get parameter, return parameter pointer is NULL. ParameterName: "<<sParameterName<<"; Component: "<<pComponentCache->GetIDPath().ToStr());
00171
00172 if (iItemPos>=smpParameter->ParameterSize()) throwStaticExceptionMacro("Cannot get parameter value, value index is out of range. ParameterName: "<<sParameterName<<"; Component: "<<pComponentCache->GetIDPath().ToStr()<<"; index: "<<iItemPos<<";parameter size: "<<smpParameter->ParameterSize());
00173
00174 if (iLayer>=smpParameter->LayerCount())
00175 {
00176 if (bGetLastValidLayer) iLayer = smpParameter->LayerCount()-1;
00177 else throwStaticExceptionMacro("Cannot get parameter value, layer index is out of range. ParameterName: "<<sParameterName<<"; Component: "<<pComponentCache->GetIDPath().ToStr()<<"; index: "<<iLayer<<";parameter layer count: "<<smpParameter->LayerCount());
00178 }
00179
00180 if (smpParameter->GetParameterValue(value,iItemPos,iLayer)) throwStaticExceptionMacro("Cannot get parameter value. ParameterName: "<<sParameterName<<"; Component: "<<pComponentCache->GetIDPath().ToStr());
00181 };
00182
00183 void
00184 SessionAccessor::
00185 GetParameterValueByIDPath(const SessionComponentCache* pComponentCache, const IDPath& parameterID, bool& value, bool bGetLastValidLayer)
00186 {
00187 std::string sValue;
00188 GetParameterValueByIDPath(pComponentCache,parameterID,sValue,bGetLastValidLayer);
00189
00190 value = Convert::ToBool(sValue);
00191 };
00192
00193 void
00194 SessionAccessor::
00195 GetParameterValueByIDPath(const SessionComponentCache* pComponentCache, const IDPath& parameterID, double& value, bool bGetLastValidLayer)
00196 {
00197 std::string sValue;
00198 GetParameterValueByIDPath(pComponentCache,parameterID,sValue,bGetLastValidLayer);
00199
00200 value = Convert::ToDouble(sValue);
00201 };
00202
00203 void
00204 SessionAccessor::
00205 GetParameterValueByIDPath(const SessionComponentCache* pComponentCache, const IDPath& parameterID, int& value, bool bGetLastValidLayer)
00206 {
00207 std::string sValue;
00208 GetParameterValueByIDPath(pComponentCache,parameterID,sValue,bGetLastValidLayer);
00209
00210 value = Convert::ToInt(sValue);
00211 };
00212
00213 void
00214 SessionAccessor::
00215 GetParameterValueByIDPath(const SessionComponentCache* pComponentCache, const IDPath& parameterID, long& value, bool bGetLastValidLayer)
00216 {
00217 std::string sValue;
00218 GetParameterValueByIDPath(pComponentCache,parameterID,sValue,bGetLastValidLayer);
00219
00220 value = Convert::ToLong(sValue);
00221 };
00222
00223 void
00224 SessionAccessor::
00225 GetParameterValueByIDPath(const SessionComponentCache* pComponentCache, const IDPath& parameterID, unsigned long& value, bool bGetLastValidLayer)
00226 {
00227 std::string sValue;
00228 GetParameterValueByIDPath(pComponentCache,parameterID,sValue,bGetLastValidLayer);
00229
00230 value = Convert::ToULong(sValue);
00231 };
00232
00233 void
00234 SessionAccessor::
00235 GetParameterValue(const SessionComponentCache* pComponentCache, const std::string& sParameterName, std::string& value, const Parameter::ValueCountType& iItemPos, const Parameter::LayerCountType& iLayer, const bool& bGetLastValidLayer)
00236 {
00237 if (!pComponentCache) throwStaticExceptionMacro("Cannot get parameter value; ComponentCache is null. ParameterName: "<<sParameterName);
00238
00239 Parameter::Pointer smpParameter = SessionAccessor::GetParameter(const_cast<SessionComponentCache*>(pComponentCache), sParameterName);
00240
00241 if (smpParameter.IsNull()) throwStaticExceptionMacro("Cannot get parameter value; parameter does not exist. ParameterName: "<<sParameterName<<"; Component: "<<pComponentCache->GetIDPath().ToStr());
00242
00243 if (iItemPos>=smpParameter->ParameterSize()) throwStaticExceptionMacro("Cannot get parameter value, value index is out of range. ParameterName: "<<sParameterName<<"; Component: "<<pComponentCache->GetIDPath().ToStr()<<"; Index: "<<iItemPos<<";parameter size: "<<smpParameter->ParameterSize());
00244
00245 Parameter::LayerCountType iActualLayer = iLayer;
00246 if (iActualLayer>=smpParameter->LayerCount())
00247 {
00248 if (bGetLastValidLayer) iActualLayer = smpParameter->LayerCount()-1;
00249 else throwStaticExceptionMacro("Cannot get parameter, layer index is out of range. ParameterName: "<<sParameterName<<"; Component: "<<pComponentCache->GetIDPath().ToStr()<<"; Index: "<<iLayer<<";parameter layer count: "<<smpParameter->LayerCount());
00250 }
00251
00252 if (!smpParameter->GetParameterValue(value,iItemPos,iActualLayer)) throwStaticExceptionMacro("Cannot get parameter value. ParameterName: "<<sParameterName<<"; Component: "<<pComponentCache->GetIDPath().ToStr());
00253 };
00254
00255 void
00256 SessionAccessor::
00257 GetParameterValue(const SessionComponentCache* pComponentCache, const std::string& sParameterName, bool& value, const Parameter::ValueCountType& iItemPos, const Parameter::LayerCountType& iLayer, const bool& bGetLastValidLayer)
00258 {
00259 std::string sValue;
00260 GetParameterValue(pComponentCache,sParameterName,sValue,iItemPos,iLayer,bGetLastValidLayer);
00261
00262 value = Convert::ToBool(sValue);
00263 };
00264
00265 void
00266 SessionAccessor::
00267 GetParameterValue(const SessionComponentCache* pComponentCache, const std::string& sParameterName, double& value, const Parameter::ValueCountType& iItemPos, const Parameter::LayerCountType& iLayer, const bool& bGetLastValidLayer)
00268 {
00269 std::string sValue;
00270 GetParameterValue(pComponentCache,sParameterName,sValue,iItemPos,iLayer,bGetLastValidLayer);
00271
00272 value = Convert::ToDouble(sValue);
00273 };
00274
00275 void
00276 SessionAccessor::
00277 GetParameterValue(const SessionComponentCache* pComponentCache, const std::string& sParameterName, int& value, const Parameter::ValueCountType& iItemPos, const Parameter::LayerCountType& iLayer, const bool& bGetLastValidLayer)
00278 {
00279 std::string sValue;
00280 GetParameterValue(pComponentCache,sParameterName,sValue,iItemPos,iLayer,bGetLastValidLayer);
00281
00282 value = Convert::ToInt(sValue);
00283 };
00284
00285 void
00286 SessionAccessor::
00287 GetParameterValue(const SessionComponentCache* pComponentCache, const std::string& sParameterName, long& value, const Parameter::ValueCountType& iItemPos, const Parameter::LayerCountType& iLayer, const bool& bGetLastValidLayer)
00288 {
00289 std::string sValue;
00290 GetParameterValue(pComponentCache,sParameterName,sValue,iItemPos,iLayer,bGetLastValidLayer);
00291
00292 value = Convert::ToLong(sValue);
00293 };
00294
00295 void
00296 SessionAccessor::
00297 GetParameterValue(const SessionComponentCache* pComponentCache, const std::string& sParameterName, unsigned long& value, const Parameter::ValueCountType& iItemPos, const Parameter::LayerCountType& iLayer, const bool& bGetLastValidLayer)
00298 {
00299 std::string sValue;
00300 GetParameterValue(pComponentCache,sParameterName,sValue,iItemPos,iLayer,bGetLastValidLayer);
00301
00302 value = Convert::ToULong(sValue);
00303 };
00304
00305 Parameter::Pointer
00306 SessionAccessor::
00307 GetParameter(const SessionComponentCache* pComponentCache, const std::string& sParameterName)
00308 {
00309 if (!pComponentCache) throwStaticExceptionMacro("Cannot get parameter, passed responsible component cache is NULL. Parameter name: "<<sParameterName);
00310 if (!pComponentCache->ControllerIsAssigned()) throwStaticExceptionMacro("Cannot get parameter, cache responsible for the parameter has no controller. Parameter name: "<<sParameterName);
00311
00312 return pComponentCache->Controller()->GetParameter(pComponentCache,sParameterName);
00313 };
00314
00315 Parameter::Pointer
00316 SessionAccessor::
00317 GetParameterByIDPath(const SessionComponentCache* pComponentCache, const IDPath& parameterID)
00318 {
00319 if (!pComponentCache) throwStaticExceptionMacro("Cannot get parameter, passed component cache is NULL. IDPath: "<<parameterID.ToStr());
00320 if (!parameterID.IsParameterSelection()) throwStaticExceptionMacro("Cannot get parameter, idpath doesn't specify a parameter. IDPath: "<<parameterID.ToStr());
00321
00322 std::string sParameterName;
00323 Parameter::ValueCountType iItemPos = 0;
00324 Parameter::LayerCountType iLayer = 0;
00325
00326 DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00327
00328
00329
00330 SessionComponentCache* pDestinationComponentCache = const_cast<SessionComponentCache*>(pComponentCache)->GetCacheByIDPath(parameterID);
00331
00332 return SessionAccessor::GetParameter(pDestinationComponentCache, sParameterName);
00333 };
00334
00335 void
00336 SessionAccessor::
00337 SetParameterValueByIDPath(SessionComponentCache* pComponentCache, const IDPath& parameterID, const std::string& value)
00338 {
00339 if (!pComponentCache) throwStaticExceptionMacro("Cannot get Parameter, passed component cache is NULL. IDPath: "<<parameterID.ToStr());
00340 if (!parameterID.IsParameterSelection()) throwStaticExceptionMacro("Cannot get Parameter, idpath doesn't specify a parameter. IDPath: "<<parameterID.ToStr());
00341
00342 std::string sParameterName;
00343 Parameter::ValueCountType iItemPos = 0;
00344 Parameter::LayerCountType iLayer = 0;
00345
00346 DispatchParameterIDPath(parameterID,sParameterName,iItemPos,iLayer);
00347 SessionComponentCache* pDestinationComponentCache = pComponentCache->GetCacheByIDPath(parameterID);
00348
00349 if (!pDestinationComponentCache) throwStaticExceptionMacro("Cannot get Parameter, responsible component cache cannot be found. IDPath: "<<parameterID.ToStr());
00350 if (!pDestinationComponentCache->ControllerIsAssigned()) throwStaticExceptionMacro("Cannot get Parameter, cache responsible for the parameter has no controller. IDPath: "<<parameterID.ToStr());
00351
00352 pDestinationComponentCache->Controller()->SetParameterValue(pDestinationComponentCache,sParameterName,value,iItemPos,iLayer);
00353 };
00354
00355 void
00356 SessionAccessor::
00357 SetParameterValueByIDPath(SessionComponentCache* pComponentCache, const IDPath& parameterID, const bool& value)
00358 {
00359 SetParameterValueByIDPath(pComponentCache,parameterID,Convert::ToStr(value));
00360 };
00361
00363 void
00364 SessionAccessor::
00365 SetParameterValueByIDPath(SessionComponentCache* pComponentCache, const IDPath& parameterID, const double& value)
00366 {
00367 SetParameterValueByIDPath(pComponentCache,parameterID,Convert::ToStr(value));
00368 };
00369
00370 void
00371 SessionAccessor::
00372 SetParameterValueByIDPath(SessionComponentCache* pComponentCache, const IDPath& parameterID, const int& value)
00373 {
00374 SetParameterValueByIDPath(pComponentCache,parameterID,Convert::ToStr(value));
00375 };
00376
00377 void
00378 SessionAccessor::
00379 SetParameterValueByIDPath(SessionComponentCache* pComponentCache, const IDPath& parameterID, const long& value)
00380 {
00381 SetParameterValueByIDPath(pComponentCache,parameterID,Convert::ToStr(value));
00382 };
00383
00384 void
00385 SessionAccessor::
00386 SetParameterValueByIDPath(SessionComponentCache* pComponentCache, const IDPath& parameterID, const unsigned long& value)
00387 {
00388 SetParameterValueByIDPath(pComponentCache,parameterID,Convert::ToStr(value));
00389 };
00390
00391 }