1/*
2 * Copyright (c) 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// The generated python module will be named "PyPfw"
31// the "directors" feature is used to derive Python classes and make them look
32// like derived C++ classes (calls to virtual methods will be properly
33// forwarded to Python) - only on classes for which is it specified, see
34// ILogger below..
35%module(directors="1", threads="1") PyPfw
36
37%feature("director:except") {
38    if ($error != NULL) {
39        throw Swig::DirectorMethodException();
40    }
41}
42%exception {
43    try { $action }
44    catch (Swig::DirectorException &e) { SWIG_fail; }
45}
46
47%include "std_string.i"
48%include "std_vector.i"
49%include "typemaps.i"
50
51// We need to tell SWIG that std::vector<std::string> is a vector of strings
52namespace std {
53    %template(StringVector) vector<string>;
54}
55
56// Tells swig that 'std::string& strError' must be treated as output parameters
57// TODO: make it return a tuple instead of a list
58%apply std::string &OUTPUT { std::string& strError };
59
60// Automatic python docstring generation
61// FIXME: because of the typemap above, the output type is wrong for methods
62// that can return an error string.
63// TODO: document each function manually ?
64%feature("autodoc", "1");
65
66
67// rename "CParameterMgrFullConnector" into the nicer "ParameterFramework" name
68%rename(ParameterFramework) CParameterMgrFullConnector;
69class CParameterMgrFullConnector
70{
71
72%{
73#include "ParameterMgrFullConnector.h"
74%}
75
76public:
77    CParameterMgrFullConnector(const std::string& strConfigurationFilePath);
78
79    bool start(std::string& strError);
80
81    void setLogger(ILogger* pLogger);
82
83    ISelectionCriterionTypeInterface* createSelectionCriterionType(bool bIsInclusive);
84    ISelectionCriterionInterface* createSelectionCriterion(const std::string& strName,
85            const ISelectionCriterionTypeInterface* pSelectionCriterionType);
86    ISelectionCriterionInterface* getSelectionCriterion(const std::string& strName);
87
88    // Configuration application
89    void applyConfigurations();
90
91    bool getForceNoRemoteInterface() const;
92    void setForceNoRemoteInterface(bool bForceNoRemoteInterface);
93
94    bool setFailureOnMissingSubsystem(bool bFail, std::string& strError);
95    bool getFailureOnMissingSubsystem() const;
96
97    bool setFailureOnFailedSettingsLoad(bool bFail, std::string& strError);
98    bool getFailureOnFailedSettingsLoad() const;
99
100    void setSchemaUri(const std::string& schemaUri);
101    const std::string& getSchemaUri() const;
102
103    bool setValidateSchemasOnStart(bool bValidate, std::string &strError);
104    bool getValidateSchemasOnStart() const;
105
106    // Tuning mode
107    bool setTuningMode(bool bOn, std::string& strError);
108    bool isTuningModeOn() const;
109
110    // Current value space for user set/get value interpretation
111    void setValueSpace(bool bIsRaw);
112    bool isValueSpaceRaw() const;
113
114    // Current Output Raw Format for user get value interpretation
115    void setOutputRawFormat(bool bIsHex);
116    bool isOutputRawFormatHex() const;
117
118    // Automatic hardware synchronization control (during tuning session)
119    bool setAutoSync(bool bAutoSyncOn, std::string& strError);
120    bool isAutoSyncOn() const;
121    bool sync(std::string& strError);
122
123    // User set/get parameters
124%apply std::string &INOUT { std::string& strValue };
125    bool accessParameterValue(const std::string& strPath, std::string& strValue, bool bSet, std::string& strError);
126    bool accessConfigurationValue(const std::string &strDomain, const std::string &strConfiguration, const std::string& strPath, std::string& strValue, bool bSet, std::string& strError);
127%clear std::string& strValue;
128
129    bool getParameterMapping(const std::string& strPath, std::string& strValue) const;
130
131    // Creation/Deletion
132    bool createDomain(const std::string& strName, std::string& strError);
133    bool deleteDomain(const std::string& strName, std::string& strError);
134    bool renameDomain(const std::string& strName, const std::string& strNewName, std::string& strError);
135    bool deleteAllDomains(std::string& strError);
136%apply std::string &OUTPUT { std::string& strResult }
137    bool setSequenceAwareness(const std::string& strName, bool bSequenceAware, std::string& strResult);
138    bool getSequenceAwareness(const std::string& strName, bool& bSequenceAware, std::string& strResult);
139%clear std::string& strResult;
140    bool createConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError);
141    bool deleteConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError);
142    bool renameConfiguration(const std::string& strDomain, const std::string& strConfiguration, const std::string& strNewConfiguration, std::string& strError);
143
144    // Save/Restore
145    bool restoreConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::list<std::string>& strError);
146    bool saveConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError);
147
148    // Configurable element - domain association
149    bool addConfigurableElementToDomain(const std::string& strDomain, const std::string& strConfigurableElementPath, std::string& strError);
150    bool removeConfigurableElementFromDomain(const std::string& strDomain, const std::string& strConfigurableElementPath, std::string& strError);
151    bool split(const std::string& strDomain, const std::string& strConfigurableElementPath, std::string& strError);
152    bool setElementSequence(const std::string& strDomain, const std::string& strConfiguration, const std::vector<std::string>& astrNewElementSequence, std::string& strError);
153
154    bool setApplicationRule(const std::string& strDomain, const std::string& strConfiguration, const std::string& strApplicationRule, std::string& strError);
155%apply std::string &OUTPUT { std::string& strResult }
156    bool getApplicationRule(const std::string& strDomain, const std::string& strConfiguration, std::string& strResult);
157%clear std::string& strResult;
158    bool clearApplicationRule(const std::string& strDomain, const std::string& strConfiguration, std::string& strError);
159
160    bool importDomainsXml(const std::string& strXmlSource, bool bWithSettings, bool bFromFile,
161                          std::string& strError);
162    bool importSingleDomainXml(const std::string& strXmlSource, bool bOverwrite,
163                               std::string& strError);
164    bool importSingleDomainXml(const std::string& xmlSource, bool overwrite, bool withSettings,
165                               bool fromFile, std::string& strError);
166
167// Tells swig that "strXmlDest" in the two following methods are "inout"
168// parameters
169%apply std::string &INOUT { std::string& strXmlDest };
170    bool exportDomainsXml(std::string& strXmlDest, bool bWithSettings, bool bToFile,
171                          std::string& strError) const;
172
173    bool exportSingleDomainXml(std::string& strXmlDest, const std::string& strDomainName, bool bWithSettings,
174                               bool bToFile, std::string& strError) const;
175%clear std::string& strXmlDest;
176};
177
178// SWIG nested class support is not complete - cf.
179// http://swig.org/Doc2.0/SWIGPlus.html#SWIGPlus_nested_classes
180// This link also explains how to trick SWIG and pretend that
181// ILogger is a toplevel class (whereas it actually is an inner class of
182// CParameterMgrFullConnector
183// Logger interface
184%feature("director") ILogger;
185// The nested workaround is used to tell swig to ignore the
186// inner class definition that would be redundant with the fake outer class.
187// It would have been useful if ParameterMgrFullConnector.h was included
188// (as opposed to copying the class definition in this .i).
189// As their is no conflicting ILogger definition, this workaround is useless.
190class ILogger
191{
192    public:
193        virtual void info(const std::string& log) = 0;
194        virtual void warning(const std::string& log) = 0;
195    protected:
196        virtual ~ILogger() {}
197};
198%{
199typedef CParameterMgrFullConnector::ILogger ILogger;
200%}
201
202class ISelectionCriterionTypeInterface
203{
204%{
205#include "SelectionCriterionTypeInterface.h"
206%}
207
208public:
209    virtual bool addValuePair(int iValue, const std::string& strValue, std::string& strError) = 0;
210    virtual bool getNumericalValue(const std::string& strValue, int& iValue) const = 0;
211    virtual bool getLiteralValue(int iValue, std::string& strValue) const = 0;
212    virtual bool isTypeInclusive() const = 0;
213    virtual std::string getFormattedState(int iValue) const = 0;
214
215protected:
216    virtual ~ISelectionCriterionTypeInterface() {}
217};
218
219class ISelectionCriterionInterface
220{
221%{
222#include "SelectionCriterionInterface.h"
223%}
224
225public:
226    virtual void setCriterionState(int iState) = 0;
227    virtual int getCriterionState() const = 0;
228    virtual std::string getCriterionName() const = 0;
229    virtual const ISelectionCriterionTypeInterface* getCriterionType() const = 0;
230
231protected:
232    virtual ~ISelectionCriterionInterface() {}
233};
234