aboutsummaryrefslogtreecommitdiffstats
path: root/xdg-launcher/src/runxdg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xdg-launcher/src/runxdg.cpp')
-rw-r--r--xdg-launcher/src/runxdg.cpp164
1 files changed, 103 insertions, 61 deletions
diff --git a/xdg-launcher/src/runxdg.cpp b/xdg-launcher/src/runxdg.cpp
index 8c984b1..1480d72 100644
--- a/xdg-launcher/src/runxdg.cpp
+++ b/xdg-launcher/src/runxdg.cpp
@@ -30,27 +30,11 @@
#include <cstdio>
+#include "cpptoml/cpptoml.h"
+
#include "runxdg.hpp"
-#ifdef TARGET_APP_PATH
-std::string target_app_path(TARGET_APP_PATH);
-#else
-std::string target_app_path("/usr/bin/weston-simple-egl");
-#endif
-
-#ifdef TARGET_APP_ID
-std::string target_app_id("\"" TARGET_APP_ID "\"");
-#else
-// for test
-std::string target_app_id("\"" weston-simple-egl@0.1 "\"");
-#endif
-
-#ifdef RUNXDG_NAME
-std::string app_name(RUNXDG_NAME);
-#else
-// for test
-std::string app_name("Navigation");
-#endif
+#define RUNXDG_CONFIG "runxdg.toml"
void fatal(const char* format, ...)
{
@@ -122,7 +106,7 @@ void RunXDG::notify_ivi_control_cb_static (ilmObjectType object, t_ilm_uint id,
runxdg->notify_ivi_control_cb(object, id, created);
}
-int POSIXLauncher::launch (std::string &name)
+int POSIXLauncher::launch (std::string& name)
{
pid_t pid;
@@ -134,20 +118,19 @@ int POSIXLauncher::launch (std::string &name)
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;
- char *const argv[2] = {
- target_app_path.c_str(),
- NULL, // test
- };
-
- AGL_DEBUG("execute %s", argv[0]);
-
- execve(argv[0], argv, environ);
+ execv(argv[0], (char **)argv);
AGL_DEBUG("fail to execve()");
exit(EXIT_FAILURE);
} else {
- AGL_DEBUG("fork [%s],pid=%d", target_app_path.c_str(), pid);
+ AGL_DEBUG("fork [%s],pid=%d", m_args_v[0], pid);
}
return pid;
@@ -165,12 +148,12 @@ void POSIXLauncher::loop (volatile sig_atomic_t* e_flag_p)
}
if (WIFEXITED(status)) {
- AGL_DEBUG("%s terminated, return %d", target_app_path.c_str(),
+ AGL_DEBUG("%s terminated, return %d", m_args_v[0].c_str(),
WEXITSTATUS(status));
}
if (WIFSIGNALED(status)) {
- AGL_DEBUG("%s terminated by signal %d", target_app_path.c_str(),
+ AGL_DEBUG("%s terminated by signal %d", m_args_v[0].c_str(),
WTERMSIG(status));
}
}
@@ -313,7 +296,7 @@ int RunXDG::init_wm (void)
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(app_name.c_str()));
+ json_object_new_string(this->m_name.c_str()));
this->m_wm->endDraw(obj);
};
@@ -347,13 +330,13 @@ int RunXDG::init_hs (void)
AGL_DEBUG("Event_TapShortcut <%s>", name);
- if (strcmp(name, app_name.c_str()) == 0) {
+ if (strcmp(name, this->m_name.c_str()) == 0) {
// check app exist and re-launch if needed
- AGL_DEBUG("Activesurface %s ", app_name.c_str());
+ 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(app_name.c_str()));
+ json_object_new_string(this->m_name.c_str()));
json_object_object_add(obj, this->m_wm->kKeyDrawingArea,
json_object_new_string("normal.full"));
@@ -372,28 +355,83 @@ int RunXDG::init_hs (void)
return 0;
}
-RunXDG::RunXDG (enum launcher_t type, int port, const char* &token)
+int RunXDG::parse_config (const char *path_to_config)
{
- m_port = port;
- m_token = std::string(token);
+ auto config = cpptoml::parse_file(path_to_config);
+
+ if (config == nullptr) {
+ AGL_DEBUG("cannot parse %s", path_to_config);
+ return -1;
+ }
+
+ 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 */
- switch (type) {
- case POSIX:
- m_launcher = new POSIXLauncher();
- break;
- case AFM_DBUS:
+ if (method == "POSIX") {
+ pl = new POSIXLauncher();
+ m_launcher = pl;
+ } else if (method == "AFM_DBUS") {
m_launcher = new AFMDBusLauncher();
- break;
- case AFM_WEBSOCKET:
+ return 0;
+ } else if (method == "AFM_WEBSOCKET") {
m_launcher = new AFMWebSocketLauncher();
- break;
- default:
+ return 0;
+ } else {
AGL_FATAL("Unknown type of launcher");
- break;
}
- m_launcher->m_rid = -1;
+ // 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)
+{
+ 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;
+
+ // 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());
// Setup HomeScreen/WindowManager API
if (init_wm())
@@ -415,10 +453,10 @@ void RunXDG::setup_surface (int 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(app_name.c_str()));
+ 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("reqestSurfaceXDG(%s,%s)", app_name.c_str(), sid.c_str());
+ AGL_DEBUG("reqestSurfaceXDG(%s,%s)", m_name.c_str(), sid.c_str());
m_wm->requestSurfaceXDG(obj);
if (m_pending_create) {
@@ -428,7 +466,7 @@ void RunXDG::setup_surface (int id)
json_object *obj = json_object_new_object();
json_object_object_add(obj, m_wm->kKeyDrawingName,
- json_object_new_string(app_name.c_str()));
+ 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);
@@ -518,9 +556,9 @@ void RunXDG::start (void)
/* Launch XDG application */
pid_t rid;
- rid = m_launcher->launch(target_app_id);
+ rid = m_launcher->launch(m_id);
if (rid < 0) {
- AGL_FATAL("cannot launch XDG app (%s)", target_app_id);
+ AGL_FATAL("cannot launch XDG app (%s)", m_id);
}
m_launcher->m_rid = rid;
@@ -537,7 +575,7 @@ void RunXDG::start (void)
if (itr != m_surfaces.end()) {
int id = itr->second;
AGL_DEBUG("surface %d for <%s> already exists", id,
- app_name.c_str());
+ m_name.c_str());
setup_surface(id);
}
}
@@ -551,21 +589,26 @@ void RunXDG::start (void)
int main (int argc, const char* argv[])
{
- AGL_DEBUG("runxdg: name(%s), target(%s)", app_name.c_str(),
- target_app_id.c_str());
+ AGL_DEBUG("[%s]", argv[0]);
// Set debug flags
setenv("USE_HMI_DEBUG", "5", 1);
// setenv("WAYLAND_DEBUG", "1", 1);
// Parse args
- long port;
- const char* token;
+ 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];
@@ -575,8 +618,7 @@ int main (int argc, const char* argv[])
AGL_FATAL("Out of range");
}
- AGL_DEBUG("port=%lu, token=[%s]", port, token);
- RunXDG runxdg(POSIX, port, token);
+ RunXDG runxdg(POSIX, port, token, afm_id);
runxdg.start();