1 // Copyright (c) 2013 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.
17 #include "xwalk/application/tools/linux/dbus_connection.h"
18 #include "xwalk/application/tools/linux/xwalk_tizen_user.h"
19 #include "xwalk/application/tools/linux/xwalk_launcher_tizen.h"
21 static const char* xwalk_service_name = "org.crosswalkproject.Runtime1";
22 static const char* xwalk_running_path = "/running1";
23 static const char* xwalk_running_manager_iface =
24 "org.crosswalkproject.Running.Manager1";
25 static const char* xwalk_running_app_iface =
26 "org.crosswalkproject.Running.Application1";
28 static const char cmd_line_fullscreen_arg[] = "--fullscreen";
30 static char* application_object_path;
32 static GMainLoop* mainloop;
34 static void object_removed(GDBusObjectManager* manager, GDBusObject* object,
36 const char* path = g_dbus_object_get_object_path(object);
38 if (g_strcmp0(path, application_object_path))
41 fprintf(stderr, "Application '%s' disappeared, exiting.\n", path);
43 g_main_loop_quit(mainloop);
46 static void on_app_properties_changed(GDBusProxy* proxy,
47 GVariant* changed_properties,
48 GStrv invalidated_properties,
50 const char* interface = g_dbus_proxy_get_interface_name(proxy);
52 fprintf(stderr, "properties changed %s\n", interface);
54 if (g_variant_n_children(changed_properties) == 0)
57 if (g_strcmp0(interface, xwalk_running_app_iface))
64 g_variant_get(changed_properties, "a{sv}", &iter);
66 while (g_variant_iter_loop(iter, "{&sv}", &key, &value)) {
67 if (g_strcmp0(key, "State"))
70 const gchar* state = g_variant_get_string(value, NULL);
72 fprintf(stderr, "Application state %s\n", state);
76 int main(int argc, char** argv) {
79 gboolean fullscreen = FALSE;
82 #if !GLIB_CHECK_VERSION(2, 36, 0)
83 // g_type_init() is deprecated on GLib since 2.36, Tizen has 2.32.
87 if (xwalk_tizen_set_home_for_user_app())
90 if (!strcmp(basename(argv[0]), "xwalk-launcher")) {
92 fprintf(stderr, "No AppID informed, nothing to do\n");
99 if (!strcmp(basename(argv[2]), cmd_line_fullscreen_arg))
104 appid = strdup(basename(argv[0]));
107 if (!strcmp(basename(argv[1]), cmd_line_fullscreen_arg))
112 GDBusConnection* connection = get_session_bus_connection(&error);
114 fprintf(stderr, "Couldn't get the session bus connection: %s\n",
119 GDBusObjectManager* running_apps_om = g_dbus_object_manager_client_new_sync(
120 connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
121 xwalk_service_name, xwalk_running_path,
122 NULL, NULL, NULL, NULL, &error);
123 if (!running_apps_om) {
124 fprintf(stderr, "Service '%s' does could not be reached: %s\n",
125 xwalk_service_name, error->message);
129 g_signal_connect(running_apps_om, "object-removed",
130 G_CALLBACK(object_removed), NULL);
132 GDBusProxy* running_proxy = g_dbus_proxy_new_sync(
134 G_DBUS_PROXY_FLAGS_NONE, NULL, xwalk_service_name,
135 xwalk_running_path, xwalk_running_manager_iface, NULL, &error);
136 if (!running_proxy) {
137 g_print("Couldn't create proxy for '%s': %s\n", xwalk_running_manager_iface,
143 unsigned int launcher_pid = getpid();
145 GVariant* result = g_dbus_proxy_call_sync(running_proxy, "Launch",
146 g_variant_new("(sub)", appid,
149 G_DBUS_CALL_FLAGS_NONE,
152 fprintf(stderr, "Couldn't call 'Launch' method: %s\n", error->message);
156 g_variant_get(result, "(o)", &application_object_path);
157 fprintf(stderr, "Application launched with path '%s'\n",
158 application_object_path);
160 GDBusProxy* app_proxy = g_dbus_proxy_new_sync(
162 G_DBUS_PROXY_FLAGS_NONE, NULL, xwalk_service_name,
163 application_object_path, xwalk_running_app_iface, NULL, &error);
165 g_print("Couldn't create proxy for '%s': %s\n", xwalk_running_app_iface,
171 g_signal_connect(app_proxy, "g-properties-changed",
172 G_CALLBACK(on_app_properties_changed), NULL);
174 mainloop = g_main_loop_new(NULL, FALSE);
176 #if defined(OS_TIZEN)
178 snprintf(name, sizeof(name), "xwalk-%s", appid);
180 if (xwalk_appcore_init(argc, argv, name)) {
181 fprintf(stderr, "Failed to initialize appcore");
186 g_main_loop_run(mainloop);