00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "freSetupManager.h"
00023 #include "freSessionBuilder.h"
00024 #include "freControllerCentral.h"
00025
00026 namespace FREE
00027 {
00028
00032 SetupManager::ControllerListType
00033 SetupManager::
00034 GetPossibleControllers(const IDPath& componentID, const bool& bCheckOnlyHypothetical)
00035 {
00036 if (m_smpSetup.IsNull()) throwStaticExceptionMacro("Manager has no setup set.");
00037
00038 ComponentSetup* pComponentSetup = m_smpSetup->GetComponentByIDPath(componentID);
00039
00040 if (!pComponentSetup) throwStaticExceptionMacro("No component setup found under given ID path. ID path: " << ComponentID(componentID));
00041
00042
00043 IDPath parentIDPath;
00044 if (pComponentSetup->GetParentComponent()) parentIDPath = pComponentSetup->GetParentComponent()->GetIDPath();
00045
00046
00047 typedef ControllerCentral::ControllerListType ListType;
00048 ListType controllers = ControllerCentral::GetControllers();
00049
00050 ControllerListType ctrlNames;
00051
00052
00053 for (ListType::iterator pos = controllers.begin(); pos!=controllers.end(); pos++)
00054 {
00055 GenericComponentController* pController = (*pos)->GetController();
00056
00057 IDPathVectorType refusers;
00058 IDPathVectorType refused;
00059 bool bValid = ValidateController(componentID,pController->ControllerID(),refusers,refused);
00060
00061
00062 bool bParentRefusal = false;
00063 for (IDPathVectorType::iterator pathPos = refusers.begin(); pathPos!= refusers.end(); pathPos++)
00064 {
00065 if (*pathPos == parentIDPath)
00066 {
00067 bParentRefusal = true;
00068 break;
00069 };
00070 };
00071
00072
00073 if (bValid || (bCheckOnlyHypothetical && !(bParentRefusal))) ctrlNames.push_back(pController->ControllerID());
00074 }
00075 return ctrlNames;
00076 };
00077
00078 bool
00079 SetupManager::
00080 ValidateController(const IDPath& componentID,
00081 const std::string& sControllername,
00082 IDPathVectorType& rRefusingComponents,
00083 IDPathVectorType& rRefusedComponents)
00084 {
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 return false;
00138 };
00139
00140 bool
00141 SetupManager::
00142 ValidateController(const IDPath& componentID, const std::string& sControllername)
00143 {
00144 IDPathVectorType refusers;
00145 IDPathVectorType refused;
00146 return ValidateController(componentID,sControllername,refusers,refused);
00147 };
00148
00149 void
00150 SetupManager::
00151 InitializeComponentSetup(Setup* pSetup, ComponentSetup* pComponentSetup)
00152 {
00153 if (pComponentSetup == NULL) throwStaticExceptionMacro("Unable to initialize setup; pComponentSetup is NULL.");
00154
00155 InitializeComponentSetup(pSetup, pComponentSetup,pComponentSetup->GetControllerID());
00156 };
00157
00158 void
00159 SetupManager::
00160 InitializeComponentSetup(Setup* pSetup, ComponentSetup* pComponentSetup, const std::string& sControllerName)
00161 {
00162 if (pSetup == NULL) throwStaticExceptionMacro("Unable to initialize setup; pSetup is NULL.");
00163 if (pComponentSetup == NULL) throwStaticExceptionMacro("Unable to initialize setup; pComponentSetup is NULL.");
00164
00165 ControllerCentral::TriggerBuildEvent(1,"...initializing "+sControllerName+" @ "+ pComponentSetup->GetIDPath().ToStr(), pComponentSetup);
00166
00167 if (sControllerName == csUndefinedController)
00168 {
00169 ComponentID componentID = pComponentSetup->GetComponentID();
00170 pComponentSetup->Reset();
00171 pComponentSetup->SetComponentID(componentID);
00172 }
00173 else
00174 {
00175 GenericComponentController* pController = ControllerCentral::GetController(sControllerName);
00176
00177 if (!pController) throwStaticExceptionMacro("Controller not found for initialization. Requested controller name: "<<sControllerName);
00178
00179 if (!ValidateController(pComponentSetup->GetIDPath(),sControllerName)) throwStaticExceptionMacro("Error; chosen controller is not valid for the given setup. ControllerID: " << sControllerName);
00180
00181
00182
00183
00184
00185 ActualizeConstraintCache(pSetup,pComponentSetup->GetIDPath(),sControllerName);
00186
00187
00188 for (ComponentSetupCollection::ElementsCountType index=0; index<pComponentSetup->Components().Size(); index++)
00189 {
00190 ComponentSetup* pSubSetup = pComponentSetup->Components().GetElement(index);
00191 if (pSubSetup->ControllerIsAssigned()) InitializeComponentSetup(pSetup,pSubSetup);
00192 }
00193 }
00194 };
00195
00196 void
00197 SetupManager::
00198 InitializeComponentSetup(ComponentSetup* pComponentSetup, const std::string& sControllerName)
00199 {
00200 if (pComponentSetup == NULL) throwStaticExceptionMacro("Unable to initialize setup; pComponentSetup is NULL.");
00201
00202 ControllerCentral::TriggerBuildEvent(1,"...initializing "+sControllerName+" @ "+ pComponentSetup->GetIDPath().ToStr(), pComponentSetup);
00203
00204 if (sControllerName == csUndefinedController)
00205 {
00206 ComponentID componentID = pComponentSetup->GetComponentID();
00207 pComponentSetup->Reset();
00208 pComponentSetup->SetComponentID(componentID);
00209 }
00210 else
00211 {
00212 GenericComponentController* pController = ControllerCentral::GetController(sControllerName);
00213
00214 if (!pController) throwStaticExceptionMacro("Controller not found for initialization. Requested controller name: "<<sControllerName);
00215
00216
00217
00218
00219
00220 for (ComponentSetupCollection::ElementsCountType index=0; index<pComponentSetup->Components().Size(); index++)
00221 {
00222 ComponentSetup* pSubSetup = pComponentSetup->Components().GetElement(index);
00223 if (pSubSetup->ControllerIsAssigned()) InitializeComponentSetup(pSubSetup, pSubSetup->GetControllerID());
00224 }
00225 }
00226 };
00227
00228 Setup*
00229 SetupManager::
00230 GetSetup() const
00231 {
00232 return m_smpSetup.GetPointer();
00233 };
00234
00235 void
00236 SetupManager::
00237 SetSetup(Setup* pSetup)
00238 {
00239 if (m_smpSetup.GetPointer()!=pSetup)
00240 {
00241 m_smpSetup = pSetup;
00242 m_smpRootCache = SessionBuilder::GeneratePassiveComponentCache(pSetup->GetRootComponent());
00243 m_RequirementCache.Reset();
00244 }
00245 };
00246
00247 const SessionComponentCache*
00248 SetupManager::
00249 GetSessionCache() const
00250 {
00251 return m_smpRootCache.GetPointer();
00252 };
00253
00254 SessionComponentCache*
00255 SetupManager::
00256 GetSessionCache()
00257 {
00258 return m_smpRootCache.GetPointer();
00259 };
00260
00261 const SetupManager::ComponentCacheCollectionType&
00262 SetupManager::
00263 GetComponentCaches() const
00264 {
00265 if (this->m_smpRootCache.IsNotNull())
00266 {
00267 return this->m_smpRootCache->SubCaches();
00268 }
00269 throwExceptionMacro("Error; cannot retrieve component caches, root cache is NULL. Ensure that session info has been properly builed.");
00270 };
00271
00272 SetupManager::ComponentCacheCollectionType&
00273 SetupManager::
00274 GetComponentCaches()
00275 {
00276 if (this->m_smpRootCache.IsNotNull())
00277 {
00278 return this->m_smpRootCache->SubCaches();
00279 }
00280 throwExceptionMacro("Error; cannot retrieve component caches, root cache is NULL. Ensure that session info has been properly builed.");
00281 };
00282
00283 SetupManager::
00284 SetupManager()
00285 {
00286 m_smpRootCache = 0;
00287 m_smpSetup = 0;
00288 };
00289
00290 void
00291 SetupManager::
00292 ActualizeConstraintCache(Setup* pSetup, const IDPath& componentID, const std::string& sControllername)
00293 {
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 };
00316
00317
00318 void
00319 SetupManager::
00320 ActualizeConstraintCache(Setup* pSetup)
00321 {
00322 m_RequirementCache.Reset();
00323
00324
00325 CtrlProfile::ProfileOption* pOption = m_RequirementCache.AddRequirement(cIDPEveryone)->AddProfileOption();
00326 pOption->CheckForIO();
00327
00328 Setup::SectionVector sections = pSetup->GetSections();
00329 for (unsigned int i = 0; i<sections.size(); i++)
00330 {
00331 ActualizeConstraintCache(pSetup,sections[i]);
00332 }
00333 };
00334
00335 void
00336 SetupManager::
00337 ActualizeConstraintCache(Setup* pSetup, ComponentSetup* pComponentSetup)
00338 {
00339 if (pComponentSetup->GetControllerID()!=csUndefinedController)
00340 {
00341 ActualizeConstraintCache(pSetup,pComponentSetup->GetIDPath(),pComponentSetup->GetControllerID());
00342 }
00343
00344 for (unsigned int i = 0; i<pComponentSetup->Components().Size(); i++)
00345 {
00346 ActualizeConstraintCache(pSetup,pComponentSetup->Components().GetElement(i));
00347 }
00348 };
00349
00350 }