Merge ExtensionServer to Runtime
authorWonYoung Choi <wy80.choi@samsung.com>
Wed, 6 May 2015 12:20:23 +0000 (21:20 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Thu, 7 May 2015 10:03:35 +0000 (19:03 +0900)
Change-Id: I759d9d3a27d23d5ab979a3069a50088b99849b20

19 files changed:
CMakeLists.txt
packaging/wrt.spec
src/bundle/CMakeLists.txt
src/bundle/extension_client_test.cc [deleted file]
src/common/CMakeLists.txt
src/common/command_line.cc
src/common/command_line.h
src/common/constants.cc
src/common/constants.h
src/common/dbus_server.cc
src/common/dbus_server.h
src/extension/CMakeLists.txt
src/extension/extension_main.cc [deleted file]
src/extension/extension_server.cc
src/extension/extension_server.h
src/runtime/CMakeLists.txt
src/runtime/main.cc [new file with mode: 0644]
src/runtime/runtime.cc
src/runtime/web_application.cc

index f98c49e..2429ad6 100644 (file)
@@ -41,7 +41,7 @@ ENDIF(WAYLAND_SUPPORT)
 # Targets names
 SET(TARGET_RUNTIME  "wrt")
 SET(TARGET_COMMON_STATIC "wrt-common-static")
-SET(TARGET_EXTENSION "wrt-extension")
+SET(TARGET_EXTENSION_STATIC "wrt-extension-static")
 SET(TARGET_INJECTED_BUNDLE "wrt-injected-bundle")
 
 # Sub Directories
index d3ba278..b248aeb 100755 (executable)
@@ -37,7 +37,7 @@ BuildRequires: pkgconfig(ecore-wayland)
 %endif
 
 #web-engine
-BuildRequires:  pkgconfig(chromium-efl)
+BuildRequires: pkgconfig(chromium-efl)
 
 %description
 Runtime for Web Application
@@ -84,7 +84,5 @@ rm -fr %{buildroot}
 
 %files
 %attr(755,root,root) %{_bindir}/wrt
-%attr(755,root,root) %{_bindir}/wrt-extension
-%attr(755,root,root) %{_bindir}/wrt-extension-client-test
 %attr(644,root,root) %{_datadir}/edje/wrt/wrt.edj
 %attr(644,root,root) %{_libdir}/libwrt-injected-bundle.so
index 38f7e48..4c636a8 100644 (file)
@@ -54,20 +54,3 @@ INSTALL(TARGETS ${TARGET_INJECTED_BUNDLE}
     PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
     GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
 )
-
-
-# Build Executable for Test
-SET(TARGET_EXTENSION_TEST "wrt-extension-client-test")
-INCLUDE_DIRECTORIES(
-  ${BASE_SRCDIR}
-  ${TARGET_INJECTED_BUNDLE_INCS})
-ADD_EXECUTABLE(${TARGET_EXTENSION_TEST}
-  ${BASE_SRCDIR}/bundle/extension_client.cc
-  ${BASE_SRCDIR}/bundle/extension_client_test.cc)
-TARGET_LINK_LIBRARIES(${TARGET_EXTENSION_TEST}
-  ${TARGET_COMMON_STATIC}
-  ${TARGET_INJECTED_BUNDLE_LIBS}
-  "-ldl"
-)
-
-INSTALL(TARGETS ${TARGET_EXTENSION_TEST} DESTINATION bin)
\ No newline at end of file
diff --git a/src/bundle/extension_client_test.cc b/src/bundle/extension_client_test.cc
deleted file mode 100644 (file)
index fae82a0..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stdio.h>
-#include <iostream>
-
-#include "bundle/extension_client.h"
-
-using namespace std;
-using namespace wrt;
-
-int main(int argc, char* argv[]) {
-
-  if (argc < 2) {
-    fprintf(stderr, "uuid is requried.\n");
-  }
-
-  ExtensionClient extension_client;
-
-  extension_client.Initialize(argv[1]);
-
-  string instance_id = extension_client.CreateInstance("tizen", NULL);
-  extension_client.DestroyInstance(instance_id);
-  cout << instance_id << endl;
-
-  return 0;
-}
index a68a433..64b7697 100755 (executable)
@@ -40,4 +40,4 @@ ADD_LIBRARY(${TARGET_COMMON_STATIC} STATIC
 )
 TARGET_LINK_LIBRARIES(${TARGET_COMMON_STATIC}
   ${TARGET_COMMON_STATIC_DEPS_LIBRARIES}
-)
\ No newline at end of file
+)
index 1ef54c8..00bf9ab 100644 (file)
@@ -40,15 +40,16 @@ CommandLine::CommandLine(int argc, char* argv[])
   }
 
   // Parse program name and appid from argv_ or arguments_
