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