Release version 0.15.20
[platform/core/appfw/launchpad.git] / src / common / inc / launchpad_common.h
1 /*
2  * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __LAUNCHPAD_COMMON_H__
18 #define __LAUNCHPAD_COMMON_H__
19
20 #ifndef _GNU_SOURCE
21 #define _GNU_SOURCE
22 #endif
23
24 #include <unistd.h>
25 #include <ctype.h>
26 #include <dlog.h>
27 #include <bundle_internal.h>
28 #include <sys/socket.h>
29 #include <sys/un.h>
30 #include <stdbool.h>
31 #include <tzplatform_config.h>
32
33 #ifdef LAUNCHPAD_LOG
34 #undef LOG_TAG
35 #define LOG_TAG "LAUNCHPAD"
36 #endif
37
38 #define MAX_PENDING_CONNECTIONS 10
39 #define MAX_LOCAL_BUFSZ 128
40 #define AUL_SOCK_MAXBUFF 131071
41 #define LOADER_ARG_LEN 1024
42
43 #define PAD_CMD_LAUNCH          0
44 #define PAD_CMD_VISIBILITY      10
45 #define PAD_CMD_ADD_LOADER      11
46 #define PAD_CMD_REMOVE_LOADER   12
47 #define PAD_CMD_MAKE_DEFAULT_SLOTS      13
48 #define PAD_CMD_DEMAND          14
49 #define PAD_CMD_PING            15
50 #define PAD_CMD_UPDATE_APP_TYPE 16
51 #define PAD_CMD_PREPARE_APP_DEFINED_LOADER      17
52
53 #define LAUNCHPAD_LAUNCH_SIGNAL 83
54 #define LAUNCHPAD_DEAD_SIGNAL 61
55 #define APP_STARTUP_SIGNAL 89
56
57 #define PAD_LOADER_ID_STATIC    0
58 #define PAD_LOADER_ID_DIRECT    1
59 #define PAD_LOADER_ID_DYNAMIC_BASE      10
60
61 #define KEY_LOADER_TYPE    "loader_type"
62 #define LOADER_TYPE_COMMON  "common-loader"
63 #define LOADER_TYPE_HW    "hw-loader"
64 #define LOADER_TYPE_SW    "sw-loader"
65
66 #define _E(fmt, arg...) LOGE(fmt, ##arg)
67 #define _D(fmt, arg...) LOGD(fmt, ##arg)
68 #define _W(fmt, arg...) LOGW(fmt, ##arg)
69 #define _I(fmt, arg...) LOGI(fmt, ##arg)
70
71 #define FREE_AND_NULL(x) do {           \
72         if (x) {                        \
73                 free(x);                \
74                 x = NULL;               \
75         }                               \
76 } while (0)
77
78 #define ARRAY_SIZE(x) ((sizeof(x)) / sizeof(x[0]))
79 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
80
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84
85 typedef struct _app_pkt_t {
86         int cmd;
87         int len;
88         int opt;
89         unsigned char data[1];
90 } app_pkt_t;
91
92 typedef struct {
93         char *appid;
94         char *app_path;
95         char *original_app_path;
96         char *pkg_type;
97         char *app_type;
98         char *hwacc;
99         char *taskmanage;
100         char *pkgid;
101         char *comp_type;
102         char *internal_pool;
103         char *root_path;
104         char *loader_name;
105         bool global;
106 } appinfo_t;
107
108 void _modify_bundle(bundle *kb, int caller_pid, appinfo_t *menu_info, int cmd);
109
110 int _send_message_to_logger(const char *tag, const char *format, ...);
111 int _send_cmd_to_amd(int cmd);
112 int _create_server_sock(const char *name);
113 app_pkt_t *_recv_pkt_raw(int fd);
114 app_pkt_t *_accept_recv_pkt_raw(int fd, int *clifd, struct ucred *cr);
115 int _send_pkt_raw(int client_fd, app_pkt_t *pkt);
116 int  _connect_to_launchpad(int type, int id);
117 int _set_sock_option(int fd, int cli);
118 void _set_env(appinfo_t *menu_info, bundle *kb);
119 char **_create_argc_argv(bundle *kb, int *margc);
120 char *_get_libdir(const char *path);
121 int _delete_sock_path(int pid, uid_t uid);
122
123 appinfo_t *_appinfo_create(bundle *kb);
124 void _appinfo_free(appinfo_t *menu_info);
125 char *_appinfo_get_app_path(appinfo_t *menu_info);
126 int _close_all_fds(void);
127 void _get_cpu_idle(unsigned long long *total, unsigned long long *idle);
128 int _setup_stdio(const char *ident);
129 int _set_priority(int prio);
130 int _wait_tep_mount(bundle *b);
131 int _prepare_app_socket(void);
132 int _enable_external_pkg(bundle *b, const char *pkgid, uid_t pkg_uid);
133 int _verify_proc_caps(void);
134 int _prepare_id_file(void);
135 void _print_hwc_log(const char *format, ...);
136
137 #ifdef __cplusplus
138 }
139 #endif
140 #endif /* __LAUNCHPAD_COMMON_H__ */
141