+  program_ = std::string(argv[0]);
   if (argc > 0) {
-    program_ = utils::BaseName(argv[0]);
-    if (program_ == kRuntimeName) {
+    std::string tmp = utils::BaseName(argv[0]);
+    if (tmp == kRuntimeName) {
       if (arguments_.size() > 0) {
         // Suppose that appid is at the first of arguments_
         appid_ = arguments_[0];
       }
     } else {
-      appid_ = program_;
+      appid_ = tmp;
     }
   }
 }
@@ -56,8 +57,8 @@ CommandLine::CommandLine(int argc, char* argv[])
 CommandLine::~CommandLine() {
 }
 
-void CommandLine::AppendOption(const char* argument) {
-  std::string option_string(argument);
+void CommandLine::AppendOption(const char* value) {
+  std::string option_string(value);
   std::string option_name;
   std::string option_value;
 
@@ -87,6 +88,26 @@ std::string CommandLine::GetOptionValue(const std::string& option_name) {
   }
 }
 
+std::string CommandLine::GetCommandString() {
+  std::string result;
+  result.append(program_);
+  result.append(" ");
+  for (auto& it : options_) {
+    result.append(kOptionPrefix);
+    result.append(it.first);
+    if (!it.second.empty()) {
+      result.append(kOptionValueSeparator);
+      result.append(it.second);
+    }
+    result.append(" ");
+  }
+  for (auto& it : arguments_) {
+    result.append(it);
+    result.append(" ");
+  }
+  return result;
+}
+
 // static
 void CommandLine::Reset() {
   if (!!current_process_commandline_) {
index 9e7b0dd..623d447 100644 (file)
@@ -26,9 +26,11 @@ class CommandLine {
   bool HasOptionName(const std::string& option_name);
   // Get the option's value
   std::string GetOptionValue(const std::string& option_name);
+  // Get command string include options and arguments
+  std::string GetCommandString();
 
-  const std::string appid() const { return appid_; }
-  const std::string program() const { return program_; }
+  std::string appid() const { return appid_; }
+  std::string program() const { return program_; }
   const OptionMap& options() const { return options_; }
   const Arguments& arguments() const { return arguments_; }
   char** argv() const { return argv_; }
@@ -38,7 +40,7 @@ class CommandLine {
   CommandLine(int argc, char* argv[]);
   virtual ~CommandLine();
 
-  void AppendOption(const char* argument);
+  void AppendOption(const char* value);
 
   // The singleton CommandLine instance of current process
   static CommandLine* current_process_commandline_;
index 2547076..d07af1a 100644 (file)
@@ -6,15 +6,19 @@
 
 namespace wrt {
 
+// Extension
 const char kSystemExtensionPath[] = "/usr/lib/tizen-extensions-crosswalk";
 const char kExtensionPrefix[] = "lib";
 const char kExtensionSuffix[] = ".so";
+const char kSwitchExtensionServer[] = "extension-server";
 
+// DBus for Application
 const char kDBusNameForApplication[] = "Application";
 const char kDBusInterfaceNameForApplication[] = "org.tizen.wrt.Application";
 const char kMethodNotifyEPCreated[] = "NotifyEPCreated";
 const char kMethodGetRuntimeVariable[] = "GetRuntimeVariable";
 
+// DBus for Extension
 const char kDBusNameForExtension[] = "Extension";
 const char kDBusInterfaceNameForExtension[] = "org.tizen.wrt.Extension";
 const char kMethodGetExtensions[] = "GetExtensions";
@@ -24,4 +28,7 @@ const char kMethodSendSyncMessage[] = "SendSyncMessage";
 const char kMethodPostMessage[] = "PostMessage";
 const char kSignalOnMessageToJS[] = "OnMessageToJS";
 
+
+
+
 }  // namespace wrt
index 9eaa205..3545551 100644 (file)
@@ -10,6 +10,7 @@ namespace wrt {
 extern const char kSystemExtensionPath[];
 extern const char kExtensionPrefix[];
 extern const char kExtensionSuffix[];
+extern const char kSwitchExtensionServer[];
 
 extern const char kDBusNameForApplication[];
 extern const char kDBusInterfaceNameForApplication[];
index 50bc712..581e75d 100644 (file)
@@ -154,18 +154,24 @@ DBusServer::~DBusServer() {
   if (server_) {
     g_object_unref(server_);
   }
+
+  if (!address_path_.empty()) {
+    unlink(address_path_.c_str());
+  }
 }
 
 void DBusServer::Start(const std::string& name) {
   GError* err = NULL;
 
-  std::string address(g_get_user_runtime_dir());
-  address.append("/.");
-  address.append(name);
-
+  address_path_.clear();
+  address_path_.append(g_get_user_runtime_dir());
+  address_path_.append("/.");
+  address_path_.append(name);
   // unlink existing bus address
-  unlink(address.c_str());
-  address = "unix:path=" + address;
+  unlink(address_path_.c_str());
+
+  std::string address("unix:path=");
+  address.append(address_path_);
 
   // create new bus socket
   // TODO(wy80.choi): bus socket (Address) should be removed gracefully
index 5e0cf57..de0e1e4 100644 (file)
@@ -50,6 +50,7 @@ class DBusServer {
   PropertyGetter GetPropertyGetter(const std::string& iface);
 
  private:
+  std::string address_path_;
   GDBusServer* server_;
   GDBusNodeInfo* node_info_;
 
index ce4d344..f50cf03 100644 (file)
@@ -2,54 +2,29 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-# Dependencies
-PKG_CHECK_MODULES(TARGET_EXTENSION_DEPS
-  uuid
+PKG_CHECK_MODULES(TARGET_EXTENSION_STATIC_DEPS
   dlog
   glib-2.0
-  gio-2.0
   REQUIRED
 )
 
-# Includes
-SET(TARGET_EXTENSION_INCS
+SET(TARGET_EXTENSION_STATIC_INCS
   ${BASE_SRCDIR}
-  ${TARGET_EXTENSION_DEPS_INCLUDE_DIRS}
+  ${TARGET_EXTENSION_STATIC_DEPS_INCLUDE_DIRS}
 )
 
-# Libraries
-SET(TARGET_EXTENSION_LIBS
-  ${TARGET_EXTENSION_DEPS_LIBRARIES}
-)
-
-# Source Files
-SET(TARGET_EXTENSION_SRCS
-  ${BASE_SRCDIR}/extension/extension_main.cc
+SET(TARGET_EXTENSION_STATIC_SRCS
   ${BASE_SRCDIR}/extension/extension.cc
   ${BASE_SRCDIR}/extension/extension_instance.cc
   ${BASE_SRCDIR}/extension/extension_adapter.cc
   ${BASE_SRCDIR}/extension/extension_server.cc
 )
 
-# Compiler Flags
-SET(TARGET_EXTENSION_CFLAGS
-  "-fPIE"
-)
-
-# Linker Flags
-SET(TARGET_EXTENSION_LDFLAGS
-  "-pie -ldl"
+INCLUDE_DIRECTORIES(${TARGET_EXTENSION_STATIC_INCS})
+ADD_LIBRARY(${TARGET_EXTENSION_STATIC} STATIC
+  ${TARGET_EXTENSION_STATIC_SRCS}
 )
-
-# Build Executable
-INCLUDE_DIRECTORIES(${TARGET_EXTENSION_INCS})
-ADD_DEFINITIONS(${TARGET_EXTENSION_CFLAGS})
-ADD_EXECUTABLE(${TARGET_EXTENSION} ${TARGET_EXTENSION_SRCS})
-TARGET_LINK_LIBRARIES(${TARGET_EXTENSION}
+TARGET_LINK_LIBRARIES(${TARGET_EXTENSION_STATIC}
+  ${TARGET_EXTENSION_STATIC_DEPS_LIBRARIES}
   ${TARGET_COMMON_STATIC}
-  ${TARGET_EXTENSION_LIBS}
-  ${TARGET_EXTENSION_LDFLAGS}
 )
-
-# Install
-INSTALL(TARGETS ${TARGET_EXTENSION} DESTINATION bin)
diff --git a/src/extension/extension_main.cc b/src/extension/extension_main.cc
deleted file mode 100644 (file)
index 9758925..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <glib.h>
-#include <glib-unix.h>
-
-#include "common/logger.h"
-#include "common/command_line.h"
-#include "extension/extension_server.h"
-
-namespace {
-
-gboolean HandleQuitSignal(gpointer data) {
-  GMainLoop* loop = reinterpret_cast<GMainLoop*>(data);
-  g_main_loop_quit(loop);
-  return false;
-}
-
-}  // namespace
-
-// TODO(wy80.choi): This main function should be merged to wrt runtime
-// to reduce static code size of memory.
-int main(int argc, char* argv[]) {
-  GMainLoop* loop;
-
-  loop = g_main_loop_new(NULL, FALSE);
-  g_unix_signal_add(SIGINT, HandleQuitSignal, loop);
-  g_unix_signal_add(SIGTERM, HandleQuitSignal, loop);
-
-  wrt::CommandLine::Init(argc, argv);
-  wrt::CommandLine* cmd = wrt::CommandLine::ForCurrentProcess();
-
-  // TODO(wy80.choi): Receive extension paths for user defined extensions.
-
-  // Receive AppID from arguments.
-  if (cmd->arguments().size() < 1) {
-    LoggerE("uuid is required.");
-    exit(1);
-  }
-  std::string uuid = cmd->arguments()[0];
-
-  // Start ExtensionServer
-  wrt::ExtensionServer server(uuid);
-  if (!server.Start()) {
-    LoggerE("Failed to start extension server.");
-    exit(1);
-  }
-
-  LoggerI("extension process has been started.");
-
-  g_main_loop_run(loop);
-
-  LoggerI("extension process is exiting.");
-
-  g_main_loop_unref(loop);
-
-  return 0;
-}
index 1a3a249..9d65e6c 100644 (file)
@@ -5,6 +5,9 @@
 #include "extension/extension_server.h"
 
 #include <glob.h>
+#include <glib.h>
+#include <glib-unix.h>
+
 #include <string>
 #include <vector>
 
@@ -12,6 +15,7 @@
 #include "common/constants.h"
 #include "common/file_utils.h"
 #include "common/string_utils.h"
+#include "common/command_line.h"
 #include "extension/extension.h"
 
 namespace wrt {
@@ -62,16 +66,6 @@ bool ExtensionServer::Start() {
 }
 
 bool ExtensionServer::Start(const StringVector& paths) {
-  // Register system extensions to support Tizen Device APIs
-  RegisterSystemExtensions();
-
-  // Register user extensions
-  for (auto it = paths.begin(); it != paths.end(); ++it) {
-    if (utils::Exists(*it)) {
-      RegisterExtension(*it);
-    }
-  }
-
   // Connect to DBusServer for Application of Runtime
   if (!dbus_application_client_.ConnectByName(
           app_uuid_ + "." + std::string(kDBusNameForApplication))) {
@@ -90,6 +84,16 @@ bool ExtensionServer::Start(const StringVector& paths) {
       std::bind(&ExtensionServer::HandleDBusMethod, this, _1, _2, _3, _4));
   dbus_server_.Start(app_uuid_ + "." + std::string(kDBusNameForExtension));
 
+  // Register system extensions to support Tizen Device APIs
+  RegisterSystemExtensions();
+
+  // Register user extensions
+  for (auto it = paths.begin(); it != paths.end(); ++it) {
+    if (utils::Exists(*it)) {
+      RegisterExtension(*it);
+    }
+  }
+
   // Send 'ready' signal to Injected Bundle.
   NotifyEPCreatedToApplication();
 
@@ -343,4 +347,48 @@ void ExtensionServer::PostMessageToJSCallback(
                                         msg.c_str()));
 }
 
+// static
+bool ExtensionServer::StartExtensionProcess() {
+  GMainLoop* loop;
+
+  loop = g_main_loop_new(NULL, FALSE);
+
+  // Register Quit Signal Handlers
+  auto quit_callback = [](gpointer data) -> gboolean {
+    GMainLoop* loop = reinterpret_cast<GMainLoop*>(data);
+    g_main_loop_quit(loop);
+    return false;
+  };
+  g_unix_signal_add(SIGINT, quit_callback, loop);
+  g_unix_signal_add(SIGTERM, quit_callback, loop);
+
+  CommandLine* cmd = CommandLine::ForCurrentProcess();
+
+  // TODO(wy80.choi): Receive extension paths for user defined extensions.
+
+  // Receive AppID from arguments.
+  if (cmd->arguments().size() < 1) {
+    LoggerE("uuid is required.");
+    return false;
+  }
+  std::string uuid = cmd->arguments()[0];
+
+  // Start ExtensionServer
+  ExtensionServer server(uuid);
+  if (!server.Start()) {
+    LoggerE("Failed to start extension server.");
+    return false;
+  }
+
+  LoggerI("extension process has been started.");
+
+  g_main_loop_run(loop);
+
+  LoggerI("extension process is exiting.");
+
+  g_main_loop_unref(loop);
+
+  return true;
+}
+
 }  // namespace wrt
index cf5d4bb..e41dc54 100644 (file)
@@ -25,6 +25,8 @@ class ExtensionServer : public Extension::ExtensionDelegate {
   explicit ExtensionServer(const std::string& appid);
   virtual ~ExtensionServer();
 
+  static bool StartExtensionProcess();
+
   bool Start();
   bool Start(const StringVector& paths);
 
index c8d91e1..5c8f3ea 100755 (executable)
@@ -11,9 +11,6 @@ IF(WAYLAND_SUPPORT)
 ENDIF(WAYLAND_SUPPORT)
 
 PKG_CHECK_MODULES(TARGET_RUNTIME_DEPS
-  glib-2.0
-  gio-2.0
-  uuid
   dlog
   ${WIN_PKG}
   elementary
@@ -41,6 +38,7 @@ SET(TARGET_RUNTIME_LIBS
 
 # Source Files
 SET(TARGET_RUNTIME_SRCS
+  ${BASE_SRCDIR}/runtime/main.cc
   ${BASE_SRCDIR}/runtime/native_window.cc
   ${BASE_SRCDIR}/runtime/native_app_window.cc
   ${BASE_SRCDIR}/runtime/web_application.cc
@@ -65,8 +63,9 @@ INCLUDE_DIRECTORIES(${TARGET_RUNTIME_INCS})
 ADD_DEFINITIONS(${TARGET_RUNTIME_CFLAGS})
 ADD_EXECUTABLE(${TARGET_RUNTIME} ${TARGET_RUNTIME_SRCS})
 TARGET_LINK_LIBRARIES(${TARGET_RUNTIME}
-  ${TARGET_COMMON_STATIC}
   ${TARGET_RUNTIME_LIBS}
+  ${TARGET_COMMON_STATIC}
+  ${TARGET_EXTENSION_STATIC}
   ${TARGET_RUNTIME_LDFLAGS}
 )
 
diff --git a/src/runtime/main.cc b/src/runtime/main.cc
new file mode 100644 (file)
index 0000000..db6d6c3
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <ewk_chromium.h>
+
+#include "common/logger.h"
+#include "common/constants.h"
+#include "common/command_line.h"
+#include "runtime/runtime.h"
+#include "extension/extension_server.h"
+
+int main(int argc, char* argv[]) {
+  // Parse commandline.
+  wrt::CommandLine::Init(argc, argv);
+
+  wrt::CommandLine* cmd = wrt::CommandLine::ForCurrentProcess();
+  if (cmd->HasOptionName(wrt::kSwitchExtensionServer)) {
+    // If cmd has the switch '--extension-server', run as extension server.
+    LoggerI("Extension server process has been created.");
+    if (!wrt::ExtensionServer::StartExtensionProcess()) {
+      LoggerE("Failed to start extension server.");
+      exit(EXIT_FAILURE);
+    }
+  } else {
+    // Default dehavior, run as runtime.
+    LoggerI("Runtime process has been created.");
+    ewk_init();
+    char* chromium_arg_options[] = {
+      argv[0],
+      const_cast<char*>("--enable-file-cookies"),
+      const_cast<char*>("--allow-file-access-from-files"),
+      const_cast<char*>("--allow-universal-access-from-files")
+    };
+    const int chromium_arg_cnt =
+        sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
+    ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
+
+    wrt::Runtime runtime;
+    int ret = runtime.Exec(argc, argv);
+    ewk_shutdown();
+    exit(ret);
+  }
+
+  return EXIT_SUCCESS;
+}
index 3e0134d..4f71821 100755 (executable)
@@ -9,11 +9,10 @@
 #include <memory>
 
 #include "common/logger.h"
-#include "common/constants.h"
 #include "common/command_line.h"
-#include "runtime/native_app_window.h"
 #include "common/app_control.h"
 #include "common/application_data.h"
+#include "runtime/native_app_window.h"
 
 namespace wrt {
 
@@ -175,24 +174,3 @@ int Runtime::Exec(int argc, char* argv[]) {
 }
 
 }  // namespace wrt
-
-int main(int argc, char* argv[]) {
-  // Initialize CommandLineParser
-  wrt::CommandLine::Init(argc, argv);
-
-  ewk_init();
-  char* chromium_arg_options[] = {
-    argv[0],
-    const_cast<char*>("--enable-file-cookies"),
-    const_cast<char*>("--allow-file-access-from-files"),
-    const_cast<char*>("--allow-universal-access-from-files")
-  };
-  const int chromium_arg_cnt =
-      sizeof(chromium_arg_options) / sizeof(chromium_arg_options[0]);
-  ewk_set_arguments(chromium_arg_cnt, chromium_arg_options);
-
-  wrt::Runtime runtime;
-  int ret = runtime.Exec(argc, argv);
-  ewk_shutdown();
-  return ret;
-}
index 88ba3ba..9a7d524 100755 (executable)
@@ -25,6 +25,8 @@
 #include "common/application_data.h"
 #include "common/resource_manager.h"
 
+namespace wrt {
+
 namespace {
 // TODO(sngn.lee) : It should be declare in common header
 const char* kKeyNameBack = "back";
@@ -104,10 +106,11 @@ void ExecExtensionProcess(const std::string& uuid) {
     LoggerE("Failed to fork child process for extension process.");
   }
   if (pid == 0) {
-    // TODO(wy80.choi): wrt-extension should be merged to this runtime exec.
-    // It should be changed to "/usr/bin/wrt --extension-process"
-    execl("/usr/bin/wrt-extension",
-          "/usr/bin/wrt-extension", uuid.c_str(), NULL);
+    CommandLine* cmd = CommandLine::ForCurrentProcess();
+    std::string switch_ext("--");
+    switch_ext.append(kSwitchExtensionServer);
+    execl(cmd->program().c_str(),
+          cmd->program().c_str(), switch_ext.c_str(), uuid.c_str(), NULL);
   }
 }
 
@@ -120,8 +123,6 @@ static void SendDownloadRequest(const std::string& url) {
 
 }  // namespace
 
-namespace wrt {
-
 WebApplication::WebApplication(
     NativeWindow* window, std::unique_ptr<ApplicationData> app_data)
     : launched_(false),