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>
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 @@
             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 @@
         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()) {