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 "parameter_export.h"
33 
34 #include "SelectionCriterionTypeInterface.h"
35 #include "SelectionCriterionInterface.h"
36 #include "ParameterHandle.h"
37 #include "ElementHandle.h"
38 #include "ParameterMgrLoggerForward.h"
39 
40 class CParameterMgr;
41 
42 class PARAMETER_EXPORT CParameterMgrPlatformConnector
43 {
44     friend class CParameterMgrLogger<CParameterMgrPlatformConnector>;
45 
46 public:
47     /** Interface to implement to provide a custom logger to the PF.
48      *
49      * Override info and warning methods to specify how each log level
50      * should be printed.
51      *
52      * @note Errors are always returned synchronously. Never logged.
53      */
54     class ILogger
55     {
56     public:
57         virtual void info(const std::string &strLog) = 0;
58         virtual void warning(const std::string &strLog) = 0;
59 
60     protected:
~ILogger()61         virtual ~ILogger() {}
62     };
63 
64     // Construction
65     CParameterMgrPlatformConnector(const std::string &strConfigurationFilePath);
66     virtual ~CParameterMgrPlatformConnector();
67 
68     // Selection Criteria interface. Beware returned objects are lent, clients shall not delete
69     // them!
70     // Should be called before start
71     ISelectionCriterionTypeInterface *createSelectionCriterionType(bool bIsInclusive = false);
72     ISelectionCriterionInterface *createSelectionCriterion(
73         const std::string &strName,
74         const ISelectionCriterionTypeInterface *pSelectionCriterionType);
75     // Selection criterion retrieval
76     ISelectionCriterionInterface *getSelectionCriterion(const std::string &strName) const;
77 
78     // Logging
79     // Should be called before start
80     void setLogger(ILogger *pLogger);
81 
82     // Start
83     bool start(std::string &strError);
84 
85     // Started state
86     bool isStarted() const;
87 
88     // Configuration application
89     void applyConfigurations();
90 
91     // Dynamic parameter handling
92     // Returned objects are owned by clients
93     // Must be cassed after successfull start
94     CParameterHandle *createParameterHandle(const std::string &strPath,
95                                             std::string &strError) const;
96 
97     /** Creates a handle to a configurable element.
98      *
99      * The returned object is owned by the client who is responsible to delete it.
100      *
101      * @param[in] path A string representing a path to a configurable element.
102      * @param[out] error On error: an human readable error message
103      *                   On success: undefined
104      *
105      * @return An element handle on success
106      *         NULL on error
107      */
108     ElementHandle *createElementHandle(const std::string &path, std::string &error) const;
109 
110     /** Is the remote interface forcefully disabled ?
111      */
112     bool getForceNoRemoteInterface() const;
113 
114     /**
115      * Forcefully disable the remote interface or cancel this policy.
116      *
117      * Has no effect if called after calling start().
118      *
119      * @param[in] bForceNoRemoteInterface disable the remote interface if true.
120      */
121     void setForceNoRemoteInterface(bool bForceNoRemoteInterface);
122 
123     /** Should start fail in case of missing subsystems.
124       *
125       * Will fail if called on started instance.
126       *
127       * @param[in] bFail: If set to true,  parameterMgr start will fail on missing subsystems
128       *                   If set to false, missing subsystems will fallbacks on virtual subsystem
129       * @param[out] strError a string describing the error if the function failed,
130                              unmodified otherwise.
131       *
132       * @return false if unable to set, true otherwise.
133       */
134     bool setFailureOnMissingSubsystem(bool bFail, std::string &strError);
135 
136     /** Would start fail in case of missing subsystems.
137       *
138       * @return if the subsystem load will fail on missing subsystem.
139       */
140     bool getFailureOnMissingSubsystem() const;
141 
142     /** Should start fail in failed settings load.
143       *
144       * Will fail if called on started instance.
145       *
146       * @param[in] bFail If set to true, parameterMgr start will fail on failed settings load.
147       *                  If set to false, failed settings load will be ignored.
148       * @param[out] strError On error: an human readable error message
149       *                      On success: undefined
150       *
151       * @return false if unable to set, true otherwise.
152       */
153     bool setFailureOnFailedSettingsLoad(bool bFail, std::string &strError);
154     /** Would start fail in case of failed settings load.
155       *
156       * @return failure on failed settings load policy state.
157       */
158     bool getFailureOnFailedSettingsLoad() const;
159 
160     /** Get the XML Schemas URI
161      *
162      * @returns the XML Schemas URI
163      */
164     const std::string &getSchemaUri() const;
165 
166     /** Override the XML Schemas URI
167      *
168      * @param[in] schemaUri the XML Schemas URI
169      */
170     void setSchemaUri(const std::string &schemaUri);
171 
172     /** Should .xml files be validated on start ?
173      *
174      * @param[in] bValidate:
175      *     If set to true, parameterMgr will abort when being unable to validate .xml files
176      *     If set to false, no .xml/xsd validation will happen (default behaviour)
177      * @param[out] strError On error: an human readable error message
178      *                      On success: undefined
179      *
180      * @return false if unable to set, true otherwise.
181      */
182     bool setValidateSchemasOnStart(bool bValidate, std::string &strError);
183 
184     /** Would .xml files be validated on start?
185      *
186      * @return areSchemasValidated
187      */
188     bool getValidateSchemasOnStart() const;
189 
190 private:
191     CParameterMgrPlatformConnector(const CParameterMgrPlatformConnector &);
192     CParameterMgrPlatformConnector &operator=(const CParameterMgrPlatformConnector &);
193     // Private logging
194     void info(const std::string &log);
195     void warning(const std::string &log);
196 
197 protected:
198     // Private logging
199     CParameterMgrLogger<CParameterMgrPlatformConnector> *_pParameterMgrLogger;
200     // Implementation
201     CParameterMgr *_pParameterMgr;
202     // State
203     bool _bStarted;
204     // Logging
205     ILogger *_pLogger;
206 };
207