aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTadao Tanikawa <tanikawa.tadao@jp.panasonic.com>2017-12-14 12:32:11 +0900
committerTadao Tanikawa <tanikawa.tadao@jp.panasonic.com>2017-12-14 12:32:11 +0900
commit8219f63bae65430ec599e91aba4a0fc80a7817e6 (patch)
treedaed92e332d4c8129e61118821d0539cf11cf47c
parente2cd83105eeaec7d820d3cb1dbebf65b22024084 (diff)
Add operations when killed by someonesandbox/ruke47/xdg-launcher
Change-Id: I5ef059f3e99947d2fd81878ba465dcda64a4efbe Signed-off-by: Tadao Tanikawa <tanikawa.tadao@jp.panasonic.com>
-rw-r--r--xdg-launcher/CMakeLists.txt10
-rwxr-xr-xxdg-launcher/package/hvac/bin/runxdg2
-rwxr-xr-xxdg-launcher/package/navi/bin/runxdg2
-rwxr-xr-xxdg-launcher/package/simple-egl/bin/runxdg2
-rw-r--r--xdg-launcher/src/runxdg.cpp840
-rw-r--r--xdg-launcher/src/runxdg.hpp22
6 files changed, 432 insertions, 446 deletions
diff --git a/xdg-launcher/CMakeLists.txt b/xdg-launcher/CMakeLists.txt
index f644c5e..196e7f5 100644
--- a/xdg-launcher/CMakeLists.txt
+++ b/xdg-launcher/CMakeLists.txt
@@ -58,20 +58,14 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBRARIES})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND cp -rf ${CMAKE_CURRENT_SOURCE_DIR}/package ${PROJECT_BINARY_DIR})
-add_custom_target(widget DEPENDS ${PROJECT_BINARY_DIR}/package/simple-egl/config.xml
- ${PROJECT_BINARY_DIR}/package/simple-egl/runxdg.toml
- COMMAND mkdir -p ${PROJECT_BINARY_DIR}/package/simple-egl/bin
- COMMAND cp -rf ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${PROJECT_BINARY_DIR}/package/simple-egl/bin/${PROJECT_NAME}
+add_custom_target(widget
+
COMMAND wgtpkg-pack -f -o ${PROJECT_BINARY_DIR}/package/simple-egl.wgt ${PROJECT_BINARY_DIR}/package/simple-egl
# override hvac to test runxdg
- COMMAND mkdir -p ${PROJECT_BINARY_DIR}/package/hvac/bin
- COMMAND cp -rf ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${PROJECT_BINARY_DIR}/package/hvac/bin/${PROJECT_NAME}
COMMAND wgtpkg-pack -f -o ${PROJECT_BINARY_DIR}/package/hvac.wgt ${PROJECT_BINARY_DIR}/package/hvac
# override navigation to test runxdg
- COMMAND mkdir -p ${PROJECT_BINARY_DIR}/package/navi/bin
- COMMAND cp -rf ${PROJECT_BINARY_DIR}/${PROJECT_NAME} ${PROJECT_BINARY_DIR}/package/navi/bin/${PROJECT_NAME}
COMMAND wgtpkg-pack -f -o ${PROJECT_BINARY_DIR}/package/navi.wgt ${PROJECT_BINARY_DIR}/package/navi
)
diff --git a/xdg-launcher/package/hvac/bin/runxdg b/xdg-launcher/package/hvac/bin/runxdg
new file mode 100755
index 0000000..dac903c
--- /dev/null
+++ b/xdg-launcher/package/hvac/bin/runxdg
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec /usr/bin/runxdg $@
diff --git a/xdg-launcher/package/navi/bin/runxdg b/xdg-launcher/package/navi/bin/runxdg
new file mode 100755
index 0000000..dac903c
--- /dev/null
+++ b/xdg-launcher/package/navi/bin/runxdg
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec /usr/bin/runxdg $@
diff --git a/xdg-launcher/package/simple-egl/bin/runxdg b/xdg-launcher/package/simple-egl/bin/runxdg
new file mode 100755
index 0000000..dac903c
--- /dev/null
+++ b/xdg-launcher/package/simple-egl/bin/runxdg
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec /usr/bin/runxdg $@
diff --git a/xdg-launcher/src/runxdg.cpp b/xdg-launcher/src/runxdg.cpp
index c65f499..6820885 100644
--- a/xdg-launcher/src/runxdg.cpp
+++ b/xdg-launcher/src/runxdg.cpp
@@ -38,592 +38,584 @@
void fatal(const char* format, ...)
{
- va_list va_args;
- va_start(va_args, format);
- vfprintf(stderr, format, va_args);
- va_end(va_args);
+ va_list va_args;
+ va_start(va_args, format);
+ vfprintf(stderr, format, va_args);
+ va_end(va_args);
- exit(EXIT_FAILURE);
+ exit(EXIT_FAILURE);
}
void warn(const char* format, ...)
{
- va_list va_args;
- va_start(va_args, format);
- vfprintf(stderr, format, va_args);
- va_end(va_args);
+ va_list va_args;
+ va_start(va_args, format);
+ vfprintf(stderr, format, va_args);
+ va_end(va_args);
}
void debug(const char* format, ...)
{
- va_list va_args;
- va_start(va_args, format);
- vfprintf(stderr, format, va_args);
- va_end(va_args);
+ va_list va_args;
+ va_start(va_args, format);
+ vfprintf(stderr, format, va_args);
+ va_end(va_args);
}
void RunXDG::notify_ivi_control_cb (ilmObjectType object, t_ilm_uint id,
t_ilm_bool created)
{
- if (object == ILM_SURFACE) {
- struct ilmSurfaceProperties surf_props;
-
- ilm_getPropertiesOfSurface(id, &surf_props);
- pid_t surf_pid = surf_props.creatorPid;
-
- if (!created) {
- AGL_DEBUG("ivi surface (id=%d, pid=%d) destroyed.", id, surf_pid);
- m_launcher->unregister_surfpid(surf_pid);
- m_surfaces.erase(surf_pid);
- return;
- }
-
- AGL_DEBUG("ivi surface (id=%d, pid=%d) is created.", id, surf_pid);
-
- m_launcher->register_surfpid(surf_pid);
- if (surf_pid == m_launcher->find_surfpid_by_rid(m_launcher->m_rid)) {
- AGL_DEBUG("match: surf:pid=%d, afm:rid=%d", surf_pid,
- m_launcher->m_rid);
- setup_surface(id);
- } else {
- AGL_DEBUG("Not match!!! %d %d", surf_pid,
- m_launcher->find_surfpid_by_rid(m_launcher->m_rid));
- }
-
- m_surfaces[surf_pid] = id;
- } else if (object == ILM_LAYER) {
- if (created)
- AGL_DEBUG("ivi layer: %d created.", id);
- else
- AGL_DEBUG("ivi layer: %d destroyed.", id);
+ if (object == ILM_SURFACE) {
+ struct ilmSurfaceProperties surf_props;
+
+ ilm_getPropertiesOfSurface(id, &surf_props);
+ pid_t surf_pid = surf_props.creatorPid;
+
+ if (!created) {
+ AGL_DEBUG("ivi surface (id=%d, pid=%d) destroyed.", id, surf_pid);
+ m_launcher->unregister_surfpid(surf_pid);
+ m_surfaces.erase(surf_pid);
+ return;
}
+
+ AGL_DEBUG("ivi surface (id=%d, pid=%d) is created.", id, surf_pid);
+
+ m_launcher->register_surfpid(surf_pid);
+ if (m_launcher->m_rid &&
+ surf_pid == m_launcher->find_surfpid_by_rid(m_launcher->m_rid)) {
+ setup_surface(id);
+ }
+ m_surfaces[surf_pid] = id;
+ } else if (object == ILM_LAYER) {
+ if (created)
+ AGL_DEBUG("ivi layer: %d created.", id);
+ else
+ AGL_DEBUG("ivi layer: %d destroyed.", id);
+ }
}
void RunXDG::notify_ivi_control_cb_static (ilmObjectType object, t_ilm_uint id,
t_ilm_bool created, void *user_data)
{
- RunXDG *runxdg = static_cast<RunXDG*>(user_data);
- runxdg->notify_ivi_control_cb(object, id, created);
+ RunXDG *runxdg = static_cast<RunXDG*>(user_data);
+ runxdg->notify_ivi_control_cb(object, id, created);
}
int POSIXLauncher::launch (std::string& name)
{
- pid_t pid;
+ pid_t pid;
- pid = fork();
- if (pid < 0) {
- AGL_DEBUG("cannot fork()");
- return -1;
- }
+ pid = fork();
+ if (pid < 0) {
+ AGL_DEBUG("cannot fork()");
+ return -1;
+ }
- if (pid == 0) {
- // child
- const char **argv = new const char * [m_args_v.size() + 1];
- for (unsigned int i = 0; i < m_args_v.size(); ++i) {
- AGL_DEBUG("argv[%d]=[%s]", i, m_args_v[i].c_str());
- argv[i] = m_args_v[i].c_str();
- }
- argv[m_args_v.size()] = NULL;
+ if (pid == 0) {
+ // child
+ const char **argv = new const char * [m_args_v.size() + 1];
+ for (unsigned int i = 0; i < m_args_v.size(); ++i) {
+ argv[i] = m_args_v[i].c_str();
+ }
+ argv[m_args_v.size()] = NULL;
- execv(argv[0], (char **)argv);
+ execv(argv[0], (char **)argv);
- AGL_DEBUG("fail to execve()");
- exit(EXIT_FAILURE);
- } else {
- AGL_DEBUG("fork [%s],pid=%d", m_args_v[0], pid);
- }
+ AGL_FATAL("fail to execve(%s)", argv[0]);
+ }
+ // parent
- return pid;
+ return pid;
}
-void POSIXLauncher::loop (volatile sig_atomic_t* e_flag_p)
+void POSIXLauncher::loop (volatile sig_atomic_t& e_flag)
{
- int status;
- pid_t ret;
+ int status;
+ pid_t ret;
+ while (!e_flag) {
ret = waitpid(m_rid, &status, 0);
if (ret < 0) {
- AGL_DEBUG("fail to waitpid(%d)", m_rid);
- return;
+ if (errno == EINTR) {
+ AGL_DEBUG("catch EINTR while waitpid()");
+ continue;
+ }
+ break;
}
+ }
+ if (ret > 0) {
if (WIFEXITED(status)) {
- AGL_DEBUG("%s terminated, return %d", m_args_v[0].c_str(),
- WEXITSTATUS(status));
+ AGL_DEBUG("%s terminated, return %d", m_args_v[0].c_str(),
+ WEXITSTATUS(status));
}
-
if (WIFSIGNALED(status)) {
- AGL_DEBUG("%s terminated by signal %d", m_args_v[0].c_str(),
- WTERMSIG(status));
+ AGL_DEBUG("%s terminated by signal %d", m_args_v[0].c_str(),
+ WTERMSIG(status));
}
+ }
+
+ if (e_flag) {
+ /* parent killed by someone, so need to kill children */
+ AGL_DEBUG("killpg(0, SIGTERM)");
+ killpg(0, SIGTERM);
+ }
}
int AFMDBusLauncher::get_dbus_message_bus (GBusType bus_type,
GDBusConnection * &conn)
{
- GError* err = NULL;
+ GError* err = NULL;
- conn = g_bus_get_sync(bus_type, NULL, &err);
- if (err) {
- AGL_WARN("Failed to get session bus: %s", err->message);
- g_clear_error (&err);
- return -1;
- }
+ conn = g_bus_get_sync(bus_type, NULL, &err);
+ if (err) {
+ AGL_WARN("Failed to get session bus: %s", err->message);
+ g_clear_error (&err);
+ return -1;
+ }
- return 0;
+ return 0;
}
int AFMDBusLauncher::launch (std::string &name)
{
- GDBusMessage* msg;
- GDBusMessage* re;
- GDBusConnection* conn;
- GError* err = NULL;
- GVariant* body;
- char* val;
- const char* xdg_app = name.c_str();
-
- if (get_dbus_message_bus(G_BUS_TYPE_SESSION, conn)) {
- return -1;
- }
+ GDBusMessage* msg;
+ GDBusMessage* re;
+ GDBusConnection* conn;
+ GError* err = NULL;
+ GVariant* body;
+ char* val;
+ const char* xdg_app = name.c_str();
+
+ if (get_dbus_message_bus(G_BUS_TYPE_SESSION, conn)) {
+ return -1;
+ }
- msg = g_dbus_message_new_method_call (
- DBUS_SERVICE,
- DBUS_PATH,
- DBUS_INTERFACE,
- "start");
+ msg = g_dbus_message_new_method_call (
+ DBUS_SERVICE,
+ DBUS_PATH,
+ DBUS_INTERFACE,
+ "start");
- if (msg == NULL) {
- AGL_WARN("Failed to allocate the dbus message");
- g_object_unref(conn);
- return -1;
- }
+ if (msg == NULL) {
+ AGL_WARN("Failed to allocate the dbus message");
+ g_object_unref(conn);
+ return -1;
+ }
- g_dbus_message_set_body(msg, g_variant_new("(s)", xdg_app));
+ g_dbus_message_set_body(msg, g_variant_new("(s)", xdg_app));
- re = g_dbus_connection_send_message_with_reply_sync (
- conn, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
+ re = g_dbus_connection_send_message_with_reply_sync (
+ conn, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
- if (err != NULL) {
- AGL_WARN("unable to send message: %s", err->message);
- g_clear_error(&err);
- g_object_unref(conn);
- g_object_unref(msg);
- return -1;
- }
+ if (err != NULL) {
+ AGL_WARN("unable to send message: %s", err->message);
+ g_clear_error(&err);
+ g_object_unref(conn);
+ g_object_unref(msg);
+ return -1;
+ }
- g_dbus_connection_flush_sync(conn, NULL, &err);
- if (err != NULL) {
- AGL_WARN("unable to flush message queue: %s", err->message);
- g_object_unref(conn);
- g_object_unref(msg);
- g_object_unref(re);
- return -1;
- }
+ g_dbus_connection_flush_sync(conn, NULL, &err);
+ if (err != NULL) {
+ AGL_WARN("unable to flush message queue: %s", err->message);
+ g_object_unref(conn);
+ g_object_unref(msg);
+ g_object_unref(re);
+ return -1;
+ }
- body = g_dbus_message_get_body(re);
- g_variant_get(body, "(&s)", &val);
+ body = g_dbus_message_get_body(re);
+ g_variant_get(body, "(&s)", &val);
- AGL_DEBUG("dbus message get (%s)", val);
+ AGL_DEBUG("dbus message get (%s)", val);
- pid_t rid = std::stol(std::string(val));
- AGL_DEBUG("RID = %d", rid);
+ pid_t rid = std::stol(std::string(val));
+ AGL_DEBUG("RID = %d", rid);
- g_object_unref(conn);
- g_object_unref(msg);
- g_object_unref(re);
+ g_object_unref(conn);
+ g_object_unref(msg);
+ g_object_unref(re);
- return rid;
+ return rid;
}
volatile sig_atomic_t e_flag = 0;
static void sigterm_handler (int signum)
{
- e_flag = 1;
+ e_flag = 1;
}
static void init_signal (void)
{
- struct sigaction act, info;
-
- /* Setup signal for SIGTERM */
- if (!sigaction(SIGTERM, NULL, &info)) {
- if (info.sa_handler == SIG_IGN) {
- AGL_DEBUG("SIGTERM being ignored.");
- } else if (info.sa_handler == SIG_DFL) {
- AGL_DEBUG("SIGTERM being defaulted.");
- }
- }
-
- act.sa_handler = &sigterm_handler;
- if (sigemptyset(&act.sa_mask) != 0) {
- AGL_FATAL("Cannot initialize sigaction");
- }
- act.sa_flags = 0;
-
- if (sigaction(SIGTERM, &act, &info) != 0) {
- AGL_FATAL("Cannot register signal handler for SIGTERM");
- }
+ struct sigaction act, info;
+
+ /* Setup signal for SIGTERM */
+ if (!sigaction(SIGTERM, NULL, &info)) {
+ if (info.sa_handler == SIG_IGN) {
+ AGL_DEBUG("SIGTERM being ignored.");
+ } else if (info.sa_handler == SIG_DFL) {
+ AGL_DEBUG("SIGTERM being defaulted.");
+ }
+ }
+
+ act.sa_handler = &sigterm_handler;
+ if (sigemptyset(&act.sa_mask) != 0) {
+ AGL_FATAL("Cannot initialize sigaction");
+ }
+ act.sa_flags = 0;
+
+ if (sigaction(SIGTERM, &act, &info) != 0) {
+ AGL_FATAL("Cannot register signal handler for SIGTERM");
+ }
}
int RunXDG::init_wm (void)
{
- m_wm = new LibWindowmanager();
- if (m_wm->init(m_port, m_token.c_str())) {
- AGL_DEBUG("cannot initialize windowmanager");
- return -1;
- }
-
- std::function< void(json_object*) > h_active = [](json_object* object) {
- AGL_DEBUG("Got Event_Active");
- };
-
- std::function< void(json_object*) > h_inactive = [](json_object* object) {
- AGL_DEBUG("Got Event_Inactive");
- };
-
- std::function< void(json_object*) > h_visible = [](json_object* object) {
- AGL_DEBUG("Got Event_Visible");
- };
-
- std::function< void(json_object*) > h_invisible = [](json_object* object) {
- AGL_DEBUG("Got Event_Invisible");
- };
-
- std::function< void(json_object*) > h_syncdraw =
- [this](json_object* object) {
- AGL_DEBUG("Got Event_SyncDraw");
- json_object* obj = json_object_new_object();
- json_object_object_add(obj, this->m_wm->kKeyDrawingName,
- json_object_new_string(this->m_name.c_str()));
- this->m_wm->endDraw(obj);
- };
-
- std::function< void(json_object*) > h_flushdraw= [](json_object* object) {
- AGL_DEBUG("Got Event_FlushDraw");
- };
-
- m_wm->set_event_handler(LibWindowmanager::Event_Active, h_active);
- m_wm->set_event_handler(LibWindowmanager::Event_Inactive, h_inactive);
- m_wm->set_event_handler(LibWindowmanager::Event_Visible, h_visible);
- m_wm->set_event_handler(LibWindowmanager::Event_Invisible, h_invisible);
- m_wm->set_event_handler(LibWindowmanager::Event_SyncDraw, h_syncdraw);
- m_wm->set_event_handler(LibWindowmanager::Event_FlushDraw, h_flushdraw);
-
- return 0;
+ m_wm = new LibWindowmanager();
+ if (m_wm->init(m_port, m_token.c_str())) {
+ AGL_DEBUG("cannot initialize windowmanager");
+ return -1;
+ }
+
+ std::function< void(json_object*) > h_active = [](json_object* object) {
+ AGL_DEBUG("Got Event_Active");
+ };
+
+ std::function< void(json_object*) > h_inactive = [](json_object* object) {
+ AGL_DEBUG("Got Event_Inactive");
+ };
+
+ std::function< void(json_object*) > h_visible = [](json_object* object) {
+ AGL_DEBUG("Got Event_Visible");
+ };
+
+ std::function< void(json_object*) > h_invisible = [](json_object* object) {
+ AGL_DEBUG("Got Event_Invisible");
+ };
+
+ std::function< void(json_object*) > h_syncdraw =
+ [this](json_object* object) {
+ AGL_DEBUG("Got Event_SyncDraw");
+ json_object* obj = json_object_new_object();
+ json_object_object_add(obj, this->m_wm->kKeyDrawingName,
+ json_object_new_string(this->m_name.c_str()));
+ this->m_wm->endDraw(obj);
+ };
+
+ std::function< void(json_object*) > h_flushdraw= [](json_object* object) {
+ AGL_DEBUG("Got Event_FlushDraw");
+ };
+
+ m_wm->set_event_handler(LibWindowmanager::Event_Active, h_active);
+ m_wm->set_event_handler(LibWindowmanager::Event_Inactive, h_inactive);
+ m_wm->set_event_handler(LibWindowmanager::Event_Visible, h_visible);
+ m_wm->set_event_handler(LibWindowmanager::Event_Invisible, h_invisible);
+ m_wm->set_event_handler(LibWindowmanager::Event_SyncDraw, h_syncdraw);
+ m_wm->set_event_handler(LibWindowmanager::Event_FlushDraw, h_flushdraw);
+
+ return 0;
}
int RunXDG::init_hs (void)
{
- m_hs = new LibHomeScreen();
- if (m_hs->init(m_port, m_token.c_str())) {
- AGL_DEBUG("cannot initialize homescreen");
- return -1;
- }
+ m_hs = new LibHomeScreen();
+ if (m_hs->init(m_port, m_token.c_str())) {
+ AGL_DEBUG("cannot initialize homescreen");
+ return -1;
+ }
- std::function< void(json_object*) > handler = [this] (json_object* object) {
- json_object *val;
+ std::function< void(json_object*) > handler = [this] (json_object* object) {
+ json_object *val;
- if (json_object_object_get_ex(object, "application_name", &val)) {
- const char *name = json_object_get_string(val);
+ if (json_object_object_get_ex(object, "application_name", &val)) {
+ const char *name = json_object_get_string(val);
- AGL_DEBUG("Event_TapShortcut <%s>", name);
+ AGL_DEBUG("Event_TapShortcut <%s>", name);
- if (strcmp(name, this->m_name.c_str()) == 0) {
- // check app exist and re-launch if needed
- AGL_DEBUG("Activesurface %s ", this->m_name.c_str());
+ if (strcmp(name, this->m_name.c_str()) == 0) {
+ // check app exist and re-launch if needed
+ AGL_DEBUG("Activesurface %s ", this->m_name.c_str());
- json_object *obj = json_object_new_object();
- json_object_object_add(obj, this->m_wm->kKeyDrawingName,
- json_object_new_string(this->m_name.c_str()));
- json_object_object_add(obj, this->m_wm->kKeyDrawingArea,
- json_object_new_string("normal.full"));
+ json_object *obj = json_object_new_object();
+ json_object_object_add(obj, this->m_wm->kKeyDrawingName,
+ json_object_new_string(this->m_name.c_str()));
+ json_object_object_add(obj, this->m_wm->kKeyDrawingArea,
+ json_object_new_string("normal.full"));
- this->m_wm->activateSurface(obj);
- }
- }
- };
- m_hs->set_event_handler(LibHomeScreen::Event_TapShortcut, handler);
+ this->m_wm->activateSurface(obj);
+ }
+ }
+ };
+ m_hs->set_event_handler(LibHomeScreen::Event_TapShortcut, handler);
- std::function< void(json_object*) > h_default= [](json_object* object) {
- const char *j_str = json_object_to_json_string(object);
- AGL_DEBUG("Got event [%s]", j_str);
- };
- m_hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, h_default);
+ std::function< void(json_object*) > h_default= [](json_object* object) {
+ const char *j_str = json_object_to_json_string(object);
+ AGL_DEBUG("Got event [%s]", j_str);
+ };
+ m_hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, h_default);
- return 0;
+ return 0;
}
int RunXDG::parse_config (const char *path_to_config)
{
- auto config = cpptoml::parse_file(path_to_config);
-
- if (config == nullptr) {
- AGL_DEBUG("cannot parse %s", path_to_config);
- return -1;
- }
+ auto config = cpptoml::parse_file(path_to_config);
- AGL_DEBUG("[%s] parsed", path_to_config);
-
- auto app = config->get_table("application");
- if (app == nullptr) {
- AGL_DEBUG("cannto find [application]");
- return -1;
- }
-
- m_name = *(app->get_as<std::string>("name"));
- m_path = *(app->get_as<std::string>("path"));
- if (m_name.empty() || m_path.empty()) {
- AGL_FATAL("No name or path defined in config");
- }
-
- std::string method = *(app->get_as<std::string>("method"));
- if (method.empty()) {
- method = std::string("POSIX");
- }
-
- POSIXLauncher *pl;
-
- /* Setup API of launcher */
- if (method == "POSIX") {
- pl = new POSIXLauncher();
- m_launcher = pl;
- } else if (method == "AFM_DBUS") {
- m_launcher = new AFMDBusLauncher();
- return 0;
- } else if (method == "AFM_WEBSOCKET") {
- m_launcher = new AFMWebSocketLauncher();
- return 0;
- } else {
- AGL_FATAL("Unknown type of launcher");
- }
-
- // setup argv[0]
- pl->m_args_v.push_back(m_path);
+ if (config == nullptr) {
+ AGL_DEBUG("cannot parse %s", path_to_config);
+ return -1;
+ }
- // setup argv[1..n]
- auto params = app->get_array_of<std::string>("params");
- for (const auto& param : *params)
- {
- pl->m_args_v.push_back(param);
- AGL_DEBUG("params[%s]", param.c_str());
- }
+ AGL_DEBUG("[%s] parsed", path_to_config);
+ auto app = config->get_table("application");
+ if (app == nullptr) {
+ AGL_DEBUG("cannto find [application]");
+ return -1;
+ }
+
+ m_name = *(app->get_as<std::string>("name"));
+ m_path = *(app->get_as<std::string>("path"));
+ if (m_name.empty() || m_path.empty()) {
+ AGL_FATAL("No name or path defined in config");
+ }
+
+ std::string method = *(app->get_as<std::string>("method"));
+ if (method.empty()) {
+ method = std::string("POSIX");
+ }
+
+ POSIXLauncher *pl;
+
+ /* Setup API of launcher */
+ if (method == "POSIX") {
+ pl = new POSIXLauncher();
+ m_launcher = pl;
+ } else if (method == "AFM_DBUS") {
+ m_launcher = new AFMDBusLauncher();
+ return 0;
+ } else if (method == "AFM_WEBSOCKET") {
+ m_launcher = new AFMWebSocketLauncher();
return 0;
+ } else {
+ AGL_FATAL("Unknown type of launcher");
+ }
+
+ // setup argv[0]
+ pl->m_args_v.push_back(m_path);
+
+ // setup argv[1..n]
+ auto params = app->get_array_of<std::string>("params");
+ for (const auto& param : *params)
+ {
+ pl->m_args_v.push_back(param);
+ AGL_DEBUG("params[%s]", param.c_str());
+ }
+
+ return 0;
}
-RunXDG::RunXDG (enum launcher_t type, int port, const char* token,
- const char* id)
+RunXDG::RunXDG (int port, const char* token, const char* id)
{
- m_id = std::string(id);
- m_port = port;
- m_token = std::string(token);
+ m_id = std::string(id);
+ m_port = port;
+ m_token = std::string(token);
- auto path = std::string(getenv("AFM_APP_INSTALL_DIR"));
- path = path + "/" + RUNXDG_CONFIG;
+ auto path = std::string(getenv("AFM_APP_INSTALL_DIR"));
+ path = path + "/" + RUNXDG_CONFIG;
- // Parse config file of runxdg
- if (parse_config(path.c_str())) {
- AGL_FATAL("Error in config");
- }
+ // Parse config file of runxdg
+ if (parse_config(path.c_str())) {
+ AGL_FATAL("Error in config");
+ }
- AGL_DEBUG("id=[%s], name=[%s], path=[%s], port=%lu, token=[%s]",
- m_id.c_str(), m_name.c_str(), m_path.c_str(),
- m_port, m_token.c_str());
+ AGL_DEBUG("id=[%s], name=[%s], path=[%s], port=%lu, token=[%s]",
+ m_id.c_str(), m_name.c_str(), m_path.c_str(),
+ m_port, m_token.c_str());
- // Setup HomeScreen/WindowManager API
- if (init_wm())
- AGL_FATAL("cannot setup wm API");
+ // Setup HomeScreen/WindowManager API
+ if (init_wm())
+ AGL_FATAL("cannot setup wm API");
- if (init_hs())
- AGL_FATAL("cannot setup hs API");
+ if (init_hs())
+ AGL_FATAL("cannot setup hs API");
- // Setup ilmController API
- m_ic = new ILMControl(notify_ivi_control_cb_static, this);
+ // Setup ilmController API
+ m_ic = new ILMControl(notify_ivi_control_cb_static, this);
- AGL_DEBUG("RunXDG created.");
+ AGL_DEBUG("RunXDG created.");
}
void RunXDG::setup_surface (int id)
{
- std::string sid = std::to_string(id);
+ std::string sid = std::to_string(id);
+
+ // This surface is mine, register pair app_name and ivi id.
+ json_object *obj = json_object_new_object();
+ json_object_object_add(obj, m_wm->kKeyDrawingName,
+ json_object_new_string(m_name.c_str()));
+ json_object_object_add(obj, m_wm->kKeyIviId,
+ json_object_new_string(sid.c_str()));
+
+ AGL_DEBUG("requestSurfaceXDG(%s,%s)", m_name.c_str(), sid.c_str());
+ m_wm->requestSurfaceXDG(obj);
+
+ if (m_pending_create) {
+ // Recovering 1st time tap_shortcut is dropped because
+ // the application has not been run yet (1st time launch)
+ m_pending_create = false;
- // This surface is mine, register pair app_name and ivi id.
json_object *obj = json_object_new_object();
json_object_object_add(obj, m_wm->kKeyDrawingName,
json_object_new_string(m_name.c_str()));
- json_object_object_add(obj, m_wm->kKeyIviId,
- json_object_new_string(sid.c_str()));
- AGL_DEBUG("requestSurfaceXDG(%s,%s)", m_name.c_str(), sid.c_str());
- m_wm->requestSurfaceXDG(obj);
-
- if (m_pending_create) {
- // Recovering 1st time tap_shortcut is dropped because
- // the application has not been run yet (1st time launch)
- m_pending_create = false;
-
- json_object *obj = json_object_new_object();
- json_object_object_add(obj, m_wm->kKeyDrawingName,
- json_object_new_string(m_name.c_str()));
- json_object_object_add(obj, m_wm->kKeyDrawingArea,
- json_object_new_string("normal.full"));
- m_wm->activateSurface(obj);
- }
+ json_object_object_add(obj, m_wm->kKeyDrawingArea,
+ json_object_new_string("normal.full"));
+ m_wm->activateSurface(obj);
+ }
}
void POSIXLauncher::register_surfpid (pid_t surf_pid)
{
- if (surf_pid == m_rid) {
- if (!std::count(m_pid_v.begin(), m_pid_v.end(), surf_pid)) {
- AGL_DEBUG("surface creator(pid=%d) registered", surf_pid);
- m_pid_v.push_back(surf_pid);
- AGL_DEBUG("m_pid_v.count(%d) = %d", surf_pid,
- std::count(m_pid_v.begin(), m_pid_v.end(), surf_pid));
- }
- }
+ if (surf_pid == m_rid) {
+ if (!std::count(m_pid_v.begin(), m_pid_v.end(), surf_pid)) {
+ AGL_DEBUG("surface creator(pid=%d) registered", surf_pid);
+ m_pid_v.push_back(surf_pid);
+ AGL_DEBUG("m_pid_v.count(%d) = %d", surf_pid,
+ std::count(m_pid_v.begin(), m_pid_v.end(), surf_pid));
+ }
+ }
}
void POSIXLauncher::unregister_surfpid (pid_t surf_pid)
{
- auto itr = m_pid_v.begin();
- while (itr != m_pid_v.end()) {
- if (*itr == surf_pid) {
- m_pid_v.erase(itr++);
- } else {
- ++itr;
- }
+ auto itr = m_pid_v.begin();
+ while (itr != m_pid_v.end()) {
+ if (*itr == surf_pid) {
+ m_pid_v.erase(itr++);
+ } else {
+ ++itr;
}
+ }
}
pid_t POSIXLauncher::find_surfpid_by_rid (pid_t rid)
{
- AGL_DEBUG("find surfpid by rid(%d)", rid);
- if (std::count(m_pid_v.begin(), m_pid_v.end(), rid)) {
- AGL_DEBUG("found return(%d)", rid);
- return rid;
- }
+ AGL_DEBUG("find surfpid by rid(%d)", rid);
+ if (std::count(m_pid_v.begin(), m_pid_v.end(), rid)) {
+ AGL_DEBUG("found return(%d)", rid);
+ return rid;
+ }
- AGL_DEBUG("Not found");
- return -1;
+ return -1;
}
void AFMLauncher::register_surfpid (pid_t surf_pid)
{
- pid_t pgid = 0;
+ pid_t pgid = 0;
- pgid = getpgid(surf_pid);
+ pgid = getpgid(surf_pid);
- if (pgid < 0) {
- AGL_DEBUG("fail to get process group id");
- return;
- }
+ if (pgid < 0) {
+ AGL_DEBUG("fail to get process group id");
+ return;
+ }
- AGL_DEBUG("Surface creator is pid=%d, pgid=%d", surf_pid, pgid);
+ AGL_DEBUG("Surface creator is pid=%d, pgid=%d", surf_pid, pgid);
- if (!m_pgids.count(pgid)) {
- m_pgids[pgid] = surf_pid;
- }
+ if (!m_pgids.count(pgid)) {
+ m_pgids[pgid] = surf_pid;
+ }
}
void AFMLauncher::unregister_surfpid (pid_t surf_pid)
{
- auto itr = m_pgids.begin();
- while (itr != m_pgids.end()) {
- if (itr->second == surf_pid) {
- m_pgids.erase(itr++);
- } else {
- ++itr;
- }
+ auto itr = m_pgids.begin();
+ while (itr != m_pgids.end()) {
+ if (itr->second == surf_pid) {
+ m_pgids.erase(itr++);
+ } else {
+ ++itr;
}
+ }
}
pid_t AFMLauncher::find_surfpid_by_rid (pid_t rid)
{
auto itr = m_pgids.find(rid);
if (itr != m_pgids.end())
- return itr->second;
+ return itr->second;
return -1;
}
void RunXDG::start (void)
{
- // Initialize SIGTERM handler
- init_signal();
-
- /* Launch XDG application */
- pid_t rid;
+ // Initialize SIGTERM handler
+ init_signal();
- rid = m_launcher->launch(m_id);
- if (rid < 0) {
- AGL_FATAL("cannot launch XDG app (%s)", m_id);
- }
- m_launcher->m_rid = rid;
+ /* Launch XDG application */
+ m_launcher->m_rid = m_launcher->launch(m_id);
+ if (m_launcher->m_rid < 0) {
+ AGL_FATAL("cannot launch XDG app (%s)", m_id);
+ }
- // take care 1st time launch
- AGL_DEBUG("waiting for notification: surafce created");
- m_pending_create = true;
+ // take care 1st time launch
+ AGL_DEBUG("waiting for notification: surafce created");
+ m_pending_create = true;
- // in case, target app has already run
+ // in case, target app has already run
+ if (m_launcher->m_rid) {
pid_t surf_pid = m_launcher->find_surfpid_by_rid(m_launcher->m_rid);
if (surf_pid > 0) {
- AGL_DEBUG("match: surf:pid=%d, afm:rid=%d", surf_pid,
- m_launcher->m_rid);
- auto itr = m_surfaces.find(surf_pid);
- if (itr != m_surfaces.end()) {
- int id = itr->second;
- AGL_DEBUG("surface %d for <%s> already exists", id,
- m_name.c_str());
- setup_surface(id);
- }
- }
-
- m_launcher->loop(&e_flag);
-
- if (e_flag) {
- AGL_DEBUG("recieved SIGTERM");
- }
+ AGL_DEBUG("match: surf:pid=%d, afm:rid=%d", surf_pid,
+ m_launcher->m_rid);
+ auto itr = m_surfaces.find(surf_pid);
+ if (itr != m_surfaces.end()) {
+ int id = itr->second;
+ AGL_DEBUG("surface %d for <%s> already exists", id,
+ m_name.c_str());
+ setup_surface(id);
+ }
+ }
+ }
+ m_launcher->loop(e_flag);
}
int main (int argc, const char* argv[])
{
- AGL_DEBUG("[%s]", argv[0]);
-
- // Set debug flags
- setenv("USE_HMI_DEBUG", "5", 1);
- // setenv("WAYLAND_DEBUG", "1", 1);
-
- // Parse args
- int port;
- const char *token;
-
- if (argc < 3) {
- AGL_FATAL("Missing port and token");
- }
-
- // Get app id
- const char *afm_id = getenv("AFM_ID");
- if (afm_id == NULL || !afm_id[0]) {
- afm_id = argv[0];
- }
-
- try {
- port = std::stol(argv[1]);
- token = argv[2];
- } catch (const std::invalid_argument& e) {
- AGL_FATAL("Invalid argument");
- } catch (const std::out_of_range& e) {
- AGL_FATAL("Out of range");
- }
-
- RunXDG runxdg(POSIX, port, token, afm_id);
-
- runxdg.start();
-
- AGL_DEBUG("terminated.\n");
-
- return 0;
+ // Set debug flags
+ // setenv("USE_HMI_DEBUG", "5", 1);
+ // setenv("WAYLAND_DEBUG", "1", 1);
+
+ // Parse args
+ int port;
+ const char *token;
+
+ if (argc < 3) {
+ AGL_FATAL("Missing port and token");
+ }
+
+ // Get app id
+ const char *afm_id = getenv("AFM_ID");
+ if (afm_id == NULL || !afm_id[0]) {
+ afm_id = argv[0];
+ }
+
+ try {
+ port = std::stol(argv[1]);
+ token = argv[2];
+ } catch (const std::invalid_argument& e) {
+ AGL_FATAL("Invalid argument");
+ } catch (const std::out_of_range& e) {
+ AGL_FATAL("Out of range");
+ }
+
+ RunXDG runxdg(port, token, afm_id);
+
+ runxdg.start();
+
+ return 0;
}
-
diff --git a/xdg-launcher/src/runxdg.hpp b/xdg-launcher/src/runxdg.hpp
index c98b95c..ca1e25a 100644
--- a/xdg-launcher/src/runxdg.hpp
+++ b/xdg-launcher/src/runxdg.hpp
@@ -58,12 +58,6 @@ class ILMControl
}
};
-enum launcher_t {
- POSIX,
- AFM_DBUS,
- AFM_WEBSOCKET,
-};
-
class Launcher
{
public:
@@ -72,9 +66,9 @@ class Launcher
virtual pid_t find_surfpid_by_rid(pid_t app_pid) = 0;
virtual int launch(std::string& name) = 0;
- virtual void loop(volatile sig_atomic_t* e_flag) = 0;
+ virtual void loop(volatile sig_atomic_t& e_flag) = 0;
- int m_rid = -1;
+ int m_rid = 0;
};
class POSIXLauncher : public Launcher
@@ -90,7 +84,7 @@ class POSIXLauncher : public Launcher
pid_t find_surfpid_by_rid(pid_t rid);
int launch(std::string& name);
- void loop(volatile sig_atomic_t* e_flag);
+ void loop(volatile sig_atomic_t& e_flag);
};
class AFMLauncher : public Launcher
@@ -108,8 +102,8 @@ class AFMDBusLauncher : public AFMLauncher
{
public:
int launch(std::string& name);
- void loop(volatile sig_atomic_t* e_flag) {
- while (!(*e_flag)) { sleep(60*60*24); } }
+ void loop(volatile sig_atomic_t& e_flag) {
+ while (!(e_flag)) { sleep(60*60*24); } }
private:
int get_dbus_message_bus(GBusType bus_type, GDBusConnection* &conn);
@@ -124,14 +118,14 @@ class AFMWebSocketLauncher : public AFMLauncher
// not implemented yet
public:
int launch(std::string& name) { return 0; }
- void loop(volatile sig_atomic_t* e_flag) {
- while (!(*e_flag)) { sleep(60*60*24); } }
+ void loop(volatile sig_atomic_t& e_flag) {
+ while (!(e_flag)) { sleep(60*60*24); } }
};
class RunXDG
{
public:
- RunXDG(enum launcher_t type, int port, const char* token, const char* id);
+ RunXDG(int port, const char* token, const char* id);
void start(void);
void notify_ivi_control_cb(ilmObjectType object, t_ilm_uint id,