Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[Tizen] Refactor XWalkLauncher for usage of RESET event.
Browse files Browse the repository at this point in the history
After this change execute xwalk-launcher on Tizen will cause
initialization of app core and launch of g_main_loop. Application
will be actually launched after xwalk-launcher receives RESET
event from platform.

BUG=XWALK-2779
  • Loading branch information
jizydorczyk committed Dec 8, 2014
1 parent 50e7278 commit 8b67e6b
Show file tree
Hide file tree
Showing 11 changed files with 588 additions and 360 deletions.
21 changes: 0 additions & 21 deletions application/tools/linux/dbus_connection.cc

This file was deleted.

12 changes: 0 additions & 12 deletions application/tools/linux/dbus_connection.h

This file was deleted.

122 changes: 122 additions & 0 deletions application/tools/linux/dbus_object_manager.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright (c) 2013 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "xwalk/application/tools/linux/dbus_object_manager.h"

#include "base/message_loop/message_loop.h"

namespace {

const char kServiceName[] = "org.crosswalkproject.Runtime1";
const char kRunningManagerIface[] = "org.crosswalkproject.Running.Manager1";
const char kRunningAppIface[] = "org.crosswalkproject.Running.Application1";
const dbus::ObjectPath kRunningManagerDBusPath("/running1");

} // namespace

DBusObjectManager::DBusObjectManager(dbus::Bus* bus,
base::MessageLoop* main_loop)
: bus_(bus),
main_loop_(main_loop) {
ConnectToApplicationManager();
}

void DBusObjectManager::DBusCallLaunchMethod(
const std::string& appid_or_url, int launcher_pid, bool fullscreen,
bool remote_debugging) {
dbus::MethodCall method_call(
kRunningManagerIface, "Launch");
dbus::MessageWriter writer(&method_call);
writer.AppendString(appid_or_url);
writer.AppendUint32(launcher_pid);
writer.AppendBool(fullscreen);
writer.AppendBool(remote_debugging);
scoped_ptr<dbus::Response> response(
running_proxy_->CallMethodAndBlock(&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));

if (!response.get())
exit(1);

dbus::MessageReader reader(response.get());
dbus::ObjectPath running_manager_path;
if (!reader.PopObjectPath(&running_manager_path))
LOG(WARNING) << "Failed to create app proxy.";
else
app_proxy_ = bus_->GetObjectProxy(std::string(kServiceName),
running_manager_path);
}

