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