From e2375e27908276d7e39a21d97c08cb5e5a17206d Mon Sep 17 00:00:00 2001 From: WonYoung Choi Date: Mon, 11 May 2015 18:13:49 +0900 Subject: [PATCH] Retry connecting to ExtensionServer at DynamicPluginStartSession() Change-Id: I865d33f9f2fcb22c26797ed691f7f31f4ccd837f --- src/bundle/extension_client.cc | 39 ++++++++++++++++++++--------- src/bundle/extension_client.h | 2 +- src/bundle/extension_renderer_controller.cc | 4 +-- src/bundle/extension_renderer_controller.h | 2 +- src/bundle/injected_bundle.cc | 2 +- src/extension/extension_server.cc | 30 ++++++++++++++-------- 6 files changed, 51 insertions(+), 28 deletions(-) diff --git a/src/bundle/extension_client.cc b/src/bundle/extension_client.cc index 500ff83..7082d4b 100755 --- a/src/bundle/extension_client.cc +++ b/src/bundle/extension_client.cc @@ -6,6 +6,7 @@ #include "bundle/extension_client.h" +#include #include #include #include @@ -98,20 +99,32 @@ std::string ExtensionClient::SendSyncMessageToNative( return ret; } -void ExtensionClient::Initialize(const std::string& uuid) { - // Connect to DBusServer for ExtensionServer - if (dbus_extension_client_.ConnectByName( - uuid + "." + std::string(kDBusNameForExtension))) { - using std::placeholders::_1; - using std::placeholders::_2; - dbus_extension_client_.SetSignalCallback( - kDBusInterfaceNameForExtension, - std::bind(&ExtensionClient::HandleSignal, this, _1, _2)); - } else { +bool ExtensionClient::Initialize(const std::string& uuid) { + // Retry connecting to ExtensionServer + // ExtensionServer can not be ready at this time yet. + const int retry_max = 20; + bool connected = false; + for (int i=0; i < retry_max; i++) { + connected = dbus_extension_client_.ConnectByName( + uuid + "." + std::string(kDBusNameForExtension)); + if (connected) break; + LOGGER(WARN) << "Failed to connect to ExtensionServer. retry " + << (i+1) << "/" << retry_max; + usleep(50*1000); + } + + if (!connected) { LOGGER(ERROR) << "Failed to connect to the dbus server for Extension."; - return; + return false; } + // Set signal handler + using std::placeholders::_1; + using std::placeholders::_2; + dbus_extension_client_.SetSignalCallback( + kDBusInterfaceNameForExtension, + std::bind(&ExtensionClient::HandleSignal, this, _1, _2)); + // get extensions from ExtensionServer GVariant* value = dbus_extension_client_.Call( kDBusInterfaceNameForExtension, kMethodGetExtensions, @@ -120,7 +133,7 @@ void ExtensionClient::Initialize(const std::string& uuid) { if (!value) { LOGGER(ERROR) << "Failed to get extension list from ExtensionServer."; - return; + return false; } gchar* name; @@ -140,6 +153,8 @@ void ExtensionClient::Initialize(const std::string& uuid) { } g_variant_unref(value); + + return true; } void ExtensionClient::HandleSignal( diff --git a/src/bundle/extension_client.h b/src/bundle/extension_client.h index 887f13f..cde88af 100755 --- a/src/bundle/extension_client.h +++ b/src/bundle/extension_client.h @@ -36,7 +36,7 @@ class ExtensionClient { std::string SendSyncMessageToNative(const std::string& instance_id, const std::string& msg); - void Initialize(const std::string& uuid); + bool Initialize(const std::string& uuid); struct ExtensionCodePoints { std::string api; diff --git a/src/bundle/extension_renderer_controller.cc b/src/bundle/extension_renderer_controller.cc index 73f746b..a04c4fa 100755 --- a/src/bundle/extension_renderer_controller.cc +++ b/src/bundle/extension_renderer_controller.cc @@ -64,9 +64,9 @@ void ExtensionRendererController::WillReleaseScriptContext( ModuleSystem::ResetModuleSystemFromContext(context); } -void ExtensionRendererController::InitializeExtensions( +bool ExtensionRendererController::InitializeExtensions( const std::string& uuid) { - extensions_client_->Initialize(uuid); + return extensions_client_->Initialize(uuid); } } // namespace wrt diff --git a/src/bundle/extension_renderer_controller.h b/src/bundle/extension_renderer_controller.h index 7cfc23d..9b7cfba 100755 --- a/src/bundle/extension_renderer_controller.h +++ b/src/bundle/extension_renderer_controller.h @@ -20,7 +20,7 @@ class ExtensionRendererController { void DidCreateScriptContext(v8::Handle context); void WillReleaseScriptContext(v8::Handle context); - void InitializeExtensions(const std::string& uuid); + bool InitializeExtensions(const std::string& uuid); private: ExtensionRendererController(); diff --git a/src/bundle/injected_bundle.cc b/src/bundle/injected_bundle.cc index 300e7bd..21df177 100755 --- a/src/bundle/injected_bundle.cc +++ b/src/bundle/injected_bundle.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include #include #include @@ -29,7 +30,6 @@ extern "C" void DynamicPluginStartSession(int /*widget_id*/, wrt::ExtensionRendererController& controller = wrt::ExtensionRendererController::GetInstance(); - // TODO(wy80.choi): Temporarily, uuid is passed as theme arguments. controller.InitializeExtensions(uuid); controller.DidCreateScriptContext(context); } diff --git a/src/extension/extension_server.cc b/src/extension/extension_server.cc index c45536d..c2305c3 100644 --- a/src/extension/extension_server.cc +++ b/src/extension/extension_server.cc @@ -66,6 +66,16 @@ 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))) { @@ -84,16 +94,6 @@ 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(); @@ -205,6 +205,7 @@ void ExtensionServer::HandleDBusMethod(GDBusConnection* connection, void ExtensionServer::OnGetExtensions(GDBusMethodInvocation* invocation) { GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); // build an array of extensions @@ -226,7 +227,14 @@ void ExtensionServer::OnGetExtensions(GDBusMethodInvocation* invocation) { // close container('(ssas)') for extension g_variant_builder_close(&builder); } - GVariant* reply = g_variant_builder_end(&builder); + + GVariant* reply = NULL; + if (extensions_.size() == 0) { + reply = g_variant_new_array(G_VARIANT_TYPE("(ssas)"), NULL, 0); + } else { + reply = g_variant_builder_end(&builder); + } + g_dbus_method_invocation_return_value( invocation, g_variant_new_tuple(&reply, 1)); } -- 2.7.4