Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame^] | 1 | /* <auto_header> |
| 2 | * <FILENAME> |
| 3 | * |
| 4 | * INTEL CONFIDENTIAL |
| 5 | * Copyright © 2011 Intel |
| 6 | * Corporation All Rights Reserved. |
| 7 | * |
| 8 | * The source code contained or described herein and all documents related to |
| 9 | * the source code ("Material") are owned by Intel Corporation or its suppliers |
| 10 | * or licensors. Title to the Material remains with Intel Corporation or its |
| 11 | * suppliers and licensors. The Material contains trade secrets and proprietary |
| 12 | * and confidential information of Intel or its suppliers and licensors. The |
| 13 | * Material is protected by worldwide copyright and trade secret laws and |
| 14 | * treaty provisions. No part of the Material may be used, copied, reproduced, |
| 15 | * modified, published, uploaded, posted, transmitted, distributed, or |
| 16 | * disclosed in any way without Intel’s prior express written permission. |
| 17 | * |
| 18 | * No license under any patent, copyright, trade secret or other intellectual |
| 19 | * property right is granted to or conferred upon you by disclosure or delivery |
| 20 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 21 | * otherwise. Any license under such intellectual property rights must be |
| 22 | * express and approved by Intel in writing. |
| 23 | * |
| 24 | * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com) |
| 25 | * CREATED: 2011-06-01 |
| 26 | * UPDATED: 2011-07-27 |
| 27 | * |
| 28 | * |
| 29 | * </auto_header> |
| 30 | */ |
| 31 | #include "ParameterMgr.h" |
| 32 | #include "XmlParser.h" |
| 33 | #include "XmlParameterSerializingContext.h" |
| 34 | #include "XmlElementSerializingContext.h" |
| 35 | #include "SystemClass.h" |
| 36 | #include "ElementLibrarySet.h" |
| 37 | #include "SubsystemLibrary.h" |
| 38 | #include "NamedElementBuilderTemplate.h" |
| 39 | #include "KindElementBuilderTemplate.h" |
| 40 | #include "ElementBuilderTemplate.h" |
| 41 | #include "SelectionCriterionType.h" |
| 42 | #include "SelectionCriterionDefinition.h" |
| 43 | #include "SubsystemElementBuilder.h" |
| 44 | #include "SelectionCriteria.h" |
| 45 | #include "ComponentType.h" |
| 46 | #include "ComponentInstance.h" |
| 47 | #include "ParameterBlockType.h" |
| 48 | #include "BooleanParameterType.h" |
| 49 | #include "IntegerParameterType.h" |
| 50 | #include "FixedPointParameterType.h" |
| 51 | #include "ParameterBlackboard.h" |
| 52 | #include "Parameter.h" |
| 53 | #include "ComputedSizeParameterType.h" |
| 54 | #include "ParameterBlackboard.h" |
| 55 | #include "ParameterAccessContext.h" |
| 56 | #include "XmlFileIncluderElement.h" |
| 57 | #include "ParameterFrameworkConfiguration.h" |
| 58 | #include "FrameworkConfigurationGroup.h" |
| 59 | #include "FrameworkConfigurationLocation.h" |
| 60 | #include "SystemClassConfiguration.h" |
| 61 | #include "ConfigurableDomains.h" |
| 62 | #include "ConfigurableDomain.h" |
| 63 | #include "DomainConfiguration.h" |
| 64 | #include "XmlComposer.h" |
| 65 | #include "XmlDomainSerializingContext.h" |
| 66 | #include "BitParameterBlockType.h" |
| 67 | #include "BitParameterType.h" |
| 68 | #include "RemoteProcessorServerInterface.h" |
| 69 | #include "ElementLocator.h" |
| 70 | #include "AutoLog.h" |
| 71 | #include "CompoundRule.h" |
| 72 | #include "SelectionCriterionRule.h" |
| 73 | #include "SimulatedBackSynchronizer.h" |
| 74 | #include "HardwareBackSynchronizer.h" |
| 75 | #include <strings.h> |
| 76 | #include <dlfcn.h> |
| 77 | #include <assert.h> |
| 78 | #include <sstream> |
| 79 | |
| 80 | #define base CElement |
| 81 | |
| 82 | // Used for remote processor server creation |
| 83 | typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler); |
| 84 | |
| 85 | // Global configuration file name (fixed) |
| 86 | const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml"; |
| 87 | const char* gacSystemSchemasSubFolder = "Schemas"; |
| 88 | |
| 89 | // Config File System looks normally like this: |
| 90 | // --------------------------------------------- |
| 91 | //├── ParameterFrameworkConfiguration.xml |
| 92 | //├── Schemas |
| 93 | //│ └── *.xsd |
| 94 | //├── Settings |
| 95 | //│ └── <SystemClassName folder>* |
| 96 | //│ ├── <ConfigurableDomains>.xml |
| 97 | //│ └── <Settings>.bin? |
| 98 | //└── Structure |
| 99 | // └── <SystemClassName folder>* |
| 100 | // ├── <SystemClassName>Class.xml |
| 101 | // └── <Subsystem>.xml* |
| 102 | // -------------------------------------------- |
| 103 | |
| 104 | |
| 105 | // Remote command parser array |
| 106 | const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gaRemoteCommandParserItems[] = { |
| 107 | /// Help |
| 108 | { "help", &CParameterMgr::helpCommandProcess, 0, "", "Show commands description and usage" }, |
| 109 | /// Status |
| 110 | { "status", &CParameterMgr::statusCommandProcess, 0, "", "Show current status" }, |
| 111 | /// Tuning Mode |
| 112 | { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1, "on|off*", "Turn on or off Tuning Mode" }, |
| 113 | { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0, "", "Show Tuning Mode" }, |
| 114 | /// Value Space |
| 115 | { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1, "raw|real*", "Assigns Value Space used for fixed point integer value interpretation" }, |
| 116 | { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0, "", "Show Value Space" }, |
| 117 | /// Sync |
| 118 | { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1, "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" }, |
| 119 | { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0, "", "Show Auto Sync state" }, |
| 120 | { "sync", &CParameterMgr::syncCommmandProcess, 0, "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" }, |
| 121 | /// Domains |
| 122 | { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0, "", "List configurable domains" }, |
| 123 | { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, "<domain>", "Create new configurable domain" }, |
| 124 | { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, "<domain>", "Delete configurable domain" }, |
| 125 | { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, "<domain> <new name>", "Rename configurable domain" }, |
| 126 | { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, "<domain>", "List elements associated to configurable domain" }, |
| 127 | { "addElement", &CParameterMgr::addElementCommmandProcess, 2, "<domain> <elem path>", "Associate element at given path to configurable domain" }, |
| 128 | { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, "<domain> <elem path>", "Dissociate element at given path from configurable domain" }, |
| 129 | { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, "<domain> <elem path>", "Split configurable domain at given associated element path" }, |
| 130 | /// Configurations |
| 131 | { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, "<domain>", "List domain configurations" }, |
| 132 | { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, "<domain> <configuration>", "Create new domain configuration" }, |
| 133 | { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, "<domain> <configuration>", "Delete domain configuration" }, |
| 134 | { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, "<domain> <configuration> <new name>", "Rename domain configuration" }, |
| 135 | { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, "<domain> <configuration>", "Save current settings into configuration" }, |
| 136 | { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, "<domain> <configuration>", "Restore current settings from configuration" }, |
| 137 | /// Elements/Parameters |
| 138 | { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, "<elem path>|/", "List elements under element at given path or root" }, |
| 139 | { "listElementsRecursive", &CParameterMgr::listElementsRecursiveCommmandProcess, 1, "<elem path>|/", "Recursively list elements under element at given path or root" }, |
| 140 | { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, "<elem path>", "Dump structure and content of element at given path" }, |
| 141 | { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, "<elem path>", "Show size of element at given path" }, |
| 142 | { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, "<elem ath>", "Get value for parameter at given path" }, |
| 143 | { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, "<elem path> <value>", "Set value for parameter at given path" }, |
| 144 | { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is contained in" }, |
| 145 | { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, "<elem path>", "List domain(s) element at given path is associated to" }, |
| 146 | /// Browse |
| 147 | { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, "", "List element sub-trees associated to at least one configurable domain" }, |
| 148 | { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, "", "List element sub-trees contained in more than one configurable domain" }, |
| 149 | { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, "", "List element sub-trees owned by no configurable domain" }, |
| 150 | /// Settings Import/Export |
| 151 | { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, "<file path> ", "Export domains to XML file" }, |
| 152 | { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, "<file path>", "Import domains from XML file" }, |
| 153 | { "exportDomainsWithSettingsXML", &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, "<file path> ", "Export domains including settings to XML file" }, |
| 154 | { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "<file path>", "Import domains including settings from XML file" }, |
| 155 | { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "<file path>", "Export settings to binary file" }, |
| 156 | { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, "<file path>", "Import settings from binary file" } |
| 157 | }; |
| 158 | // Remote command parsers array Size |
| 159 | const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gaRemoteCommandParserItems) / sizeof(gaRemoteCommandParserItems[0]); |
| 160 | |
| 161 | CParameterMgr::CParameterMgr(const string& strParameterFrameworkConfigurationFolderPath, const string& strSystemClassName) : |
| 162 | _bTuningModeIsOn(false), |
| 163 | _bValueSpaceIsRaw(false), |
| 164 | _bAutoSyncOn(true), |
| 165 | _pMainParameterBlackboard(new CParameterBlackboard), |
| 166 | _pElementLibrarySet(new CElementLibrarySet), |
| 167 | _strParameterFrameworkConfigurationFolderPath(strParameterFrameworkConfigurationFolderPath), |
| 168 | _strSchemaFolderLocation(strParameterFrameworkConfigurationFolderPath + "/" + gacSystemSchemasSubFolder), |
| 169 | _pSystemClassConfiguration(NULL), |
| 170 | _uiStructureChecksum(0), |
| 171 | _pRemoteProcessorServer(NULL), |
| 172 | _uiMaxCommandUsageLength(0), |
| 173 | _pLogger(NULL), |
| 174 | _uiLogDepth(0) |
| 175 | { |
| 176 | // Tuning Mode Mutex |
| 177 | bzero(&_tuningModeMutex, sizeof(_tuningModeMutex)); |
| 178 | pthread_mutex_init(&_tuningModeMutex, NULL); |
| 179 | |
| 180 | // Deal with children |
| 181 | addChild(new CParameterFrameworkConfiguration); |
| 182 | addChild(new CSelectionCriteria); |
| 183 | addChild(new CSystemClass(strSystemClassName)); |
| 184 | addChild(new CConfigurableDomains(strSystemClassName)); |
| 185 | |
| 186 | // Feed element library |
| 187 | feedElementLibraries(); |
| 188 | } |
| 189 | |
| 190 | CParameterMgr::~CParameterMgr() |
| 191 | { |
| 192 | // Children |
| 193 | delete _pRemoteProcessorServer; |
| 194 | delete _pMainParameterBlackboard; |
| 195 | delete _pElementLibrarySet; |
| 196 | |
| 197 | // Tuning Mode Mutex |
| 198 | pthread_mutex_destroy(&_tuningModeMutex); |
| 199 | } |
| 200 | |
| 201 | string CParameterMgr::getKind() const |
| 202 | { |
| 203 | return "ParameterMgr"; |
| 204 | } |
| 205 | |
| 206 | // Logging |
| 207 | void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger) |
| 208 | { |
| 209 | _pLogger = pLogger; |
| 210 | } |
| 211 | |
| 212 | // Logging |
| 213 | void CParameterMgr::doLog(const string& strLog) const |
| 214 | { |
| 215 | if (_pLogger) { |
| 216 | |
| 217 | // Nest |
| 218 | string strIndent; |
| 219 | |
| 220 | // Level |
| 221 | uint32_t uiNbIndents = _uiLogDepth; |
| 222 | |
| 223 | while (uiNbIndents--) { |
| 224 | |
| 225 | strIndent += " "; |
| 226 | } |
| 227 | |
| 228 | // Log |
| 229 | _pLogger->log(strIndent + strLog); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | void CParameterMgr::nestLog() const |
| 234 | { |
| 235 | ((uint32_t&)_uiLogDepth)++; |
| 236 | } |
| 237 | |
| 238 | void CParameterMgr::unnestLog() const |
| 239 | { |
| 240 | ((uint32_t&)_uiLogDepth)--; |
| 241 | } |
| 242 | |
| 243 | bool CParameterMgr::load(string& strError) |
| 244 | { |
| 245 | CAutoLog autoLog(this, "Loading"); |
| 246 | |
| 247 | // Load Framework configuration |
| 248 | if (!loadFrameworkConfiguration(strError)) { |
| 249 | |
| 250 | return false; |
| 251 | } |
| 252 | |
| 253 | // Load subsystems |
| 254 | if (!getSystemClass()->loadSubsystems(strError, _astrPluginFolderPaths)) { |
| 255 | |
| 256 | return false; |
| 257 | } |
| 258 | |
| 259 | // Load structure |
| 260 | if (!loadStructure(strError)) { |
| 261 | |
| 262 | return false; |
| 263 | } |
| 264 | |
| 265 | // Load settings |
| 266 | if (!loadSettings(strError)) { |
| 267 | |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | // All is loaded, we're ready to observe selection criteria events |
| 272 | getSelectionCriteria()->setObserver(this); |
| 273 | |
| 274 | // Load and start Remote processor server if appropriate |
| 275 | if (!handleRemoteProcessingInterface(strError)) { |
| 276 | |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | return true; |
| 281 | } |
| 282 | |
| 283 | bool CParameterMgr::loadFrameworkConfiguration(string& strError) |
| 284 | { |
| 285 | CAutoLog autoLog(this, "Loading framework configuration"); |
| 286 | |
| 287 | // Get Xml config file name |
| 288 | string strXmlConfigurationFilePath = _strParameterFrameworkConfigurationFolderPath + "/" + gacParameterFrameworkConfigurationFileName; |
| 289 | |
| 290 | // Parse Structure XML file |
| 291 | CXmlElementSerializingContext elementSerializingContext(strError); |
| 292 | |
| 293 | if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), strXmlConfigurationFilePath, _strParameterFrameworkConfigurationFolderPath, EFrameworkConfigurationLibrary)) { |
| 294 | |
| 295 | return false; |
| 296 | } |
| 297 | // Get subsystem plugins folders element |
| 298 | const CFrameworkConfigurationGroup* pSubsystemPluginFolders= static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChild("SubsystemPluginFolders")); |
| 299 | |
| 300 | if (!pSubsystemPluginFolders) { |
| 301 | |
| 302 | strError = "Parameter Framework Configuration: couldn't find SubsystemPluginFolders element"; |
| 303 | |
| 304 | return false; |
| 305 | } |
| 306 | // Get plugin locations |
| 307 | uint32_t uiPluginFolderLocation; |
| 308 | uint32_t uiNbPluginFolderLocations = pSubsystemPluginFolders->getNbChildren(); |
| 309 | |
| 310 | if (!uiNbPluginFolderLocations) { |
| 311 | |
| 312 | strError = "Parameter Framework Configuration: couldn't find any PluginFolderLocation element"; |
| 313 | |
| 314 | return false; |
| 315 | } |
| 316 | |
| 317 | for (uiPluginFolderLocation = 0; uiPluginFolderLocation < uiNbPluginFolderLocations; uiPluginFolderLocation++) { |
| 318 | |
| 319 | const CFrameworkConfigurationLocation* pSubsystemPluginLocation = static_cast<const CFrameworkConfigurationLocation*>(pSubsystemPluginFolders->getChild(uiPluginFolderLocation)); |
| 320 | |
| 321 | _astrPluginFolderPaths.push_back(pSubsystemPluginLocation->getFilePath(_strParameterFrameworkConfigurationFolderPath)); |
| 322 | } |
| 323 | |
| 324 | // Get configuration for current system class |
| 325 | const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("ParameterConfiguration")); |
| 326 | |
| 327 | if (!pParameterConfigurationGroup) { |
| 328 | |
| 329 | strError = "Parameter Framework Configuration: couldn't find ParameterConfiguration element"; |
| 330 | |
| 331 | return false; |
| 332 | } |
| 333 | _pSystemClassConfiguration = static_cast<const CSystemClassConfiguration*>(pParameterConfigurationGroup->findChild(getSystemClass()->getName())); |
| 334 | |
| 335 | if (!_pSystemClassConfiguration) { |
| 336 | |
| 337 | strError = "No framework configuration found for SystemClass " + getSystemClass()->getName(); |
| 338 | |
| 339 | return false; |
| 340 | } |
| 341 | // Log tuning availability |
| 342 | log("Tuning %s", _pSystemClassConfiguration->isTuningAllowed() ? "allowed" : "prohibited"); |
| 343 | |
| 344 | return true; |
| 345 | } |
| 346 | |
| 347 | bool CParameterMgr::loadStructure(string& strError) |
| 348 | { |
| 349 | // Retrieve system to load structure to |
| 350 | CSystemClass* pSystemClass = getSystemClass(); |
| 351 | |
| 352 | CAutoLog autoLog(this, "Loading " + pSystemClass->getName() + " system class structure"); |
| 353 | |
| 354 | // Get structure description element |
| 355 | const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(_pSystemClassConfiguration->findChildOfKind("StructureDescriptionFileLocation")); |
| 356 | |
| 357 | if (!pStructureDescriptionFileLocation) { |
| 358 | |
| 359 | strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName(); |
| 360 | |
| 361 | return false; |
| 362 | } |
| 363 | |
| 364 | // Get Xml structure folder |
| 365 | string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strParameterFrameworkConfigurationFolderPath); |
| 366 | |
| 367 | // Get Xml structure file name |
| 368 | string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strParameterFrameworkConfigurationFolderPath); |
| 369 | |
| 370 | // Parse Structure XML file |
| 371 | CXmlParameterSerializingContext parameterBuildContext(strError); |
| 372 | |
| 373 | if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) { |
| 374 | |
| 375 | return false; |
| 376 | } |
| 377 | |
| 378 | // Initialize offsets |
| 379 | pSystemClass->setOffset(0); |
| 380 | |
| 381 | // Initialize main blackboard's size |
| 382 | _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint()); |
| 383 | |
| 384 | return true; |
| 385 | } |
| 386 | |
| 387 | bool CParameterMgr::loadSettings(string& strError) |
| 388 | { |
| 389 | CAutoLog autoLog(this, "Loading settings"); |
| 390 | |
| 391 | // Get settings configuration element |
| 392 | const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(_pSystemClassConfiguration->findChildOfKind("SettingsConfiguration")); |
| 393 | |
| 394 | if (!pParameterConfigurationGroup) { |
| 395 | |
| 396 | // No settings to load |
| 397 | |
| 398 | return true; |
| 399 | } |
| 400 | // Get binary settings file location |
| 401 | const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation")); |
| 402 | |
| 403 | string strXmlBinarySettingsFilePath; |
| 404 | |
| 405 | if (pBinarySettingsFileLocation) { |
| 406 | |
| 407 | // Get Xml binary settings file name |
| 408 | strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strParameterFrameworkConfigurationFolderPath); |
| 409 | } |
| 410 | |
| 411 | // Get configurable domains element |
| 412 | const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation")); |
| 413 | |
| 414 | if (!pConfigurableDomainsFileLocation) { |
| 415 | |
| 416 | strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName(); |
| 417 | |
| 418 | return false; |
| 419 | } |
| 420 | // Get destination root element |
| 421 | CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); |
| 422 | |
| 423 | // Get Xml configuration domains file name |
| 424 | string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strParameterFrameworkConfigurationFolderPath); |
| 425 | |
| 426 | // Get Xml configuration domains folder |
| 427 | string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strParameterFrameworkConfigurationFolderPath); |
| 428 | |
| 429 | // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary) |
| 430 | CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation); |
| 431 | |
| 432 | // Selection criteria definition for rule creation |
| 433 | xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition()); |
| 434 | |
| 435 | // Do parse |
| 436 | if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) { |
| 437 | |
| 438 | return false; |
| 439 | } |
| 440 | // We have loaded the whole system structure, compute checksum |
| 441 | const CSystemClass* pSystemClass = getConstSystemClass(); |
| 442 | _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum(); |
| 443 | |
| 444 | // Load binary settings if any provided |
| 445 | if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) { |
| 446 | |
| 447 | return false; |
| 448 | } |
| 449 | |
| 450 | // Back synchronization for areas in parameter blackboard no covered by any domain |
| 451 | CBackSynchronizer* pBackSynchronizer = createBackSynchronizer(strError); |
| 452 | |
| 453 | log("Main blackboard back synchronization"); |
| 454 | |
| 455 | // Back-synchronize |
| 456 | if (!pBackSynchronizer->sync()) { |
| 457 | // Get rif of back synchronizer |
| 458 | delete pBackSynchronizer; |
| 459 | |
| 460 | strError = "Main blackboard back synchronization failed: " + strError; |
| 461 | |
| 462 | return false; |
| 463 | } |
| 464 | // Get rif of back synchronizer |
| 465 | delete pBackSynchronizer; |
| 466 | |
| 467 | // We're done loading the settings |
| 468 | // We need to ensure all domains are valid |
| 469 | pConfigurableDomains->validate(_pMainParameterBlackboard); |
| 470 | |
| 471 | // Ensure application of currently selected configurations |
| 472 | // Force-apply configuration(s) |
| 473 | return pConfigurableDomains->apply(_pMainParameterBlackboard, true, strError); |
| 474 | } |
| 475 | |
| 476 | // XML parsing |
| 477 | bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName) |
| 478 | { |
| 479 | // Init serializing context |
| 480 | elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary), strXmlFolder, _strSchemaFolderLocation); |
| 481 | |
| 482 | // Get Schema file associated to root element |
| 483 | string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd"; |
| 484 | |
| 485 | // Parse Structure XML file |
| 486 | CXmlParser parser(strXmlFilePath, strXmlSchemaFilePath, pRootElement->getKind(), elementSerializingContext); |
| 487 | |
| 488 | if (!parser.open()) { |
| 489 | |
| 490 | return false; |
| 491 | } |
| 492 | |
| 493 | // Check Root element name attribute (if any) |
| 494 | string strRootElementName = parser.getRootElementAttributeString(strNameAttrituteName); |
| 495 | |
| 496 | if (!strRootElementName.empty() && strRootElementName != pRootElement->getName()) { |
| 497 | |
| 498 | elementSerializingContext.setError("Error: Wrong XML structure file " + strXmlFilePath); |
| 499 | elementSerializingContext.appendLineToError(pRootElement->getKind() + " element " + pRootElement->getName() + " mismatches expected " + pRootElement->getKind() + " type " + pRootElement->getName()); |
| 500 | |
| 501 | return false; |
| 502 | } |
| 503 | |
| 504 | // Start clean |
| 505 | pRootElement->clean(); |
| 506 | |
| 507 | // Parse |
| 508 | if (!parser.parse(pRootElement)) { |
| 509 | |
| 510 | // Cleanup |
| 511 | pRootElement->clean(); |
| 512 | |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | // Close parser |
| 517 | if (!parser.close()) { |
| 518 | |
| 519 | return false; |
| 520 | } |
| 521 | |
| 522 | return true; |
| 523 | } |
| 524 | |
| 525 | // Init |
| 526 | bool CParameterMgr::init(string& strError) |
| 527 | { |
| 528 | return base::init(strError); |
| 529 | } |
| 530 | |
| 531 | // Selection criteria interface |
| 532 | CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive) |
| 533 | { |
| 534 | // Propagate |
| 535 | return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive); |
| 536 | } |
| 537 | |
| 538 | CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType) |
| 539 | { |
| 540 | // Propagate |
| 541 | return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType); |
| 542 | } |
| 543 | |
| 544 | // Selection criteria changed event |
| 545 | void CParameterMgr::selectionCriterionChanged(const CSelectionCriterion* pSelectionCriterion) |
| 546 | { |
| 547 | CAutoLog autoLog(this, pSelectionCriterion->getName() + " selection criterion changed event"); |
| 548 | |
| 549 | // Lock state |
| 550 | pthread_mutex_lock(&_tuningModeMutex); |
| 551 | |
| 552 | if (!_bTuningModeIsOn) { |
| 553 | |
| 554 | // Apply configuration(s) |
| 555 | string strError; |
| 556 | |
| 557 | if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, false, strError)) { |
| 558 | |
| 559 | log("Failed to apply configurations!"); |
| 560 | } |
| 561 | } |
| 562 | // Unlock state |
| 563 | pthread_mutex_unlock(&_tuningModeMutex); |
| 564 | } |
| 565 | |
| 566 | // Command processing |
| 567 | bool CParameterMgr::remoteCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 568 | { |
| 569 | log("Processing remote command: \"%s\"", remoteCommand.getCommand().c_str()); |
| 570 | |
| 571 | // Dispatch |
| 572 | uint32_t uiRemoteCommandParserItem; |
| 573 | |
| 574 | for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) { |
| 575 | |
| 576 | const SRemoteCommandParserItem* pRemoteCommandParserItem = &gaRemoteCommandParserItems[uiRemoteCommandParserItem]; |
| 577 | |
| 578 | if (string(pRemoteCommandParserItem->_pcCommandName) == remoteCommand.getCommand()) { |
| 579 | |
| 580 | // Check enough arguments supplied |
| 581 | if (remoteCommand.getArgumentCount() < pRemoteCommandParserItem->_uiMinArgumentCount) { |
| 582 | |
| 583 | strResult = string("Not enough arguments supplied\nUsage:\n") + pRemoteCommandParserItem->usage(); |
| 584 | |
| 585 | return false; |
| 586 | } |
| 587 | |
| 588 | switch ((this->*pRemoteCommandParserItem->_pfnParser)(remoteCommand, strResult)) { |
| 589 | case EDone: |
| 590 | strResult = "Done"; |
| 591 | case ESucceeded: |
| 592 | return true; |
| 593 | case EShowUsgae: |
| 594 | strResult = pRemoteCommandParserItem->usage(); |
| 595 | // Fall through intentionally |
| 596 | case EFailed: |
| 597 | return false; |
| 598 | default: |
| 599 | assert(0); |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | // Not found |
| 604 | strResult = "Command not found!"; |
| 605 | |
| 606 | return false; |
| 607 | } |
| 608 | |
| 609 | // Max command usage length, use for formatting |
| 610 | void CParameterMgr::setMaxCommandUsageLength() |
| 611 | { |
| 612 | // Show usages |
| 613 | uint32_t uiRemoteCommandParserItem; |
| 614 | |
| 615 | for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) { |
| 616 | |
| 617 | const SRemoteCommandParserItem* pRemoteCommandParserItem = &gaRemoteCommandParserItems[uiRemoteCommandParserItem]; |
| 618 | |
| 619 | uint32_t uiRemoteCommandUsageLength = pRemoteCommandParserItem->usage().length(); |
| 620 | |
| 621 | if (uiRemoteCommandUsageLength > _uiMaxCommandUsageLength) { |
| 622 | |
| 623 | _uiMaxCommandUsageLength = uiRemoteCommandUsageLength; |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | /////////////////// Remote command parsers |
| 629 | /// Help |
| 630 | CParameterMgr::CommandStatus CParameterMgr::helpCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 631 | { |
| 632 | (void)remoteCommand; |
| 633 | |
| 634 | strResult = "\n"; |
| 635 | |
| 636 | // Show usages |
| 637 | uint32_t uiRemoteCommandParserItem; |
| 638 | |
| 639 | for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) { |
| 640 | |
| 641 | const SRemoteCommandParserItem* pRemoteCommandParserItem = &gaRemoteCommandParserItems[uiRemoteCommandParserItem]; |
| 642 | |
| 643 | string strUsage = pRemoteCommandParserItem->usage(); |
| 644 | |
| 645 | strResult += strUsage; |
| 646 | |
| 647 | // Align |
| 648 | uint32_t uiToSpacesAdd = _uiMaxCommandUsageLength + 5 - strUsage.length(); |
| 649 | |
| 650 | while (uiToSpacesAdd--) { |
| 651 | |
| 652 | strResult += " "; |
| 653 | } |
| 654 | |
| 655 | strResult += string("=> ") + string(pRemoteCommandParserItem->_pcDescription) + "\n"; |
| 656 | |
| 657 | } |
| 658 | return ESucceeded; |
| 659 | } |
| 660 | |
| 661 | /// Status |
| 662 | CParameterMgr::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 663 | { |
| 664 | (void)remoteCommand; |
| 665 | // System class |
| 666 | const CSystemClass* pSystemClass = getSystemClass(); |
| 667 | |
| 668 | strResult = "\n"; |
| 669 | |
| 670 | // Show status |
| 671 | /// System class |
| 672 | strResult += "System Class: "; |
| 673 | strResult += pSystemClass->getName(); |
| 674 | strResult += "\n"; |
| 675 | |
| 676 | /// Tuning mode |
| 677 | strResult += "Tuning Mode: "; |
| 678 | strResult += tuningModeOn() ? "on" : "off"; |
| 679 | strResult += "\n"; |
| 680 | |
| 681 | /// Value space |
| 682 | strResult += "Value Space: "; |
| 683 | strResult += valueSpaceIsRaw() ? "raw" : "real"; |
| 684 | strResult += "\n"; |
| 685 | |
| 686 | /// Value space |
| 687 | strResult += "Auto Sync: "; |
| 688 | strResult += autoSyncOn() ? "on" : "off"; |
| 689 | strResult += "\n"; |
| 690 | |
| 691 | /// Subsystem list |
| 692 | strResult += "\nSubsystems:"; |
| 693 | string strSubsystemList; |
| 694 | pSystemClass->listChildrenPaths(strSubsystemList); |
| 695 | strResult += strSubsystemList; |
| 696 | |
| 697 | /// Last applied configurations |
| 698 | strResult += "\nLast applied configurations:"; |
| 699 | string strLastAppliedConfigurations; |
| 700 | getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations); |
| 701 | strResult += strLastAppliedConfigurations; |
| 702 | |
| 703 | return ESucceeded; |
| 704 | } |
| 705 | |
| 706 | /// Tuning Mode |
| 707 | CParameterMgr::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 708 | { |
| 709 | if (remoteCommand.getArgument(0) == "on") { |
| 710 | |
| 711 | if (setTuningMode(true, strResult)) { |
| 712 | |
| 713 | return EDone; |
| 714 | } |
| 715 | } else if (remoteCommand.getArgument(0) == "off") { |
| 716 | |
| 717 | if (setTuningMode(false, strResult)) { |
| 718 | |
| 719 | return EDone; |
| 720 | } |
| 721 | } else { |
| 722 | // Show usage |
| 723 | return EShowUsgae; |
| 724 | } |
| 725 | return EFailed; |
| 726 | } |
| 727 | |
| 728 | CParameterMgr::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 729 | { |
| 730 | (void)remoteCommand; |
| 731 | |
| 732 | strResult = tuningModeOn() ? "on" : "off"; |
| 733 | |
| 734 | return ESucceeded; |
| 735 | } |
| 736 | |
| 737 | /// Value Space |
| 738 | CParameterMgr::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 739 | { |
| 740 | (void)strResult; |
| 741 | |
| 742 | if (remoteCommand.getArgument(0) == "raw") { |
| 743 | |
| 744 | setValueSpace(true); |
| 745 | |
| 746 | return EDone; |
| 747 | |
| 748 | } else if (remoteCommand.getArgument(0) == "real") { |
| 749 | |
| 750 | setValueSpace(false); |
| 751 | |
| 752 | return EDone; |
| 753 | |
| 754 | } else { |
| 755 | // Show usage |
| 756 | return EShowUsgae; |
| 757 | } |
| 758 | return EFailed; |
| 759 | } |
| 760 | |
| 761 | CParameterMgr::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 762 | { |
| 763 | (void)remoteCommand; |
| 764 | |
| 765 | strResult = valueSpaceIsRaw() ? "raw" : "real"; |
| 766 | |
| 767 | return ESucceeded; |
| 768 | } |
| 769 | |
| 770 | /// Sync |
| 771 | CParameterMgr::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 772 | { |
| 773 | if (remoteCommand.getArgument(0) == "on") { |
| 774 | |
| 775 | if (setAutoSync(true, strResult)) { |
| 776 | |
| 777 | return EDone; |
| 778 | } |
| 779 | } else if (remoteCommand.getArgument(0) == "off") { |
| 780 | |
| 781 | if (setAutoSync(false, strResult)) { |
| 782 | |
| 783 | return EDone; |
| 784 | } |
| 785 | } else { |
| 786 | // Show usage |
| 787 | return EShowUsgae; |
| 788 | } |
| 789 | return EFailed; |
| 790 | } |
| 791 | |
| 792 | CParameterMgr::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 793 | { |
| 794 | (void)remoteCommand; |
| 795 | |
| 796 | strResult = autoSyncOn() ? "on" : "off"; |
| 797 | |
| 798 | return ESucceeded; |
| 799 | } |
| 800 | |
| 801 | CParameterMgr::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 802 | { |
| 803 | (void)remoteCommand; |
| 804 | |
| 805 | return sync(strResult) ? EDone : EFailed; |
| 806 | } |
| 807 | |
| 808 | |
| 809 | /// Domains |
| 810 | CParameterMgr::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 811 | { |
| 812 | (void)remoteCommand; |
| 813 | |
| 814 | getConfigurableDomains()->listChildren(strResult); |
| 815 | |
| 816 | return ESucceeded; |
| 817 | } |
| 818 | |
| 819 | CParameterMgr::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 820 | { |
| 821 | return createDomain(remoteCommand.getArgument(0), strResult) ? EDone : EFailed; |
| 822 | } |
| 823 | |
| 824 | CParameterMgr::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 825 | { |
| 826 | return deleteDomain(remoteCommand.getArgument(0), strResult) ? EDone : EFailed; |
| 827 | } |
| 828 | |
| 829 | CParameterMgr::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 830 | { |
| 831 | return getConfigurableDomains()->renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed; |
| 832 | } |
| 833 | |
| 834 | CParameterMgr::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 835 | { |
| 836 | return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? ESucceeded : EFailed; |
| 837 | } |
| 838 | |
| 839 | CParameterMgr::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 840 | { |
| 841 | return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed; |
| 842 | } |
| 843 | |
| 844 | CParameterMgr::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 845 | { |
| 846 | return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed; |
| 847 | } |
| 848 | |
| 849 | CParameterMgr::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 850 | { |
| 851 | return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed; |
| 852 | } |
| 853 | |
| 854 | /// Configurations |
| 855 | CParameterMgr::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 856 | { |
| 857 | return getConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? ESucceeded : EFailed; |
| 858 | } |
| 859 | |
| 860 | CParameterMgr::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 861 | { |
| 862 | return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed; |
| 863 | } |
| 864 | |
| 865 | CParameterMgr::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 866 | { |
| 867 | return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed; |
| 868 | } |
| 869 | |
| 870 | CParameterMgr::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 871 | { |
| 872 | return getConfigurableDomains()->renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strResult) ? EDone : EFailed; |
| 873 | } |
| 874 | |
| 875 | CParameterMgr::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 876 | { |
| 877 | return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed; |
| 878 | } |
| 879 | |
| 880 | CParameterMgr::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 881 | { |
| 882 | return restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed; |
| 883 | } |
| 884 | |
| 885 | /// Elements/Parameters |
| 886 | CParameterMgr::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 887 | { |
| 888 | CElementLocator elementLocator(getSystemClass(), false); |
| 889 | |
| 890 | CElement* pLocatedElement = NULL; |
| 891 | |
| 892 | if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { |
| 893 | |
| 894 | return EFailed; |
| 895 | } |
| 896 | |
| 897 | strResult = string("\n"); |
| 898 | |
| 899 | if (!pLocatedElement) { |
| 900 | |
| 901 | // List from root folder |
| 902 | |
| 903 | // Return system class qualified name |
| 904 | pLocatedElement = getSystemClass(); |
| 905 | } |
| 906 | |
| 907 | // Return sub-elements |
| 908 | strResult += pLocatedElement->listQualifiedPaths(false); |
| 909 | |
| 910 | return ESucceeded; |
| 911 | } |
| 912 | |
| 913 | /// Elements/Parameters |
| 914 | CParameterMgr::CommandStatus CParameterMgr::listElementsRecursiveCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 915 | { |
| 916 | CElementLocator elementLocator(getSystemClass(), false); |
| 917 | |
| 918 | CElement* pLocatedElement = NULL; |
| 919 | |
| 920 | if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { |
| 921 | |
| 922 | return EFailed; |
| 923 | } |
| 924 | |
| 925 | strResult = string("\n"); |
| 926 | |
| 927 | if (!pLocatedElement) { |
| 928 | |
| 929 | // List from root folder |
| 930 | |
| 931 | // Return system class qualified name |
| 932 | pLocatedElement = getSystemClass(); |
| 933 | } |
| 934 | |
| 935 | // Return sub-elements |
| 936 | strResult += pLocatedElement->listQualifiedPaths(true); |
| 937 | |
| 938 | return ESucceeded; |
| 939 | } |
| 940 | |
| 941 | CParameterMgr::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 942 | { |
| 943 | CElementLocator elementLocator(getSystemClass()); |
| 944 | |
| 945 | CElement* pLocatedElement = NULL; |
| 946 | |
| 947 | if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { |
| 948 | |
| 949 | return EFailed; |
| 950 | } |
| 951 | |
| 952 | string strError; |
| 953 | |
| 954 | CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw); |
| 955 | |
| 956 | // Dump elements |
| 957 | pLocatedElement->dumpContent(strResult, parameterAccessContext); |
| 958 | |
| 959 | return ESucceeded; |
| 960 | } |
| 961 | |
| 962 | CParameterMgr::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 963 | { |
| 964 | CElementLocator elementLocator(getSystemClass()); |
| 965 | |
| 966 | CElement* pLocatedElement = NULL; |
| 967 | |
| 968 | if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { |
| 969 | |
| 970 | return EFailed; |
| 971 | } |
| 972 | |
| 973 | // Converted to actual sizable element |
| 974 | const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement); |
| 975 | |
| 976 | // Get size as string |
| 977 | ostringstream str; |
| 978 | |
| 979 | str << endl << pConfigurableElement->getFootPrint() << " bytes" << endl; |
| 980 | |
| 981 | strResult = str.str(); |
| 982 | |
| 983 | return ESucceeded; |
| 984 | } |
| 985 | |
| 986 | CParameterMgr::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 987 | { |
| 988 | string strValue; |
| 989 | |
| 990 | if (!getValue(remoteCommand.getArgument(0), strValue, strResult)) { |
| 991 | |
| 992 | return EFailed; |
| 993 | } |
| 994 | // Succeeded |
| 995 | strResult = strValue; |
| 996 | |
| 997 | return ESucceeded; |
| 998 | } |
| 999 | |
| 1000 | CParameterMgr::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1001 | { |
| 1002 | return setValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? EDone : EFailed; |
| 1003 | } |
| 1004 | |
| 1005 | CParameterMgr::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1006 | { |
| 1007 | CElementLocator elementLocator(getSystemClass()); |
| 1008 | |
| 1009 | CElement* pLocatedElement = NULL; |
| 1010 | |
| 1011 | if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { |
| 1012 | |
| 1013 | return EFailed; |
| 1014 | } |
| 1015 | |
| 1016 | // Convert element |
| 1017 | const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement); |
| 1018 | |
| 1019 | // Return element belonging domains |
| 1020 | pConfigurableElement->listBelongingDomains(strResult); |
| 1021 | |
| 1022 | return ESucceeded; |
| 1023 | } |
| 1024 | |
| 1025 | CParameterMgr::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1026 | { |
| 1027 | CElementLocator elementLocator(getSystemClass()); |
| 1028 | |
| 1029 | CElement* pLocatedElement = NULL; |
| 1030 | |
| 1031 | if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { |
| 1032 | |
| 1033 | return EFailed; |
| 1034 | } |
| 1035 | |
| 1036 | // Convert element |
| 1037 | const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement); |
| 1038 | |
| 1039 | // Return element belonging domains |
| 1040 | pConfigurableElement->listAssociatedDomains(strResult); |
| 1041 | |
| 1042 | return ESucceeded; |
| 1043 | } |
| 1044 | |
| 1045 | CParameterMgr::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1046 | { |
| 1047 | (void)remoteCommand; |
| 1048 | |
| 1049 | getConfigurableDomains()->listAssociatedElements(strResult); |
| 1050 | |
| 1051 | return ESucceeded; |
| 1052 | } |
| 1053 | |
| 1054 | CParameterMgr::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1055 | { |
| 1056 | (void)remoteCommand; |
| 1057 | |
| 1058 | getConfigurableDomains()->listConflictingElements(strResult); |
| 1059 | |
| 1060 | return ESucceeded; |
| 1061 | } |
| 1062 | |
| 1063 | CParameterMgr::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1064 | { |
| 1065 | (void)remoteCommand; |
| 1066 | |
| 1067 | getSystemClass()->listRogueElements(strResult); |
| 1068 | |
| 1069 | return ESucceeded; |
| 1070 | } |
| 1071 | |
| 1072 | /// Settings Import/Export |
| 1073 | CParameterMgr::CommandStatus CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1074 | { |
| 1075 | return exportDomainsXml(remoteCommand.getArgument(0), false, strResult) ? EDone : EFailed; |
| 1076 | } |
| 1077 | |
| 1078 | CParameterMgr::CommandStatus CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1079 | { |
| 1080 | return importDomainsXml(remoteCommand.getArgument(0), false, strResult) ? EDone : EFailed; |
| 1081 | } |
| 1082 | |
| 1083 | CParameterMgr::CommandStatus CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1084 | { |
| 1085 | return exportDomainsXml(remoteCommand.getArgument(0), true, strResult) ? EDone : EFailed; |
| 1086 | } |
| 1087 | |
| 1088 | CParameterMgr::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1089 | { |
| 1090 | return importDomainsXml(remoteCommand.getArgument(0), true, strResult) ? EDone : EFailed; |
| 1091 | } |
| 1092 | |
| 1093 | CParameterMgr::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1094 | { |
| 1095 | return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? EDone : EFailed; |
| 1096 | } |
| 1097 | |
| 1098 | CParameterMgr::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) |
| 1099 | { |
| 1100 | return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? EDone : EFailed; |
| 1101 | } |
| 1102 | |
| 1103 | // User set/get parameters |
| 1104 | bool CParameterMgr::setValue(const string& strPath, const string& strValue, string& strError) |
| 1105 | { |
| 1106 | // Check tuning mode |
| 1107 | if (!checkTuningModeOn(strError)) { |
| 1108 | |
| 1109 | return false; |
| 1110 | } |
| 1111 | |
| 1112 | CPathNavigator pathNavigator(strPath); |
| 1113 | |
| 1114 | if (!pathNavigator.isPathValid()) { |
| 1115 | |
| 1116 | strError = "Path not well formed"; |
| 1117 | |
| 1118 | return false; |
| 1119 | } |
| 1120 | |
| 1121 | string* pStrChildName = pathNavigator.next(); |
| 1122 | |
| 1123 | if (!pStrChildName) { |
| 1124 | |
| 1125 | strError = "Non settable element"; |
| 1126 | |
| 1127 | return false; |
| 1128 | } |
| 1129 | |
| 1130 | if (*pStrChildName != getSystemClass()->getName()) { |
| 1131 | |
| 1132 | strError = "Path not found"; |
| 1133 | |
| 1134 | return false; |
| 1135 | } |
| 1136 | |
| 1137 | // Define context |
| 1138 | CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw); |
| 1139 | |
| 1140 | // Set auto sync |
| 1141 | parameterAccessContext.setAutoSync(_bAutoSyncOn); |
| 1142 | |
| 1143 | // Do the set |
| 1144 | return getSystemClass()->setValue(pathNavigator, strValue, parameterAccessContext); |
| 1145 | } |
| 1146 | |
| 1147 | bool CParameterMgr::getValue(const string& strPath, string& strValue, string& strError) const |
| 1148 | { |
| 1149 | CPathNavigator pathNavigator(strPath); |
| 1150 | |
| 1151 | if (!pathNavigator.isPathValid()) { |
| 1152 | |
| 1153 | strError = "Path not well formed"; |
| 1154 | |
| 1155 | return false; |
| 1156 | } |
| 1157 | |
| 1158 | string* pStrChildName = pathNavigator.next(); |
| 1159 | |
| 1160 | if (!pStrChildName) { |
| 1161 | |
| 1162 | strError = "Non settable element"; |
| 1163 | |
| 1164 | return false; |
| 1165 | } |
| 1166 | |
| 1167 | if (*pStrChildName != getConstSystemClass()->getName()) { |
| 1168 | |
| 1169 | strError = "Path not found"; |
| 1170 | |
| 1171 | return false; |
| 1172 | } |
| 1173 | |
| 1174 | // Define context |
| 1175 | CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw); |
| 1176 | |
| 1177 | // Do the get |
| 1178 | return getConstSystemClass()->getValue(pathNavigator, strValue, parameterAccessContext); |
| 1179 | } |
| 1180 | |
| 1181 | // Tuning mode |
| 1182 | bool CParameterMgr::setTuningMode(bool bOn, string& strError) |
| 1183 | { |
| 1184 | // Tuning allowed? |
| 1185 | if (bOn && !_pSystemClassConfiguration->isTuningAllowed()) { |
| 1186 | |
| 1187 | strError = "Tuning prohibited"; |
| 1188 | |
| 1189 | return false; |
| 1190 | } |
| 1191 | // Lock state |
| 1192 | pthread_mutex_lock(&_tuningModeMutex); |
| 1193 | |
| 1194 | // Warn domains about exiting tuning mode |
| 1195 | if (!bOn && _bTuningModeIsOn) { |
| 1196 | |
| 1197 | // Ensure application of currently selected configurations |
| 1198 | // Force-apply configuration(s) |
| 1199 | if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) { |
| 1200 | |
| 1201 | return false; |
| 1202 | } |
| 1203 | // Turn auto sync back on |
| 1204 | _bAutoSyncOn = true; |
| 1205 | } |
| 1206 | |
| 1207 | // Store |
| 1208 | _bTuningModeIsOn = bOn; |
| 1209 | |
| 1210 | // Unlock state |
| 1211 | pthread_mutex_unlock(&_tuningModeMutex); |
| 1212 | |
| 1213 | return true; |
| 1214 | } |
| 1215 | |
| 1216 | bool CParameterMgr::tuningModeOn() const |
| 1217 | { |
| 1218 | return _bTuningModeIsOn; |
| 1219 | } |
| 1220 | |
| 1221 | // Current value space for user set/get value interpretation |
| 1222 | void CParameterMgr::setValueSpace(bool bIsRaw) |
| 1223 | { |
| 1224 | _bValueSpaceIsRaw = bIsRaw; |
| 1225 | } |
| 1226 | |
| 1227 | bool CParameterMgr::valueSpaceIsRaw() |
| 1228 | { |
| 1229 | return _bValueSpaceIsRaw; |
| 1230 | } |
| 1231 | |
| 1232 | /// Sync |
| 1233 | // Automatic hardware synchronization control (during tuning session) |
| 1234 | bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError) |
| 1235 | { |
| 1236 | // Check tuning mode |
| 1237 | if (!checkTuningModeOn(strError)) { |
| 1238 | |
| 1239 | return false; |
| 1240 | } |
| 1241 | // Warn domains about turning auto sync back on |
| 1242 | if (bAutoSyncOn && !_bAutoSyncOn) { |
| 1243 | |
| 1244 | // Ensure application of currently selected configurations |
| 1245 | // Force-apply configuration(s) |
| 1246 | if (!getConfigurableDomains()->apply(_pMainParameterBlackboard, true, strError)) { |
| 1247 | |
| 1248 | return false; |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | // Set Auto sync |
| 1253 | _bAutoSyncOn = bAutoSyncOn; |
| 1254 | |
| 1255 | return true; |
| 1256 | } |
| 1257 | |
| 1258 | bool CParameterMgr::autoSyncOn() const |
| 1259 | { |
| 1260 | return _bAutoSyncOn; |
| 1261 | } |
| 1262 | |
| 1263 | // Manual hardware synchronization control (during tuning session) |
| 1264 | bool CParameterMgr::sync(string& strError) |
| 1265 | { |
| 1266 | // Check tuning mode |
| 1267 | if (!checkTuningModeOn(strError)) { |
| 1268 | |
| 1269 | return false; |
| 1270 | } |
| 1271 | // Warn domains about turning auto sync back on |
| 1272 | if (_bAutoSyncOn) { |
| 1273 | |
| 1274 | strError = "Feature unavailable when Auto Sync is on"; |
| 1275 | |
| 1276 | return false; |
| 1277 | } |
| 1278 | |
| 1279 | // Get syncer set |
| 1280 | CSyncerSet syncerSet; |
| 1281 | // ... from system class |
| 1282 | getConstSystemClass()->fillSyncerSet(syncerSet); |
| 1283 | // Sync |
| 1284 | return syncerSet.sync(*_pMainParameterBlackboard, false, strError); |
| 1285 | } |
| 1286 | |
| 1287 | // Content dump |
| 1288 | void CParameterMgr::logStructureContent(string& strContent) const |
| 1289 | { |
| 1290 | string strError; |
| 1291 | |
| 1292 | CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw); |
| 1293 | |
| 1294 | dumpContent(strContent, parameterAccessContext); |
| 1295 | } |
| 1296 | |
| 1297 | // Configuration/Domains handling |
| 1298 | bool CParameterMgr::createDomain(const string& strName, string& strError) |
| 1299 | { |
| 1300 | // Check tuning mode |
| 1301 | if (!checkTuningModeOn(strError)) { |
| 1302 | |
| 1303 | return false; |
| 1304 | } |
| 1305 | |
| 1306 | // Delegate to configurable domains |
| 1307 | return getConfigurableDomains()->createDomain(strName, strError); |
| 1308 | } |
| 1309 | |
| 1310 | bool CParameterMgr::deleteDomain(const string& strName, string& strError) |
| 1311 | { |
| 1312 | // Check tuning mode |
| 1313 | if (!checkTuningModeOn(strError)) { |
| 1314 | |
| 1315 | return false; |
| 1316 | } |
| 1317 | |
| 1318 | // Delegate to configurable domains |
| 1319 | return getConfigurableDomains()->deleteDomain(strName, strError); |
| 1320 | } |
| 1321 | |
| 1322 | bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError) |
| 1323 | { |
| 1324 | // Check tuning mode |
| 1325 | if (!checkTuningModeOn(strError)) { |
| 1326 | |
| 1327 | return false; |
| 1328 | } |
| 1329 | |
| 1330 | // Delegate to configurable domains |
| 1331 | return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError); |
| 1332 | } |
| 1333 | |
| 1334 | bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError) |
| 1335 | { |
| 1336 | // Check tuning mode |
| 1337 | if (!checkTuningModeOn(strError)) { |
| 1338 | |
| 1339 | return false; |
| 1340 | } |
| 1341 | |
| 1342 | // Delegate to configurable domains |
| 1343 | return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError); |
| 1344 | } |
| 1345 | |
| 1346 | bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, string& strError) |
| 1347 | { |
| 1348 | // Check tuning mode |
| 1349 | if (!checkTuningModeOn(strError)) { |
| 1350 | |
| 1351 | return false; |
| 1352 | } |
| 1353 | |
| 1354 | // Delegate to configurable domains |
| 1355 | return getConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, strError); |
| 1356 | } |
| 1357 | |
| 1358 | bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError) |
| 1359 | { |
| 1360 | // Check tuning mode |
| 1361 | if (!checkTuningModeOn(strError)) { |
| 1362 | |
| 1363 | return false; |
| 1364 | } |
| 1365 | |
| 1366 | // Delegate to configurable domains |
| 1367 | return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError); |
| 1368 | } |
| 1369 | |
| 1370 | // Configurable element - domain association |
| 1371 | bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) |
| 1372 | { |
| 1373 | // Check tuning mode |
| 1374 | if (!checkTuningModeOn(strError)) { |
| 1375 | |
| 1376 | return false; |
| 1377 | } |
| 1378 | |
| 1379 | CElementLocator elementLocator(getSystemClass()); |
| 1380 | |
| 1381 | CElement* pLocatedElement = NULL; |
| 1382 | |
| 1383 | if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { |
| 1384 | |
| 1385 | return false; |
| 1386 | } |
| 1387 | |
| 1388 | // Convert element |
| 1389 | CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement); |
| 1390 | |
| 1391 | // Delegate |
| 1392 | return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError); |
| 1393 | } |
| 1394 | |
| 1395 | bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) |
| 1396 | { |
| 1397 | // Check tuning mode |
| 1398 | if (!checkTuningModeOn(strError)) { |
| 1399 | |
| 1400 | return false; |
| 1401 | } |
| 1402 | |
| 1403 | CElementLocator elementLocator(getSystemClass()); |
| 1404 | |
| 1405 | CElement* pLocatedElement = NULL; |
| 1406 | |
| 1407 | if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { |
| 1408 | |
| 1409 | return EFailed; |
| 1410 | } |
| 1411 | |
| 1412 | // Convert element |
| 1413 | CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement); |
| 1414 | |
| 1415 | // Delegate |
| 1416 | return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError); |
| 1417 | } |
| 1418 | |
| 1419 | bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError) |
| 1420 | { |
| 1421 | // Check tuning mode |
| 1422 | if (!checkTuningModeOn(strError)) { |
| 1423 | |
| 1424 | return false; |
| 1425 | } |
| 1426 | |
| 1427 | CElementLocator elementLocator(getSystemClass()); |
| 1428 | |
| 1429 | CElement* pLocatedElement = NULL; |
| 1430 | |
| 1431 | if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { |
| 1432 | |
| 1433 | return EFailed; |
| 1434 | } |
| 1435 | |
| 1436 | // Convert element |
| 1437 | CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement); |
| 1438 | |
| 1439 | // Delegate |
| 1440 | return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError); |
| 1441 | } |
| 1442 | |
| 1443 | // XML Import/Export |
| 1444 | bool CParameterMgr::importDomainsXml(const string& strFileName, bool bWithSettings, string& strError) |
| 1445 | { |
| 1446 | // Check tuning mode |
| 1447 | if (!checkTuningModeOn(strError)) { |
| 1448 | |
| 1449 | return false; |
| 1450 | } |
| 1451 | |
| 1452 | // check path is absolute |
| 1453 | if (strFileName[0] != '/') { |
| 1454 | |
| 1455 | strError = "Please provide absolute path"; |
| 1456 | |
| 1457 | return false; |
| 1458 | } |
| 1459 | // Root element |
| 1460 | CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); |
| 1461 | |
| 1462 | // Context |
| 1463 | CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings); |
| 1464 | |
| 1465 | // Secltion criteria definition for rule creation |
| 1466 | xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition()); |
| 1467 | |
| 1468 | // Parse |
| 1469 | if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strFileName, "", EParameterConfigurationLibrary, "SystemClassName")) { |
| 1470 | |
| 1471 | return false; |
| 1472 | } |
| 1473 | |
| 1474 | // Validate domains after XML import |
| 1475 | pConfigurableDomains->validate(_pMainParameterBlackboard); |
| 1476 | |
| 1477 | return true; |
| 1478 | } |
| 1479 | |
| 1480 | bool CParameterMgr::exportDomainsXml(const string& strFileName, bool bWithSettings, string& strError) const |
| 1481 | { |
| 1482 | // check path is absolute |
| 1483 | if (strFileName[0] != '/') { |
| 1484 | |
| 1485 | strError = "Please provide absolute path"; |
| 1486 | |
| 1487 | return false; |
| 1488 | } |
| 1489 | |
| 1490 | // Root element |
| 1491 | const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains(); |
| 1492 | |
| 1493 | // Get Schema file associated to root element |
| 1494 | string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pConfigurableDomains->getKind() + ".xsd"; |
| 1495 | |
| 1496 | // Context |
| 1497 | CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings); |
| 1498 | |
| 1499 | // Value space |
| 1500 | xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw); |
| 1501 | |
| 1502 | // Instantiate composer |
| 1503 | CXmlComposer xmlComposer(strFileName, strXmlSchemaFilePath, pConfigurableDomains->getKind(), xmlDomainSerializingContext); |
| 1504 | |
| 1505 | // Open composer |
| 1506 | if (!xmlComposer.open()) { |
| 1507 | |
| 1508 | return false; |
| 1509 | } |
| 1510 | |
| 1511 | // Compose |
| 1512 | xmlComposer.compose(pConfigurableDomains); |
| 1513 | |
| 1514 | // Close composer |
| 1515 | if (!xmlComposer.close()) { |
| 1516 | |
| 1517 | return false; |
| 1518 | } |
| 1519 | |
| 1520 | return true; |
| 1521 | } |
| 1522 | |
| 1523 | // Binary Import/Export |
| 1524 | bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError) |
| 1525 | { |
| 1526 | // Check tuning mode |
| 1527 | if (!checkTuningModeOn(strError)) { |
| 1528 | |
| 1529 | return false; |
| 1530 | } |
| 1531 | // check path is absolute |
| 1532 | if (strFileName[0] != '/') { |
| 1533 | |
| 1534 | strError = "Please provide absolute path"; |
| 1535 | |
| 1536 | return false; |
| 1537 | } |
| 1538 | // Root element |
| 1539 | CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); |
| 1540 | |
| 1541 | // Serialize in |
| 1542 | return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError); |
| 1543 | } |
| 1544 | |
| 1545 | bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError) |
| 1546 | { |
| 1547 | // check path is absolute |
| 1548 | if (strFileName[0] != '/') { |
| 1549 | |
| 1550 | strError = "Please provide absolute path"; |
| 1551 | |
| 1552 | return false; |
| 1553 | } |
| 1554 | // Check tuning mode |
| 1555 | if (!checkTuningModeOn(strError)) { |
| 1556 | |
| 1557 | return false; |
| 1558 | } |
| 1559 | // Root element |
| 1560 | CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); |
| 1561 | |
| 1562 | // Serialize out |
| 1563 | return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError); |
| 1564 | } |
| 1565 | |
| 1566 | // For tuning, check we're in tuning mode |
| 1567 | bool CParameterMgr::checkTuningModeOn(string& strError) const |
| 1568 | { |
| 1569 | // Tuning Mode on? |
| 1570 | if (!_bTuningModeIsOn) { |
| 1571 | |
| 1572 | strError = "Tuning Mode must be on"; |
| 1573 | |
| 1574 | return false; |
| 1575 | } |
| 1576 | return true; |
| 1577 | } |
| 1578 | |
| 1579 | // Dynamic creation library feeding |
| 1580 | void CParameterMgr::feedElementLibraries() |
| 1581 | { |
| 1582 | // Global Configuration handling |
| 1583 | CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary; |
| 1584 | |
| 1585 | pFrameworkConfigurationLibrary->addElementBuilder(new CElementBuilderTemplate<CParameterFrameworkConfiguration>("ParameterFrameworkConfiguration")); |
| 1586 | pFrameworkConfigurationLibrary->addElementBuilder(new CKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SubsystemPluginFolders")); |
| 1587 | pFrameworkConfigurationLibrary->addElementBuilder(new CKindElementBuilderTemplate<CFrameworkConfigurationLocation>("PluginFolderLocation")); |
| 1588 | pFrameworkConfigurationLibrary->addElementBuilder(new CKindElementBuilderTemplate<CFrameworkConfigurationGroup>("ParameterConfiguration")); |
| 1589 | pFrameworkConfigurationLibrary->addElementBuilder(new CKindElementBuilderTemplate<CSystemClassConfiguration>("SystemClassConfiguration")); |
| 1590 | pFrameworkConfigurationLibrary->addElementBuilder(new CKindElementBuilderTemplate<CFrameworkConfigurationLocation>("StructureDescriptionFileLocation")); |
| 1591 | pFrameworkConfigurationLibrary->addElementBuilder(new CKindElementBuilderTemplate<CFrameworkConfigurationGroup>("SettingsConfiguration")); |
| 1592 | pFrameworkConfigurationLibrary->addElementBuilder(new CKindElementBuilderTemplate<CFrameworkConfigurationLocation>("ConfigurableDomainsFileLocation")); |
| 1593 | pFrameworkConfigurationLibrary->addElementBuilder(new CKindElementBuilderTemplate<CFrameworkConfigurationLocation>("BinarySettingsFileLocation")); |
| 1594 | |
| 1595 | _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary); |
| 1596 | |
| 1597 | // Parameter creation |
| 1598 | CElementLibrary* pParameterCreationLibrary = new CElementLibrary; |
| 1599 | |
| 1600 | pParameterCreationLibrary->addElementBuilder(new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary())); |
| 1601 | pParameterCreationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CComponentType>("ComponentType")); |
| 1602 | pParameterCreationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CComponentInstance>("Component")); |
| 1603 | pParameterCreationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CBitParameterType>("BitParameter")); |
| 1604 | pParameterCreationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CBitParameterBlockType>("BitParameterBlock")); |
| 1605 | pParameterCreationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CParameterBlockType>("ParameterBlock")); |
| 1606 | pParameterCreationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CBooleanParameterType>("BooleanParameter")); |
| 1607 | pParameterCreationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CIntegerParameterType>("IntegerParameter")); |
| 1608 | pParameterCreationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CFixedPointParameterType>("FixedPointParameter")); |
| 1609 | pParameterCreationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CComputedSizeParameterType>("ComputedSizeParameter")); |
| 1610 | pParameterCreationLibrary->addElementBuilder(new CKindElementBuilderTemplate<CXmlFileIncluderElement>("SubsystemInclude")); |
| 1611 | |
| 1612 | _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary); |
| 1613 | |
| 1614 | // Parameter Configuration Domains creation |
| 1615 | CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary; |
| 1616 | |
| 1617 | pParameterConfigurationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CConfigurableDomain>("ConfigurableDomain")); |
| 1618 | pParameterConfigurationLibrary->addElementBuilder(new CNamedElementBuilderTemplate<CDomainConfiguration>("Configuration")); |
| 1619 | pParameterConfigurationLibrary->addElementBuilder(new CElementBuilderTemplate<CCompoundRule>("CompoundRule")); |
| 1620 | pParameterConfigurationLibrary->addElementBuilder(new CElementBuilderTemplate<CSelectionCriterionRule>("SelectionCriterionRule")); |
| 1621 | |
| 1622 | _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary); |
| 1623 | } |
| 1624 | |
| 1625 | // Remote Processor Server connection handling |
| 1626 | bool CParameterMgr::handleRemoteProcessingInterface(string& strError) |
| 1627 | { |
| 1628 | CAutoLog autoLog(this, "Handling remote processing interface"); |
| 1629 | |
| 1630 | // Start server if tuning allowed |
| 1631 | if (_pSystemClassConfiguration->isTuningAllowed()) { |
| 1632 | |
| 1633 | log("Loading remote processor library"); |
| 1634 | |
| 1635 | // Load library |
| 1636 | void* lib_handle = dlopen("libremote-processor.so", RTLD_NOW); |
| 1637 | |
| 1638 | if (!lib_handle) { |
| 1639 | |
| 1640 | // Return error |
| 1641 | const char* pcError = dlerror(); |
| 1642 | |
| 1643 | if (pcError) { |
| 1644 | |
| 1645 | strError = pcError; |
| 1646 | } else { |
| 1647 | |
| 1648 | strError = "Unable to load libremote-processor.so library"; |
| 1649 | } |
| 1650 | |
| 1651 | return false; |
| 1652 | } |
| 1653 | |
| 1654 | CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(lib_handle, "createRemoteProcessorServer"); |
| 1655 | |
| 1656 | if (!pfnCreateRemoteProcessorServer) { |
| 1657 | |
| 1658 | strError = "libremote-process.so does not contain createRemoteProcessorServer symbol."; |
| 1659 | |
| 1660 | return false; |
| 1661 | } |
| 1662 | |
| 1663 | // Create server |
| 1664 | _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(_pSystemClassConfiguration->getServerPort(), this); |
| 1665 | |
| 1666 | // Compute max command usage length |
| 1667 | setMaxCommandUsageLength(); |
| 1668 | |
| 1669 | log("Starting remote processor server on port %d", _pSystemClassConfiguration->getServerPort()); |
| 1670 | // Start |
| 1671 | if (!_pRemoteProcessorServer->start()) { |
| 1672 | |
| 1673 | strError = "Unable to start remote processor server"; |
| 1674 | |
| 1675 | return false; |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | return true; |
| 1680 | } |
| 1681 | |
| 1682 | // Back synchronization |
| 1683 | CBackSynchronizer* CParameterMgr::createBackSynchronizer(string& strError) const |
| 1684 | { |
| 1685 | #ifdef SIMULATION |
| 1686 | // In simulation, back synchronization of the blackboard won't probably work |
| 1687 | // We need to ensure though the blackboard is initialized with valid data |
| 1688 | return new CSimulatedBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard); |
| 1689 | #else |
| 1690 | // Real back synchronizer from subsystems |
| 1691 | return new CHardwareBackSynchronizer(getConstSystemClass(), strError, _pMainParameterBlackboard); |
| 1692 | #endif |
| 1693 | } |
| 1694 | |
| 1695 | // Children typwise access |
| 1696 | CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration() |
| 1697 | { |
| 1698 | return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration)); |
| 1699 | } |
| 1700 | |
| 1701 | const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration() |
| 1702 | { |
| 1703 | return getFrameworkConfiguration(); |
| 1704 | } |
| 1705 | |
| 1706 | CSelectionCriteria* CParameterMgr::getSelectionCriteria() |
| 1707 | { |
| 1708 | return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria)); |
| 1709 | } |
| 1710 | |
| 1711 | const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria() |
| 1712 | { |
| 1713 | return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria)); |
| 1714 | } |
| 1715 | |
| 1716 | CSystemClass* CParameterMgr::getSystemClass() |
| 1717 | { |
| 1718 | return static_cast<CSystemClass*>(getChild(ESystemClass)); |
| 1719 | } |
| 1720 | |
| 1721 | const CSystemClass* CParameterMgr::getConstSystemClass() const |
| 1722 | { |
| 1723 | return static_cast<const CSystemClass*>(getChild(ESystemClass)); |
| 1724 | } |
| 1725 | |
| 1726 | // Configurable Domains |
| 1727 | CConfigurableDomains* CParameterMgr::getConfigurableDomains() |
| 1728 | { |
| 1729 | return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains)); |
| 1730 | } |
| 1731 | |
| 1732 | const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() |
| 1733 | { |
| 1734 | return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains)); |
| 1735 | } |
| 1736 | |
| 1737 | const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const |
| 1738 | { |
| 1739 | return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains)); |
| 1740 | } |