c1f9bb304173ca7a23e6371270404811841e707f
[platform/core/appfw/app-core.git] / include / appcore-internal.h
1 /*
2  *  app-core
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22
23
24 #ifndef __APPCORE_INTERNAL_H__
25 #define __APPCORE_INTERNAL_H__
26
27 #define LOG_TAG "APP_CORE"
28
29 #include <stdio.h>
30 #include <stdbool.h>
31 #include <dlog.h>
32 #include "appcore-common.h"
33
34
35 #ifndef EXPORT_API
36 #  define EXPORT_API __attribute__ ((visibility("default")))
37 #endif
38
39 #ifndef _DLOG_H_
40 #define _ERR(fmt, arg...) fprintf(stderr, "appcore: "fmt"\n", ##arg)
41 #define _INFO(fmt, arg...) fprintf(stdout, fmt"\n", ##arg)
42 #define _DBG(fmt, arg...) \
43         do { \
44                 if (getenv("APPCORE_DEBUG")) { \
45                         fprintf(stdout, fmt"\n", ##arg); \
46                 } \
47         } while (0)
48 #else
49 #define _ERR(fmt, arg...) LOGE(fmt, ##arg)
50 #define _INFO(...) LOGI(__VA_ARGS__)
51 #define _DBG(...) LOGD(__VA_ARGS__)
52 #endif
53
54 #define _warn_if(expr, fmt, arg...) do { \
55                 if (expr) { \
56                         _ERR(fmt, ##arg); \
57                 } \
58         } while (0)
59
60 #define _ret_if(expr) do { \
61                 if (expr) { \
62                         return; \
63                 } \
64         } while (0)
65
66 #define _retv_if(expr, val) do { \
67                 if (expr) { \
68                         return (val); \
69                 } \
70         } while (0)
71
72 #define _retm_if(expr, fmt, arg...) do { \
73                 if (expr) { \
74                         _ERR(fmt, ##arg); \
75                         return; \
76                 } \
77         } while (0)
78
79 #define _retvm_if(expr, val, fmt, arg...) do { \
80                 if (expr) { \
81                         _ERR(fmt, ##arg); \
82                         return (val); \
83                 } \
84         } while (0)
85
86 /**
87  * Appcore internal state
88  */
89 enum app_state {
90         AS_NONE,
91         AS_CREATED,
92         AS_RUNNING,
93         AS_PAUSED,
94         AS_DYING,
95 };
96
97 /**
98  * Appcore internal event
99  */
100 enum app_event {
101         AE_UNKNOWN,
102         AE_CREATE,
103         AE_TERMINATE,
104         AE_TERMINATE_BGAPP,
105         AE_PAUSE,
106         AE_RESUME,
107         AE_RAISE,
108         AE_LOWER,
109         AE_RESET,
110         AE_LOWMEM_POST,
111         AE_MEM_FLUSH,
112         AE_UPDATE_REQUESTED,
113         AE_MAX
114 };
115
116 /**
117  * Appcore internal system event
118  */
119 enum sys_event {
120         SE_UNKNOWN,
121         SE_LOWMEM,
122         SE_LOWBAT,
123         SE_LANGCHG,
124         SE_REGIONCHG,
125         SE_SUSPENDED_STATE,
126         SE_UPDATE_REQUESTED,
127         SE_MAX
128 };
129
130 /**
131  * Appcore system event operation
132  */
133 struct sys_op {
134         int (*func) (void *, void *);
135         void *data;
136 };
137
138 /**
139  * Appcore internal structure
140  */
141 struct appcore {
142         int state;
143         unsigned int tid;
144         bool suspended_state;
145         bool allowed_bg;
146
147         const struct ui_ops *ops;
148         struct sys_op sops[SE_MAX];
149 };
150
151 /**
152  * Appcore UI operation
153  */
154 struct ui_ops {
155         void *data;
156         void (*cb_app) (enum app_event evnt, void *data, bundle *b);
157 };
158
159 /* appcore-i18n.c */
160 extern void update_lang(void);
161 extern int set_i18n(const char *domainname, const char *dirname);
162 void update_region(void);
163
164
165 /* appcore-X.c */
166 extern int x_raise_win(pid_t pid);
167 extern int x_pause_win(pid_t pid);
168
169 /* appcore-util.c */
170 /* extern void stack_trim(void);*/
171
172 int appcore_pause_rotation_cb(void);
173 int appcore_resume_rotation_cb(void);
174
175 struct ui_wm_rotate {
176         int (*set_rotation_cb) (int (*cb)(void *event_info, enum appcore_rm, void *), void *data);
177         int (*unset_rotation_cb) (void);
178         int (*get_rotation_state) (enum appcore_rm *curr);
179         int (*pause_rotation_cb) (void);
180         int (*resume_rotation_cb) (void);
181 };
182 int appcore_set_wm_rotation(struct ui_wm_rotate* wm_rotate);
183
184 void appcore_group_attach();
185 void appcore_group_lower();
186 unsigned int appcore_get_main_window(void);
187 #if defined(WAYLAND)
188 unsigned int appcore_get_main_surface(void);
189 #endif
190 void appcore_get_app_core(struct appcore **ac);
191
192 #define ENV_START "APP_START_TIME"
193
194 #define MEMORY_FLUSH_ACTIVATE
195
196 typedef enum {
197         TIZEN_PROFILE_UNKNOWN = 0,
198         TIZEN_PROFILE_MOBILE = 0x1,
199         TIZEN_PROFILE_WEARABLE = 0x2,
200         TIZEN_PROFILE_TV = 0x4,
201         TIZEN_PROFILE_IVI = 0x8,
202         TIZEN_PROFILE_COMMON = 0x10,
203 } tizen_profile_t;
204 extern tizen_profile_t _get_tizen_profile();
205
206 #define _APPFW_FEATURE_BACKGROUND_MANAGEMENT (_get_tizen_profile() & (TIZEN_PROFILE_WEARABLE | TIZEN_PROFILE_MOBILE))
207
208 #endif                          /* __APPCORE_INTERNAL_H__ */