Update extension lazy loading logic
authorSeungkeun Lee <sngn.lee@samsung.com>
Mon, 31 Aug 2015 00:33:58 +0000 (09:33 +0900)
committerSeungkeun Lee <sngn.lee@samsung.com>
Mon, 31 Aug 2015 05:22:13 +0000 (22:22 -0700)
 - Fix widget loading issue
 - *.json files can be extension metadata
 - All extension plugins should provide the metadata file(.json)
   If does not provide metadata file, It can't load in lazy load mode

Change-Id: I2efd4bb4ede7d3f6cfbbc7cd2e603b9a89ab6bd7

packaging/wrt.spec
src/extension/extension_server.cc
src/extension/extension_server.h
src/extension/widget/CMakeLists.txt
src/extension/widget/widget.json [new file with mode: 0755]

index 5bd481b..6ab8dc8 100755 (executable)
@@ -113,6 +113,7 @@ rm -fr %{buildroot}
 %attr(644,root,root) %{_datadir}/edje/wrt/wrt.edj
 %attr(644,root,root) %{injected_bundle_path}
 %attr(644,root,root) %{extension_path}/libwidget-plugin.so
+%attr(644,root,root) %{extension_path}/widget.json
 %attr(755,root,root) %{_datadir}/locale/*
 
 %files tests
index b2c3320..c4af0ba 100755 (executable)
@@ -38,7 +38,7 @@ namespace {
 
 const char kExtensionPrefix[] = "lib";
 const char kExtensionSuffix[] = ".so";
-const char kExtensionMetadata[] = "plugins.json";
+const char kExtensionMetadataSuffix[] = ".json";
 
 const char kDBusIntrospectionXML[] =
   "<node>"
@@ -74,7 +74,8 @@ const char kDBusIntrospectionXML[] =
   "  </interface>"
   "</node>";
 
-void LoadFrequentlyUsedModules(std::map<std::string, Extension*>& modules) {
+void LoadFrequentlyUsedModules(
+    const std::map<std::string, Extension*>& modules) {
   auto it = modules.find("tizen");
   if (it != modules.end()) {
     it->second->Initialize();
@@ -190,14 +191,31 @@ void ExtensionServer::RegisterSystemExtensionsByMetadata() {
 #else
   #error EXTENSION_PATH is not set.
 #endif
-
   extension_path.append("/");
-  extension_path.append(kExtensionMetadata);
-  std::ifstream metafile(extension_path.c_str());
-  if (!metafile.is_open()) {
-    LOGGER(ERROR) << "Fail to open the plugin metadata file(plugins.json)";
-    LOGGER(ERROR) << "Fallback - load plugin without lazy loading";
+  extension_path.append("*");
+  extension_path.append(kExtensionMetadataSuffix);
+
+  glob_t glob_result;
+  glob(extension_path.c_str(), GLOB_TILDE, NULL, &glob_result);
+  for (unsigned int i = 0; i < glob_result.gl_pathc; ++i) {
+    RegisterSystemExtensionsByMetadata(glob_result.gl_pathv[i]);
+  }
+  if (glob_result.gl_pathc == 0) {
     RegisterSystemExtensions();
+  }
+}
+
+void ExtensionServer::RegisterSystemExtensionsByMetadata(
+    const std::string& metadata_path) {
+#ifdef EXTENSION_PATH
+  std::string extension_path(EXTENSION_PATH);
+#else
+  #error EXTENSION_PATH is not set.
+#endif
+
+  std::ifstream metafile(metadata_path.c_str());
+  if (!metafile.is_open()) {
+    LOGGER(ERROR) << "Fail to open the plugin metadata file :" << metadata_path;
     return;
   }
 
@@ -211,6 +229,10 @@ void ExtensionServer::RegisterSystemExtensionsByMetadata() {
 
       std::string name = plugin->get("name").to_str();
       std::string lib = plugin->get("lib").to_str();
+      if (!utils::StartsWith(lib, "/")) {
+        lib = extension_path + "/" + lib;
+      }
+
       std::vector<std::string> entries;
       auto& entry_points_value = plugin->get("entry_points");
       if (entry_points_value.is<picojson::array>()) {
@@ -224,20 +246,9 @@ void ExtensionServer::RegisterSystemExtensionsByMetadata() {
       RegisterExtension(extension);
     }
   } else {
-    SLOGE("%s is not plugin metadata", extension_path.c_str());
+    SLOGE("%s is not plugin metadata", metadata_path.c_str());
   }
   metafile.close();
-
-  // widget API
-  std::string widget_api_lib_path(EXTENSION_PATH);
-  widget_api_lib_path.append("/");
-  widget_api_lib_path.append("libwidget-plugin.so");
-  std::vector<std::string> widget_entries = {"widget"};
-  Extension* widget = new Extension(widget_api_lib_path,
-                                    "Widget",
-                                    widget_entries,
-                                    this);
-  RegisterExtension(widget);
 }
 
 
index dc0ecbf..ff14a05 100755 (executable)
@@ -47,6 +47,7 @@ class ExtensionServer : public Extension::ExtensionDelegate {
   void RegisterExtension(Extension* extension);
   void RegisterSystemExtensions();
   void RegisterSystemExtensionsByMetadata();
+  void RegisterSystemExtensionsByMetadata(const std::string& metadata_path);
   bool RegisterSymbols(Extension* extension);
 
   void GetRuntimeVariable(const char* key, char* value, size_t value_len);
index f23711d..e7712e1 100755 (executable)
@@ -67,3 +67,8 @@ INSTALL(TARGETS ${TARGET_WIDGET_PLUGIN}
     PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
     GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
 )
+
+INSTALL(FILES
+    ${BASE_SRCDIR}/extension/widget/widget.json
+    DESTINATION ${EXTENSION_PATH}
+)
diff --git a/src/extension/widget/widget.json b/src/extension/widget/widget.json
new file mode 100755 (executable)
index 0000000..eb02e2a
--- /dev/null
@@ -0,0 +1,7 @@
+[\r
+  {\r
+    "name":"Widget",\r
+    "lib":"libwidget-plugin.so",\r
+    "entry_points":["widget"]\r
+  }\r
+]\r