Home | History | Annotate | Download | only in parameter
      1 /*
      2  * Copyright (c) 2011-2015, Intel Corporation
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without modification,
      6  * are permitted provided that the following conditions are met:
      7  *
      8  * 1. Redistributions of source code must retain the above copyright notice, this
      9  * list of conditions and the following disclaimer.
     10  *
     11  * 2. Redistributions in binary form must reproduce the above copyright notice,
     12  * this list of conditions and the following disclaimer in the documentation and/or
     13  * other materials provided with the distribution.
     14  *
     15  * 3. Neither the name of the copyright holder nor the names of its contributors
     16  * may be used to endorse or promote products derived from this software without
     17  * specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
     23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 #include "ParameterMgr.h"
     31 #include "XmlParameterSerializingContext.h"
     32 #include "XmlElementSerializingContext.h"
     33 #include "SystemClass.h"
     34 #include "ElementLibrarySet.h"
     35 #include "SubsystemLibrary.h"
     36 #include "NamedElementBuilderTemplate.h"
     37 #include "KindElementBuilderTemplate.h"
     38 #include "ElementBuilderTemplate.h"
     39 #include "XmlFileIncluderElement.h"
     40 #include "SelectionCriterionType.h"
     41 #include "SubsystemElementBuilder.h"
     42 #include "FileIncluderElementBuilder.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"
     52 #include "ParameterAccessContext.h"
     53 #include "XmlFileIncluderElement.h"
     54 #include "ParameterFrameworkConfiguration.h"
     55 #include "FrameworkConfigurationGroup.h"
     56 #include "PluginLocation.h"
     57 #include "SubsystemPlugins.h"
     58 #include "FrameworkConfigurationLocation.h"
     59 #include "ConfigurableDomains.h"
     60 #include "ConfigurableDomain.h"
     61 #include "DomainConfiguration.h"
     62 #include "XmlDomainSerializingContext.h"
     63 #include "XmlDomainExportContext.h"
     64 #include "XmlDomainImportContext.h"
     65 #include "BitParameterBlockType.h"
     66 #include "BitParameterType.h"
     67 #include "StringParameterType.h"
     68 #include "EnumParameterType.h"
     69 #include "RemoteProcessorServerInterface.h"
     70 #include "ElementLocator.h"
     71 #include "AutoLog.h"
     72 #include "CompoundRule.h"
     73 #include "SelectionCriterionRule.h"
     74 #include "SimulatedBackSynchronizer.h"
     75 #include "HardwareBackSynchronizer.h"
     76 #include "AutoLock.h"
     77 #include <strings.h>
     78 #include <dlfcn.h>
     79 #include <assert.h>
     80 #include "ParameterHandle.h"
     81 #include "LinearParameterAdaptation.h"
     82 #include "LogarithmicParameterAdaptation.h"
     83 #include "EnumValuePair.h"
     84 #include "Subsystem.h"
     85 #include "XmlStreamDocSink.h"
     86 #include "XmlMemoryDocSink.h"
     87 #include "XmlDocSource.h"
     88 #include "XmlMemoryDocSource.h"
     89 #include "SelectionCriteriaDefinition.h"
     90 #include "Utility.h"
     91 #include <sstream>
     92 #include <fstream>
     93 #include <algorithm>
     94 #include <ctype.h>
     95 #include <memory>
     96 
     97 #define base CElement
     98 
     99 #ifdef SIMULATION
    100     // In simulation, back synchronization of the blackboard won't probably work
    101     // We need to ensure though the blackboard is initialized with valid data
    102     typedef CSimulatedBackSynchronizer BackSynchronizer;
    103 #else
    104     // Real back synchronizer from subsystems
    105     typedef CHardwareBackSynchronizer BackSynchronizer;
    106 #endif
    107 
    108 using std::string;
    109 using std::list;
    110 using std::vector;
    111 using std::ostringstream;
    112 using std::ofstream;
    113 using std::ifstream;
    114 
    115 // Used for remote processor server creation
    116 typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
    117 
    118 // Global configuration file name (fixed)
    119 const char* gacParameterFrameworkConfigurationFileName = "ParameterFrameworkConfiguration.xml";
    120 const char* gacSystemSchemasSubFolder = "Schemas";
    121 
    122 // Config File System looks normally like this:
    123 // ---------------------------------------------
    124 //|-- <ParameterFrameworkConfiguration>.xml
    125 //|-- Schemas
    126 //|   `-- *.xsd
    127 //|-- Settings
    128 //|   `-- <SystemClassName folder>*
    129 //|       |-- <ConfigurableDomains>.xml
    130 //|       `-- <Settings>.bin?
    131 //`-- Structure
    132 //    `-- <SystemClassName folder>*
    133 //        |-- <SystemClassName>Class.xml
    134 //        `-- <Subsystem>.xml*
    135 // --------------------------------------------
    136 
    137 
    138 // Remote command parser array
    139 const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = {
    140 
    141     /// Version
    142     { "version", &CParameterMgr::versionCommandProcess, 0,
    143             "", "Show version" },
    144 
    145     /// Status
    146     { "status", &CParameterMgr::statusCommandProcess, 0, "",
    147             "Show current status" },
    148 
    149     /// Tuning Mode
    150     { "setTuningMode", &CParameterMgr::setTuningModeCommandProcess, 1,
    151             "on|off*", "Turn on or off Tuning Mode" },
    152     { "getTuningMode", &CParameterMgr::getTuningModeCommandProcess, 0,
    153             "", "Show Tuning Mode" },
    154 
    155     /// Value Space
    156     { "setValueSpace", &CParameterMgr::setValueSpaceCommandProcess, 1,
    157             "raw|real*", "Assigns Value Space used for parameter value interpretation" },
    158     { "getValueSpace", &CParameterMgr::getValueSpaceCommandProcess, 0,
    159             "", "Show Value Space" },
    160 
    161     /// Output Raw Format
    162     { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommandProcess, 1,
    163             "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" },
    164     { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommandProcess, 0,
    165             "", "Show Output Raw Format" },
    166 
    167     /// Sync
    168     { "setAutoSync", &CParameterMgr::setAutoSyncCommandProcess, 1,
    169             "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" },
    170     { "getAutoSync", &CParameterMgr::getAutoSyncCommandProcess, 0,
    171             "", "Show Auto Sync state" },
    172     { "sync", &CParameterMgr::syncCommandProcess, 0,
    173             "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" },
    174 
    175     /// Criteria
    176     { "listCriteria", &CParameterMgr::listCriteriaCommandProcess, 0,
    177             "[CSV|XML]", "List selection criteria" },
    178 
    179     /// Domains
    180     { "listDomains", &CParameterMgr::listDomainsCommandProcess, 0,
    181             "", "List configurable domains" },
    182     { "dumpDomains", &CParameterMgr::dumpDomainsCommandProcess, 0,
    183             "", "Show all domains and configurations, including applicability conditions" },
    184     { "createDomain", &CParameterMgr::createDomainCommandProcess, 1,
    185             "<domain>", "Create new configurable domain" },
    186     { "deleteDomain", &CParameterMgr::deleteDomainCommandProcess, 1,
    187             "<domain>", "Delete configurable domain" },
    188     { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommandProcess, 0,
    189             "", "Delete all configurable domains" },
    190     { "renameDomain", &CParameterMgr::renameDomainCommandProcess, 2,
    191             "<domain> <new name>", "Rename configurable domain" },
    192     { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommandProcess, 1,
    193             "<domain> true|false*", "Set configurable domain sequence awareness" },
    194     { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommandProcess, 1,
    195             "<domain>", "Get configurable domain sequence awareness" },
    196     { "listDomainElements", &CParameterMgr::listDomainElementsCommandProcess, 1,
    197             "<domain>", "List elements associated to configurable domain" },
    198     { "addElement", &CParameterMgr::addElementCommandProcess, 2,
    199             "<domain> <elem path>", "Associate element at given path to configurable domain" },
    200     { "removeElement", &CParameterMgr::removeElementCommandProcess, 2,
    201             "<domain> <elem path>", "Dissociate element at given path from configurable domain" },
    202     { "splitDomain", &CParameterMgr::splitDomainCommandProcess, 2,
    203             "<domain> <elem path>", "Split configurable domain at given associated element path" },
    204 
    205     /// Configurations
    206     { "listConfigurations", &CParameterMgr::listConfigurationsCommandProcess, 1,
    207             "<domain>", "List domain configurations" },
    208     { "createConfiguration", &CParameterMgr::createConfigurationCommandProcess, 2,
    209             "<domain> <configuration>", "Create new domain configuration" },
    210     { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommandProcess, 2,
    211             "<domain> <configuration>", "Delete domain configuration" },
    212     { "renameConfiguration", &CParameterMgr::renameConfigurationCommandProcess, 3,
    213             "<domain> <configuration> <new name>", "Rename domain configuration" },
    214     { "saveConfiguration", &CParameterMgr::saveConfigurationCommandProcess, 2,
    215             "<domain> <configuration>", "Save current settings into configuration" },
    216     { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommandProcess, 2,
    217             "<domain> <configuration>", "Restore current settings from configuration" },
    218     { "setElementSequence", &CParameterMgr::setElementSequenceCommandProcess, 3,
    219             "<domain> <configuration> <elem path list>",
    220             "Set element application order for configuration" },
    221     { "getElementSequence", &CParameterMgr::getElementSequenceCommandProcess, 2,
    222             "<domain> <configuration>", "Get element application order for configuration" },
    223     { "setRule", &CParameterMgr::setRuleCommandProcess, 3,
    224             "<domain> <configuration> <rule>", "Set configuration application rule" },
    225     { "clearRule", &CParameterMgr::clearRuleCommandProcess, 2,
    226             "<domain> <configuration>", "Clear configuration application rule" },
    227     { "getRule", &CParameterMgr::getRuleCommandProcess, 2,
    228             "<domain> <configuration>", "Get configuration application rule" },
    229 
    230     /// Elements/Parameters
    231     { "listElements", &CParameterMgr::listElementsCommandProcess, 1,
    232             "<elem path>|/", "List elements under element at given path or root" },
    233     { "listParameters", &CParameterMgr::listParametersCommandProcess, 1,
    234             "<elem path>|/", "List parameters under element at given path or root" },
    235     { "dumpElement", &CParameterMgr::dumpElementCommandProcess, 1,
    236             "<elem path>", "Dump structure and content of element at given path" },
    237     { "getElementSize", &CParameterMgr::getElementSizeCommandProcess, 1,
    238             "<elem path>", "Show size of element at given path" },
    239     { "showProperties", &CParameterMgr::showPropertiesCommandProcess, 1,
    240             "<elem path>", "Show properties of element at given path" },
    241     { "getParameter", &CParameterMgr::getParameterCommandProcess, 1,
    242             "<param path>", "Get value for parameter at given path" },
    243     { "setParameter", &CParameterMgr::setParameterCommandProcess, 2,
    244             "<param path> <value>", "Set value for parameter at given path" },
    245     { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommandProcess, 1,
    246             "<elem path>", "List domain(s) element at given path belongs to" },
    247     { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommandProcess, 1,
    248             "<elem path>", "List domain(s) element at given path is associated to" },
    249     { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommandProcess, 3,
    250             "<domain> <configuration> <param path>",
    251             "Get value for parameter at given path from configuration" },
    252     { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommandProcess, 4,
    253             "<domain> <configuration> <param path> <value>",
    254             "Set value for parameter at given path to configuration" },
    255     { "showMapping", &CParameterMgr::showMappingCommandProcess, 1,
    256             "<elem path>", "Show mapping for an element at given path" },
    257 
    258     /// Browse
    259     { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommandProcess, 0,
    260             "", "List element sub-trees associated to at least one configurable domain" },
    261     { "listConflictingElements", &CParameterMgr::listConflictingElementsCommandProcess, 0,
    262             "", "List element sub-trees contained in more than one configurable domain" },
    263     { "listRogueElements", &CParameterMgr::listRogueElementsCommandProcess, 0,
    264             "", "List element sub-trees owned by no configurable domain" },
    265 
    266     /// Settings Import/Export
    267     { "exportDomainsXML", &CParameterMgr::exportDomainsXMLCommandProcess, 1,
    268             "<file path> ", "Export domains to an XML file (provide an absolute path or relative"
    269                             "to the client's working directory)" },
    270     { "importDomainsXML", &CParameterMgr::importDomainsXMLCommandProcess, 1,
    271             "<file path>", "Import domains from an XML file (provide an absolute path or relative"
    272                             "to the client's working directory)" },
    273     { "exportDomainsWithSettingsXML",
    274             &CParameterMgr::exportDomainsWithSettingsXMLCommandProcess, 1,
    275             "<file path> ", "Export domains including settings to XML file (provide an absolute path or relative"
    276                             "to the client's working directory)" },
    277     { "exportDomainWithSettingsXML",
    278             &CParameterMgr::exportDomainWithSettingsXMLCommandProcess, 2,
    279             "<domain> <file path> ", "Export a single given domain including settings to XML file"
    280                                      " (provide an absolute path or relative to the client's"
    281                                      " working directory)" },
    282     { "importDomainsWithSettingsXML",
    283             &CParameterMgr::importDomainsWithSettingsXMLCommandProcess, 1,
    284             "<file path>", "Import domains including settings from XML file (provide an absolute path or relative"
    285                             "to the client's working directory)" },
    286     { "importDomainWithSettingsXML",
    287             &CParameterMgr::importDomainWithSettingsXMLCommandProcess, 1,
    288             "<file path> [overwrite]", "Import a single domain including settings from XML file."
    289             " Does not overwrite an existing domain unless 'overwrite' is passed as second"
    290             " argument. Provide an absolute path or relative to the client's working directory)" },
    291     { "exportSettings", &CParameterMgr::exportSettingsCommandProcess, 1,
    292             "<file path>", "Export settings to binary file (provide an absolute path or relative"
    293                             "to the client's working directory)" },
    294     { "importSettings", &CParameterMgr::importSettingsCommandProcess, 1,
    295             "<file path>", "Import settings from binary file (provide an absolute path or relative"
    296                             "to the client's working directory)" },
    297     { "getDomainsWithSettingsXML",
    298             &CParameterMgr::getDomainsWithSettingsXMLCommandProcess, 0,
    299             "", "Print domains including settings as XML" },
    300     { "getDomainWithSettingsXML",
    301             &CParameterMgr::getDomainWithSettingsXMLCommandProcess, 1,
    302             "<domain>", "Print the given domain including settings as XML" },
    303     { "setDomainsWithSettingsXML",
    304             &CParameterMgr::setDomainsWithSettingsXMLCommandProcess, 1,
    305             "<xml configurable domains>", "Import domains including settings from XML string" },
    306     { "setDomainWithSettingsXML",
    307             &CParameterMgr::setDomainWithSettingsXMLCommandProcess, 1,
    308             "<xml configurable domain> [overwrite]", "Import domains including settings from XML"
    309             " string. Does not overwrite an existing domain unless 'overwrite' is passed as second"
    310             " argument" },
    311     /// Structure Export
    312     { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommandProcess, 0 ,
    313             "", "Print parameter structure as XML" },
    314     /// Deprecated Commands
    315     { "getDomainsXML",
    316             &CParameterMgr::getDomainsWithSettingsXMLCommandProcess, 0,
    317             "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" },
    318 
    319 };
    320 
    321 // Remote command parsers array Size
    322 const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]);
    323 
    324 CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) :
    325     _bTuningModeIsOn(false),
    326     _bValueSpaceIsRaw(false),
    327     _bOutputRawFormatIsHex(false),
    328     _bAutoSyncOn(true),
    329     _pMainParameterBlackboard(new CParameterBlackboard),
    330     _pElementLibrarySet(new CElementLibrarySet),
    331     _strXmlConfigurationFilePath(strConfigurationFilePath),
    332     _pSubsystemPlugins(NULL),
    333     _pvLibRemoteProcessorHandle(NULL),
    334     _uiStructureChecksum(0),
    335     _pRemoteProcessorServer(NULL),
    336     _uiMaxCommandUsageLength(0),
    337     _pLogger(NULL),
    338     _uiLogDepth(0),
    339     _bForceNoRemoteInterface(false),
    340     _bFailOnMissingSubsystem(true),
    341     _bFailOnFailedSettingsLoad(true),
    342     _bValidateSchemasOnStart(false)
    343 
    344 {
    345     // Tuning Mode Mutex
    346     bzero(&_blackboardMutex, sizeof(_blackboardMutex));
    347     pthread_mutex_init(&_blackboardMutex, NULL);
    348 
    349     // Deal with children
    350     addChild(new CParameterFrameworkConfiguration);
    351     addChild(new CSelectionCriteria);
    352     addChild(new CSystemClass);
    353     addChild(new CConfigurableDomains);
    354 
    355     _pCommandHandler = new CCommandHandler(this);
    356 
    357     // Add command parsers
    358     uint32_t uiRemoteCommandParserItem;
    359 
    360     for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) {
    361 
    362         const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem];
    363 
    364         _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName,
    365                                            pRemoteCommandParserItem->_pfnParser,
    366                                            pRemoteCommandParserItem->_uiMinArgumentCount,
    367                                            pRemoteCommandParserItem->_pcHelp,
    368                                            pRemoteCommandParserItem->_pcDescription);
    369     }
    370 
    371     // Configuration file folder
    372     std::string::size_type slashPos = _strXmlConfigurationFilePath.rfind('/', -1);
    373     if(slashPos == std::string::npos) {
    374         // Configuration folder is the current folder
    375         _strXmlConfigurationFolderPath = '.';
    376     } else {
    377         _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, slashPos);
    378     }
    379 
    380     // Schema absolute folder location
    381     _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder;
    382 }
    383 
    384 CParameterMgr::~CParameterMgr()
    385 {
    386     // Children
    387     delete _pRemoteProcessorServer;
    388     delete _pCommandHandler;
    389     delete _pMainParameterBlackboard;
    390     delete _pElementLibrarySet;
    391 
    392     // Close remote processor library
    393     if (_pvLibRemoteProcessorHandle) {
    394 
    395         dlclose(_pvLibRemoteProcessorHandle);
    396     }
    397 
    398     // Tuning Mode Mutex
    399     pthread_mutex_destroy(&_blackboardMutex);
    400 }
    401 
    402 string CParameterMgr::getKind() const
    403 {
    404     return "ParameterMgr";
    405 }
    406 
    407 // Logging
    408 void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger)
    409 {
    410     _pLogger = pLogger;
    411 }
    412 
    413 // Logging
    414 void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const
    415 {
    416     if (_pLogger) {
    417 
    418         // Nest
    419         string strIndent;
    420 
    421         // Level
    422         uint32_t uiNbIndents = _uiLogDepth;
    423 
    424         while (uiNbIndents--) {
    425 
    426             strIndent += "    ";
    427         }
    428 
    429         // Log
    430         _pLogger->log(bIsWarning, strIndent + strLog);
    431     }
    432 }
    433 
    434 void CParameterMgr::nestLog() const
    435 {
    436     _uiLogDepth++;
    437 }
    438 
    439 void CParameterMgr::unnestLog() const
    440 {
    441     _uiLogDepth--;
    442 }
    443 
    444 // Version
    445 string CParameterMgr::getVersion() const
    446 {
    447     string strVersion;
    448 
    449     // Major
    450     strVersion = CUtility::toString(guiEditionMajor) + ".";
    451     // Minor
    452     strVersion += CUtility::toString(guiEditionMinor) + ".";
    453     // Revision
    454     strVersion += CUtility::toString(guiRevision);
    455 
    456     return strVersion;
    457 }
    458 
    459 bool CParameterMgr::load(string& strError)
    460 {
    461     CAutoLog autoLog(this, "Loading");
    462 
    463     feedElementLibraries();
    464 
    465     // Load Framework configuration
    466     if (!loadFrameworkConfiguration(strError)) {
    467 
    468         return false;
    469     }
    470 
    471     // Load subsystems
    472     if (!getSystemClass()->loadSubsystems(strError,
    473                                           _pSubsystemPlugins, !_bFailOnMissingSubsystem)) {
    474 
    475         return false;
    476     }
    477 
    478     // Load structure
    479     if (!loadStructure(strError)) {
    480 
    481         return false;
    482     }
    483 
    484     // Load settings
    485     if (!loadSettings(strError)) {
    486 
    487         return false;
    488     }
    489 
    490     // Init flow of element tree
    491     if (!init(strError)) {
    492 
    493         return false;
    494     }
    495 
    496 
    497     {
    498         CAutoLog autoLog(this, "Main blackboard back synchronization");
    499 
    500 	// Back synchronization for areas in parameter blackboard not covered by any domain
    501 	BackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard).sync();
    502     }
    503 
    504     // We're done loading the settings and back synchronizing
    505     CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
    506 
    507     // We need to ensure all domains are valid
    508     pConfigurableDomains->validate(_pMainParameterBlackboard);
    509 
    510     // Log selection criterion states
    511     {
    512         CAutoLog autoLog(this, "Criterion states");
    513 
    514         const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria();
    515 
    516         list<string> lstrSelectionCriteron;
    517         selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false);
    518 
    519         log_table(false, lstrSelectionCriteron);
    520     }
    521 
    522     // Subsystem can not ask for resync as they have not been synced yet
    523     getSystemClass()->cleanSubsystemsNeedToResync();
    524 
    525     // At initialization, check subsystems that need resync
    526     doApplyConfigurations(true);
    527 
    528     // Start remote processor server if appropriate
    529     return handleRemoteProcessingInterface(strError);
    530 }
    531 
    532 bool CParameterMgr::loadFrameworkConfiguration(string& strError)
    533 {
    534     CAutoLog autoLog(this, "Loading framework configuration");
    535 
    536     // Parse Structure XML file
    537     CXmlElementSerializingContext elementSerializingContext(strError);
    538 
    539     _xmlDoc *doc = CXmlDocSource::mkXmlDoc(_strXmlConfigurationFilePath, true, true, strError);
    540     if (doc == NULL) {
    541         return false;
    542     }
    543 
    544     if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), doc,
    545                   _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) {
    546 
    547         return false;
    548     }
    549     // Set class name to system class and configurable domains
    550     getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName());
    551     getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName());
    552 
    553     // Get subsystem plugins elements
    554     _pSubsystemPlugins = static_cast<const CSubsystemPlugins*>(getConstFrameworkConfiguration()->findChild("SubsystemPlugins"));
    555 
    556     if (!_pSubsystemPlugins) {
    557 
    558         strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element";
    559 
    560         return false;
    561     }
    562 
    563     // Log tuning availability
    564     log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited");
    565 
    566     return true;
    567 }
    568 
    569 bool CParameterMgr::loadStructure(string& strError)
    570 {
    571     // Retrieve system to load structure to
    572     CSystemClass* pSystemClass = getSystemClass();
    573 
    574     log_info("Loading %s system class structure", pSystemClass->getName().c_str());
    575 
    576     // Get structure description element
    577     const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast<const CFrameworkConfigurationLocation*>(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation"));
    578 
    579     if (!pStructureDescriptionFileLocation) {
    580 
    581         strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName();
    582 
    583         return false;
    584     }
    585 
    586     // Get Xml structure folder
    587     string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
    588 
    589     // Get Xml structure file name
    590     string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath);
    591 
    592     // Parse Structure XML file
    593     CXmlParameterSerializingContext parameterBuildContext(strError);
    594 
    595     CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath);
    596 
    597     _xmlDoc *doc = CXmlDocSource::mkXmlDoc(strXmlStructureFilePath, true, true, strError);
    598     if (doc == NULL) {
    599         return false;
    600     }
    601 
    602     if (!xmlParse(parameterBuildContext, pSystemClass, doc, strXmlStructureFolder, EParameterCreationLibrary)) {
    603 
    604         return false;
    605     }
    606 
    607     // Initialize offsets
    608     pSystemClass->setOffset(0);
    609 
    610     // Initialize main blackboard's size
    611     _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint());
    612 
    613     return true;
    614 }
    615 
    616 bool CParameterMgr::loadSettings(string& strError)
    617 {
    618     string strLoadError;
    619     bool success = loadSettingsFromConfigFile(strLoadError);
    620 
    621     if (!success && !_bFailOnFailedSettingsLoad) {
    622         // Load can not fail, ie continue but log the load errors
    623         log_info("%s", strLoadError.c_str());
    624         log_info("Failed to load settings, continue without domains.");
    625         success = true;
    626     }
    627 
    628     if (!success) {
    629         // Propagate the litteral error only if the function fails
    630         strError = strLoadError;
    631         return false;
    632     }
    633 
    634     return true;
    635 }
    636 
    637 bool CParameterMgr::loadSettingsFromConfigFile(string& strError)
    638 {
    639     CAutoLog autoLog(this, "Loading settings");
    640 
    641     // Get settings configuration element
    642     const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast<const CFrameworkConfigurationGroup*>(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration"));
    643 
    644     if (!pParameterConfigurationGroup) {
    645 
    646         // No settings to load
    647 
    648         return true;
    649     }
    650     // Get binary settings file location
    651     const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation"));
    652 
    653     string strXmlBinarySettingsFilePath;
    654 
    655     if (pBinarySettingsFileLocation) {
    656 
    657         // Get Xml binary settings file name
    658         strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
    659     }
    660 
    661     // Get configurable domains element
    662     const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast<const CFrameworkConfigurationLocation*>(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation"));
    663 
    664     if (!pConfigurableDomainsFileLocation) {
    665 
    666         strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName();
    667 
    668         return false;
    669     }
    670     // Get destination root element
    671     CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
    672 
    673     // Get Xml configuration domains file name
    674     string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath);
    675 
    676     // Get Xml configuration domains folder
    677     string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath);
    678 
    679     // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary)
    680     CXmlDomainImportContext xmlDomainImportContext(strError, !pBinarySettingsFileLocation,
    681             *getSystemClass());
    682 
    683     // Selection criteria definition for rule creation
    684     xmlDomainImportContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition());
    685 
    686     // Auto validation of configurations if no binary settings provided
    687     xmlDomainImportContext.setAutoValidationRequired(!pBinarySettingsFileLocation);
    688 
    689     log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with");
    690 
    691     _xmlDoc *doc = CXmlDocSource::mkXmlDoc(strXmlConfigurationDomainsFilePath, true, true, strError);
    692     if (doc == NULL) {
    693         return false;
    694     }
    695 
    696     if (!xmlParse(xmlDomainImportContext, pConfigurableDomains, doc, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) {
    697 
    698         return false;
    699     }
    700     // We have loaded the whole system structure, compute checksum
    701     const CSystemClass* pSystemClass = getConstSystemClass();
    702     _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum();
    703 
    704     // Load binary settings if any provided
    705     if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) {
    706 
    707         return false;
    708     }
    709 
    710     return true;
    711 }
    712 
    713 // XML parsing
    714 bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext,
    715                              CElement* pRootElement, _xmlDoc* doc,
    716                              const string& strXmlFolder,
    717                              CParameterMgr::ElementLibrary eElementLibrary,
    718                              const string& strNameAttributeName)
    719 {
    720     // Init serializing context
    721     elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(
    722                                       eElementLibrary), strXmlFolder, _strSchemaFolderLocation);
    723 
    724     // Get Schema file associated to root element
    725     string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd";
    726 
    727     CXmlDocSource docSource(doc, _bValidateSchemasOnStart,
    728                             strXmlSchemaFilePath,
    729                             pRootElement->getKind(),
    730                             pRootElement->getName(),
    731                             strNameAttributeName);
    732 
    733     // Start clean
    734     pRootElement->clean();
    735 
    736     CXmlMemoryDocSink memorySink(pRootElement);
    737 
    738     if (!memorySink.process(docSource, elementSerializingContext)) {
    739         //Cleanup
    740         pRootElement->clean();
    741 
    742         return false;
    743     }
    744 
    745     return true;
    746 }
    747 
    748 // Init
    749 bool CParameterMgr::init(string& strError)
    750 {
    751     return base::init(strError);
    752 }
    753 
    754 // Selection criteria interface
    755 CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive)
    756 {
    757     // Propagate
    758     return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive);
    759 }
    760 
    761 CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType)
    762 {
    763     // Propagate
    764     return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType);
    765 }
    766 
    767 // Selection criterion retrieval
    768 CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName)
    769 {
    770     // Propagate
    771     return getSelectionCriteria()->getSelectionCriterion(strName);
    772 }
    773 
    774 // Configuration application
    775 void CParameterMgr::applyConfigurations()
    776 {
    777     CAutoLog autoLog(this, "Configuration application request");
    778 
    779     // Lock state
    780     CAutoLock autoLock(&_blackboardMutex);
    781 
    782     if (!_bTuningModeIsOn) {
    783 
    784         // Apply configuration(s)
    785         doApplyConfigurations(false);
    786     } else {
    787 
    788         log_warning("Configurations were not applied because the TuningMode is on");
    789     }
    790 }
    791 
    792 // Get the configurableElement corresponding to the given path
    793 const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& strPath,
    794                                                                   string& strError) const
    795 {
    796     CPathNavigator pathNavigator(strPath);
    797 
    798     // Nagivate through system class
    799     if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
    800 
    801         return NULL;
    802     }
    803 
    804     // Find element
    805     const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator);
    806 
    807     if (!pElement) {
    808 
    809         strError = "Path not found: " + strPath;
    810 
    811         return NULL;
    812     }
    813 
    814     // Check found element is a parameter
    815     const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pElement);
    816 
    817     return pConfigurableElement;
    818 }
    819 
    820 // Dynamic parameter handling
    821 CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, string& strError)
    822 {
    823     const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strError);
    824 
    825     if (!pConfigurableElement) {
    826 
    827         // Element not found
    828         strError = "Element not found: " + strPath;
    829         return NULL;
    830     }
    831 
    832     if (!pConfigurableElement->isParameter()) {
    833 
    834         // Element is not parameter
    835         strError = "Not a parameter: " + strPath;
    836 
    837         return NULL;
    838     }
    839 
    840     // Convert as parameter and return new handle
    841     return new CParameterHandle(static_cast<const CBaseParameter*>(pConfigurableElement), this);
    842 }
    843 
    844 void CParameterMgr::setFailureOnMissingSubsystem(bool bFail)
    845 {
    846     _bFailOnMissingSubsystem = bFail;
    847 }
    848 
    849 bool CParameterMgr::getFailureOnMissingSubsystem() const
    850 {
    851     return _bFailOnMissingSubsystem;
    852 }
    853 
    854 void CParameterMgr::setFailureOnFailedSettingsLoad(bool bFail)
    855 {
    856     _bFailOnFailedSettingsLoad = bFail;
    857 }
    858 
    859 bool CParameterMgr::getFailureOnFailedSettingsLoad()
    860 {
    861     return _bFailOnFailedSettingsLoad;
    862 }
    863 
    864 const string& CParameterMgr::getSchemaFolderLocation() const
    865 {
    866     return _strSchemaFolderLocation;
    867 }
    868 
    869 void CParameterMgr::setSchemaFolderLocation(const string& strSchemaFolderLocation)
    870 {
    871     _strSchemaFolderLocation = strSchemaFolderLocation;
    872 }
    873 
    874 void CParameterMgr::setValidateSchemasOnStart(bool bValidate)
    875 {
    876     _bValidateSchemasOnStart = bValidate;
    877 }
    878 
    879 bool CParameterMgr::getValidateSchemasOnStart() const
    880 {
    881     return _bValidateSchemasOnStart;
    882 }
    883 
    884 /////////////////// Remote command parsers
    885 /// Version
    886 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
    887 {
    888     (void)remoteCommand;
    889 
    890     // Show version
    891     strResult = getVersion();
    892 
    893     return CCommandHandler::ESucceeded;
    894 }
    895 
    896 /// Status
    897 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
    898 {
    899     (void)remoteCommand;
    900     // System class
    901     const CSystemClass* pSystemClass = getSystemClass();
    902 
    903     // Show status
    904     /// General section
    905     CUtility::appendTitle(strResult, "General:");
    906     // System class
    907     strResult += "System Class: ";
    908     strResult += pSystemClass->getName();
    909     strResult += "\n";
    910 
    911     // Tuning mode
    912     strResult += "Tuning Mode: ";
    913     strResult += tuningModeOn() ? "on" : "off";
    914     strResult += "\n";
    915 
    916     // Value space
    917     strResult += "Value Space: ";
    918     strResult += valueSpaceIsRaw() ? "raw" : "real";
    919     strResult += "\n";
    920 
    921     // Output raw format
    922     strResult += "Output Raw Format: ";
    923     strResult += outputRawFormatIsHex() ? "hex" : "dec";
    924     strResult += "\n";
    925 
    926     // Auto Sync
    927     strResult += "Auto Sync: ";
    928     strResult += autoSyncOn() ? "on" : "off";
    929     strResult += "\n";
    930 
    931     /// Subsystem list
    932     CUtility::appendTitle(strResult, "Subsystems:");
    933     string strSubsystemList;
    934     pSystemClass->listChildrenPaths(strSubsystemList);
    935     strResult += strSubsystemList;
    936 
    937     /// Last applied configurations
    938     CUtility::appendTitle(strResult, "Last Applied [Pending] Configurations:");
    939     string strLastAppliedConfigurations;
    940     getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations);
    941     strResult += strLastAppliedConfigurations;
    942 
    943     /// Criteria states
    944     CUtility::appendTitle(strResult, "Selection Criteria:");
    945     list<string> lstrSelectionCriteria;
    946     getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true);
    947     // Concatenate the criterion list as the command result
    948     string strCriteriaStates;
    949     CUtility::asString(lstrSelectionCriteria, strCriteriaStates);
    950     strResult += strCriteriaStates;
    951 
    952     return CCommandHandler::ESucceeded;
    953 }
    954 
    955 /// Tuning Mode
    956 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
    957 {
    958     if (remoteCommand.getArgument(0) == "on") {
    959 
    960         if (setTuningMode(true, strResult)) {
    961 
    962             return CCommandHandler::EDone;
    963         }
    964     } else if (remoteCommand.getArgument(0) == "off") {
    965 
    966         if (setTuningMode(false, strResult)) {
    967 
    968             return CCommandHandler::EDone;
    969         }
    970     } else {
    971         // Show usage
    972         return CCommandHandler::EShowUsage;
    973     }
    974     return CCommandHandler::EFailed;
    975 }
    976 
    977 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
    978 {
    979     (void)remoteCommand;
    980 
    981     strResult = tuningModeOn() ? "on" : "off";
    982 
    983     return CCommandHandler::ESucceeded;
    984 }
    985 
    986 /// Value Space
    987 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
    988 {
    989     (void)strResult;
    990 
    991     if (remoteCommand.getArgument(0) == "raw") {
    992 
    993         setValueSpace(true);
    994 
    995         return CCommandHandler::EDone;
    996 
    997     } else if (remoteCommand.getArgument(0) == "real") {
    998 
    999         setValueSpace(false);
   1000 
   1001         return CCommandHandler::EDone;
   1002 
   1003     } else {
   1004         // Show usage
   1005         return CCommandHandler::EShowUsage;
   1006     }
   1007     return CCommandHandler::EFailed;
   1008 }
   1009 
   1010 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1011 {
   1012     (void)remoteCommand;
   1013 
   1014     strResult = valueSpaceIsRaw() ? "raw" : "real";
   1015 
   1016     return CCommandHandler::ESucceeded;
   1017 }
   1018 
   1019 /// Output Raw Format
   1020 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1021 {
   1022     (void)strResult;
   1023 
   1024     if (remoteCommand.getArgument(0) == "hex") {
   1025 
   1026         setOutputRawFormat(true);
   1027 
   1028         return CCommandHandler::EDone;
   1029 
   1030     } else if (remoteCommand.getArgument(0) == "dec") {
   1031 
   1032         setOutputRawFormat(false);
   1033 
   1034         return CCommandHandler::EDone;
   1035 
   1036     } else {
   1037         // Show usage
   1038         return CCommandHandler::EShowUsage;
   1039     }
   1040     return CCommandHandler::EFailed;
   1041 }
   1042 
   1043 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1044 {
   1045     (void)remoteCommand;
   1046 
   1047     strResult = outputRawFormatIsHex() ? "hex" : "dec";
   1048 
   1049     return CCommandHandler::ESucceeded;
   1050 }
   1051 
   1052 /// Sync
   1053 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1054 {
   1055     if (remoteCommand.getArgument(0) == "on") {
   1056 
   1057         if (setAutoSync(true, strResult)) {
   1058 
   1059             return CCommandHandler::EDone;
   1060         }
   1061     } else if (remoteCommand.getArgument(0) == "off") {
   1062 
   1063         if (setAutoSync(false, strResult)) {
   1064 
   1065             return CCommandHandler::EDone;
   1066         }
   1067     } else {
   1068         // Show usage
   1069         return CCommandHandler::EShowUsage;
   1070     }
   1071     return CCommandHandler::EFailed;
   1072 }
   1073 
   1074 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1075 {
   1076     (void)remoteCommand;
   1077 
   1078     strResult = autoSyncOn() ? "on" : "off";
   1079 
   1080     return CCommandHandler::ESucceeded;
   1081 }
   1082 
   1083 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1084 {
   1085     (void)remoteCommand;
   1086 
   1087     return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1088 }
   1089 
   1090 /// Criteria
   1091 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1092 {
   1093     if (remoteCommand.getArgumentCount() > 1) {
   1094 
   1095         return CCommandHandler::EShowUsage;
   1096     }
   1097 
   1098     string strOutputFormat;
   1099 
   1100     // Look for optional arguments
   1101     if (remoteCommand.getArgumentCount() == 1) {
   1102 
   1103         // Get requested format
   1104         strOutputFormat = remoteCommand.getArgument(0);
   1105 
   1106         // Capitalize
   1107         std::transform(strOutputFormat.begin(), strOutputFormat.end(), strOutputFormat.begin(), ::toupper);
   1108 
   1109         if (strOutputFormat != "XML" && strOutputFormat != "CSV") {
   1110 
   1111             return CCommandHandler::EShowUsage;
   1112         }
   1113     }
   1114 
   1115     if (strOutputFormat == "XML") {
   1116         // Get Root element where to export from
   1117         const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition = getConstSelectionCriteria()->getSelectionCriteriaDefinition();
   1118 
   1119         if (!exportElementToXMLString(pSelectionCriteriaDefinition, "SelectionCriteria",
   1120                                       strResult)) {
   1121 
   1122             return CCommandHandler::EFailed;
   1123         }
   1124 
   1125         // Succeeded
   1126         return CCommandHandler::ESucceeded;
   1127     } else {
   1128 
   1129         // Requested format will be either CSV or human readable based on strOutputFormat content
   1130         bool bHumanReadable = strOutputFormat.empty();
   1131 
   1132         list<string> lstrResult;
   1133         getSelectionCriteria()->listSelectionCriteria(lstrResult, true, bHumanReadable);
   1134 
   1135         // Concatenate the criterion list as the command result
   1136         CUtility::asString(lstrResult, strResult);
   1137 
   1138         return CCommandHandler::ESucceeded;
   1139     }
   1140 }
   1141 
   1142 /// Domains
   1143 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1144 {
   1145     (void)remoteCommand;
   1146 
   1147     getConfigurableDomains()->listDomains(strResult);
   1148 
   1149     return CCommandHandler::ESucceeded;
   1150 }
   1151 
   1152 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1153 {
   1154     return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1155 }
   1156 
   1157 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1158 {
   1159     return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1160 }
   1161 
   1162 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1163 {
   1164     (void)remoteCommand;
   1165 
   1166     return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1167 }
   1168 
   1169 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1170 {
   1171     return renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ?
   1172         CCommandHandler::EDone : CCommandHandler::EFailed;
   1173 }
   1174 
   1175 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1176 {
   1177     // Set property
   1178     bool bSequenceAware;
   1179 
   1180     if (remoteCommand.getArgument(1) == "true") {
   1181 
   1182         bSequenceAware = true;
   1183 
   1184     } else if (remoteCommand.getArgument(1) == "false") {
   1185 
   1186         bSequenceAware = false;
   1187 
   1188     } else {
   1189         // Show usage
   1190         return CCommandHandler::EShowUsage;
   1191     }
   1192 
   1193     return setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ?
   1194         CCommandHandler::EDone : CCommandHandler::EFailed;
   1195 }
   1196 
   1197 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1198 {
   1199     // Get property
   1200     bool bSequenceAware;
   1201 
   1202     if (!getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) {
   1203 
   1204         return CCommandHandler::EFailed;
   1205     }
   1206 
   1207     strResult = bSequenceAware ? "true" : "false";
   1208 
   1209     return CCommandHandler::ESucceeded;
   1210 }
   1211 
   1212 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1213 {
   1214     return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
   1215 }
   1216 
   1217 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1218 {
   1219     return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1220 }
   1221 
   1222 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1223 {
   1224     return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1225 }
   1226 
   1227 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1228 {
   1229     return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1230 }
   1231 
   1232 /// Configurations
   1233 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1234 {
   1235     return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
   1236 }
   1237 
   1238 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1239 {
   1240     (void)remoteCommand;
   1241 
   1242     // Dummy error context
   1243     string strError;
   1244     CErrorContext errorContext(strError);
   1245 
   1246     // Dump
   1247     getConstConfigurableDomains()->dumpContent(strResult, errorContext);
   1248 
   1249     return CCommandHandler::ESucceeded;
   1250 }
   1251 
   1252 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1253 {
   1254     return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1255 }
   1256 
   1257 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1258 {
   1259     return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1260 }
   1261 
   1262 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1263 {
   1264     return renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
   1265             remoteCommand.getArgument(2), strResult) ?
   1266         CCommandHandler::EDone : CCommandHandler::EFailed;
   1267 }
   1268 
   1269 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1270 {
   1271     return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1272 }
   1273 
   1274 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1275 {
   1276     list<string> lstrResult;
   1277     if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) {
   1278         //Concatenate the error list as the command result
   1279         CUtility::asString(lstrResult, strResult);
   1280 
   1281         return  CCommandHandler::EFailed;
   1282     }
   1283     return CCommandHandler::EDone;
   1284 }
   1285 
   1286 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1287 {
   1288     // Build configurable element path list
   1289     std::vector<string> astrNewElementSequence;
   1290 
   1291     uint32_t uiArgument;
   1292 
   1293     for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) {
   1294 
   1295         astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument));
   1296     }
   1297 
   1298     // Delegate to configurable domains
   1299     return setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
   1300             astrNewElementSequence, strResult) ?
   1301         CCommandHandler::EDone : CCommandHandler::EFailed;
   1302 }
   1303 
   1304 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1305 {
   1306     // Delegate to configurable domains
   1307     return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed;
   1308 }
   1309 
   1310 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1311 {
   1312     // Delegate to configurable domains
   1313     return setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
   1314             remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), strResult) ?
   1315         CCommandHandler::EDone : CCommandHandler::EFailed;
   1316 }
   1317 
   1318 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1319 {
   1320     // Delegate to configurable domains
   1321     return clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
   1322             strResult) ?
   1323         CCommandHandler::EDone : CCommandHandler::EFailed;
   1324 }
   1325 
   1326 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1327 {
   1328     // Delegate to configurable domains
   1329     return getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1),
   1330             strResult) ?
   1331         CCommandHandler::ESucceeded : CCommandHandler::EFailed;
   1332 }
   1333 
   1334 /// Elements/Parameters
   1335 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1336 {
   1337     CElementLocator elementLocator(getSystemClass(), false);
   1338 
   1339     CElement* pLocatedElement = NULL;
   1340 
   1341     if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
   1342 
   1343         return CCommandHandler::EFailed;
   1344     }
   1345 
   1346     strResult = string("\n");
   1347 
   1348     if (!pLocatedElement) {
   1349 
   1350         // List from root folder
   1351 
   1352         // Return system class qualified name
   1353         pLocatedElement = getSystemClass();
   1354     }
   1355 
   1356     // Return sub-elements
   1357     strResult += pLocatedElement->listQualifiedPaths(false);
   1358 
   1359     return CCommandHandler::ESucceeded;
   1360 }
   1361 
   1362 /// Elements/Parameters
   1363 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1364 {
   1365     CElementLocator elementLocator(getSystemClass(), false);
   1366 
   1367     CElement* pLocatedElement = NULL;
   1368 
   1369     if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
   1370 
   1371         return CCommandHandler::EFailed;
   1372     }
   1373 
   1374     strResult = string("\n");
   1375 
   1376     if (!pLocatedElement) {
   1377 
   1378         // List from root folder
   1379 
   1380         // Return system class qualified name
   1381         pLocatedElement = getSystemClass();
   1382     }
   1383 
   1384     // Return sub-elements
   1385     strResult += pLocatedElement->listQualifiedPaths(true);
   1386 
   1387     return CCommandHandler::ESucceeded;
   1388 }
   1389 
   1390 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1391 {
   1392     CElementLocator elementLocator(getSystemClass());
   1393 
   1394     CElement* pLocatedElement = NULL;
   1395 
   1396     if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
   1397 
   1398         return CCommandHandler::EFailed;
   1399     }
   1400 
   1401     string strError;
   1402 
   1403     CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
   1404 
   1405     // Dump elements
   1406     pLocatedElement->dumpContent(strResult, parameterAccessContext);
   1407 
   1408     return CCommandHandler::ESucceeded;
   1409 }
   1410 
   1411 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1412 {
   1413     CElementLocator elementLocator(getSystemClass());
   1414 
   1415     CElement* pLocatedElement = NULL;
   1416 
   1417     if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
   1418 
   1419         return CCommandHandler::EFailed;
   1420     }
   1421 
   1422     // Converted to actual sizable element
   1423     const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
   1424 
   1425     // Get size as string
   1426     strResult = pConfigurableElement->getFootprintAsString();
   1427 
   1428     return CCommandHandler::ESucceeded;
   1429 }
   1430 
   1431 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1432 {
   1433     CElementLocator elementLocator(getSystemClass());
   1434 
   1435     CElement* pLocatedElement = NULL;
   1436 
   1437     if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
   1438 
   1439         return CCommandHandler::EFailed;
   1440     }
   1441 
   1442     // Convert element
   1443     const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
   1444 
   1445     // Return element properties
   1446     pConfigurableElement->showProperties(strResult);
   1447 
   1448     return CCommandHandler::ESucceeded;
   1449 }
   1450 
   1451 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1452 {
   1453     string strValue;
   1454 
   1455     if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) {
   1456 
   1457         return CCommandHandler::EFailed;
   1458     }
   1459     // Succeeded
   1460     strResult = strValue;
   1461 
   1462     return CCommandHandler::ESucceeded;
   1463 }
   1464 
   1465 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1466 {
   1467     // Get value to set
   1468     string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1);
   1469 
   1470     return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1471 }
   1472 
   1473 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1474 {
   1475     CElementLocator elementLocator(getSystemClass());
   1476 
   1477     CElement* pLocatedElement = NULL;
   1478 
   1479     if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
   1480 
   1481         return CCommandHandler::EFailed;
   1482     }
   1483 
   1484     // Convert element
   1485     const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
   1486 
   1487     // Return element belonging domains
   1488     pConfigurableElement->listBelongingDomains(strResult);
   1489 
   1490     return CCommandHandler::ESucceeded;
   1491 }
   1492 
   1493 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1494 {
   1495     CElementLocator elementLocator(getSystemClass());
   1496 
   1497     CElement* pLocatedElement = NULL;
   1498 
   1499     if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) {
   1500 
   1501         return CCommandHandler::EFailed;
   1502     }
   1503 
   1504     // Convert element
   1505     const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
   1506 
   1507     // Return element belonging domains
   1508     pConfigurableElement->listAssociatedDomains(strResult);
   1509 
   1510     return CCommandHandler::ESucceeded;
   1511 }
   1512 
   1513 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1514 {
   1515     (void)remoteCommand;
   1516 
   1517     getConfigurableDomains()->listAssociatedElements(strResult);
   1518 
   1519     return CCommandHandler::ESucceeded;
   1520 }
   1521 
   1522 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1523 {
   1524     (void)remoteCommand;
   1525 
   1526     getConfigurableDomains()->listConflictingElements(strResult);
   1527 
   1528     return CCommandHandler::ESucceeded;
   1529 }
   1530 
   1531 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1532 {
   1533     (void)remoteCommand;
   1534 
   1535     getSystemClass()->listRogueElements(strResult);
   1536 
   1537     return CCommandHandler::ESucceeded;
   1538 }
   1539 
   1540 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1541 {
   1542     string strOutputValue;
   1543     string strError;
   1544 
   1545     if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) {
   1546 
   1547         strResult = strError;
   1548         return CCommandHandler::EFailed;
   1549     }
   1550     // Succeeded
   1551     strResult = strOutputValue;
   1552 
   1553     return CCommandHandler::ESucceeded;
   1554 }
   1555 
   1556 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1557 {
   1558     // Get value to set
   1559     string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3);
   1560 
   1561     bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0),
   1562                                             remoteCommand.getArgument(1),
   1563                                             remoteCommand.getArgument(2),
   1564                                             strValue, true, strResult);
   1565 
   1566     return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1567 }
   1568 
   1569 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommandProcess(
   1570         const IRemoteCommand& remoteCommand,
   1571         string& strResult)
   1572 {
   1573     if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) {
   1574 
   1575         return CCommandHandler::EFailed;
   1576     }
   1577 
   1578     return CCommandHandler::ESucceeded;
   1579 }
   1580 
   1581 /// Settings Import/Export
   1582 CParameterMgr::CCommandHandler::CommandStatus
   1583         CParameterMgr::exportDomainsXMLCommandProcess(
   1584                 const IRemoteCommand& remoteCommand, string& strResult)
   1585 {
   1586     string strFileName = remoteCommand.getArgument(0);
   1587     return exportDomainsXml(strFileName, false, true, strResult) ?
   1588             CCommandHandler::EDone : CCommandHandler::EFailed;
   1589 }
   1590 
   1591 CParameterMgr::CCommandHandler::CommandStatus
   1592         CParameterMgr::importDomainsXMLCommandProcess(
   1593                 const IRemoteCommand& remoteCommand, string& strResult)
   1594 {
   1595     return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ?
   1596             CCommandHandler::EDone : CCommandHandler::EFailed;
   1597 }
   1598 
   1599 CParameterMgr::CCommandHandler::CommandStatus
   1600         CParameterMgr::exportDomainsWithSettingsXMLCommandProcess(
   1601                 const IRemoteCommand& remoteCommand, string& strResult)
   1602 {
   1603     string strFileName = remoteCommand.getArgument(0);
   1604     return exportDomainsXml(strFileName, true, true, strResult) ?
   1605             CCommandHandler::EDone : CCommandHandler::EFailed;
   1606 }
   1607 
   1608 CParameterMgr::CCommandHandler::CommandStatus
   1609         CParameterMgr::exportDomainWithSettingsXMLCommandProcess(
   1610                 const IRemoteCommand& remoteCommand, string& result)
   1611 {
   1612     string domainName = remoteCommand.getArgument(0);
   1613     string fileName = remoteCommand.getArgument(1);
   1614     return exportSingleDomainXml(fileName, domainName, true, true, result) ?
   1615             CCommandHandler::EDone : CCommandHandler::EFailed;
   1616 }
   1617 
   1618 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importDomainsWithSettingsXMLCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1619 {
   1620     return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1621 }
   1622 
   1623 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importDomainWithSettingsXMLCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1624 {
   1625     bool bOverwrite = false;
   1626 
   1627     // Look for optional arguments
   1628     if (remoteCommand.getArgumentCount() > 1) {
   1629 
   1630         if (remoteCommand.getArgument(1) == "overwrite") {
   1631 
   1632             bOverwrite = true;
   1633         } else {
   1634             // Show usage
   1635             return CCommandHandler::EShowUsage;
   1636         }
   1637     }
   1638 
   1639     return importSingleDomainXml(remoteCommand.getArgument(0), bOverwrite, true, true, strResult) ?
   1640         CCommandHandler::EDone : CCommandHandler::EFailed;
   1641 }
   1642 
   1643 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1644 {
   1645     return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1646 }
   1647 
   1648 CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult)
   1649 {
   1650     return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed;
   1651 }
   1652 
   1653 CParameterMgr::CCommandHandler::CommandStatus
   1654         CParameterMgr::getDomainsWithSettingsXMLCommandProcess(
   1655                 const IRemoteCommand& remoteCommand, string& strResult)
   1656 {
   1657     (void)remoteCommand;
   1658 
   1659     if (!exportDomainsXml(strResult, true, false, strResult)) {
   1660 
   1661         return CCommandHandler::EFailed;
   1662     }
   1663     // Succeeded
   1664     return CCommandHandler::ESucceeded;
   1665 }
   1666 
   1667 CParameterMgr::CCommandHandler::CommandStatus
   1668         CParameterMgr::getDomainWithSettingsXMLCommandProcess(
   1669                 const IRemoteCommand& remoteCommand, string& strResult)
   1670 {
   1671     string strDomainName = remoteCommand.getArgument(0);
   1672 
   1673     return exportSingleDomainXml(strResult, strDomainName, true, false, strResult) ?
   1674         CCommandHandler::ESucceeded : CCommandHandler::EFailed;
   1675 }
   1676 
   1677 CParameterMgr::CCommandHandler::CommandStatus
   1678         CParameterMgr::setDomainsWithSettingsXMLCommandProcess(
   1679                 const IRemoteCommand& remoteCommand, string& strResult)
   1680 {
   1681     return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ?
   1682             CCommandHandler::EDone : CCommandHandler::EFailed;
   1683 }
   1684 
   1685 CParameterMgr::CCommandHandler::CommandStatus
   1686         CParameterMgr::setDomainWithSettingsXMLCommandProcess(
   1687                 const IRemoteCommand& remoteCommand, string& result)
   1688 {
   1689     bool overwrite = false;
   1690 
   1691     if (remoteCommand.getArgumentCount() > 1) {
   1692 
   1693         if (remoteCommand.getArgument(1) == "overwrite") {
   1694 
   1695             overwrite = true;
   1696         } else {
   1697             // Show usage
   1698             return CCommandHandler::EShowUsage;
   1699         }
   1700     }
   1701 
   1702     return importSingleDomainXml(remoteCommand.getArgument(0), overwrite, true, false, result) ?
   1703         CCommandHandler::EDone : CCommandHandler::EFailed;
   1704 }
   1705 
   1706 CParameterMgr::CCommandHandler::CommandStatus
   1707         CParameterMgr::getSystemClassXMLCommandProcess(
   1708                 const IRemoteCommand& remoteCommand, string& strResult)
   1709 {
   1710     (void)remoteCommand;
   1711 
   1712     // Get Root element where to export from
   1713     const CSystemClass* pSystemClass = getSystemClass();
   1714 
   1715     if (!exportElementToXMLString(pSystemClass, pSystemClass->getKind(), strResult)) {
   1716 
   1717         return CCommandHandler::EFailed;
   1718     }
   1719     // Succeeded
   1720     return CCommandHandler::ESucceeded;
   1721 }
   1722 
   1723 // User set/get parameters in main BlackBoard
   1724 bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError)
   1725 {
   1726     // Forbid write access when not in TuningMode
   1727     if (bSet && !checkTuningModeOn(strError)) {
   1728 
   1729         return false;
   1730     }
   1731 
   1732     // Define context
   1733     CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex);
   1734 
   1735     // Activate the auto synchronization with the hardware
   1736     if (bSet) {
   1737 
   1738         parameterAccessContext.setAutoSync(_bAutoSyncOn);
   1739     }
   1740 
   1741     return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
   1742 }
   1743 
   1744 // User get parameter mapping
   1745 bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult) const
   1746 {
   1747     CPathNavigator pathNavigator(strPath);
   1748 
   1749     // Nagivate through system class
   1750     if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) {
   1751 
   1752         return false;
   1753     }
   1754 
   1755     // Get the ConfigurableElement corresponding to strPath
   1756     const CConfigurableElement* pConfigurableElement = getConfigurableElement(strPath, strResult);
   1757     if (!pConfigurableElement) {
   1758 
   1759         return false;
   1760     }
   1761 
   1762     // Find the list of the ancestors of the current ConfigurableElement that have a mapping
   1763     list<const CConfigurableElement*> configurableElementPath;
   1764     pConfigurableElement->getListOfElementsWithMapping(configurableElementPath);
   1765 
   1766     // Get the Subsystem containing the ConfigurableElement
   1767     const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem();
   1768     if (!pSubsystem) {
   1769 
   1770         strResult = "Unable to find the Subsystem containing the parameter";
   1771         return false;
   1772     }
   1773 
   1774     // Fetch the mapping corresponding to the ConfigurableElement
   1775     strResult = pSubsystem->getMapping(configurableElementPath);
   1776 
   1777     return true;
   1778 }
   1779 
   1780 // User set/get parameters in specific Configuration BlackBoard
   1781 bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError)
   1782 {
   1783     CElementLocator elementLocator(getSystemClass());
   1784 
   1785     CElement* pLocatedElement = NULL;
   1786 
   1787     if (!elementLocator.locate(strPath, &pLocatedElement, strError)) {
   1788 
   1789         return false;
   1790     }
   1791 
   1792     // Convert element
   1793     const CConfigurableElement* pConfigurableElement = static_cast<const CConfigurableElement*>(pLocatedElement);
   1794 
   1795     // Get the Configuration blackboard and the Base Offset of the configurable element in this blackboard
   1796     uint32_t uiBaseOffset;
   1797     bool bIsLastApplied;
   1798 
   1799     CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError);
   1800 
   1801     if (!pConfigurationBlackboard) {
   1802 
   1803         return false;
   1804     }
   1805 
   1806     log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset);
   1807 
   1808     /// Update the Configuration Blackboard
   1809 
   1810     // Define Configuration context using Base Offset and keep Auto Sync off to prevent access to HW
   1811     CParameterAccessContext parameterAccessContext(strError, pConfigurationBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex, uiBaseOffset);
   1812 
   1813     // Deactivate the auto synchronization with the hardware during the Configuration Blackboard
   1814     // access (only Main Blackboard shall be synchronized, Configurations Blackboards are copied
   1815     // into the Main Blackboard each time a configuration is restored but they are not synchronized
   1816     // directly).
   1817     if (bSet) {
   1818 
   1819         parameterAccessContext.setAutoSync(false);
   1820     }
   1821 
   1822     // Access Value in the Configuration Blackboard
   1823     if (!accessValue(parameterAccessContext, strPath, strValue, bSet, strError)) {
   1824 
   1825         return false;
   1826     }
   1827 
   1828     /// If the Configuration is the last one applied, update the Main Blackboard as well
   1829 
   1830     if (bIsLastApplied) {
   1831 
   1832         // Define Main context
   1833         parameterAccessContext.setParameterBlackboard(_pMainParameterBlackboard);
   1834 
   1835         // Activate the auto synchronization with the hardware
   1836         if (bSet) {
   1837 
   1838             parameterAccessContext.setAutoSync(_bAutoSyncOn);
   1839         }
   1840 
   1841         // Access Value in the Main Blackboard
   1842         return accessValue(parameterAccessContext, strPath, strValue, bSet, strError);
   1843     }
   1844 
   1845     return true;
   1846 }
   1847 
   1848 // User set/get parameters
   1849 bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, const string& strPath, string& strValue, bool bSet, string& strError)
   1850 {
   1851     // Lock state
   1852     CAutoLock autoLock(&_blackboardMutex);
   1853 
   1854     CPathNavigator pathNavigator(strPath);
   1855 
   1856     // Nagivate through system class
   1857     if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
   1858 
   1859         parameterAccessContext.setError(strError);
   1860 
   1861         return false;
   1862     }
   1863 
   1864     // Do the get
   1865     return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext);
   1866 }
   1867 
   1868 // Tuning mode
   1869 bool CParameterMgr::setTuningMode(bool bOn, string& strError)
   1870 {
   1871     // Tuning allowed?
   1872     if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) {
   1873 
   1874         strError = "Tuning prohibited";
   1875 
   1876         return false;
   1877     }
   1878     // Lock state
   1879     CAutoLock autoLock(&_blackboardMutex);
   1880 
   1881     // Warn domains about exiting tuning mode
   1882     if (!bOn && _bTuningModeIsOn) {
   1883 
   1884         // Ensure application of currently selected configurations
   1885         // Force-apply configurations
   1886         doApplyConfigurations(true);
   1887 
   1888         // Turn auto sync back on
   1889         _bAutoSyncOn = true;
   1890     }
   1891 
   1892     // Store
   1893     _bTuningModeIsOn = bOn;
   1894 
   1895     return true;
   1896 }
   1897 
   1898 bool CParameterMgr::tuningModeOn() const
   1899 {
   1900     return _bTuningModeIsOn;
   1901 }
   1902 
   1903 // Current value space for user set/get value interpretation
   1904 void CParameterMgr::setValueSpace(bool bIsRaw)
   1905 {
   1906     _bValueSpaceIsRaw = bIsRaw;
   1907 }
   1908 
   1909 bool CParameterMgr::valueSpaceIsRaw()
   1910 {
   1911     return _bValueSpaceIsRaw;
   1912 }
   1913 
   1914 // Current Output Raw Format for user get value interpretation
   1915 void CParameterMgr::setOutputRawFormat(bool bIsHex)
   1916 {
   1917     _bOutputRawFormatIsHex = bIsHex;
   1918 }
   1919 
   1920 bool CParameterMgr::outputRawFormatIsHex()
   1921 {
   1922     return _bOutputRawFormatIsHex;
   1923 }
   1924 
   1925 /// Sync
   1926 // Automatic hardware synchronization control (during tuning session)
   1927 bool CParameterMgr::setAutoSync(bool bAutoSyncOn, string& strError)
   1928 {
   1929     // Check tuning mode
   1930     if (!checkTuningModeOn(strError)) {
   1931 
   1932         return false;
   1933     }
   1934     // Warn domains about turning auto sync back on
   1935     if (bAutoSyncOn && !_bAutoSyncOn) {
   1936 
   1937         // Do the synchronization at system class level (could be optimized by keeping track of all modified parameters)
   1938         if (!sync(strError)) {
   1939 
   1940             return false;
   1941         }
   1942     }
   1943 
   1944     // Set Auto sync
   1945     _bAutoSyncOn = bAutoSyncOn;
   1946 
   1947     return true;
   1948 }
   1949 
   1950 bool CParameterMgr::autoSyncOn() const
   1951 {
   1952     return _bAutoSyncOn;
   1953 }
   1954 
   1955 // Manual hardware synchronization control (during tuning session)
   1956 bool CParameterMgr::sync(string& strError)
   1957 {
   1958     // Check tuning mode
   1959     if (!checkTuningModeOn(strError)) {
   1960 
   1961         return false;
   1962     }
   1963     // Warn domains about turning auto sync back on
   1964     if (_bAutoSyncOn) {
   1965 
   1966         strError = "Feature unavailable when Auto Sync is on";
   1967 
   1968         return false;
   1969     }
   1970 
   1971     // Get syncer set
   1972     CSyncerSet syncerSet;
   1973     // ... from system class
   1974     getConstSystemClass()->fillSyncerSet(syncerSet);
   1975 
   1976     // Sync
   1977     list<string> lstrError;
   1978     if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){
   1979 
   1980         CUtility::asString(lstrError, strError);
   1981         return false;
   1982     };
   1983 
   1984     return true;
   1985 }
   1986 
   1987 // Configuration/Domains handling
   1988 bool CParameterMgr::createDomain(const string& strName, string& strError)
   1989 {
   1990     // Check tuning mode
   1991     if (!checkTuningModeOn(strError)) {
   1992 
   1993         return false;
   1994     }
   1995 
   1996     // Delegate to configurable domains
   1997     return getConfigurableDomains()->createDomain(strName, strError);
   1998 }
   1999 
   2000 bool CParameterMgr::deleteDomain(const string& strName, string& strError)
   2001 {
   2002     // Check tuning mode
   2003     if (!checkTuningModeOn(strError)) {
   2004 
   2005         return false;
   2006     }
   2007 
   2008     // Delegate to configurable domains
   2009     return getConfigurableDomains()->deleteDomain(strName, strError);
   2010 }
   2011 
   2012 bool CParameterMgr::renameDomain(const string& strName, const string& strNewName, string& strError)
   2013 {
   2014     // Delegate to configurable domains
   2015     return getConfigurableDomains()->renameDomain(strName, strNewName, strError);
   2016 }
   2017 
   2018 bool CParameterMgr::deleteAllDomains(string& strError)
   2019 {
   2020     // Check tuning mode
   2021     if (!checkTuningModeOn(strError)) {
   2022 
   2023         return false;
   2024     }
   2025 
   2026     // Delegate to configurable domains
   2027     getConfigurableDomains()->deleteAllDomains();
   2028 
   2029     return true;
   2030 }
   2031 
   2032 bool CParameterMgr::setSequenceAwareness(const string& strName, bool bSequenceAware, string& strResult)
   2033 {
   2034     // Check tuning mode
   2035     if (!checkTuningModeOn(strResult)) {
   2036 
   2037         return false;
   2038     }
   2039 
   2040     return getConfigurableDomains()->setSequenceAwareness(strName, bSequenceAware, strResult);
   2041 }
   2042 
   2043 bool CParameterMgr::getSequenceAwareness(const string& strName, bool& bSequenceAware,
   2044                                          string& strResult)
   2045 {
   2046     return getConfigurableDomains()->getSequenceAwareness(strName, bSequenceAware, strResult);
   2047 }
   2048 
   2049 bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
   2050 {
   2051     // Check tuning mode
   2052     if (!checkTuningModeOn(strError)) {
   2053 
   2054         return false;
   2055     }
   2056 
   2057     // Delegate to configurable domains
   2058     return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
   2059 }
   2060 bool CParameterMgr::renameConfiguration(const string& strDomain, const string& strConfiguration,
   2061                                         const string& strNewConfiguration, string& strError)
   2062 {
   2063     return getConfigurableDomains()->renameConfiguration(strDomain, strConfiguration,
   2064             strNewConfiguration, strError);
   2065 }
   2066 
   2067 bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
   2068 {
   2069     // Check tuning mode
   2070     if (!checkTuningModeOn(strError)) {
   2071 
   2072         return false;
   2073     }
   2074 
   2075     // Delegate to configurable domains
   2076     return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError);
   2077 }
   2078 
   2079 bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list<string>& lstrError)
   2080 {
   2081     string strError;
   2082     // Check tuning mode
   2083     if (!checkTuningModeOn(strError)) {
   2084 
   2085         lstrError.push_back(strError);
   2086         return false;
   2087     }
   2088 
   2089     // Delegate to configurable domains
   2090     return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError);
   2091 }
   2092 
   2093 bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError)
   2094 {
   2095     // Check tuning mode
   2096     if (!checkTuningModeOn(strError)) {
   2097 
   2098         return false;
   2099     }
   2100 
   2101     // Delegate to configurable domains
   2102     return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError);
   2103 }
   2104 
   2105 // Configurable element - domain association
   2106 bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
   2107 {
   2108     // Check tuning mode
   2109     if (!checkTuningModeOn(strError)) {
   2110 
   2111         return false;
   2112     }
   2113 
   2114     CElementLocator elementLocator(getSystemClass());
   2115 
   2116     CElement* pLocatedElement = NULL;
   2117 
   2118     if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
   2119 
   2120         return false;
   2121     }
   2122 
   2123     // Convert element
   2124     CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
   2125 
   2126     // Delegate
   2127     return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError);
   2128 }
   2129 
   2130 bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError)
   2131 {
   2132     // Check tuning mode
   2133     if (!checkTuningModeOn(strError)) {
   2134 
   2135         return false;
   2136     }
   2137 
   2138     CElementLocator elementLocator(getSystemClass());
   2139 
   2140     CElement* pLocatedElement = NULL;
   2141 
   2142     if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
   2143 
   2144         return false;
   2145     }
   2146 
   2147     // Convert element
   2148     CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
   2149 
   2150     // Delegate
   2151     return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError);
   2152 }
   2153 
   2154 bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError)
   2155 {
   2156     // Check tuning mode
   2157     if (!checkTuningModeOn(strError)) {
   2158 
   2159         return false;
   2160     }
   2161 
   2162     CElementLocator elementLocator(getSystemClass());
   2163 
   2164     CElement* pLocatedElement = NULL;
   2165 
   2166     if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) {
   2167 
   2168         return false;
   2169     }
   2170 
   2171     // Convert element
   2172     CConfigurableElement* pConfigurableElement = static_cast<CConfigurableElement*>(pLocatedElement);
   2173 
   2174     // Delegate
   2175     return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError);
   2176 }
   2177 
   2178 bool CParameterMgr::setElementSequence(const string& strDomain, const string& strConfiguration,
   2179                                        const std::vector<string>& astrNewElementSequence,
   2180                                        string& strError)
   2181 {
   2182     // Check tuning mode
   2183     if (!checkTuningModeOn(strError)) {
   2184 
   2185         return false;
   2186     }
   2187 
   2188     return getConfigurableDomains()->setElementSequence(strDomain, strConfiguration,
   2189             astrNewElementSequence, strError);
   2190 }
   2191 
   2192 bool CParameterMgr::getApplicationRule(const string& strDomain, const string& strConfiguration,
   2193                                        string& strResult)
   2194 {
   2195     return getConfigurableDomains()->getApplicationRule(strDomain, strConfiguration, strResult);
   2196 }
   2197 
   2198 bool CParameterMgr::setApplicationRule(const string& strDomain, const string& strConfiguration,
   2199                                        const string& strApplicationRule, string& strError)
   2200 {
   2201     return getConfigurableDomains()->setApplicationRule(strDomain, strConfiguration,
   2202             strApplicationRule, getConstSelectionCriteria()->getSelectionCriteriaDefinition(),
   2203             strError);
   2204 }
   2205 
   2206 bool CParameterMgr::clearApplicationRule(const string& strDomain, const string& strConfiguration,
   2207                                          string& strError)
   2208 {
   2209     return getConfigurableDomains()->clearApplicationRule(strDomain, strConfiguration, strError);
   2210 }
   2211 
   2212 bool CParameterMgr::importDomainsXml(const string& xmlSource, bool withSettings,
   2213                                      bool fromFile, string& errorMsg)
   2214 {
   2215     // Check tuning mode
   2216     if (!checkTuningModeOn(errorMsg)) {
   2217 
   2218         return false;
   2219     }
   2220 
   2221     CAutoLog autoLog(this, string("Importing domains from ") +
   2222             (fromFile ? ("\"" + xmlSource + "\"") : "a user-provided buffer"));
   2223 
   2224     // Root element
   2225     CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
   2226 
   2227     bool importSuccess = wrapLegacyXmlImport(xmlSource, fromFile, withSettings,
   2228                                              *pConfigurableDomains, "SystemClassName", errorMsg);
   2229 
   2230     if (importSuccess) {
   2231 
   2232         // Validate domains after XML import
   2233         pConfigurableDomains->validate(_pMainParameterBlackboard);
   2234     }
   2235 
   2236     return importSuccess;
   2237 }
   2238 
   2239 bool CParameterMgr::importSingleDomainXml(const string& xmlSource, bool overwrite,
   2240                                           bool withSettings, bool fromFile, string& errorMsg)
   2241 {
   2242     if (!checkTuningModeOn(errorMsg)) {
   2243 
   2244         return false;
   2245     }
   2246 
   2247     CAutoLog autoLog(this, string("Importing a single domain from ") +
   2248             (fromFile ? ("\"" + xmlSource + "\"") : "a user-provided buffer"));
   2249 
   2250     // We initialize the domain with an empty name but since we have set the isDomainStandalone
   2251     // context, the name will be retrieved during de-serialization
   2252     std::auto_ptr<CConfigurableDomain> standaloneDomain(new CConfigurableDomain());
   2253 
   2254     if (!wrapLegacyXmlImport(xmlSource, fromFile, withSettings, *standaloneDomain, "", errorMsg)) {
   2255         return false;
   2256     }
   2257 
   2258     if (!getConfigurableDomains()->addDomain(*standaloneDomain, overwrite, errorMsg)) {
   2259         return false;
   2260     }
   2261 
   2262     // ownership has been transfered to the ConfigurableDomains object
   2263     standaloneDomain.release();
   2264     return true;
   2265 }
   2266 
   2267 bool CParameterMgr::wrapLegacyXmlImport(const string& xmlSource, bool fromFile,
   2268                                         bool withSettings, CElement& element,
   2269                                         const string& nameAttributeName, string& errorMsg)
   2270 {
   2271     CXmlDomainImportContext xmlDomainImportContext(errorMsg, withSettings, *getSystemClass());
   2272 
   2273     // Selection criteria definition for rule creation
   2274     xmlDomainImportContext.setSelectionCriteriaDefinition(
   2275             getConstSelectionCriteria()->getSelectionCriteriaDefinition());
   2276 
   2277     // It doesn't make sense to resolve XIncludes on an imported file because
   2278     // we can't reliably decide of a "base url"
   2279     _xmlDoc *doc = CXmlDocSource::mkXmlDoc(xmlSource, fromFile, false, errorMsg);
   2280     if (doc == NULL) {
   2281         return false;
   2282     }
   2283 
   2284     return xmlParse(xmlDomainImportContext, &element, doc, "", EParameterConfigurationLibrary, nameAttributeName);
   2285 }
   2286 
   2287 bool CParameterMgr::serializeElement(std::ostream& output,
   2288                                      CXmlSerializingContext& xmlSerializingContext,
   2289                                      const CElement& element) const
   2290 {
   2291     if (!output.good()) {
   2292         xmlSerializingContext.setError("Can't write XML: the output is in a bad state.");
   2293         return false;
   2294     }
   2295 
   2296     // Get Schema file associated to root element
   2297     string xmlSchemaFilePath = _strSchemaFolderLocation + "/" +
   2298                                   element.getKind() + ".xsd";
   2299 
   2300     // Use a doc source by loading data from instantiated Configurable Domains
   2301     CXmlMemoryDocSource memorySource(&element, _bValidateSchemasOnStart,
   2302                                      element.getKind(),
   2303                                      xmlSchemaFilePath,
   2304                                      "parameter-framework",
   2305                                      getVersion());
   2306 
   2307     // Use a doc sink to write the doc data in a stream
   2308     CXmlStreamDocSink sink(output);
   2309 
   2310     bool processSuccess = sink.process(memorySource, xmlSerializingContext);
   2311 
   2312     return processSuccess;
   2313 }
   2314 
   2315 bool CParameterMgr::exportDomainsXml(string& xmlDest, bool withSettings, bool toFile,
   2316                                      string& errorMsg) const
   2317 {
   2318     CAutoLog autoLog(this, string("Exporting domains to ") +
   2319             (toFile ? ("\"" + xmlDest + "\"") : " a user-provided buffer"));
   2320 
   2321     const CConfigurableDomains* configurableDomains = getConstConfigurableDomains();
   2322 
   2323     return wrapLegacyXmlExport(xmlDest, toFile, withSettings, *configurableDomains, errorMsg);
   2324 }
   2325 
   2326 bool CParameterMgr::exportSingleDomainXml(string& xmlDest, const string& domainName,
   2327                                           bool withSettings, bool toFile, string& errorMsg) const
   2328 {
   2329     CAutoLog autoLog(this, string("Exporting single domain '") + domainName + "' to " +
   2330             (toFile ? ("\"" + xmlDest + "\"") : " a user-provided buffer"));
   2331 
   2332     // Element to be serialized
   2333     const CConfigurableDomain* requestedDomain =
   2334         getConstConfigurableDomains()->findConfigurableDomain(domainName, errorMsg);
   2335 
   2336     if (requestedDomain == NULL) {
   2337         return false;
   2338     }
   2339 
   2340     return wrapLegacyXmlExport(xmlDest, toFile, withSettings, *requestedDomain, errorMsg);
   2341 }
   2342 
   2343 bool CParameterMgr::wrapLegacyXmlExport(string& xmlDest, bool toFile, bool withSettings,
   2344                                         const CElement& element, string& errorMsg) const
   2345 {
   2346     CXmlDomainExportContext context(errorMsg, withSettings, _bValueSpaceIsRaw,
   2347                                     _bOutputRawFormatIsHex);
   2348 
   2349     if (toFile) {
   2350         return wrapLegacyXmlExportToFile(xmlDest, element, context);
   2351     } else {
   2352         return wrapLegacyXmlExportToString(xmlDest, element, context);
   2353     }
   2354 }
   2355 
   2356 bool CParameterMgr::wrapLegacyXmlExportToFile(string& xmlDest,
   2357                                               const CElement& element,
   2358                                               CXmlDomainExportContext &context) const
   2359 {
   2360     std::ofstream output(xmlDest.c_str());
   2361 
   2362     if (output.fail()) {
   2363         context.setError("Failed to open \"" + xmlDest + "\" for writing.");
   2364         return false;
   2365     }
   2366 
   2367     return serializeElement(output, context, element);
   2368 
   2369 }
   2370 
   2371 bool CParameterMgr::wrapLegacyXmlExportToString(string& xmlDest,
   2372                                                 const CElement& element,
   2373                                                 CXmlDomainExportContext &context) const
   2374 {
   2375     std::ostringstream output;
   2376 
   2377     if (!serializeElement(output, context, element)) {
   2378         return false;
   2379     }
   2380 
   2381     xmlDest = output.str();
   2382 
   2383     return true;
   2384 }
   2385 
   2386 // Binary Import/Export
   2387 bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError)
   2388 {
   2389     // Check tuning mode
   2390     if (!checkTuningModeOn(strError)) {
   2391 
   2392         return false;
   2393     }
   2394 
   2395     CAutoLog autoLog(this, string("Importing domains from binary file \"") + strFileName + "\"");
   2396     // Root element
   2397     CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
   2398 
   2399     // Serialize in
   2400     return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError);
   2401 }
   2402 
   2403 bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError)
   2404 {
   2405     CAutoLog autoLog(this, string("Exporting domains to binary file \"") + strFileName + "\"");
   2406     // Root element
   2407     CConfigurableDomains* pConfigurableDomains = getConfigurableDomains();
   2408 
   2409     // Serialize out
   2410     return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError);
   2411 }
   2412 
   2413 // For tuning, check we're in tuning mode
   2414 bool CParameterMgr::checkTuningModeOn(string& strError) const
   2415 {
   2416     // Tuning Mode on?
   2417     if (!_bTuningModeIsOn) {
   2418 
   2419         strError = "Tuning Mode must be on";
   2420 
   2421         return false;
   2422     }
   2423     return true;
   2424 }
   2425 
   2426 // Tuning mutex dynamic parameter handling
   2427 pthread_mutex_t* CParameterMgr::getBlackboardMutex()
   2428 {
   2429     return &_blackboardMutex;
   2430 }
   2431 
   2432 // Blackboard reference (dynamic parameter handling)
   2433 CParameterBlackboard* CParameterMgr::getParameterBlackboard()
   2434 {
   2435     return _pMainParameterBlackboard;
   2436 }
   2437 
   2438 // Dynamic creation library feeding
   2439 void CParameterMgr::feedElementLibraries()
   2440 {
   2441     // Global Configuration handling
   2442     CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary;
   2443 
   2444     pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate<CParameterFrameworkConfiguration>());
   2445     pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate<CSubsystemPlugins>());
   2446     pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate<CPluginLocation>());
   2447     pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
   2448     pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate<CFrameworkConfigurationGroup>());
   2449     pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
   2450     pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate<CFrameworkConfigurationLocation>());
   2451 
   2452     _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary);
   2453 
   2454     // Parameter creation
   2455     CElementLibrary* pParameterCreationLibrary = new CElementLibrary;
   2456 
   2457     pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary()));
   2458     pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate<CComponentType>());
   2459     pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate<CComponentInstance>());
   2460     pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate<CBitParameterType>());
   2461     pParameterCreationLibrary->addElementBuilder("BitParameterBlock", new TNamedElementBuilderTemplate<CBitParameterBlockType>());
   2462     pParameterCreationLibrary->addElementBuilder("StringParameter", new TNamedElementBuilderTemplate<CStringParameterType>());
   2463     pParameterCreationLibrary->addElementBuilder("ParameterBlock", new TNamedElementBuilderTemplate<CParameterBlockType>());
   2464     pParameterCreationLibrary->addElementBuilder("BooleanParameter", new TNamedElementBuilderTemplate<CBooleanParameterType>());
   2465     pParameterCreationLibrary->addElementBuilder("IntegerParameter", new TNamedElementBuilderTemplate<CIntegerParameterType>());
   2466     pParameterCreationLibrary->addElementBuilder("LinearAdaptation", new TElementBuilderTemplate<CLinearParameterAdaptation>());
   2467     pParameterCreationLibrary->addElementBuilder("LogarithmicAdaptation", new TElementBuilderTemplate<CLogarithmicParameterAdaptation>());
   2468     pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate<CEnumParameterType>());
   2469     pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate<CEnumValuePair>());
   2470     pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate<CFixedPointParameterType>());
   2471     pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart));
   2472 
   2473     _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary);
   2474 
   2475     // Parameter Configuration Domains creation
   2476     CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary;
   2477 
   2478     pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TElementBuilderTemplate<CConfigurableDomain>());
   2479     pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate<CDomainConfiguration>());
   2480     pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate<CCompoundRule>());
   2481     pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate<CSelectionCriterionRule>());
   2482 
   2483     _pElementLibrarySet->addElementLibrary(pParameterConfigurationLibrary);
   2484 }
   2485 
   2486 bool CParameterMgr::getForceNoRemoteInterface() const
   2487 {
   2488     return _bForceNoRemoteInterface;
   2489 }
   2490 
   2491 void CParameterMgr::setForceNoRemoteInterface(bool bForceNoRemoteInterface)
   2492 {
   2493     _bForceNoRemoteInterface = bForceNoRemoteInterface;
   2494 }
   2495 
   2496 // Remote Processor Server connection handling
   2497 bool CParameterMgr::handleRemoteProcessingInterface(string& strError)
   2498 {
   2499     CAutoLog autoLog(this, "Handling remote processing interface");
   2500 
   2501     if (_bForceNoRemoteInterface) {
   2502         // The user requested not to start the remote interface
   2503         return true;
   2504     }
   2505 
   2506     // Start server if tuning allowed
   2507     if (getConstFrameworkConfiguration()->isTuningAllowed()) {
   2508 
   2509         log_info("Loading remote processor library");
   2510 
   2511         // Load library
   2512         _pvLibRemoteProcessorHandle = dlopen("libremote-processor.so", RTLD_NOW);
   2513 
   2514         if (!_pvLibRemoteProcessorHandle) {
   2515 
   2516             // Return error
   2517             const char* pcError = dlerror();
   2518 
   2519             if (pcError) {
   2520 
   2521                 strError = pcError;
   2522             } else {
   2523 
   2524                 strError = "Unable to load libremote-processor.so library";
   2525             }
   2526 
   2527             return false;
   2528         }
   2529 
   2530         CreateRemoteProcessorServer pfnCreateRemoteProcessorServer = (CreateRemoteProcessorServer)dlsym(_pvLibRemoteProcessorHandle, "createRemoteProcessorServer");
   2531 
   2532         if (!pfnCreateRemoteProcessorServer) {
   2533 
   2534             strError = "libremote-process.so does not contain createRemoteProcessorServer symbol.";
   2535 
   2536             return false;
   2537         }
   2538 
   2539         // Create server
   2540         _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler);
   2541 
   2542         log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort());
   2543         // Start
   2544         if (!_pRemoteProcessorServer->start(strError)) {
   2545 
   2546             ostringstream oss;
   2547             oss << "ParameterMgr: Unable to start remote processor server on port "
   2548                 << getConstFrameworkConfiguration()->getServerPort();
   2549             strError = oss.str() + ": " + strError;
   2550 
   2551             return false;
   2552         }
   2553     }
   2554 
   2555     return true;
   2556 }
   2557 
   2558 // Children typwise access
   2559 CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration()
   2560 {
   2561     return static_cast<CParameterFrameworkConfiguration*>(getChild(EFrameworkConfiguration));
   2562 }
   2563 
   2564 const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration()
   2565 {
   2566     return getFrameworkConfiguration();
   2567 }
   2568 
   2569 CSelectionCriteria* CParameterMgr::getSelectionCriteria()
   2570 {
   2571     return static_cast<CSelectionCriteria*>(getChild(ESelectionCriteria));
   2572 }
   2573 
   2574 const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria()
   2575 {
   2576     return static_cast<const CSelectionCriteria*>(getChild(ESelectionCriteria));
   2577 }
   2578 
   2579 CSystemClass* CParameterMgr::getSystemClass()
   2580 {
   2581     return static_cast<CSystemClass*>(getChild(ESystemClass));
   2582 }
   2583 
   2584 const CSystemClass* CParameterMgr::getConstSystemClass() const
   2585 {
   2586     return static_cast<const CSystemClass*>(getChild(ESystemClass));
   2587 }
   2588 
   2589 // Configurable Domains
   2590 CConfigurableDomains* CParameterMgr::getConfigurableDomains()
   2591 {
   2592     return static_cast<CConfigurableDomains*>(getChild(EConfigurableDomains));
   2593 }
   2594 
   2595 const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains()
   2596 {
   2597     return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
   2598 }
   2599 
   2600 const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const
   2601 {
   2602     return static_cast<const CConfigurableDomains*>(getChild(EConfigurableDomains));
   2603 }
   2604 
   2605 // Apply configurations
   2606 void CParameterMgr::doApplyConfigurations(bool bForce)
   2607 {
   2608     CSyncerSet syncerSet;
   2609 
   2610     // Check subsystems that need resync
   2611     getSystemClass()->checkForSubsystemsToResync(syncerSet);
   2612 
   2613     // Ensure application of currently selected configurations
   2614     getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce);
   2615 
   2616     // Reset the modified status of the current criteria to indicate that a new configuration has been applied
   2617     getSelectionCriteria()->resetModifiedStatus();
   2618 }
   2619 
   2620 // Export to XML string
   2621 bool CParameterMgr::exportElementToXMLString(const IXmlSource* pXmlSource,
   2622                                              const string& strRootElementType,
   2623                                              string& strResult) const
   2624 {
   2625     string strError;
   2626 
   2627     CXmlSerializingContext xmlSerializingContext(strError);
   2628 
   2629     // Use a doc source by loading data from instantiated Configurable Domains
   2630     CXmlMemoryDocSource memorySource(pXmlSource, false, strRootElementType);
   2631 
   2632     // Use a doc sink that write the doc data in a string
   2633     ostringstream output;
   2634     CXmlStreamDocSink streamSink(output);
   2635 
   2636     // Do the export
   2637     bool bProcessSuccess = streamSink.process(memorySource, xmlSerializingContext);
   2638 
   2639     if (bProcessSuccess) {
   2640         strResult = output.str();
   2641     } else {
   2642         strResult = strError;
   2643     }
   2644 
   2645     return bProcessSuccess;
   2646 }
   2647