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 } catch(Swig::DirectorException & e)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 52 namespace 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; 69 class CParameterMgrFullConnector 70 { 71 72 %{ 73 #include "ParameterMgrFullConnector.h" 74 %} 75 76 public: 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 void setFailureOnMissingSubsystem(bool bFail); 95 bool getFailureOnMissingSubsystem() const; 96 97 void setFailureOnFailedSettingsLoad(bool bFail); 98 bool getFailureOnFailedSettingsLoad(); 99 100 void setSchemaFolderLocation(const std::string& strSchemaFolderLocation); 101 void setValidateSchemasOnStart(bool bValidate); 102 bool getValidateSchemasOnStart() const; 103 104 // Tuning mode 105 bool setTuningMode(bool bOn, std::string& strError); 106 bool isTuningModeOn() const; 107 108 // Current value space for user set/get value interpretation 109 void setValueSpace(bool bIsRaw); 110 bool isValueSpaceRaw() const; 111 112 // Current Output Raw Format for user get value interpretation 113 void setOutputRawFormat(bool bIsHex); 114 bool isOutputRawFormatHex() const; 115 116 // Automatic hardware synchronization control (during tuning session) 117 bool setAutoSync(bool bAutoSyncOn, std::string& strError); 118 bool isAutoSyncOn() const; 119 bool sync(std::string& strError); 120 121 // User set/get parameters 122 %apply std::string &INOUT { std::string& strValue }; 123 bool accessParameterValue(const std::string& strPath, std::string& strValue, bool bSet, std::string& strError); 124 bool accessConfigurationValue(const std::string &strDomain, const std::string &strConfiguration, const std::string& strPath, std::string& strValue, bool bSet, std::string& strError); 125 %clear std::string& strValue; 126 127 bool getParameterMapping(const std::string& strPath, std::string& strValue) const; 128 129 // Creation/Deletion 130 bool createDomain(const std::string& strName, std::string& strError); 131 bool deleteDomain(const std::string& strName, std::string& strError); 132 bool renameDomain(const std::string& strName, const std::string& strNewName, std::string& strError); 133 bool deleteAllDomains(std::string& strError); 134 %apply std::string &OUTPUT { std::string& strResult } 135 bool setSequenceAwareness(const std::string& strName, bool bSequenceAware, std::string& strResult); 136 bool getSequenceAwareness(const std::string& strName, bool& bSequenceAware, std::string& strResult); 137 %clear std::string& strResult; 138 bool createConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); 139 bool deleteConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); 140 bool renameConfiguration(const std::string& strDomain, const std::string& strConfiguration, const std::string& strNewConfiguration, std::string& strError); 141 142 // Save/Restore 143 bool restoreConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::list<std::string>& strError); 144 bool saveConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); 145 146 // Configurable element - domain association 147 bool addConfigurableElementToDomain(const std::string& strDomain, const std::string& strConfigurableElementPath, std::string& strError); 148 bool removeConfigurableElementFromDomain(const std::string& strDomain, const std::string& strConfigurableElementPath, std::string& strError); 149 bool split(const std::string& strDomain, const std::string& strConfigurableElementPath, std::string& strError); 150 bool setElementSequence(const std::string& strDomain, const std::string& strConfiguration, const std::vector<std::string>& astrNewElementSequence, std::string& strError); 151 152 bool setApplicationRule(const std::string& strDomain, const std::string& strConfiguration, const std::string& strApplicationRule, std::string& strError); 153 %apply std::string &OUTPUT { std::string& strResult } 154 bool getApplicationRule(const std::string& strDomain, const std::string& strConfiguration, std::string& strResult); 155 %clear std::string& strResult; 156 bool clearApplicationRule(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); 157 158 bool importDomainsXml(const std::string& strXmlSource, bool bWithSettings, bool bFromFile, 159 std::string& strError); 160 bool importSingleDomainXml(const std::string& strXmlSource, bool bOverwrite, 161 std::string& strError); 162 bool importSingleDomainXml(const std::string& xmlSource, bool overwrite, bool withSettings, 163 bool fromFile, std::string& strError); 164 165 // Tells swig that "strXmlDest" in the two following methods are "inout" 166 // parameters 167 %apply std::string &INOUT { std::string& strXmlDest }; 168 bool exportDomainsXml(std::string& strXmlDest, bool bWithSettings, bool bToFile, 169 std::string& strError) const; 170 171 bool exportSingleDomainXml(std::string& strXmlDest, const std::string& strDomainName, bool bWithSettings, 172 bool bToFile, std::string& strError) const; 173 %clear std::string& strXmlDest; 174 }; 175 176 // SWIG nested class support is not complete - cf. 177 // http://swig.org/Doc2.0/SWIGPlus.html#SWIGPlus_nested_classes 178 // This link also explains how to trick SWIG and pretend that 179 // ILogger is a toplevel class (whereas it actually is an inner class of 180 // CParameterMgrFullConnector 181 // Logger interface 182 %feature("director") ILogger; 183 %nestedworkaround CParameterMgrFullConnector::ILogger; 184 class ILogger 185 { 186 public: 187 virtual void log(bool bIsWarning, const std::string& strLog) = 0; 188 protected: ~ILogger()189 virtual ~ILogger() {} 190 }; 191 %{ 192 typedef CParameterMgrFullConnector::ILogger ILogger; 193 %} 194 195 class ISelectionCriterionTypeInterface 196 { 197 %{ 198 #include "SelectionCriterionTypeInterface.h" 199 %} 200 201 public: 202 virtual bool addValuePair(int iValue, const std::string& strValue) = 0; 203 virtual bool getNumericalValue(const std::string& strValue, int& iValue) const = 0; 204 virtual bool getLiteralValue(int iValue, std::string& strValue) const = 0; 205 virtual bool isTypeInclusive() const = 0; 206 virtual std::string getFormattedState(int iValue) const = 0; 207 208 protected: ~ISelectionCriterionTypeInterface()209 virtual ~ISelectionCriterionTypeInterface() {} 210 }; 211 212 class ISelectionCriterionInterface 213 { 214 %{ 215 #include "SelectionCriterionInterface.h" 216 %} 217 218 public: 219 virtual void setCriterionState(int iState) = 0; 220 virtual int getCriterionState() const = 0; 221 virtual std::string getCriterionName() const = 0; 222 virtual const ISelectionCriterionTypeInterface* getCriterionType() const = 0; 223 224 protected: ~ISelectionCriterionInterface()225 virtual ~ISelectionCriterionInterface() {} 226 }; 227