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