summaryrefslogtreecommitdiffstats
path: root/parameter/SystemClass.cpp
diff options
context:
space:
mode:
authorPatrick Benavoli <patrickx.benavoli@intel.com>2011-10-27 14:34:38 +0200
committerDavid Wagner <david.wagner@intel.com>2014-02-10 17:14:58 +0100
commitec0f84e3f601ac4ffb029b903c06007956c4b02a (patch)
tree90f209076cf433b594fffb7a1a39734d074a5342 /parameter/SystemClass.cpp
parent9fc3c0d2118102588ba82b1cad85b1d7c27967aa (diff)
downloadexternal_parameter-framework-ec0f84e3f601ac4ffb029b903c06007956c4b02a.zip
external_parameter-framework-ec0f84e3f601ac4ffb029b903c06007956c4b02a.tar.gz
external_parameter-framework-ec0f84e3f601ac4ffb029b903c06007956c4b02a.tar.bz2
PFW: Plugin inheritance
BZ: 13276 Modified the subsystem plugin symbol lookup sttrategy so as to allow the plugins to be extensible in the form of richer plugins. Now the plugin symbol is of the form: get<TYPE>SusbystemBuilder where TYPE comes from the name of the plugin file itself: lib<type>-subsystem.so Change-Id: Ie698c5200227c51a0fecf06f7e91a55cd7ee1fde Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com> Reviewed-on: http://android.intel.com:8080/22636 Reviewed-by: Centelles, Sylvain <sylvain.centelles@intel.com> Tested-by: Barthes, FabienX <fabienx.barthes@intel.com> Reviewed-by: buildbot <buildbot@intel.com> Tested-by: buildbot <buildbot@intel.com> Reviewed-on: http://android.intel.com:8080/26783 Reviewed-by: Barthes, FabienX <fabienx.barthes@intel.com>
Diffstat (limited to 'parameter/SystemClass.cpp')
-rw-r--r--parameter/SystemClass.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp
index 2314c4f..d2adaac 100644
--- a/parameter/SystemClass.cpp
+++ b/parameter/SystemClass.cpp
@@ -30,12 +30,27 @@
*/
#include <dlfcn.h>
#include <dirent.h>
+#include <algorithm>
+#include <ctype.h>
#include "SystemClass.h"
#include "SubsystemLibrary.h"
#include "AutoLog.h"
#define base CConfigurableElement
+// A plugin file name is of the form:
+// lib<type>-subsystem.so
+// The plugin symbol is of the form:
+// get<TYPE>SusbystemBuilder
+
+// Plugin file naming
+const char* gpcPluginPattern = "-subsystem.so";
+const char* gpcLibraryPrefix = "lib";
+
+// Plugin symbol naming
+const char* gpcPluginSymbolPrefix = "get";
+const char* gpcPluginSymbolSuffix = "SusbystemBuilder";
+
// Used by subsystem plugins
typedef void (*GetSusbystemBuilder)(CSubsystemLibrary*);
@@ -115,11 +130,26 @@ bool CSystemClass::loadSubsystems(string& strError, const vector<string>& astrPl
return false;
}
- GetSusbystemBuilder pfnGetSusbystemBuilder = (GetSusbystemBuilder)dlsym(lib_handle, "getSusbystemBuilder");
+ // Extract plugin type out of file name
+ string strPluginPattern = gpcPluginPattern;
+ string strLibraryPrefix = gpcLibraryPrefix;
+ // Remove folder
+ int32_t iSlashPos = strPluginFileName.rfind('/') + 1 + strLibraryPrefix.length();
+ // Get type
+ string strPluginType = strPluginFileName.substr(iSlashPos, strPluginFileName.length() - iSlashPos - strPluginPattern.length());
+
+ // Make it upper case
+ std::transform(strPluginType.begin(), strPluginType.end(), strPluginType.begin(), ::toupper);
+
+ // Get plugin symbol
+ string strPluginSymbol = gpcPluginSymbolPrefix + strPluginType + gpcPluginSymbolSuffix;
+
+ // Load symbol from library
+ GetSusbystemBuilder pfnGetSusbystemBuilder = (GetSusbystemBuilder)dlsym(lib_handle, strPluginSymbol.c_str());
if (!pfnGetSusbystemBuilder) {
- strError = "Subsystem plugin " + strPluginFileName + " does not contain getSusbystemBuilder symbol.";
+ strError = "Subsystem plugin " + strPluginFileName + " does not contain " + strPluginSymbol + " symbol.";
_pSubsystemLibrary->clean();
@@ -145,14 +175,14 @@ bool CSystemClass::getPluginFiles(const string& strPluginPath, vector<string>& a
return false;
}
- const string strPluginPattern("-subsystem.so");
+ const string strPluginPattern(gpcPluginPattern);
// Parse it and load plugins
while ((dp = readdir(dirp)) != NULL) {
string strFileName(dp->d_name);
- // Check file name ends with "-susbsystem.so"
+ // Check file name ends with pattern
size_t uiPatternPos = strFileName.rfind(strPluginPattern, -1);
if (uiPatternPos != (size_t)-1 && uiPatternPos == strFileName.size() - strPluginPattern.size()) {