scoped_ptr<dbus::Response> DBusObjectManager::CallGetEPChannelMethod() {
dbus::MethodCall method_call(kRunningAppIface, "GetEPChannel");
return app_proxy_->CallMethodAndBlock(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
}

scoped_ptr<dbus::Response> DBusObjectManager::DBusCallSuspendMethod() {
dbus::MethodCall method_call(kRunningAppIface, "Suspend");
return app_proxy_->CallMethodAndBlock(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
}

scoped_ptr<dbus::Response> DBusObjectManager::DBusCallResumeMethod() {
dbus::MethodCall method_call(kRunningAppIface, "Resume");
return app_proxy_->CallMethodAndBlock(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
}

void DBusObjectManager::OnOwnershipCallback(const std::string& service_name,
bool success) {
LOG(WARNING) << "Couldn't get ownership of D-Bus service name: "
<< service_name << ".";
}

void DBusObjectManager::ConnectToApplicationManager() {
bus_->RequestOwnershipAndBlock(kServiceName,
dbus::Bus::REQUIRE_PRIMARY);
running_apps_manager_ = bus_->GetObjectManager(kServiceName,
kRunningManagerDBusPath);
running_apps_manager_->RegisterInterface(kRunningAppIface, this);
running_proxy_ = bus_->GetObjectProxy(kServiceName, kRunningManagerDBusPath);
}

void DBusObjectManager::ObjectAdded(const dbus::ObjectPath& object_path,
const std::string& interface_name) {
}

void DBusObjectManager::ObjectRemoved(const dbus::ObjectPath& object_path,
const std::string& interface_name) {
if (object_path != app_proxy_->object_path())
return;
LOG(INFO) << "Application '" << object_path.value().c_str()
<< "' disappeared, exiting.";
main_loop_->QuitNow();
}

dbus::PropertySet* DBusObjectManager::CreateProperties(
dbus::ObjectProxy *object_proxy,
const dbus::ObjectPath& object_path,
const std::string& interface_name) {
Properties* properties = new Properties(
object_proxy, interface_name,
base::Bind(&DBusObjectManager::OnPropertyChanged,
base::Unretained(this), object_path));
return static_cast<dbus::PropertySet*>(properties);
}

void DBusObjectManager::OnPropertyChanged(const dbus::ObjectPath& object_path,
const std::string& name) {
if (!running_apps_manager_)
ConnectToApplicationManager();
}

dbus::ObjectProxy& DBusObjectManager::GetAppProxy() {
return *app_proxy_;
}

scoped_refptr<dbus::ObjectManager> DBusObjectManager::GetRunningAppsManager() {
if (!running_apps_manager_)
ConnectToApplicationManager();
return running_apps_manager_;
}
73 changes: 73 additions & 0 deletions application/tools/linux/dbus_object_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) 2013 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef XWALK_APPLICATION_TOOLS_LINUX_DBUS_OBJECT_MANAGER_H_
#define XWALK_APPLICATION_TOOLS_LINUX_DBUS_OBJECT_MANAGER_H_

#include <string>
#include <map>

#include "base/macros.h"
#include "base/threading/thread.h"
#include "base/values.h"
#include "dbus/bus.h"
#include "dbus/exported_object.h"
#include "dbus/message.h"
#include "dbus/object_manager.h"
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
#include "dbus/property.h"

class DBusObjectManager : public dbus::ObjectManager::Interface {
public:
DBusObjectManager(dbus::Bus* bus, base::MessageLoop* main_loop);

void DBusCallLaunchMethod(const std::string& appid_or_url, int launcher_pid,
bool fullscreen, bool remote_debugging);
scoped_ptr<dbus::Response> CallGetEPChannelMethod();
scoped_ptr<dbus::Response> DBusCallSuspendMethod();
scoped_ptr<dbus::Response> DBusCallResumeMethod();

dbus::ObjectProxy& GetAppProxy();
scoped_refptr<dbus::ObjectManager> GetRunningAppsManager();

struct Properties : public dbus::PropertySet {
dbus::Property<std::string> app_id;

Properties(dbus::ObjectProxy* object_proxy,
const std::string& interface_name,
PropertyChangedCallback property_changed_callback)
: PropertySet(object_proxy, interface_name, property_changed_callback) {
RegisterProperty("AppID", &app_id);
}
};

private:
void OnOwnershipCallback(const std::string& service_name, bool success);
void ObjectAdded(const dbus::ObjectPath& object_path,
const std::string& interface_name) override;
void ObjectRemoved(const dbus::ObjectPath& object_path,
const std::string& interface_name) override;
dbus::PropertySet* CreateProperties(
dbus::ObjectProxy* object_proxy,
const dbus::ObjectPath& object_path,
const std::string& interface_name) override;

void OnPropertyChanged(const dbus::ObjectPath& object_path,
const std::string& name);

void ConnectToApplicationManager();

scoped_refptr<dbus::Bus> bus_;
dbus::ObjectManager* running_apps_manager_;
dbus::ObjectProxy* running_proxy_;
dbus::ObjectProxy* app_proxy_;

// this is needed for exit events which come via dbus interface
base::MessageLoop* main_loop_;

DISALLOW_COPY_AND_ASSIGN(DBusObjectManager);
};

#endif // XWALK_APPLICATION_TOOLS_LINUX_DBUS_OBJECT_MANAGER_H_
7 changes: 5 additions & 2 deletions application/tools/linux/xwalk_application_tools.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
'../../../build/system.gyp:gio',
'../../../extensions/extensions.gyp:xwalk_extensions',
'../../../application/common/xwalk_application_common.gypi:xwalk_application_common_lib',
'../../../dbus/xwalk_dbus.gyp:xwalk_dbus'
],
'sources': [
'dbus_connection.cc',
'dbus_connection.h',
'dbus_object_manager.cc',
'dbus_object_manager.h',
'xwalk_extension_process_launcher.cc',
'xwalk_extension_process_launcher.h',
'xwalk_launcher_main.cc',
Expand All @@ -27,6 +28,8 @@
'../../../build/system.gyp:tizen_appcore_common'
],
'sources': [
'xwalk_launcher.cc',
'xwalk_launcher.h',
'xwalk_launcher_tizen.cc',
'xwalk_launcher_tizen.h',
'../tizen/xwalk_tizen_user.cc',
Expand Down
Loading

0 comments on commit 8b67e6b

Please sign in to comment.