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 #pragma once
     31 
     32 #include "Element.h"
     33 #include "Results.h"
     34 #include <set>
     35 #include <string>
     36 
     37 class CParameterBlackboard;
     38 class CConfigurableElement;
     39 class CSyncerSet;
     40 class CConfigurableDomain;
     41 class CSelectionCriteriaDefinition;
     42 
     43 class CConfigurableDomains : public CElement
     44 {
     45 public:
     46     // Configuration/Domains handling
     47     /// Domains
     48     bool createDomain(const std::string &strName, std::string &strError);
     49 
     50     /*
     51      * Adds a domain object to configurable domains. The ConfigurableDomains
     52      * object takes ownership of the ConfigurableDomain object.
     53      *
     54      * @param[in] pDomain the domain object.
     55      * @param[in] bOverwrite if false, will refuse to overwrite an existing
     56      * domain, otherwise, an existing domain with the same name will first be
     57      * removed.
     58      * @param[in,out] strError error message
     59      *
     60      * @returns true if the domain was successfully added
     61      */
     62     bool addDomain(CConfigurableDomain &domain, bool bOverwrite, std::string &strError);
     63 
     64     /**
     65      * Delete a domain by name
     66      *
     67      * @param[in] strName name of the domain to be deleted
     68      * @param[in,out] strError error message
     69      *
     70      * @returns true of the domain was sucessfully deleted, false otherwise (i.e.
     71      * the domain didn't exist).
     72      */
     73     bool deleteDomain(const std::string &strName, std::string &strError);
     74     void deleteAllDomains();
     75     bool renameDomain(const std::string &strName, const std::string &strNewName,
     76                       std::string &strError);
     77     bool setSequenceAwareness(const std::string &strDomain, bool bSequenceAware,
     78                               std::string &strError);
     79     bool getSequenceAwareness(const std::string &strDomain, bool &bSequenceAware,
     80                               std::string &strError) const;
     81     bool listDomainElements(const std::string &strDomain, std::string &strResult) const;
     82 
     83     /** Split a domain in two.
     84      * Remove an element of a domain and create a new domain which owns the element.
     85      *
     86      * @param[in] domainName the domain name
     87      * @param[in] element pointer to the element to remove
     88      * @param[out] infos useful information we can provide to client
     89      * @return true if succeed false otherwise
     90      */
     91     bool split(const std::string &domainName, CConfigurableElement *element, core::Results &infos);
     92 
     93     void listAssociatedElements(std::string &strResult) const;
     94     void listConflictingElements(std::string &strResult) const;
     95     void listDomains(std::string &strResult) const;
     96     /// Configurations
     97     bool listConfigurations(const std::string &strDomain, std::string &strResult) const;
     98     bool createConfiguration(const std::string &strDomain, const std::string &strConfiguration,
     99                              const CParameterBlackboard *pMainBlackboard, std::string &strError);
    100     bool deleteConfiguration(const std::string &strDomain, const std::string &strConfiguration,
    101                              std::string &strError);
    102     bool renameConfiguration(const std::string &strDomain, const std::string &strConfigurationName,
    103                              const std::string &strNewConfigurationName, std::string &strError);
    104 
    105     /** Restore a configuration
    106      *
    107      * @param[in] strDomain the domain name
    108      * @param[in] strConfiguration the configuration name
    109      * @param[in] pMainBlackboard the application main blackboard
    110      * @param[in] bAutoSync boolean which indicates if auto sync mechanism is on
    111      * @param[out] errors, errors encountered during restoration
    112      * @return true if success false otherwise
    113      */
    114     bool restoreConfiguration(const std::string &strDomain, const std::string &strConfiguration,
    115                               CParameterBlackboard *pMainBlackboard, bool bAutoSync,
    116                               core::Results &errors) const;
    117 
    118     bool saveConfiguration(const std::string &strDomain, const std::string &strConfiguration,
    119                            const CParameterBlackboard *pMainBlackboard, std::string &strError);
    120     bool setElementSequence(const std::string &strDomain, const std::string &strConfiguration,
    121                             const std::vector<std::string> &astrNewElementSequence,
    122                             std::string &strError);
    123     bool getElementSequence(const std::string &strDomain, const std::string &strConfiguration,
    124                             std::string &strResult) const;
    125     bool setApplicationRule(const std::string &strDomain, const std::string &strConfiguration,
    126                             const std::string &strApplicationRule,
    127                             const CSelectionCriteriaDefinition *pSelectionCriteriaDefinition,
    128                             std::string &strError);
    129     bool clearApplicationRule(const std::string &strDomain, const std::string &strConfiguration,
    130                               std::string &strError);
    131     bool getApplicationRule(const std::string &strDomain, const std::string &strConfiguration,
    132                             std::string &strResult) const;
    133 
    134     // Last applied configurations
    135     void listLastAppliedConfigurations(std::string &strResult) const;
    136 
    137     /** Associate a configurable element to a domain
    138      *
    139      * @param[in] domainName the domain name
    140      * @param[in] element pointer to the element to add
    141      * @param[in] mainBlackboard pointer to the application main blackboard
    142      * @param[out] infos useful information we can provide to client
    143      * @return true if succeed false otherwise
    144      */
    145     bool addConfigurableElementToDomain(const std::string &domainName,
    146                                         CConfigurableElement *element,
    147                                         const CParameterBlackboard *mainBlackboard,
    148                                         core::Results &infos);
    149 
    150     bool removeConfigurableElementFromDomain(const std::string &strDomain,
    151                                              CConfigurableElement *pConfigurableElement,
    152                                              std::string &strError);
    153 
    154     // Configuration Blackboard for element
    155     CParameterBlackboard *findConfigurationBlackboard(
    156         const std::string &strDomain, const std::string &strConfiguration,
    157         const CConfigurableElement *pConfigurableElement, size_t &baseOffset, bool &bIsLastApplied,
    158         std::string &strError) const;
    159 
    160     const CConfigurableDomain *findConfigurableDomain(const std::string &strDomain,
    161                                                       std::string &strError) const;
    162 
    163     // From IXmlSource
    164     virtual void toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const;
    165 
    166     // Ensure validity on whole domains from main blackboard
    167     void validate(const CParameterBlackboard *pMainBlackboard);
    168 
    169     /** Apply the configuration if required
    170      *
    171      * @param[in] pParameterBlackboard the blackboard to synchronize
    172      * @param[in] syncerSet the set containing application syncers
    173      * @param[in] bForce boolean used to force configuration application
    174      * @param[out] infos useful information we can provide to client
    175      */
    176     void apply(CParameterBlackboard *pParameterBlackboard, CSyncerSet &syncerSet, bool bForce,
    177                core::Results &infos) const;
    178 
    179     // Class kind
    180     virtual std::string getKind() const;
    181 
    182 private:
    183     /** Delete a domain
    184      *
    185      * @param(in] configurableDomain domain to be deleted
    186      * @param[in,out] strError error message
    187      * @returns true of the domain was sucessfully deleted, false otherwise (i.e.
    188      * the domain didn't exist).
    189      */
    190     void deleteDomain(CConfigurableDomain &configurableDomain);
    191     // Returns true if children dynamic creation is to be dealt with
    192     virtual bool childrenAreDynamic() const;
    193     // Gather owned configurable elements owned by any domain
    194     void gatherAllOwnedConfigurableElements(
    195         std::set<const CConfigurableElement *> &configurableElementSet) const;
    196     // Domain retrieval
    197     CConfigurableDomain *findConfigurableDomain(const std::string &strDomain,
    198                                                 std::string &strError);
    199 };
    200