tizen 2.4 release
[framework/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 <bundle.h>
33 #include "appcore-common.h"
34
35
36 #ifndef EXPORT_API
37 #  define EXPORT_API __attribute__ ((visibility("default")))
38 #endif
39
40 #  define _ERR(fmt, arg...) LOGE(fmt, ##arg)
41 #  define _WARN(fmt, arg...) LOGW(fmt, ##arg)
42 #  define _INFO(...) LOGI(__VA_ARGS__)
43 #  define _DBG(...) LOGD(__VA_ARGS__)
44
45 #define _warn_if(expr, fmt, arg...) do { \
46                 if (expr) { \
47                         _ERR(fmt, ##arg); \
48                 } \
49         } while (0)
50
51 #define _ret_if(expr) do { \
52                 if (expr) { \
53                         return; \
54                 } \
55         } while (0)
56
57 #define _retv_if(expr, val) do { \
58                 if (expr) { \
59                         return (val); \
60                 } \
61         } while (0)
62
63 #define _retm_if(expr, fmt, arg...) do { \
64                 if (expr) { \
65                         _ERR(fmt, ##arg); \
66                         return; \
67                 } \
68         } while (0)
69
70 #define _retvm_if(expr, val, fmt, arg...) do { \
71                 if (expr) { \
72                         _ERR(fmt, ##arg); \
73                         return (val); \
74                 } \
75         } while (0)
76
77 #define goto_if(expr, val) do { \
78                         if(expr) { \
79                                 _ERR("(%s) -> goto", #expr); \
80                                 goto val; \
81                         } \
82                 } while (0)
83
84 #define break_if(expr) { \
85                         if(expr) { \
86                                 _ERR("(%s) -> break", #expr); \
87                                 break; \
88                         } \
89                 }
90
91 #define continue_if(expr) { \
92                         if(expr) { \
93                                 _ERR("(%s) -> continue", #expr); \
94                                 continue; \
95                         } \
96                 }
97
98 /**
99  * Appcore internal state
100  */
101 enum app_state {
102         AS_NONE,
103         AS_CREATED,
104         AS_RUNNING,
105         AS_PAUSED,
106         AS_DYING,
107 };
108
109 /**
110  * Appcore internal event
111  */
112 enum app_event {
113         AE_UNKNOWN,
114         AE_CREATE,
115         AE_TERMINATE,
116         AE_TERMINATE_BGAPP,
117         AE_PAUSE,
118         AE_RESUME,
119         AE_RESET,
120         AE_LOWMEM_POST,
121         AE_MEM_FLUSH,
122         AE_MAX
123 };
124
125 /**
126  * Appcore internal system event
127  */
128 enum sys_event {
129         SE_UNKNOWN,
130         SE_LOWMEM,
131         SE_LOWBAT,
132         SE_LANGCHG,
133         SE_REGIONCHG,
134         SE_SUSPENDED_STATE,
135         SE_MAX
136 };
137
138 /**
139  * Appcore system event operation
140  */
141 struct sys_op {
142         int (*func) (void *, void *);
143         void *data;
144 };
145
146 /**
147  * Appcore internal structure
148  */
149 struct appcore {
150         int state;
151         unsigned int tid;
152         bool suspended_state;
153         bool allowed_bg;
154
155         const struct ui_ops *ops;
156         struct sys_op sops[SE_MAX];
157 };
158
159 /**
160  * Appcore UI operation
161  */
162 struct ui_ops {
163         void *data;
164         void (*cb_app) (enum app_event evnt, void *data, bundle *b);
165 };
166
167 /* appcore-i18n.c */
168 extern void update_lang(void);
169 extern int set_i18n(const char *domainname, const char *dirname);
170 void update_region(void);
171
172
173 /* appcore-X.c */
174 extern int x_raise_win(pid_t pid);
175 extern int x_pause_win(pid_t pid);
176
177 /* appcore-util.c */
178 /* extern void stack_trim(void);*/
179
180 int appcore_pause_rotation_cb(void);
181 int appcore_resume_rotation_cb(void);
182
183 struct ui_wm_rotate {
184    int (*set_rotation_cb) (int (*cb) (void *event_info, enum appcore_rm, void *), void *data);
185    int (*unset_rotation_cb) (void);
186    int (*get_rotation_state) (enum appcore_rm *curr);
187    int (*pause_rotation_cb) (void);
188    int (*resume_rotation_cb) (void);
189 };
190 int appcore_set_wm_rotation(struct ui_wm_rotate* wm_rotate);
191
192 void appcore_group_reset(bundle *b);
193 void appcore_group_attach();
194 void appcore_group_lower();
195 unsigned int appcore_get_main_window();
196
197 int _appcore_request_to_suspend(int pid);
198 int _appcore_init_suspend_dbus_handler(void *data);
199 int _appcore_fini_suspend_dbus_handler(void *data);
200
201 #define ENV_START "APP_START_TIME"
202
203 #define MEMORY_FLUSH_ACTIVATE
204
205 #define APPID_MAX 256
206
207 #endif                          /* __APPCORE_INTERNAL_H__ */