return 1;
}
+#if !GLIB_CHECK_VERSION(2, 36, 0)
g_type_init();
+#endif
/* TODO: use private bus? */
err = NULL;
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+
#include <glib.h>
+
#include <aul.h>
#include <pkgmgr-info.h>
#include "app_sock.h"
#include "simple_util.h"
+#include "amd_launch.h"
+#include "amd_app_group.h"
#define APP_SVC_K_LAUNCH_MODE "__APP_SVC_LAUNCH_MODE__"
return FALSE;
}
-static void __print_table()
-{
- GHashTableIter iter;
- gpointer key, value;
-
- g_hash_table_iter_init(&iter, app_group_hash);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- GList *list = (GList*) value;
- GList *i = g_list_first(list);
-
- while (i != NULL) {
- app_group_context_t *ac = (app_group_context_t*) i->data;
-
- _D("app_group key= %d pid=%d", (int ) key, ac->pid);
- i = g_list_next(i);
- }
- }
-
-}
-
static gboolean __is_top(int pid)
{
int cnt;
int *pids = NULL;
GList *list = NULL;
gboolean found = FALSE;
+ int i, j;
app_group_get_leader_pids(&cnt, &pids);
- int i, j;
- int lpid = -1;
-
for (i = 0; i < cnt; i++) {
int *gpids = NULL;
int gcnt;
return list;
}
-void app_group_init()
+void app_group_init(void)
{
app_group_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
NULL);
leader_pids = (int*) malloc(sizeof(int) * size);
if (leader_pids == NULL) {
_E("out of memory");
- *cnt = NULL;
+ *cnt = 0;
*pids = NULL;
return;
}
#include <glib.h>
#include <bundle.h>
+void app_group_init(void);
void app_group_add(int leader_pid, int pid, int wid);
void app_group_remove(int pid);
int app_group_get_window(int pid);
void app_group_get_group_pids(int leader_pid, int *cnt, int **pids);
gboolean app_group_is_leader_pid(int pid);
void app_group_resume(int pid);
-gboolean app_group_is_group_app(bundle* kb);
+gboolean app_group_is_group_app(bundle* kb, uid_t uid);
gboolean app_group_is_sub_app(int pid);
void app_group_reroute(int pid);
int app_group_get_caller_pid();
#include "simple_util.h"
#include "amd_appinfo.h"
#include "amd_launch.h"
+#include "amd_status.h"
#define SERVICE_GROUP "Service"
}
if (uid != GLOBAL_USER) {
- appinfo_foreach(uid, __handle_onboot, uid);
- appinfo_foreach(GLOBAL_USER, __handle_onboot, uid);
+ appinfo_foreach(uid, __handle_onboot, (void *)uid);
+ appinfo_foreach(GLOBAL_USER, __handle_onboot, (void *)uid);
}
_D("loaded appinfo table for uid %d", uid);
static void _appinfo_insert_on_event(uid_t uid, const char *pkgid)
{
appinfo_insert(uid, pkgid);
- appinfo_foreach(uid, __handle_onboot, uid);
+ appinfo_foreach(uid, __handle_onboot, (void *)uid);
}
static int __package_event_cb(uid_t target_uid, int req_id,
_E("appinfo init failed: %s", strerror(errno));
return -1;
}
- fgets(buf, sizeof(buf), fp);
- tmp = strstr(buf, "gles");
- if(tmp != NULL) {
- sscanf(tmp,"gles=%d", &gles);
+
+ if (fgets(buf, sizeof(buf), fp) != NULL) {
+ tmp = strstr(buf, "gles");
+ if (tmp != NULL)
+ sscanf(tmp, "gles=%d", &gles);
}
fclose(fp);
_fini_package_event_handler();
}
-const struct appinfo *appinfo_find(uid_t caller_uid, const char *appid)
+struct appinfo *appinfo_find(uid_t caller_uid, const char *appid)
{
struct user_appinfo *info;
struct appinfo *ai;
r = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, info, info->uid);
if (r != PMINFO_R_OK) {
_remove_user_appinfo(info->uid);
- return NULL;
+ return;
}
_D("reloaded appinfo table for uid %d", info->uid);
int appinfo_insert(uid_t uid, const char *pkgid);
-const struct appinfo *appinfo_find(uid_t caller_uid, const char *appid);
+struct appinfo *appinfo_find(uid_t caller_uid, const char *appid);
const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type);
int appinfo_set_value(struct appinfo *c, enum appinfo_type, const char *val);
const char *appinfo_get_filename(const struct appinfo *c);
#include "amd_launch.h"
#include "amd_appinfo.h"
#include "amd_status.h"
+#include "amd_app_group.h"
#include "app_sock.h"
#include "simple_util.h"
#include "launch.h"
char *pkg_type;
} app_info_from_pkgmgr;
-static GList *_kill_list;
-
-struct ktimer {
- pid_t pid;
- char *group;
- guint tid; /* timer ID */
-};
-
static void __set_reply_handler(int fd, int pid, int clifd, int cmd);
static void __real_send(int clifd, int ret);
static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd);
-static void _set_sdk_env(const char* appid, char* str) {
- char buf[MAX_LOCAL_BUFSZ];
- int ret;
-
- _D("key : %s / value : %s", AUL_K_SDK, str);
- /* http://gcc.gnu.org/onlinedocs/gcc/Cross_002dprofiling.html*/
- /* GCOV_PREFIX contains the prefix to add to the absolute paths in the object file. */
- /* Prefix can be absolute, or relative. The default is no prefix. */
- /* GCOV_PREFIX_STRIP indicates the how many initial directory names */
- /* to stripoff the hardwired absolute paths. Default value is 0. */
- if (strncmp(str, SDK_CODE_COVERAGE, strlen(str)) == 0) {
- snprintf(buf, MAX_LOCAL_BUFSZ, "%s/%s"PATH_DATA, PATH_APP_ROOT, appid);
- ret = setenv("GCOV_PREFIX", buf, 1);
- _D("GCOV_PREFIX : %d", ret);
- ret = setenv("GCOV_PREFIX_STRIP", "4096", 1);
- _D("GCOV_PREFIX_STRIP : %d", ret);
- } else if (strncmp(str, SDK_DYNAMIC_ANALYSIS, strlen(str)) == 0) {
- ret = setenv("LD_PRELOAD", PATH_DA_SO, 1);
- _D("LD_PRELOAD : %d", ret);
- }
-}
-
-
-static void _set_env(const char *appid, bundle * kb, const char *hwacc)
-{
- const char *str;
- const char **str_array;
- int len;
- int i;
-
- setenv("PKG_NAME", appid, 1);
-
- USE_ENGINE("gl")
-
- str = bundle_get_val(kb, AUL_K_STARTTIME);
- if (str != NULL)
- setenv("APP_START_TIME", str, 1);
-
- if(bundle_get_type(kb, AUL_K_SDK) & BUNDLE_TYPE_ARRAY) {
- str_array = bundle_get_str_array(kb, AUL_K_SDK, &len);
- if(str_array != NULL) {
- for (i = 0; i < len; i++) {
- _D("index : [%d]", i);
- _set_sdk_env(appid, (char *)str_array[i]);
- }
- }
- } else {
- str = bundle_get_val(kb, AUL_K_SDK);
- if(str != NULL) {
- _set_sdk_env(appid, (char *)str);
- }
- }
- if (hwacc != NULL)
- setenv("HWACC", hwacc, 1);
-}
-
-static void _prepare_exec(const char *appid, bundle *kb)
-{
- const struct appinfo *ai;
- const char *app_path = NULL;
- const char *pkg_type = NULL;
- char *file_name;
- char process_name[AUL_PR_NAME];
- const char *hwacc;
- int ret;
-
- setsid();
-
- signal(SIGINT, SIG_DFL);
- signal(SIGTERM, SIG_DFL);
- signal(SIGCHLD, SIG_DFL);
-
- ai = appinfo_find(getuid(), appid);
-
- app_path = appinfo_get_value(ai, AIT_EXEC);
- pkg_type = appinfo_get_value(ai, AIT_TYPE);
- hwacc = appinfo_get_value(ai, AIT_HWACC);
-
- /* SET PRIVILEGES*/
- _D("appid : %s / pkg_type : %s / app_path : %s ", appid, pkg_type, app_path);
- if ((ret = __set_access(appid, pkg_type, app_path)) < 0) {
- _D("fail to set privileges - check your package's credential : %d\n", ret);
- return;
- }
-
- /* SET DUMPABLE - for coredump*/
- prctl(PR_SET_DUMPABLE, 1);
-
- /* SET PROCESS NAME*/
- if (app_path == NULL) {
- _D("app_path should not be NULL - check menu db");
- return;
- }
- file_name = strrchr(app_path, '/') + 1;
- if (file_name == NULL) {
- _D("can't locate file name to execute");
- return;
- }
- memset(process_name, '\0', AUL_PR_NAME);
- snprintf(process_name, AUL_PR_NAME, "%s", file_name);
- prctl(PR_SET_NAME, process_name);
-
- /* SET ENVIROMENT*/
- _set_env(appid, kb, hwacc);
-
- /* TODO: do security job */
- /* TODO: setuid */
-}
-static char **__create_argc_argv(bundle * kb, int *margc)
-{
- char **argv;
- int argc;
-
- argc = bundle_export_to_argv(kb, &argv);
-
- *margc = argc;
- return argv;
-}
-
static void __set_stime(bundle *kb)
{
struct timeval tv;
bundle_add(kb, AUL_K_STARTTIME, tmp);
}
-int _start_app_local(uid_t uid, char *appid)
+int _start_app_local(uid_t uid, const char *appid)
{
int ret;
int pid;
- struct appinfo* ai;
+ const struct appinfo *ai;
bundle *kb;
const char *app_path;
const char *pkg_type;
return pid;
}
-static void _free_kt(struct ktimer *kt)
-{
- if (!kt)
- return;
- free(kt->group);
- free(kt);
-}
-
-static void _kill_pid( pid_t pid)
-{
- int r;
-
- if (pid <= INIT_PID) /* block sending to all process or init */
- return;
- /* TODO: check pid exist in group */
-
- r = kill(pid, 0);
- if (r == -1) {
- _D("send SIGKILL: pid %d not exist", pid);
- return;
- }
-
- r = kill(pid, SIGKILL);
- if (r == -1)
- _E("send SIGKILL: %s", strerror(errno));
-}
-
-static gboolean _ktimer_cb(gpointer data)
-{
- struct ktimer *kt = data;
-
- _kill_pid(kt->pid);
- _kill_list = g_list_remove(_kill_list, kt);
- _free_kt(kt);
-
- return FALSE;
-}
-
-static void _add_list(const char *group, pid_t pid)
-{
- struct ktimer *kt;
-
- kt = calloc(1, sizeof(*kt));
- if (!kt)
- return;
-
- kt->pid = pid;
- kt->group = strdup(group);
- if (!kt->group) {
- free(kt);
- return;
- }
- kt->tid = g_timeout_add_seconds(TERM_WAIT_SEC, _ktimer_cb, kt);
-
- _kill_list = g_list_append(_kill_list, kt);
-}
-
-static inline void _del_list(GList *l)
-{
- struct ktimer *kt;
-
- if (!l)
- return;
-
- kt = l->data;
-
- g_source_remove(kt->tid);
- _free_kt(kt);
- _kill_list = g_list_delete_link(_kill_list, l);
-}
-
-static int _kill_pid_cb(void *user_data, const char *group, pid_t pid)
-{
- int r;
-
- if (pid <= INIT_PID) /* block sending to all process or init */
- return 0;
-
- r = kill(pid, SIGTERM);
- if (r == -1)
- _E("send SIGTERM: %s", strerror(errno));
-
- _add_list(group, pid);
-
- return 0;
-}
-
-void service_release(const char *group)
-{
- GList *l;
- GList *d;
-
- if (!group || !*group)
- return;
-
- group = FILENAME(group);
-
- d = NULL;
- for (l = _kill_list; l; l = g_list_next(l)) {
- struct ktimer *k = l->data;
-
- _del_list(d);
-
- if (k->group && !strcmp(k->group, group))
- d = l;
- }
-
- _del_list(d);
-}
-
int _send_to_sigkill(int pid)
{
int pgid;
return ret;
}
-void _term_sub_app(int pid)
+int _term_sub_app(int pid)
{
int dummy;
int ret;
_E("terminate packet send error - use SIGKILL");
if (_send_to_sigkill(pid) < 0) {
_E("fail to killing - %d\n", pid);
- return;
+ return -1;
}
}
+
+ return 0;
}
int _term_app(int pid, int clifd)
static int __nofork_processing(int cmd, int pid, bundle * kb, int clifd)
{
- int ret = -1;
- int r;
- GPollFD *gpollfd;
- GSource *src;
- struct reply_info *r_info;
- GMainContext *reply_context;
+ int ret;
switch (cmd) {
case APP_OPEN:
_E("fake_launch failed. error code = %d", ret);
_D("fake launch done");
break;
+ default:
+ _E("unknown command: %d", cmd);
+ ret = -1;
}
return ret;
const struct appinfo *ai;
int ret = -1;
const char *status;
- const char *componet = NULL;
const char *multiple = NULL;
const char *app_path = NULL;
const char *pkg_type = NULL;
}
}
- componet = appinfo_get_value(ai, AIT_COMP);
app_path = appinfo_get_value(ai, AIT_EXEC);
pkg_type = appinfo_get_value(ai, AIT_TYPE);
permission = appinfo_get_value(ai, AIT_PERM);
}
}
- pkgmgrinfo_client_request_enable_external_pkg(pkgid);
-
multiple = appinfo_get_value(ai, AIT_MULTI);
if (!multiple || strncmp(multiple, "false", 5) == 0) {
pid = _status_app_is_running(appid, caller_uid);
int _term_app(int pid, int clifd);
int _term_req_app(int pid, int clifd);
int _term_bgapp(int pid, int clifd);
+int _term_sub_app(int pid);
int _fake_launch_app(int cmd, int pid, bundle * kb, int clifd);
int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_uid, int fd);
-int _start_app_local(uid_t uid, char *appid);
-void service_release(const char *group);
+int _start_app_local(uid_t uid, const char *appid);
#endif /* __AUL_AMD_LAUNCH_H_ */
{
__remove_item_running_list_with_uid(user);
_status_remove_app_info_list_with_uid(user);
+ return 0;
}
static int __init()
#include <string.h>
#include <dlfcn.h>
#include <poll.h>
-#include <aul.h>
+
#include <glib.h>
+
+#include <aul.h>
#include <bundle.h>
#include <tzplatform_config.h>
#include "amd_launch.h"
#include "amd_appinfo.h"
#include "amd_status.h"
-
+#include "amd_app_group.h"
#define INHOUSE_UID tzplatform_getuid(TZ_USER_NAME)
case APP_PAUSE_BY_PID:
ret = _pause_app(pid, clifd);
break;
+ default:
+ _E("unknown command: %d", cmd);
+ ret = -1;
}
return ret;
}
-static int __get_pid_cb(void *user_data, const char *group, pid_t pid)
-{
- int *sz = user_data;
-
- _D("%s: %d : %d", *sz, pid);
- *sz = 1; /* 1 is enough */
-
- return -1; /* stop the iteration */
-}
-
-static int __release_srv(uid_t caller_uid, const char *filename)
+static int __release_srv(uid_t caller_uid, const char *appid)
{
int r;
const struct appinfo *ai;
- ai = (struct appinfo *)appinfo_find(caller_uid, filename);
+ ai = (struct appinfo *)appinfo_find(caller_uid, appid);
if (!ai) {
- SECURE_LOGE("release service: '%s' not found", filename);
+ SECURE_LOGE("release service: '%s' not found", appid);
return -1;
}
r = appinfo_get_boolean(ai, AIT_RESTART);
if (r == 1) {
/* Auto restart */
- SECURE_LOGD("Auto restart set: '%s'", filename);
- return _start_app_local(ai, NULL);
+ SECURE_LOGD("Auto restart set: '%s'", appid);
+ return _start_app_local(caller_uid, appid);
}
- service_release(filename);
-
return 0;
}
static void __dispatch_app_group_get_leader_pids(int clifd,
const app_pkt_t *pkt)
{
- char *buf;
int cnt;
int *pids;
int empty[1] = { 0 };
app_group_get_leader_pids(&cnt, &pids);
if (pids == NULL || cnt == 0) {
- __send_result_data(clifd, APP_GROUP_GET_LEADER_PIDS, empty, 0);
+ __send_result_data(clifd, APP_GROUP_GET_LEADER_PIDS,
+ (unsigned char *)empty, 0);
} else {
- __send_result_data(clifd, APP_GROUP_GET_LEADER_PIDS, pids,
- cnt * sizeof(int));
+ __send_result_data(clifd, APP_GROUP_GET_LEADER_PIDS,
+ (unsigned char *)pids, cnt * sizeof(int));
}
if (pids != NULL)
free(pids);
app_group_get_group_pids(leader_pid, &cnt, &pids);
if (pids == NULL || cnt == 0) {
- __send_result_data(clifd, APP_GROUP_GET_GROUP_PIDS, empty, 0);
+ __send_result_data(clifd, APP_GROUP_GET_GROUP_PIDS,
+ (unsigned char *)empty, 0);
} else {
- __send_result_data(clifd, APP_GROUP_GET_GROUP_PIDS, pids,
- cnt * sizeof(int));
+ __send_result_data(clifd, APP_GROUP_GET_GROUP_PIDS,
+ (unsigned char *)pids, cnt * sizeof(int));
}
if (pids != NULL)
free(pids);
bundle *kb = NULL;
item_pkt_t *item;
pkt_t *pkt_uid;
- const struct appinfo *ai;
+ struct appinfo *ai;
if ((pkt = __app_recv_raw(fd, &clifd, &cr)) == NULL) {
_E("recv error");
case APP_RELEASED:
appid = malloc(MAX_PACKAGE_STR_SIZE);
strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1);
- ret = __release_srv(cr.uid,appid);
+ ret = __release_srv(cr.uid, appid);
__send_result_to_client(clifd, ret);
free(appid);
break;
GSList *app_status_info_list = NULL;
-int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid, uid_t uid)
+int _status_add_app_info_list(const char *appid, const char *app_path, int pid, int pad_pid, uid_t uid)
{
GSList *iter;
GSList *iter_next;
return -1;
}
-int _status_app_is_running(char *appid, uid_t uid)
+int _status_app_is_running(const char *appid, uid_t uid)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
return 0;
}
-int _status_app_is_running_v2(char *appid, uid_t caller_uid)
+int _status_app_is_running_v2(const char *appid, uid_t caller_uid)
{
- char *apppath = NULL;
- int ret = 0;
+ char *apppath;
+ int ret;
int i = 0;
- const struct appinfo *ai;
+ struct appinfo *ai;
- if(appid == NULL)
+ if (appid == NULL)
return -1;
ai = appinfo_find(caller_uid, appid);
-int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid, uid_t uid);
+int _status_add_app_info_list(const char *appid, const char *app_path, int pid, int pad_pid, uid_t uid);
int _status_update_app_info_list(int pid, int status, uid_t uid);
+int _status_remove_app_info_list_with_uid(uid_t uid);
int _status_remove_app_info_list(int pid, uid_t uid);
int _status_get_app_info_status(int pid, uid_t uid);
int _status_send_running_appinfo(int fd, uid_t uid);
-int _status_app_is_running(char *appid, uid_t uid);
-int _status_app_is_running_v2(char *appid, uid_t caller_uid);
+int _status_app_is_running(const char *appid, uid_t uid);
+int _status_app_is_running_v2(const char *appid, uid_t caller_uid);
char *_status_app_get_appid_bypid(int pid);
int _status_send_running_appinfo_v2(int fd); //depcrecated
int _status_get_appid_bypid(int fd, int pid);
{
struct rua_rec rec;
- rec.pkg_name = pkg_name;
- rec.app_path = app_path;
- rec.arg = arg;
+ rec.pkg_name = (char *)pkg_name;
+ rec.app_path = (char *)app_path;
+ rec.arg = (char *)arg;
if (rua_add_history(&rec))
_E("rua add history error");
}
}
__send_dead_siganl_to_amd();
+
+ return 0;
}
printf("... successfully launched pid = %d with debug %d\n",
pid, launch_arg_data->flag_debug);
if (launch_arg_data->sync) {
- aul_listen_app_dead_signal(__launch_app_dead_handler, pid);
+ aul_listen_app_dead_signal(__launch_app_dead_handler, (void *)pid);
return FALSE;
}
} else {
char *appid;
if (pkgmgrinfo_appinfo_get_label(handle, &label)) {
- printf("Failed to get pkgid\n");
+ printf("Failed to get app label\n");
return -1;
}
int aul_set_subapp(subapp_fn cb, void *data);
int aul_subapp_terminate_request_pid(int pid);
int aul_is_subapp(void);
+int aul_kill_pid(int pid);
typedef int (*data_control_provider_handler_fn) (bundle *b, int request_id, void *data);
int aul_set_data_control_provider_cb(data_control_provider_handler_fn handler);
#include <stdlib.h>
#include <string.h>
#include <limits.h>
+
#include <bundle.h>
+
#include "aul.h"
#include "aul_api.h"
#include "aul_util.h"
#include "app_sock.h"
#include "simple_util.h"
+#include "launch.h"
#ifdef WAYLAND
#include <wayland-client.h>
SLPAPI void aul_app_group_add(int leader_pid, int pid, int wid)
{
- int ret;
bundle *b;
char buf[128];
snprintf(buf, 128, "%d", wid);
bundle_add_str(b, AUL_K_WID, buf);
- ret = app_send_cmd(AUL_UTIL_PID, APP_GROUP_ADD, b);
+ app_send_cmd(AUL_UTIL_PID, APP_GROUP_ADD, b);
bundle_free(b);
}
SLPAPI void aul_app_group_remove(int pid)
{
- int ret;
bundle *b;
char buf[128];
snprintf(buf, 128, "%d", pid);
bundle_add_str(b, AUL_K_PID, buf);
- ret = app_send_cmd(AUL_UTIL_PID, APP_GROUP_REMOVE, b);
+ app_send_cmd(AUL_UTIL_PID, APP_GROUP_REMOVE, b);
bundle_free(b);
}
SLPAPI int aul_app_group_clear_top(void)
{
int dummy[1] = { 0 };
- return __app_send_raw(AUL_UTIL_PID, APP_GROUP_RESUME, dummy, 0);
+ return __app_send_raw(AUL_UTIL_PID, APP_GROUP_RESUME, (unsigned char *)dummy, 0);
}
SLPAPI int aul_app_group_is_top(void)
open_app.c)
target_link_libraries(open_app aul ${pkgs_LDFLAGS})
INSTALL(TARGETS open_app DESTINATION bin)
-
-add_executable(dbusapp_test
- dbusapp_test.c)
-target_link_libraries(dbusapp_test aul ${pkgs_LDFLAGS})
-
-add_executable(aul_dbus
- aul_dbus.c)
-target_link_libraries(aul_dbus aul ${pkgs_LDFLAGS})
-
-add_executable(test_app
- app_test.c)
-set_target_properties(test_app PROPERTIES COMPILE_FLAGS "-fpie")
-target_link_libraries(test_app "-pie" aul ${pkgs_LDFLAGS} )
-
-
-
-### Unit tests ###
-## avatar test ##
-#add_library(test_avatar STATIC EXCLUDE_FROM_ALL
-# test_avatar.c)
-#target_link_libraries(test_avatar avatar_v2_lib)
-
-## Main test function ##
-#add_executable(test_all EXCLUDE_FROM_ALL test.c)
-#target_link_libraries(test_all test_avatar)
-#set_target_properties(test_all
-# PROPERTIES SKIP_BUILD_RPATH true
-# ) # remove rpath option that is automatically generated by cmake.
-
-## 'test' target in Makefile ##
-# Run test by 'make test'
-#add_custom_target(test
-# COMMAND ./test_all
-# DEPENDS test_all
-# WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
-# COMMENT ""
-# )
+++ /dev/null
-/*
- * aul
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <poll.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <glib.h>
-#include "aul.h"
-
-extern int aul_listen_app_dead_signal(int (*func) (int, void *), void *data);
-
-static GMainLoop *mainloop = NULL;
-
-void do_create()
-{
- /* call real create callback*/
-}
-
-void do_resume()
-{
- /* call real resume callback*/
- static int times = 0;
- printf("=================================\n");
- printf("resumed - %d\n", times++);
- printf("=================================\n");
-}
-
-static void prt_bundle(const char *key, const char *value, void *d)
-{
- printf("bundle - key: %s, value: %s\n", key, value);
-}
-
-int do_start(void *data)
-{
- bundle *kb = data;
- const char *tmp;
- struct timeval tv;
- struct timeval cur;
- struct timeval res;
- static int times = 0;
-
- printf("=================================\n");
- printf("start callback with glib - %d\n", times++);
- printf("=================================\n");
-
- tmp = bundle_get_val(kb, AUL_K_STARTTIME);
- if (tmp != NULL) {
- sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
- gettimeofday(&cur, NULL);
- timersub(&cur, &tv, &res);
- printf("=================================\n");
- printf("launched time = %ld sec %ld msec\n", res.tv_sec,
- res.tv_usec / 1000);
- printf("=================================\n");
- }
- bundle_del(kb, AUL_K_STARTTIME);
-
- bundle_iterate(kb, prt_bundle, NULL);
-
- return 0;
-}
-
-static int aul_handler(aul_type type, bundle *kb, void *data)
-{
- bundle *b;
-
- switch (type) {
- case AUL_START:
- b = bundle_dup(kb);
- do_start((void *)b);
- bundle_free(b);
- break;
- case AUL_RESUME:
- do_resume();
- break;
- case AUL_TERMINATE:
- exit(0);
- break;
- }
- return 0;
-}
-
-int app_dead_handler(int pid, void *data)
-{
- printf("===> %s : %d\n", __FUNCTION__, pid);
- return 0;
-}
-
-int app_launch_handler(int pid, void *data)
-{
- printf("===> %s : %d\n", __FUNCTION__, pid);
- return 0;
-}
-
-__attribute__ ((visibility("default")))
-int main(int argc, char **argv)
-{
- do_create();
-
- if (aul_launch_init(aul_handler, NULL) < 0)
- printf("error aul_init\n");
- if (aul_launch_argv_handler(argc, argv) < 0)
- printf("error argv\n");
-
- aul_listen_app_dead_signal(app_dead_handler, NULL);
-
- aul_listen_app_launch_signal(app_launch_handler, NULL);
-
- if (fork() == 0) {
- printf("child test\n");
- exit(0);
- }
-
- mainloop = g_main_loop_new(NULL, FALSE);
- if (!mainloop) {
- printf("failed to create glib main loop\n");
- exit(EXIT_FAILURE);
- }
- g_main_loop_run(mainloop);
-
- return 0;
-}
-
-/* vi: set ts=8 sts=8 sw=8: */
+++ /dev/null
-/*
- * aul
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <glib.h>
-#include "aul_dbus.h"
-#include <sys/time.h>
-#include <stdlib.h>
-
-#define MAX_LOCAL_BUFSZ 128
-
-void request_cb(DBusPendingCall *pc, void *user_data)
-{
- DBusMessage *reply;
- DBusError error;
- char *str;
-
- reply = dbus_pending_call_steal_reply(pc);
- dbus_pending_call_unref(pc);
-
- dbus_error_init(&error);
-
- if (!dbus_message_get_args(reply, &error,
- DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
- _E("Failed to complete call");
-
- printf("filename = %s\n", str);
-
- dbus_message_unref(reply);
-
- exit(0);
-}
-
-int main(int argc, char **argv)
-{
- DBusConnection *bus;
- DBusError error;
- DBusMessage *message;
- DBusPendingCall *pc;
- GMainLoop *loop;
- dbus_bool_t ret;
-
- char tmp[MAX_LOCAL_BUFSZ];
- char *s;
- struct timeval tv;
-
- loop = g_main_loop_new(NULL, FALSE);
-
- dbus_error_init(&error);
-
- bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
- if (bus == NULL)
- _E("Failed to open bus to bus")
-
- dbus_connection_setup_with_g_main(bus, NULL);
-
- message = dbus_message_new_method_call (
- SERVICE_NAME,PATH_NAME,INTERFACE_NAME,
- METHOD_NAME);
-
- gettimeofday(&tv, NULL);
- snprintf(tmp, MAX_LOCAL_BUFSZ, "%ld/%ld", tv.tv_sec, tv.tv_usec);
- s = tmp;
-
- dbus_message_append_args(message,
- DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID);
-
- ret = dbus_connection_send_with_reply(bus, message, &pc, INT_MAX);
- if (!ret) {
- _E("dbus_connection_send_with_reply() failed.");
- dbus_message_unref(message);
- return -1;
- }
- if (!dbus_pending_call_set_notify(pc, request_cb, NULL, NULL))
- _E("pending call set fail");
-
- dbus_message_unref(message);
-
- printf("wait result\n");
-
- g_main_loop_run(loop);
-
- return 0;
-}
-
+++ /dev/null
-/*
- * aul
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#define _E(fmt, arg...)\
- do {\
- printf(fmt " : %s\n", ##arg, error.message);\
- dbus_error_free(&error);\
- exit(1);\
- } while (0);
-
-#define SERVICE_NAME "org.tizen.camera"
-#define PATH_NAME "/org/tizen/camera"
-#define INTERFACE_NAME SERVICE_NAME".app_result"
-#define METHOD_NAME "take_and_get"
+++ /dev/null
-[D-BUS Service]
-Name=org.tizen.camera
-Exec=/usr/bin/aul_test dbuslaunch deb.org.tizen.camera
+++ /dev/null
-/*
- * aul
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <glib.h>
-#include "aul_dbus.h"
-#include "aul.h"
-#include <sys/time.h>
-#include <stdlib.h>
-
-#define MAX_LOCAL_BUFSZ 128
-
-gboolean result_func(gpointer data)
-{
- char *str;
- DBusMessage *reply;
- DBusConnection *bus;
- DBusError error;
- DBusMessage *msg;
-
- msg = data;
-
- dbus_error_init(&error);
-
- bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
-
- reply = dbus_message_new_method_return(msg);
- dbus_message_unref(msg);
- str = "picture0.jpg";
-
- dbus_message_append_args(reply, DBUS_TYPE_STRING,
- &str, DBUS_TYPE_INVALID);
-
- dbus_connection_send(bus, reply, NULL);
- dbus_message_unref(reply);
-
- return 0;
-}
-
-void create_take_picture_ui(DBusMessage *msg)
-{
- /* simulate, take photo and save time is 30 sec.*/
- g_timeout_add(5 * 1000, result_func, msg);
-}
-
-static DBusHandlerResult
-dbus_handler(DBusConnection *connection,
- DBusMessage *message, void *user_data)
-{
- DBusMessage *msg;
- char *s;
- DBusError error;
- struct timeval tv;
- struct timeval cur;
- struct timeval res;
-
- if (dbus_message_is_method_call(message, INTERFACE_NAME, METHOD_NAME)) {
- dbus_error_init(&error);
- msg = dbus_message_ref(message);
- /* real draw */
- if (dbus_message_get_args
- (message, &error, DBUS_TYPE_STRING, &s,
- DBUS_TYPE_INVALID)) {
- sscanf(s, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
- gettimeofday(&cur, NULL);
- timersub(&cur, &tv, &res);
- printf("=================================\n");
- printf("launched time = %ld sec %ld msec\n", res.tv_sec,
- res.tv_usec / 1000);
- printf("=================================\n");
- }
- create_take_picture_ui(msg);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static int init_dbus()
-{
- DBusConnection *bus;
- DBusError error;
- char rules[MAX_LOCAL_BUFSZ];
-
- dbus_error_init(&error);
-
- bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
- if (!bus)
- _E("couldn't access session bus");
-
- dbus_connection_setup_with_g_main(bus, NULL);
-
- dbus_bus_request_name(bus, SERVICE_NAME, 0, &error);
- if (dbus_error_is_set(&error))
- _E("couldn't request name");
-
- snprintf(rules, MAX_LOCAL_BUFSZ,
- "path='%s',type='method_call',interface='%s'",
- PATH_NAME, INTERFACE_NAME);
- dbus_bus_add_match(bus, rules, &error);
-
- if (!dbus_connection_add_filter(bus, dbus_handler, NULL, NULL))
- _E("couldn't add filter");
-
- return 0;
-}
-
-static int aul_handler(aul_type type, bundle *kb, void *data)
-{
- const char *tmp;
- struct timeval tv;
- struct timeval cur;
- struct timeval res;
-
- switch (type) {
- case AUL_START:
- printf("app start & add dbus\n");
- tmp = bundle_get_val(kb, AUL_K_STARTTIME);
- if (tmp != NULL) {
- sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
- gettimeofday(&cur, NULL);
- timersub(&cur, &tv, &res);
- printf("=================================\n");
- printf("launched time by aul= %ld sec %ld msec\n",
- res.tv_sec, res.tv_usec / 1000);
- printf("=================================\n");
- }
- /* DONOT draw if auto-activated by dbus */
- init_dbus();
- break;
- case AUL_RESUME:
- break;
- case AUL_TERMINATE:
- exit(0);
- break;
- }
- return 0;
-}
-
-int main(int argc, char *argv[])
-{
- GMainLoop *loop;
-
- loop = g_main_loop_new(NULL, FALSE);
-
- aul_launch_init(aul_handler, NULL);
- aul_launch_argv_handler(argc, argv);
-
- g_main_loop_run(loop);
-
- return 0;
-}
-
return kb;
}
-int launch()
+int launch(void)
{
int pid = -1;
static gboolean run_func(void *data)
{
- int pid = -1;
- char *str = NULL;
+ int pid;
+ const char *str;
if ((pid = launch()) > 0) {
printf("... successfully launched\n");
- str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
+ str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
- if( str && strcmp(str, "SYNC") == 0 ) {
- aul_listen_app_dead_signal(__launch_app_dead_handler, pid);
- } else {
+ if (str && strcmp(str, "SYNC") == 0 )
+ aul_listen_app_dead_signal(__launch_app_dead_handler, (void *)pid);
+ else
g_main_loop_quit(mainloop);
- }
} else {
printf("... launch failed\n");
g_main_loop_quit(mainloop);
static bundle *create_internal_bundle()
{
bundle *kb;
- int i;
- char arg[1024] = {0, };
- char* val_array[128];
kb = bundle_create();
bundle_add(kb, AUL_K_DEBUG, "1");
int launch(int debug_option)
{
- int pid = -1;
-
+ int pid;
if(!debug_option)
pid = aul_open_app(gargv[1]);
static gboolean run_func(void *data)
{
- int pid = -1;
- char *str = NULL;
- if ((pid = launch(debugFlag)) > 0) {
+ int pid;
+ const char *str;
+
+ if ((pid = launch(debugFlag)) > 0)
printf("... successfully launched\n");
- } else {
+ else
printf("... launch failed\n");
- }
+
if (kb) {
str = bundle_get_val(kb, "__LAUNCH_APP_MODE__");
- if( str && strcmp(str, "SYNC") == 0 ) {
- aul_listen_app_dead_signal(__launch_app_dead_handler, pid);
- } else {
+ if (str && strcmp(str, "SYNC") == 0 )
+ aul_listen_app_dead_signal(__launch_app_dead_handler, (void *)pid);
+ else
g_main_loop_quit(mainloop);
- }
bundle_free(kb);
kb = NULL;
- } else
+ } else {
g_main_loop_quit(mainloop);
+ }
return TRUE;