Split subsystems loading

BZ: 122982

The CSystemClass::loadSubsystems was too long.

Create a subfunction to load subsystems defined in shared libraries.

Change-Id: I8f40ee271f25d0996e1976d8ee2ef6c12581d1d4
Signed-off-by: Kevin Rocard <kevinx.rocard@intel.com>
Reviewed-on: http://android.intel.com:8080/118192
Reviewed-by: Centelles, Sylvain <sylvain.centelles@intel.com>
Tested-by: Barthes, FabienX <fabienx.barthes@intel.com>
Reviewed-by: cactus <cactus@intel.com>
Tested-by: cactus <cactus@intel.com>
diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp
index 8dd5f9c..5d435d7 100644
--- a/parameter/SystemClass.cpp
+++ b/parameter/SystemClass.cpp
@@ -75,10 +75,43 @@
 }
 
 bool CSystemClass::loadSubsystems(string& strError,
-        const CSubsystemPlugins* pSubsystemPlugins, bool bVirtualSubsystemFallback)
+                                  const CSubsystemPlugins* pSubsystemPlugins,
+                                  bool bVirtualSubsystemFallback)
 {
     CAutoLog autoLog_info(this, "Loading subsystem plugins");
 
+    // Start clean
+    _pSubsystemLibrary->clean();
+
+    // Add virtual subsystem builder
+    _pSubsystemLibrary->addElementBuilder("Virtual",
+                                          new TNamedElementBuilderTemplate<CVirtualSubsystem>());
+    // Set virtual subsytem as builder fallback if required
+    _pSubsystemLibrary->enableDefaultMechanism(bVirtualSubsystemFallback);
+
+    // Add subsystem defined in shared libraries
+    list<string> lstrError;
+    bool bLoadPluginsSuccess = loadSubsystemsFromSharedLibraries(lstrError, pSubsystemPlugins);
+
+    if (bLoadPluginsSuccess) {
+        log_info("All subsystem plugins successfully loaded");
+    } else {
+        // Log plugin as warning if no fallback available
+        log_table(!bVirtualSubsystemFallback, lstrError);
+    }
+
+    if (!bVirtualSubsystemFallback) {
+        // Any problem reported is an error as there is no fallback.
+        // Fill strError for caller.
+        CUtility::asString(lstrError, strError);
+    }
+
+    return bLoadPluginsSuccess || bVirtualSubsystemFallback;
+}
+
+bool CSystemClass::loadSubsystemsFromSharedLibraries(list<string>& lstrError,
+                                                     const CSubsystemPlugins* pSubsystemPlugins)
+{
     // Plugin list
     list<string> lstrPluginFiles;
 
@@ -103,13 +136,8 @@
         }
     }
 
-    // Start clean
-    _pSubsystemLibrary->clean();
-    list<string> lstrError;
-
-    bool bLoadPluginsSuccess = true;
     // Actually load plugins
-    while (lstrPluginFiles.size()) {
+    while (!lstrPluginFiles.empty()) {
 
         // Because plugins might depend on one another, loading will be done
         // as an iteration process that finishes successfully when the remaining
@@ -124,26 +152,16 @@
         }
     }
 
-    if (lstrPluginFiles.empty()) {
-        log_info("All subsystem plugins successfully loaded");
-    } else {
-        // Log plugin as warning if fallback available, error otherwise
-        log_table(bVirtualSubsystemFallback, lstrError);
-    }
-    if (!bVirtualSubsystemFallback) {
-        // Any problem reported is an error as there is no fallback.
-        // Fill strError for caller.
-        CUtility::asString(lstrError, strError);
+    if (!lstrPluginFiles.empty()) {
+        // Unable to load at least one plugin
+        string strPluginUnloaded;
+        CUtility::asString(lstrPluginFiles, strPluginUnloaded, ", ");
+
+        lstrError.push_back("Unable to load the folowings plugings: " + strPluginUnloaded + ".");
+        return false;
     }
 
-    // Add virtual subsystem builder
-    _pSubsystemLibrary->addElementBuilder("Virtual",
-                                          new TNamedElementBuilderTemplate<CVirtualSubsystem>());
-
-    // Set virtual subsytem as builder fallback
-    _pSubsystemLibrary->enableDefaultMechanism(bVirtualSubsystemFallback);
-
-    return bLoadPluginsSuccess || bVirtualSubsystemFallback;
+    return true;
 }
 
 // Plugin symbol computation