1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
10 #include "base/at_exit.h"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/path_service.h"
15 #include "xwalk/application/common/tizen/application_storage.h"
16 #include "xwalk/runtime/common/xwalk_paths.h"
19 #include "dbus/message.h"
20 #include "dbus/object_proxy.h"
23 #include "xwalk/application/tools/tizen/xwalk_tizen_user.h"
26 using xwalk::application::ApplicationData;
27 using xwalk::application::ApplicationStorage;
31 const gint debugging_port_not_set = std::numeric_limits<gint>::min();
33 gint debugging_port = debugging_port_not_set;
34 GOptionEntry entries[] = {
35 { "debugging_port", 'd', 0, G_OPTION_ARG_INT, &debugging_port,
36 "Enable remote debugging, port number 0 means to disable", NULL },
40 const char kServiceName[] = "org.crosswalkproject.Runtime1";
41 const char kRunningManagerIface[] =
42 "org.crosswalkproject.Running.Manager1";
43 const dbus::ObjectPath kRunningManagerDBusPath("/running1");
45 bool EnableRemoteDebugging(int port) {
47 g_print("Remote debugging port cannot be negative\n");
51 DLOG(ERROR) << "Invalid http debugger port number " << port;
55 dbus::Bus::Options options;
56 #if defined(OS_TIZEN_MOBILE)
57 options.bus_type = dbus::Bus::CUSTOM_ADDRESS;
58 options.address.assign("unix:path=/run/user/app/dbus/user_bus_socket");
60 scoped_refptr<dbus::Bus> bus(new dbus::Bus(options));
61 dbus::ObjectProxy* app_proxy =
64 kRunningManagerDBusPath);
66 DLOG(ERROR) << "Failed to get application proxy.";
70 dbus::MethodCall method_call(
71 kRunningManagerIface, "EnableRemoteDebugging");
72 dbus::MessageWriter writer(&method_call);
73 writer.AppendUint32(port);
75 app_proxy->CallMethodAndBlock(&method_call, 1000);
78 g_print("Remote debugging has been disabled \n");
80 g_print("Remote debugging enabled at port %d \n", port);
84 bool list_applications(ApplicationStorage* storage) {
85 std::vector<std::string> app_ids;
86 if (!storage->GetInstalledApplicationIDs(app_ids))
89 g_print("Application ID Application Name\n");
90 g_print("-----------------------------------------------------\n");
91 for (auto id : app_ids) {
92 scoped_refptr<ApplicationData> app_data = storage->GetApplicationData(id);
93 if (!app_data.get()) {
94 g_print("Failed to obtain app data for xwalk id: %s\n",
98 g_print("%s %s\n", id.c_str(), app_data->Name().c_str());
100 g_print("-----------------------------------------------------\n");
107 int main(int argc, char* argv[]) {
108 #if defined(OS_TIZEN)
109 if (xwalk_tizen_check_group_users())
112 GOptionContext* context = g_option_context_new("- Crosswalk Setter");
113 g_option_context_add_main_entries(context, entries, NULL);
114 GError* error = nullptr;
115 if (!g_option_context_parse(context, &argc, &argv, &error)) {
116 g_print("option parsing failed: %s\n", error->message);
117 g_option_context_free(context);
120 g_option_context_free(context);
121 base::AtExitManager at_exit;
123 if (debugging_port != debugging_port_not_set) {
124 if (!EnableRemoteDebugging(static_cast<int>(debugging_port)))
127 // FIXME : there should be a way to get application Id from platform, so
128 // the below code should not be needed.
129 xwalk::RegisterPathProvider();
130 base::FilePath data_path;
131 PathService::Get(xwalk::DIR_DATA_PATH, &data_path);
132 scoped_ptr<ApplicationStorage> storage(new ApplicationStorage(data_path));
133 if (!list_applications(storage.get()))