freControllerBase.txx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freControllerBase.h,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #ifndef __freControllerBase_txx
00023 #define __freControllerBase_txx
00024 
00025 #include "freControllerBase.h"
00026 #include "freComponentSetupCollection.h"
00027 #include "freSessionBuilder.h"
00028 #include "freSessionAccessor.h"
00029 #include "freControllerNotificator.h"
00030 
00031 namespace FREE
00032 {
00033 
00034 
00038 
00039 template <class TControlledComponent>
00040 bool
00041 ComponentControllerBase<TControlledComponent>::
00042 ControllerIsResponsible(const GenericComponentType* pComponent) const
00043 {
00044   if (pComponent==0) return false;
00045 
00046   ComponentPointer smpTemp = ComponentType::New();
00047 
00048   return  pComponent->GetNameOfClass() == smpTemp->GetNameOfClass();
00049 };
00050 
00051 template <class TControlledComponent>
00052 void
00053 ComponentControllerBase<TControlledComponent>::
00054 InitializeSetup(ComponentSetup* pComponentSetup, SessionComponentCache* pComponentCache) const
00055 {
00056   //TODO Wenn auf neue Profile umgestellt wurd sollte es eine Klasse geben die setups für einen Controller anhand seines Profils erzeugt.
00057   //wahrscheinlich einfach in den Builder. Das ganze eben ins externe verlagern. oder wenn dann schnittstelle ändern. Und dem Controller
00058   //nur die möglichkeit der Finalisierung lassen. Vermutlich wirklich einfach den standard programieren und Überladungen zulassen
00060 
00061         //if (!pComponentSetup) throwCtrlExceptionMacro("","Error; trying to initialize pComponentSetup with NULL.");
00062 
00063         //pComponentSetup->SetControllerID(ControllerID());
00064  // pComponentSetup->SetComponentType(ComponentSetup::CTComponent);
00065 
00067 
00068         //pComponentSetup->ResetParameters();
00069 
00070         //for (CtrlProfile::ProfileParameters::ElementsCountType paramPos = 0; paramPos<m_Profile->Parameters().Size(); paramPos++)
00071         //{
00072         //      CtrlProfile::Parameter* pProfileParameter = m_Profile->Parameters().GetElement(paramPos);
00073 
00074         //      unsigned int iLayerCount = pProfileParameter->GetLayerCount();
00075         //      if (pProfileParameter->GetIsArbitrarilyLayered())
00076  //   {
00077  //     iLayerCount = 0;
00078  //     if (pProfileParameter->GetHasDefault()) iLayerCount = pProfileParameter->LayerCount();
00079  //   }
00080         //      /*if a parameter has no fixed layer count and has no default definition, it will be created with no layer.
00081  //     Otherwise the default layers will be copied.*/
00082 
00083         //      Parameter* pSetuParameter = pComponentSetup->Parameters().AddParameter(pProfileParameter->GetParameterName(), pProfileParameter->ParameterSize(), iLayerCount);
00084 
00085  //   //Set default values in all layers
00086  //   for (CtrlProfile::Parameter::LayerCountType iLayerIndex = 0; iLayerIndex<iLayerCount; iLayerIndex++)
00087  //   {
00088  //     ParameterLayer* pLayer = pSetuParameter->GetParameterLayer(iLayerIndex);
00089  //     
00090  //     //if more layers needed then default layers defined, the use the last default layer for the rest.
00091  //     int iDefaultLayerIndex = iLayerIndex;
00092  //     if (iDefaultLayerIndex>pProfileParameter->LayerCount()-1) iDefaultLayerIndex = pProfileParameter->LayerCount()-1;
00093  //     ParameterLayer* pDefaultLayer = pProfileParameter->GetParameterLayer(iDefaultLayerIndex);
00094 
00095  //     *pLayer = *pDefaultLayer;
00096  //   }
00097         //}
00098 
00100         //pComponentSetup->Components().Reset();
00101 
00102         //for (CtrlProfile::ProfileSubComponents::ElementsCountType compPos = 0; compPos<m_Profile->SubComponents().Size(); compPos++)
00103         //{
00104         //      CtrlProfile::SubComponent* pComponent = m_Profile->SubComponents().GetElement(compPos);
00105         //      ComponentSetupCollection::ComponentsCountType index = pComponentSetup->Components().AddElement(pComponent->GetComponentID(), (pComponent->GetIsRequired()>0));
00106         //      
00107         //      if (pComponent->GetControllerID()!=csUndefinedController)
00108         //      {
00109         //              pComponentSetup->Components().GetElement(index)->SetControllerID(pComponent->GetControllerID());
00110         //      }
00111         //}
00112 }
00113 
00114 template <class TControlledComponent>
00115 SessionComponentCache::Pointer
00116 ComponentControllerBase<TControlledComponent>::
00117 BuildSetup(ComponentSetup* pComponentSetup, SessionComponentCache* pParentComponentCache) const
00118 {
00119   if (!pComponentSetup) throwCtrlExceptionMacro("","Error; no component setup specified.");
00120 
00121   try
00122   {
00123     const GenericComponentController* pController = (GenericComponentController*)(this);
00124     SessionComponentCache::Pointer smpCache = SessionComponentCache::New(pParentComponentCache, pComponentSetup, pController, NULL); 
00125     
00126     ComponentPointer smpMainComponent = BuildMainComponent(pComponentSetup, smpCache);
00127     SessionComponentCache::GenericComponentType* pGenericComp = 0;
00128 
00129     if (smpMainComponent.IsNotNull())
00130     {
00131       try
00132       {
00133         pGenericComp = dynamic_cast<GenericComponentType*>(smpMainComponent.GetPointer());
00134       }
00135       catchAllNPassMacro("Error. Try to cast passed component. Seems to be wrong type. Please ensure correct initialisation. Name of component: "<<smpMainComponent->GetNameOfClass()<<" ; ControllerID: "<<this->ControllerID());
00136       if (!pGenericComp) throwCtrlExceptionMacro("","Error. Try to cast passed component. Seems to be wrong type. Please ensure correct initialisation. Name of component: "<<smpMainComponent->GetNameOfClass()<<" ; ControllerID: "<<this->ControllerID());
00137     }
00138     else throwCtrlExceptionMacro("","Error. No component created by controller.");
00139     DirectSessionComponentAccessor::SetComponent(pGenericComp,smpCache);
00140 
00141     BuildSubComponents(pComponentSetup,smpCache);
00142     BuildFinalization(pComponentSetup,smpCache);
00143     
00144     return smpCache;
00145   }
00146   catchAllNPassMacro("Unknown error while building component.");
00147 };
00148 
00149 template <class TControlledComponent>
00150 void
00151 ComponentControllerBase<TControlledComponent>::
00152 ActualizeComponent(SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo, const unsigned int& iActiveLayer) const
00153 {
00154   if (!pSessionInfo) throwCtrlExceptionMacro("","Error; no session info available, null pointer passed with function call.");
00155   if (!pComponentCache) throwCtrlExceptionMacro("","Error; no component cache available, null pointer passed with function call.");
00156   if (pComponentCache->IsActive())
00157   {
00158     try
00159     {
00160       ComponentType* pCastedComponent = dynamic_cast<ComponentType*>(DirectSessionComponentAccessor::GetComponent(pComponentCache));
00161 
00162       ActualizeMainComponent(pCastedComponent, pComponentCache, pSessionInfo, iActiveLayer);
00163       ActualizeSubComponents(pCastedComponent, pComponentCache, pSessionInfo, iActiveLayer);
00164       ActualizeFinalization(pCastedComponent, pComponentCache, pSessionInfo, iActiveLayer);
00165     }
00166     catchAllNPassMacro("Unknown error while actualizing component.");
00167   }
00168   else if (SessionBuilder::CheckComponentNecessity(pComponentCache)) throwCtrlExceptionMacro("","No active component cash, but component is necessary.");
00169 };
00170 
00171 template <class TControlledComponent>
00172 void
00173 ComponentControllerBase<TControlledComponent>::
00174 ResetComponent(SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00175 {
00176   if (!pSessionInfo) throwCtrlExceptionMacro("","Error; no session info available, null pointer passed with function call.");
00177   if (!pComponentCache) throwCtrlExceptionMacro("","Error; no component cache available, null pointer passed with function call.");
00178   if (pComponentCache->IsActive())
00179   {
00180     try
00181     {
00182       ResetMainComponent(pComponentCache, pSessionInfo);
00183       ResetSubComponents(pComponentCache, pSessionInfo);
00184       ResetFinalization(pComponentCache, pSessionInfo);
00185     }
00186     catchAllNPassMacro("Unknown error while resetting component.");
00187   }
00188 };
00189 
00190 template <class TControlledComponent>
00191 void
00192 ComponentControllerBase<TControlledComponent>::
00193 SetStatisticEntry(StatisticEntry& rStatisticEntry, SessionComponentCache* pComponentCache,
00194                  SessionInfo* pSessionInfo) const
00195 {
00196   if (!pComponentCache) throwCtrlExceptionMacro("","Error; no component cache available, null pointer passed with function call.");
00197   if (!pSessionInfo) throwCtrlExceptionMacro("","Error; no session info available, null pointer passed with function call.");
00198   if (!pSessionInfo->GetStatistic()) throwCtrlExceptionMacro("","Error; no statistic in session info available, cannot set statistic entry without statistic.");
00199   if (!pComponentCache->ComponentIsAssigned()) throwCtrlExceptionMacro("","Error; main component cache has no component.");
00200 
00201   try
00202   {
00203     ComponentType* pComponent = dynamic_cast<ComponentType*>(DirectSessionComponentAccessor::GetComponent(pComponentCache));
00204     StatisticDictionary& rDictionary = pSessionInfo->GetStatistic()->GetDictionary();
00205     SetStatisticEntryMainComponent(rStatisticEntry, pComponent, pComponentCache, pSessionInfo, rDictionary);
00206     SetStatisticEntrySubComponents(rStatisticEntry, pComponentCache, pSessionInfo, rDictionary);
00207   }
00208   catchAllNPassMacro("Unknown error while setting step statistic.");
00209 };
00210 
00211 template <class TControlledComponent>
00212 const bool
00213 ComponentControllerBase<TControlledComponent>::
00214 CheckComponentActualizationNecessity(const SessionComponentCache* pComponentCache) const
00215 {
00216         bool result = CheckCmpActNecessityMainCmp(pComponentCache);
00217 
00218         if (!result) result = CheckCmpActNecessitySubCmp(pComponentCache);
00219 
00220         return result;
00221 };
00222 
00223 
00224 template <class TControlledComponent>
00225 typename ComponentControllerBase<TControlledComponent>::ComponentPointer
00226 ComponentControllerBase<TControlledComponent>::
00227 GetComponent(const SessionComponentCache* pComponentCache) const
00228 {
00229   if (!pComponentCache) throwCtrlExceptionMacro("","Error; no cache has been specified. Null pointer was passed instead.");
00230 
00231   SessionComponentCache::GenericComponentPointer genericComp = DirectSessionComponentAccessor::GetComponent(pComponentCache);
00232   ComponentPointer result;
00233   
00234   if (genericComp.IsNotNull())
00235   {
00236     try
00237     {
00238       result = dynamic_cast<ComponentType*>(genericComp.GetPointer());
00239     }
00240     catchAllNPassMacro("Error. Try to cast component stored in cache. Seems to be wrong type. Please ensure correct initialisation. Name of component: "<<genericComp->GetNameOfClass()<<" ; ControllerID: "<<this->ControllerID());
00241   }
00242 
00243   return result;
00244 }; 
00245 
00246 template <class TControlledComponent>
00247 void
00248 ComponentControllerBase<TControlledComponent>::
00249 SetComponent(ComponentType* pComponent, SessionComponentCache* pComponentCache) const
00250 {
00251   if (!pComponentCache) throwCtrlExceptionMacro("","Error; no cache has been specified. Null pointer was passed instead.");
00252 
00253   SessionComponentCache::GenericComponentType* pGenericComp = 0;
00254 
00255   if (pComponent)
00256   {
00257     try
00258     {
00259       pGenericComp = dynamic_cast<GenericComponentType*>(pComponent);
00260     }
00261     catchAllNPassMacro("Error. Try to cast passed component. Seems to be wrong type. Please ensure correct initialisation. Name of component: "<<pComponent->GetNameOfClass()<<" ; ControllerID: "<<this->ControllerID());
00262   }
00263 
00264   DirectSessionComponentAccessor::SetComponent(pGenericComp,pComponentCache);
00265 }; 
00266 
00267 template <class TControlledComponent>
00268 typename ComponentControllerBase<TControlledComponent>::GenericComponentPointer
00269 ComponentControllerBase<TControlledComponent>::
00270 GetGenericComponent(const SessionComponentCache* pComponentCache) const
00271 {
00272   ComponentPointer smpComp = GetComponent(pComponentCache);
00273   GenericComponentPointer result;
00274   if (smpComp.IsNotNull())
00275   {
00276     try
00277     {
00278       result = dynamic_cast<GenericComponentType*>(smpComp.GetPointer());
00279     }
00280     catchAllNPassMacro("Error. Try to cast component. Seems to be wrong type. Please ensure correct initialisation. Name of component: "<<smpComp->GetNameOfClass()<<" ; ControllerID: "<<this->ControllerID());
00281   }
00282 
00283   return result;
00284 }; 
00285 
00286 template <class TControlledComponent>
00287 void
00288 ComponentControllerBase<TControlledComponent>::
00289 SetGenericComponent(GenericComponentType* pGenericComponent, SessionComponentCache* pComponentCache) const
00290 {
00291   ComponentType* pComponent = 0;
00292 
00293   if (pGenericComponent)
00294   {
00295     try
00296     {
00297       pComponent = dynamic_cast<ComponentType*>(pGenericComponent);
00298     }
00299     catchAllNPassMacro("Error. Try to cast passed component. Seems to be wrong type. Please ensure correct initialisation. Name of component: "<<pGenericComponent->GetNameOfClass()<<" ; ControllerID: "<<this->ControllerID());
00300   }
00301 
00302   SetComponent(pComponent,pComponentCache);
00303 }; 
00304 
00305 
00306 template <class TControlledComponent>
00307 typename ComponentControllerBase<TControlledComponent>::GenericComponentType*
00308 ComponentControllerBase<TControlledComponent>::
00309 GetSubComponent(SessionComponentCache* pMainComponentCache, const ComponentID compID) const
00310 {
00311   if (!pMainComponentCache) throwCtrlExceptionMacro("", "Error; no main component cache available, null pointer passed with function call.");
00312   if (!pMainComponentCache->ComponentIsAssigned()) throwCtrlExceptionMacro("", "Error; no main component available, null pointer passed with function call.");
00313 
00314   ComponentType* pCastedComponent = dynamic_cast<ComponentType*>(DirectSessionComponentAccessor::GetComponent(pMainComponentCache));
00315 
00316   return GetSubComponentCasted(pCastedComponent,compID,pMainComponentCache);
00317 }; 
00318 
00319 template <class TControlledComponent>
00320 void
00321 ComponentControllerBase<TControlledComponent>::
00322 SetSubComponent(SessionComponentCache* pMainComponentCache, GenericComponentType* pSubComponent, 
00323                 const ComponentID compID) const
00324 {
00325   if (!pMainComponentCache) throwCtrlExceptionMacro("", "Error; no main component cache available, null pointer passed with function call.");
00326 
00327   ComponentType* pCastedComponent = dynamic_cast<ComponentType*>(DirectSessionComponentAccessor::GetComponent(pMainComponentCache));
00328 
00329   SetSubComponentCasted(pSubComponent,pCastedComponent,compID,pMainComponentCache);
00330 }; 
00331 
00332 template <class TControlledComponent>
00333 typename ComponentControllerBase<TControlledComponent>::GenericMediaPointer
00334 ComponentControllerBase<TControlledComponent>::
00335 GetMedia(const MediaID& mediaID, SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00336 {
00337   if (!pComponentCache) throwCtrlExceptionMacro("", "Error; no component cache available, null pointer passed with function call.");
00338   if (!pComponentCache->ComponentIsAssigned()) throwCtrlExceptionMacro("", "Error; no component available in cache.");
00339 
00340   ComponentType* pCastedComponent = dynamic_cast<ComponentType*>(DirectSessionComponentAccessor::GetComponent(pComponentCache));
00341 
00342   return GetMediaCasted(mediaID, pCastedComponent, pComponentCache, pSessionInfo);
00343 }; 
00344 
00345 template <class TControlledComponent>
00346 void
00347 ComponentControllerBase<TControlledComponent>::
00348 SetMedia(const MediaID& mediaID, GenericMediaType* pMedia, SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00349 {
00350   if (!pComponentCache) throwCtrlExceptionMacro("", "Error; no component cache available, null pointer passed with function call.");
00351   if (!pComponentCache->ComponentIsAssigned()) throwCtrlExceptionMacro("", "Error; no component available in cache.");
00352 
00353   ComponentType* pCastedComponent = dynamic_cast<ComponentType*>(DirectSessionComponentAccessor::GetComponent(pComponentCache));
00354 
00355   SetMediaCasted(mediaID, pMedia, pCastedComponent, pComponentCache, pSessionInfo);
00356 }; 
00357 
00358 template <class TControlledComponent>
00359 ValidityTag::Pointer
00360 ComponentControllerBase<TControlledComponent>::
00361 GetMediaValidityTag(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00362 {
00363         if (!pComponentCache) throwCtrlExceptionMacro("", "Error; passed component cache is NULL");
00364 
00365   std::string sElementKey = SessionComponentRepositoryKeys::MediaValidity(mediaID);
00366   SessionComponentCache::GenericComponentPointer smpGenericTag = DirectSessionComponentAccessor::GetRepositoryElement(sElementKey,pComponentCache);
00367 
00368   if (smpGenericTag.IsNotNull())
00369   { //there is a tag saved for the media
00370     ValidityTag::Pointer smpTag;
00371     try
00372     {
00373       smpTag = dynamic_cast<ValidityTag*>(smpGenericTag.GetPointer());
00374     }
00375     catchAllNPassMacro("Error; cannot determine the media validity tag. Found a repository element, but element was not of type ValidityTag. MediaID :" << mediaID);
00376     if (smpTag.IsNull()) throwCtrlExceptionMacro("","Error; cannot determine the media validity tag. Found a repository element, but element was not of type ValidityTag. MediaID :" << mediaID);
00377 
00378     return smpTag;
00379   }
00380 
00381   //check for a profile entry
00382         if (!pComponentCache->ControllerIsAssigned()) throwCtrlExceptionMacro("", "Error; validity tag for "<<mediaID<<" cannot be retrieved. No controller avaible. Check if session was correctly initialized.");
00383 
00384   CtrlProfile::ControllerProfile::Pointer smpProfile = pComponentCache->Controller()->GetProfile(pComponentCache);
00385   CtrlProfile::ProfileMediaMap::ElementType* pProfileEntry = smpProfile->MediaMap().GetElement(mediaID);
00386   if (pProfileEntry)
00387   { //there is at least an entry in the profile
00388     ValidityTag::Pointer smpTag = ValidityTag::NewNull();
00389     return smpTag;
00390   }
00391 
00392   // neither a stored ValidityTag nor a profile entry could be found
00393   // request seems to be invalid -> throw exception
00394   throwCtrlExceptionMacro("", "Error; media is not specified for this controller. Cannot retrieved any ValidityTag. MediaID: "<<mediaID);
00395 
00396   return ValidityTag::NewNull();
00397 }; 
00398 
00399 template <class TControlledComponent>
00400 ValidityTag::Pointer
00401 ComponentControllerBase<TControlledComponent>::
00402 GetMediaValidityTagRequirement(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00403 {
00404   //reimplement to realize a certain dependency chain for certain media
00405   return this->GetMediaValidityTag(mediaID, pComponentCache);
00406 };
00407 
00408 template <class TControlledComponent>
00409 std::string
00410 ComponentControllerBase<TControlledComponent>::
00411 GetMediaControllerID(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00412 {
00413         if (!pComponentCache) throwCtrlExceptionMacro("", "Error; passed component cache is NULL");
00414         if (!pComponentCache->ControllerIsAssigned()) throwCtrlExceptionMacro("", "Error; controller ID for "<<mediaID<<" cannot be retrieved. No controller avaible. Check if session was correctly initialized.");
00415 
00416         //Check if there is a media link
00417         if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("", "Error; controller ID for "<<mediaID<<" cannot be retrieved. No setup avaible to check media links. Check if session was correctly initialized.");
00418         ComponentMediaLink* pLink = pComponentCache->Setup()->MediaLinks().GetElement(mediaID);
00419         if (pLink)
00420         { //there is a link for this media
00421                 return SessionAccessor::GetMediaControllerID(pLink->GetSourceIDPath(),pComponentCache);
00422         }
00423         
00424         //Check if it is a media component of the controlled component
00425   CtrlProfile::ControllerProfile::Pointer smpProfile = this->GetProfile(pComponentCache);
00426         CtrlProfile::Media* pMedia = smpProfile->MediaMap().GetElement(mediaID);
00427         if (pMedia)
00428         {
00429     return pMedia->GetDataType();
00430         }
00431 
00432   return csUndefinedController;
00433 }; 
00434 
00435 template <class TControlledComponent>
00436 Parameter::Pointer
00437 ComponentControllerBase<TControlledComponent>::
00438 GetParameter(const SessionComponentCache* pComponentCache, const std::string& sParameterName) const
00439 {
00440         if (!pComponentCache) throwCtrlExceptionMacro("", "Error; cannot get parameter "<<sParameterName<<", passed component cache is NULL.");
00441   if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("", "Error; cannot get parameter "<<sParameterName<<", component setup of cache is NULL.");
00442 
00443   Parameter::Pointer smpParam = pComponentCache->Setup()->Parameters().GetParameter(sParameterName);
00444 
00445   return smpParam;
00446 };
00447 
00448 template <class TControlledComponent>
00449 std::string
00450 ComponentControllerBase<TControlledComponent>::
00451 GetParameterValue(const SessionComponentCache* pComponentCache, const std::string& sParameterName, const Parameter::ValueCountType iItemPos, const Parameter::LayerCountType iLayer) const
00452 {
00453         if (!pComponentCache) throwCtrlExceptionMacro("", "Error; cannot get value of parameter "<<sParameterName<<", passed component cache is NULL.");
00454   if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("", "Error; cannot get value of parameter "<<sParameterName<<", component setup of cache is NULL.");
00455 
00456   Parameter::Pointer smpParam = this->GetParameter(pComponentCache, sParameterName);
00457 
00458   if (smpParam.IsNull())  throwCtrlExceptionMacro("", "Error; cannot get value; parameter "<<sParameterName<<" was not found.");
00459 
00460   std::string sValue;
00461   if (!smpParam->GetParameterValue(sValue, iItemPos, iLayer)) throwExceptionMacro("Cannot found parameter " << sParameterName<<"  (item pos"<<iItemPos<<"; layer "<<iLayer<<") in component setup.");
00462 
00463   return sValue;
00464 }; 
00465 
00466 template <class TControlledComponent>
00467 void
00468 ComponentControllerBase<TControlledComponent>::
00469 SetParameterValue(SessionComponentCache* pComponentCache, const std::string& sParameterName, const std::string& sValue, const Parameter::ValueCountType iItemPos, const Parameter::LayerCountType iLayer) const
00470 {
00471         if (!pComponentCache) throwCtrlExceptionMacro("", "Error; cannot set value of parameter "<<sParameterName<<", passed component cache is NULL.");
00472   if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("", "Error; cannot set value of parameter "<<sParameterName<<", component setup of cache is NULL.");
00473   
00474   //check if it profile allowes the setting of the parameter value
00475   CtrlProfile::ControllerProfile::Pointer smpProfile = this->GetProfile(pComponentCache);
00476   CtrlProfile::Parameter* pParameter = smpProfile->Parameters().GetElement(sParameterName);
00477   
00478   if (pParameter)
00479   {
00480     if (!(pParameter->GetAccess() == DAAny) || !(pParameter->GetAccess() == DASet)) throwExceptionMacro("Cannot set parameter value" << sParameterName<<"; parameter has wrong access mode ("<<Convert::ToStr(pParameter->GetAccess())<<").");
00481   }
00482 
00483   Parameter::Pointer smpParam = this->GetParameter(pComponentCache, sParameterName);
00484   if (smpParam.IsNull())  throwCtrlExceptionMacro("", "Error; cannot set value; parameter "<<sParameterName<<" was not found.");
00485 
00486   //set the value
00487   if (!smpParam->SetParameterValue(sValue, iItemPos, iLayer))
00488   { //setting failed, detect the reason for the failure
00489     if (smpParam->ParameterSize() <= iItemPos) throwExceptionMacro("Cannot set parameter " << sParameterName<<" (item pos"<<iItemPos<<"; layer "<<iLayer<<"); item pos exceeds size of parameter ("<<smpParam->ParameterSize()<<").");
00490     if (smpParam->LayerCount() <= iLayer) throwExceptionMacro("Cannot set parameter " << sParameterName<<" (item pos"<<iItemPos<<"; layer "<<iLayer<<"); layer index exceeds layer count of parameter ("<<smpParam->LayerCount()<<").");
00491     throwExceptionMacro("Cannot set parameter " << sParameterName<<" (item pos"<<iItemPos<<"; layer "<<iLayer<<"); reason unkown");
00492   }
00493 }; 
00494 
00495 template <class TControlledComponent>
00496 ValidityTag::Pointer
00497 ComponentControllerBase<TControlledComponent>::
00498 GetParameterValidityTag(const std::string& sParameterName, SessionComponentCache* pComponentCache) const
00499 {
00500         if (!pComponentCache) throwCtrlExceptionMacro("", "Error; passed component cache is NULL");
00501 
00502   std::string sElementKey = SessionComponentRepositoryKeys::ParameterValidity(sParameterName);
00503   SessionComponentCache::GenericComponentPointer smpGenericTag = DirectSessionComponentAccessor::GetRepositoryElement(sElementKey,pComponentCache);
00504 
00505   if (smpGenericTag.IsNotNull())
00506   { //there is a tag saved for the media
00507     ValidityTag::Pointer smpTag;
00508     try
00509     {
00510       smpTag = dynamic_cast<ValidityTag*>(smpGenericTag.GetPointer());
00511     }
00512     catchAllNPassMacro("Error; cannot determine the parameter validity tag. Found a repository element, but element was not of type ValidityTag. ParameterName :" << sParameterName);
00513     if (smpTag.IsNull()) throwCtrlExceptionMacro("","Error; cannot determine the parameter validity tag. Found a repository element, but element was not of type ValidityTag. ParameterName :" << sParameterName);
00514 
00515     return smpTag;
00516   }
00517 
00518   //check for a profile entry
00519         if (!pComponentCache->ControllerIsAssigned()) throwCtrlExceptionMacro("", "Error; validity tag for "<<sParameterName<<" cannot be retrieved. No controller avaible. Check if session was correctly initialized.");
00520 
00521   CtrlProfile::ControllerProfile::Pointer smpProfile = pComponentCache->Controller()->GetProfile(pComponentCache);
00522   CtrlProfile::ProfileParameters::ElementType* pProfileEntry = smpProfile->Parameters().GetElement(sParameterName);
00523   if (pProfileEntry)
00524   { //there is at least an entry in the profile
00525     ValidityTag::Pointer smpTag = ValidityTag::NewNull();
00526     return smpTag;
00527   }
00528 
00529   // neither a stored ValidityTag nor a profile entry could be found
00530   // request seems to be invalid -> throw exception
00531   throwCtrlExceptionMacro("", "Error; parameter is not specified for this controller. Cannot retrieved any ValidityTag. ParameterName: "<<sParameterName);
00532 
00533   return ValidityTag::NewNull();
00534 }; 
00535 
00536 template <class TControlledComponent>
00537 ValidityTag::Pointer
00538 ComponentControllerBase<TControlledComponent>::
00539 GetParameterValidityTagRequirement(const std::string& sParameterName, SessionComponentCache* pComponentCache) const
00540 {
00541   //reimplement to realize a certain dependency chain for certain parameters
00542   return this->GetParameterValidityTag(sParameterName, pComponentCache);
00543 };
00544 
00545 template <class TControlledComponent>
00546 ComponentControllerBase<TControlledComponent>::
00547 ~ComponentControllerBase()
00548 { 
00549 };
00550 
00551 template <class TControlledComponent>
00552 ComponentControllerBase<TControlledComponent>::
00553 ComponentControllerBase()
00554 {
00555   this->m_ControllerID =  ControllerID::ComponentControllerBase;
00556   this->m_Description = "Base class for all component controller; not for practical use.";
00557 };
00558 
00559 template <class TControlledComponent>
00560 bool
00561 ComponentControllerBase<TControlledComponent>::
00562 MakeCallback(const CallbackCtrlEventBase::CallbackType& callbackID,
00563              void* pData, SessionComponentCache* pSender, long threadID) const
00564 {
00565   IDPath path;
00566   if (pSender) path = pSender->GetIDPath();
00567 
00568   return ControllerNotificator::TriggerCallback(path, callbackID,pData,pSender,threadID);
00569 };
00570 
00571 template <class TControlledComponent>
00572 void
00573 ComponentControllerBase<TControlledComponent>::
00574 NotifyProgress(const ProgressCtrlEventBase::StatusID& statusID,
00575                const std::string& sComment,
00576                SessionComponentCache* pSender, long threadID) const
00577 {
00578   IDPath path;
00579   if (pSender) path = pSender->GetIDPath();
00580 
00581   ControllerNotificator::TriggerProgressEvent(path,statusID,sComment,pSender,threadID);
00582 };
00583 
00584 template <class TControlledComponent>
00585 typename ComponentControllerBase<TControlledComponent>::ComponentPointer
00586 ComponentControllerBase<TControlledComponent>::
00587 BuildMainComponent(ComponentSetup* pComponentSetup, SessionComponentCache* pComponentCache) const
00588 {
00591   ComponentPointer smpComponent = ComponentType::New();
00592 
00593   return smpComponent;
00594 };
00595 
00596 template <class TControlledComponent>
00597 void
00598 ComponentControllerBase<TControlledComponent>::
00599 BuildSubComponents(ComponentSetup* pParentComponentSetup, SessionComponentCache* pParentComponentCache) const
00600 {
00601   typedef ComponentSetupCollection::ComponentsCountType IndexType;
00602 
00603         if (!pParentComponentSetup) throwCtrlExceptionMacro("","Error while buildung subcomponent; invalid parent component setup (null pointer).");
00604         if (!pParentComponentCache) throwCtrlExceptionMacro("","Error while buildung subcomponent; invalid parent component cache. ComponentID: " << pParentComponentSetup->GetComponentID());
00605 
00606   ComponentSetupCollection& rSetups = pParentComponentSetup->Components();
00607   
00608   for (IndexType index=0; index<rSetups.Size(); index++)
00609   {
00610     ComponentSetup* pSubSetup = rSetups.GetElement(index); 
00611     SessionComponentCache::Pointer smpSubCache = NULL;
00612 
00613     try
00614     {
00615       smpSubCache = SessionBuilder::BuildComponent(pSubSetup,pParentComponentCache);
00616                         if (smpSubCache.IsNull()) throwCtrlExceptionMacro("","Unable to build valid subcomponent. ComponentID: " << pSubSetup->GetComponentID());
00617 
00618                         pParentComponentCache->SubCaches().AddElement(smpSubCache);
00619 
00620       //Add subcomponent to the main component. Use direct access for component retrieval
00621       //to avoid circular building/loading of components (e.g. image media)
00622       GenericComponentPointer smpSubComponent = DirectSessionComponentAccessor::GetComponent(smpSubCache);
00623       if (smpSubComponent.IsNotNull()) SetSubComponent(pParentComponentCache,smpSubComponent,pSubSetup->GetComponentID());
00624     }
00625                 catchAllNPassMacro("Error while building subcomponent. ComponentID: " << pSubSetup->GetComponentID());
00626   }
00627 };
00628 
00629 template <class TControlledComponent>
00630 void
00631 ComponentControllerBase<TControlledComponent>::
00632 BuildFinalization(ComponentSetup* pComponentSetup, SessionComponentCache* pComponentCache) const
00633 {
00637 };
00638 
00639 template <class TControlledComponent>
00640 void
00641 ComponentControllerBase<TControlledComponent>::
00642 ActualizeMainComponent(ComponentType* pMainComponent,
00643                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00644                                                                                          const unsigned int& iActLevel) const
00645 {
00648 };
00649 
00650 template <class TControlledComponent>
00651 void
00652 ComponentControllerBase<TControlledComponent>::
00653 ActualizeSubComponents(ComponentType* pMainComponent, SessionComponentCache* pComponentCache,
00654                        SessionInfo* pSessionInfo, const unsigned int& iActLevel) const
00655 {
00656         typedef SessionComponentCache::ComponentCacheCollectionType::ElementsCountType IndexType;
00657 
00658         for (IndexType index=0; index<pComponentCache->SubCaches().Size(); index++)
00659   {
00660     try
00661     {
00662                         SessionComponentCache* pSubCache = pComponentCache->SubCaches().GetElement(index);
00663 
00664       if (pSubCache->ControllerIsAssigned())
00665       {
00666         pSubCache->Controller()->ActualizeComponent(pSubCache,pSessionInfo,iActLevel);
00667       }
00668       else
00669       {
00670                                 if (SessionBuilder::CheckComponentNecessity(pSubCache)) throwCtrlExceptionMacro("","Error; no controller assigned for component, but component is required. ComponentID: " << pSubCache->GetComponentID());
00671       }
00672     }
00673     catchAllNPassMacro("Error while actualizing subcomponent.");
00674   }
00675 };
00676 
00677 template <class TControlledComponent>
00678 void
00679 ComponentControllerBase<TControlledComponent>::
00680 ActualizeFinalization(ComponentType* pMainComponent, SessionComponentCache* pComponentCache,
00681                        SessionInfo* pSessionInfo, const unsigned int& iActLevel) const
00682 {
00685 };
00686  
00687 template <class TControlledComponent>
00688 void
00689 ComponentControllerBase<TControlledComponent>::
00690 ResetMainComponent(SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00691 {
00692         if (!pComponentCache) throwCtrlExceptionMacro("","Error while resetting component; invalid parent component cache (null pointer).");
00693         if (!pSessionInfo) throwCtrlExceptionMacro("","Error while resetting component; invalid session info (null pointer).");
00694 
00695   if (pComponentCache->IsActive())
00696   {
00697     try
00698     {
00699       ComponentPointer smpMainComponent = BuildMainComponent(pComponentCache->Setup(), pComponentCache);
00700       SessionComponentCache::GenericComponentType* pGenericComp = 0;
00701 
00702       if (smpMainComponent.IsNotNull())
00703       {
00704         try
00705         {
00706           pGenericComp = dynamic_cast<GenericComponentType*>(smpMainComponent.GetPointer());
00707         }
00708         catchAllNPassMacro("Error. Try to cast passed component. Seems to be wrong type. Please ensure correct initialisation. Name of component: "<<smpMainComponent->GetNameOfClass()<<" ; ControllerID: "<<this->ControllerID());
00709         if (!pGenericComp) throwCtrlExceptionMacro("","Error. Try to cast passed component. Seems to be wrong type. Please ensure correct initialisation. Name of component: "<<smpMainComponent->GetNameOfClass()<<" ; ControllerID: "<<this->ControllerID());
00710       }
00711       else throwCtrlExceptionMacro("","Error. No component created by controller.");
00712       DirectSessionComponentAccessor::SetComponent(pGenericComp,pComponentCache);
00713 
00714     }
00715     catchAllNPassMacro("Unknown error while resetting component.");
00716   }
00717 
00720 };
00721 
00722 template <class TControlledComponent>
00723 void
00724 ComponentControllerBase<TControlledComponent>::
00725 ResetSubComponents(SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00726 {
00727         if (!pComponentCache) throwCtrlExceptionMacro("","Error while resetting sub components; invalid parent component cache (null pointer).");
00728         if (!pSessionInfo) throwCtrlExceptionMacro("","Error while resetting sub components; invalid session info (null pointer).");
00729 
00730         typedef SessionComponentCache::ComponentCacheCollectionType::ElementsCountType IndexType;
00731 
00732         for (IndexType index=0; index<pComponentCache->SubCaches().Size(); index++)
00733   {
00734     try
00735     {
00736                         SessionComponentCache* pSubCache = pComponentCache->SubCaches().GetElement(index);
00737 
00738       if (pSubCache->ControllerIsAssigned())
00739       {
00740         pSubCache->Controller()->ResetComponent(pSubCache,pSessionInfo);
00741       }
00742     }
00743     catchAllNPassMacro("Error while actualizing subcomponent.");
00744   }
00745 };
00746 
00747 template <class TControlledComponent>
00748 void
00749 ComponentControllerBase<TControlledComponent>::
00750 ResetFinalization(SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00751 {
00754 };
00755 
00756 template <class TControlledComponent>
00757 void
00758 ComponentControllerBase<TControlledComponent>::
00759 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00760                                              ComponentType* pMainComponent,
00761                                              SessionComponentCache* pMainComponentCache,
00762                                              SessionInfo* pSessionInfo,
00763                                              StatisticDictionary& rDictionary) const
00764 {
00767 };
00768 
00769 template <class TControlledComponent>
00770 void
00771 ComponentControllerBase<TControlledComponent>::
00772 SetStatisticEntrySubComponents(StatisticEntry& rStatisticEntry, SessionComponentCache* pComponentCache,
00773                               SessionInfo* pSessionInfo, StatisticDictionary& rDictionary) const
00774 {
00775   for (unsigned int index=0; index<pComponentCache->SubCaches().Size(); index++)
00776   {
00777     try
00778     {
00779       SessionComponentCache* pSubCache = (pComponentCache->SubCaches()).GetElement(index);
00780 
00781       SessionBuilder::SetStatisticEntry(rStatisticEntry, pSubCache, pSessionInfo);
00782     }
00783     catchAllNPassMacro("Error while setting step statistic of subcomponent.");
00784   }
00785 };
00786 
00787 template <class TControlledComponent>
00788 const bool
00789 ComponentControllerBase<TControlledComponent>::
00790 CheckCmpActNecessitySubCmp(const SessionComponentCache* pComponentCache) const
00791 {
00792         typedef SessionComponentCache::ComponentCacheCollectionType::ElementsCountType IndexType;
00793 
00794         for (IndexType index=0; index<pComponentCache->SubCaches().Size(); index++)
00795   {
00796                 SessionComponentCache* pSubCache = pComponentCache->SubCaches().GetElement(index);
00797       
00798     if (pSubCache->ControllerIsAssigned())
00799     {
00800                         if (pSubCache->Controller()->CheckComponentActualizationNecessity(pSubCache)) return true;
00801     }
00802   }
00803 
00804         return false;
00805 };
00806 
00807 template <class TControlledComponent>
00808 const bool
00809 ComponentControllerBase<TControlledComponent>::
00810 CheckCmpActNecessityMainCmp(const SessionComponentCache* pComponentCache) const
00811 {
00812   CtrlProfile::ControllerProfile::Pointer smpProfile = this->GetProfile(pComponentCache);
00813 
00814         for (CtrlProfile::ProfileParameters::ElementsCountType i = 0; i < smpProfile->Parameters().Size(); i++)
00815         {
00816                 if (smpProfile->Parameters().GetElement(i)->GetIsMultiResDynamic()) return true;
00817         }
00818         return false;
00819 };
00820 
00821 template <class TControlledComponent>
00822 typename ComponentControllerBase<TControlledComponent>::GenericComponentType*
00823 ComponentControllerBase<TControlledComponent>::
00824 GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID, SessionComponentCache* pMainComponentCache) const
00825 {
00827   return NULL;
00828 }; 
00829 
00830 template <class TControlledComponent>
00831 void
00832 ComponentControllerBase<TControlledComponent>::
00833 SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00834                       const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00835   {
00838   }; 
00839 
00840 template <class TControlledComponent>
00841 typename ComponentControllerBase<TControlledComponent>::GenericMediaPointer
00842 ComponentControllerBase<TControlledComponent>::
00843 GetMediaCasted(const MediaID& mediaID, ComponentType* pComponent,
00844                SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00845 {
00848   throwCtrlExceptionMacro("","MediaID ("<<mediaID<<") is unkown and cannot be retrieved. Component: "<<pComponentCache->GetIDPath().ToStr());
00849 }; 
00850 
00851 template <class TControlledComponent>
00852 void
00853 ComponentControllerBase<TControlledComponent>::
00854 SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia,
00855                                                    ComponentType* pComponent,
00856                SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00857 {
00858   throwCtrlExceptionMacro("","MediaID ("<<mediaID<<") is unkown and cannot be set. Component: "<<pComponentCache->GetIDPath().ToStr());
00861 }; 
00862 
00863 template <class TControlledComponent>
00864 void
00865 ComponentControllerBase<TControlledComponent>::
00866 ActualizeMediaValidityTag(const MediaID& mediaID,
00867                           SessionComponentCache* pComponentCache) const
00868 {
00869   DirectSessionComponentAccessor::SetRepositoryElement(SessionComponentRepositoryKeys::MediaValidity(mediaID),ValidityTag::New(),pComponentCache);
00870 };
00871 
00872 template <class TControlledComponent>
00873 void
00874 ComponentControllerBase<TControlledComponent>::
00875 ActualizeParameterValidityTag(const std::string& sParameterName,
00876                               SessionComponentCache* pComponentCache) const
00877 {
00878   DirectSessionComponentAccessor::SetRepositoryElement(SessionComponentRepositoryKeys::ParameterValidity(sParameterName),ValidityTag::New(),pComponentCache);
00879 };
00880 
00881 template <class TControlledComponent>
00882 void
00883 ComponentControllerBase<TControlledComponent>::
00884 ActualizeValidityTag(const std::string& sID,
00885                      SessionComponentCache* pComponentCache) const
00886 {
00887   DirectSessionComponentAccessor::SetRepositoryElement(SessionComponentRepositoryKeys::Validity(sID),ValidityTag::New(),pComponentCache);
00888 };
00889 
00890 template <class TControlledComponent>
00891 ValidityTag::Pointer
00892 ComponentControllerBase<TControlledComponent>::
00893 GetValidityTag(const std::string& id, SessionComponentCache* pComponentCache) const
00894 {
00895         if (!pComponentCache) throwCtrlExceptionMacro("", "Error; passed component cache is NULL");
00896 
00897   std::string sElementKey = SessionComponentRepositoryKeys::Validity(id);
00898   SessionComponentCache::GenericComponentPointer smpGenericTag = DirectSessionComponentAccessor::GetRepositoryElement(sElementKey,pComponentCache);
00899 
00900   if (smpGenericTag.IsNotNull())
00901   { //there is a tag saved for the element
00902     ValidityTag::Pointer smpTag;
00903     try
00904     {
00905       smpTag = dynamic_cast<ValidityTag*>(smpGenericTag.GetPointer());
00906     }
00907     catchAllNPassMacro("Error; cannot determine the validity tag. Found a repository element, but element was not of type ValidityTag. ID :" << id);
00908     if (smpTag.IsNull()) throwCtrlExceptionMacro("","Error; cannot determine the validity tag. Found a repository element, but element was not of type ValidityTag. ID :" << id);
00909 
00910     return smpTag;
00911   }
00912 
00913   // no stored ValidityTag could be found
00914   // request seems to be invalid -> throw exception
00915   throwCtrlExceptionMacro("", "Error; element ValidityTag is not specified for this controller. Cannot retrieved any ValidityTag. ID: "<< id);
00916 
00917   return ValidityTag::NewNull();
00918 }; 
00919 
00920 template <class TControlledComponent>
00921 ValidityTag::Pointer
00922 ComponentControllerBase<TControlledComponent>::
00923 GetValidityTagRequirement(const std::string& id, SessionComponentCache* pComponentCache) const
00924 {
00925   //reimplement to realize a certain dependency chain for certain element
00926   return this->GetValidityTag(id, pComponentCache);
00927 };
00928 
00929 
00930 template <class TControlledComponent>
00931 void
00932 ComponentControllerBase<TControlledComponent>::
00933 GenerateProfile(CtrlProfile::ControllerProfile& profile, 
00934                 const SessionComponentCache* pComponentCache,
00935                 bool bRegardOldSetup) const
00936 {
00937 };
00938 
00939 template <class TControlledComponent>
00940 void
00941 ComponentControllerBase<TControlledComponent>::
00942 GenerateProfileTemplateRealization(CtrlProfile::ControllerProfile& profile,
00943                                    const SessionComponentCache* pComponentCache,
00944                                    const ComponentSetup& oldSetup) const
00945 {
00946   //browes throw all parameters and search for templated ones
00947   for ( unsigned int i = 0; i < oldSetup.Parameters().Size(); i++)
00948   {
00949     Parameter* pParam = oldSetup.Parameters().GetParameter(i);
00950     if (pParam->IsTemplateBased())
00951     { //found a parameter based on a template -> get the parameter profile
00952       CtrlProfile::Parameter* pParamProfile = profile.Parameters().GetElement(pParam->GetTemplateID());
00953 
00954       if (pParamProfile)
00955       {//ok there is a profile specification, so add one based on this
00956         CtrlProfile::Parameter::Pointer smpNewParamProfile = CtrlProfile::Parameter::New();
00957         smpNewParamProfile->operator = (*pParamProfile); //copy all profile settings
00958         smpNewParamProfile->SetParameterName(pParam->GetParameterName()); //set new name of profile
00959         smpNewParamProfile->SetTemplateID(""); //no template anymore
00960             profile.Parameters().AddElement(smpNewParamProfile);
00961       }
00962     }
00963   }
00964 
00965   //browes throw all media links and search for templated ones
00966   for ( unsigned int i = 0; i < oldSetup.MediaLinks().Size(); i++)
00967   {
00968     ComponentMediaLink* pLink = oldSetup.MediaLinks().GetElement(i);
00969     if (pLink->IsTemplateBased())
00970     { //found a media component based on a template -> get the media profile
00971       CtrlProfile::Media* pMediaProfile = profile.MediaMap().GetElement(pLink->GetTemplateID());
00972 
00973       if (pMediaProfile)
00974       {//ok there is a profile specification, so add one based on this
00975         CtrlProfile::Media::Pointer smpNewMediaProfile = CtrlProfile::Media::New();
00976         smpNewMediaProfile->operator = (*pMediaProfile); //copy all profile settings
00977         smpNewMediaProfile->SetName(pLink->GetMediaID()); //set new name of profile
00978         smpNewMediaProfile->SetIsTemplate(false); //no template anymore
00979             profile.MediaMap().AddElement(smpNewMediaProfile);
00980       }
00981     }
00982   }
00983 
00984   //browes throw all subcomponents and search for templated
00985   for ( unsigned int i = 0; i < oldSetup.Components().Size(); i++)
00986   {
00987     ComponentSetup* pComponent = oldSetup.Components().GetElement(i);
00988     if (pComponent->IsTemplateBased())
00989     { //found a subcomponent based on a template -> get the subcomponent profile
00990       CtrlProfile::SubComponent* pSubCompProfile = profile.SubComponents().GetElement(pComponent->GetTemplateID());
00991 
00992       if (pSubCompProfile)
00993       {//ok there is a profile specification, so add one based on this
00994         CtrlProfile::SubComponent::Pointer smpNewSubCompProfile = CtrlProfile::SubComponent::New();
00995         smpNewSubCompProfile->operator = (*pSubCompProfile); //copy all profile settings
00996         smpNewSubCompProfile->SetComponentID(pComponent->GetComponentID()); //set new name of profile
00997         smpNewSubCompProfile->SetIsTemplate(false); //no template anymore
00998             profile.SubComponents().AddElement(smpNewSubCompProfile);
00999       }
01000     }
01001   }
01002 };
01003 
01004 template <class TControlledComponent>
01005 CtrlProfile::ControllerProfile::Pointer
01006 ComponentControllerBase<TControlledComponent>::
01007 GetProfile(const SessionComponentCache* pComponentCache) const
01008 {
01009   bool bRegardOldSetup = false;
01010   if (pComponentCache)
01011   {
01012     if (pComponentCache->SetupIsAssigned())
01013     {
01014       if (pComponentCache->Setup()->GetControllerID() == this->ControllerID())
01015       {
01016         bRegardOldSetup = true;
01017       }
01018     }
01019   }
01020 
01021   CtrlProfile::ControllerProfile::Pointer profile = CtrlProfile::ControllerProfile::New();
01022 
01023   //This basic information have already set via the constructor of the controller and its
01024   //ancestor classes. So just add it to the profile. GenerateProfile() only has to care about
01025   //parameter, component and media definitions and about requirements.
01026   profile->ControllerID() = this->m_ControllerID;
01027   profile->Description() = this->m_Description;
01028   profile->Inheritance() = this->m_Inheritance;
01029 
01030   this->GenerateProfile(*(profile.GetPointer()),pComponentCache,bRegardOldSetup);
01031 
01032   if (bRegardOldSetup)
01033   {
01034     this->GenerateProfileTemplateRealization(*(profile.GetPointer()), pComponentCache, *(pComponentCache->Setup()));
01035   }
01036 
01037   return profile;
01038 };
01039 
01040 template <class TControlledComponent>
01041 typename ComponentControllerBase<TControlledComponent>::AffectedElementListType
01042 ComponentControllerBase<TControlledComponent>::
01043 GetAffectedProfileElements(const IDPath& affectorID,
01044                            SessionComponentCache* pComponentCache,
01045                            const ComponentSetup* pNewAffectorSetup) const
01046 { //normaly no elements are affected
01047   return AffectedElementListType();
01048 };
01049 
01050 template <class TControlledComponent>
01051 StatisticEntry*
01052 ComponentControllerBase<TControlledComponent>::
01053 AddStatisticEntry(SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
01054                   const std::string& sName, const std::string& sDescription) const
01055 {
01056   if (!pComponentCache) throwCtrlExceptionMacro("","Error while adding statistic entry; invalid component cache (null pointer). Entry name: "<<sName);
01057   if (!pSessionInfo) throwCtrlExceptionMacro("","Error while adding statistic entry; invalid session info (null pointer). Entry name:"<<sName);
01058 
01059   if (pSessionInfo->GetStatistic()==0) return 0;
01060 
01061   StatisticEntryDefinition* pEntryDef = pSessionInfo->GetStatistic()->GetDictionary().GetEntryDefinitionByName(pComponentCache->GetIDPath(),sName);
01062   if (!pEntryDef)
01063   {
01064     pEntryDef = pSessionInfo->GetStatistic()->GetDictionary().AddEntryDefinition(pComponentCache->GetIDPath(),sName,pComponentCache->GetControllerID(),sDescription);
01065   }  
01066 
01067   StatisticEntry* pEntry =pSessionInfo->GetStatistic()->GetData().CreateChildEntry(pSessionInfo->GetStatistic()->GetData().GetCurrentEntryID());
01068 
01069   pEntry->SetRefID(pEntryDef->GetRefID());
01070 
01071   return pEntry;
01072 };
01073 
01074 } //end of namespace FREE
01075 
01076 #endif

Generated at Sat Oct 13 15:39:55 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000