2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <sys/types.h>
23 #include "stc-plugin-popup.h"
24 #include "stc-error.h"
25 #include "stc-manager-util.h"
27 #define APP_LAUNCHER_EXEC_PATH "/usr/bin/app_launcher"
28 #define STC_POPUP_PACKAGE_NAME "net.stc-popup"
30 #define MAX_SIZE_ERROR_BUFFER 256
31 #define STC_POPUP_START_TIMER 10
33 static void _no_wait_signal_handler(int sig)
38 child_pid = waitpid(-1, &state, WNOHANG);
40 STC_LOGD("child_id(%d) state(%d)", child_pid, WEXITSTATUS(state));
43 static int _execute_file_no_wait(const char *file_path, char *const args[])
48 register unsigned int index = 0;
52 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
54 act.sa_handler = _no_wait_signal_handler;
55 sigemptyset(&act.sa_mask);
58 state = sigaction(SIGCHLD, &act, 0);
60 STC_LOGD("sigaction() : %d");
64 while (args[index] != NULL) {
65 STC_LOGD("%s", args[index]);
69 if (!(pid = fork())) {
70 STC_LOGD("pid(%d), ppid (%d)", getpid(), getppid());
71 STC_LOGD("Inside child, exec (%s) command", file_path);
74 if (execvp(file_path, args) == -1) {
75 STC_LOGE("Fail to execute command (%s)",
76 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
80 STC_LOGE("Successfully launched child process");
84 STC_LOGD("failed to fork(%s)",
85 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
89 static gboolean _start_stc_popup(gpointer user_data)
91 gboolean *launched = (gboolean *)user_data;
93 const char *start_path = APP_LAUNCHER_EXEC_PATH;
94 char *const start_args[] = { APP_LAUNCHER_EXEC_PATH, "-s",
95 STC_POPUP_PACKAGE_NAME, NULL };
97 ret = _execute_file_no_wait(start_path, start_args);
99 STC_LOGD("Failed to launch stc-popup, ret : %d", ret);
108 int stc_plugin_popup_initialize(void)
110 static gboolean stc_popup_launched = FALSE;
112 if (stc_popup_launched == FALSE)
113 g_timeout_add_seconds(STC_POPUP_START_TIMER, _start_stc_popup,
114 &stc_popup_launched);
116 return STC_ERROR_FAIL;
118 return STC_ERROR_NONE;
121 int stc_plugin_popup_deinitialize(void)
123 /* close stc popup application */
124 return STC_ERROR_NONE;
127 int stc_plugin_popup_show(const char *content, const char *type,
128 const char *app_id, const char *iftype,
134 API stc_plugin_popup_s stc_plugin_popup = {
136 stc_plugin_popup_initialize,
137 .deinitialize_plugin =
138 stc_plugin_popup_deinitialize,
139 .show_popup = stc_plugin_popup_show