Initialize Tizen 2.3
[framework/appfw/aul-1.git] / test / app_test.c
1 /*
2  *  aul
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 #include <poll.h>
23 #include <stdio.h>
24 #include <unistd.h>
25 #include "aul.h"
26
27 /* ecore-glib integration */
28
29 #include <Ecore.h>
30
31 extern int aul_listen_app_dead_signal(int (*func) (int, void *), void *data);
32
33 void do_create()
34 {
35         /* call real create callback*/
36 }
37
38 void do_resume()
39 {
40         /* call real resume callback*/
41         static int times = 0;
42         printf("=================================\n");
43         printf("resumed - %d\n", times++);
44         printf("=================================\n");
45 }
46
47 static Eina_Bool send_result(void *data)
48 {
49         bundle *kb;
50         bundle *res_b;
51         kb = (bundle *) data;
52
53         aul_create_result_bundle(kb, &res_b);
54         if (res_b == NULL)
55                 return 0;
56
57         aul_send_service_result(res_b);
58         bundle_free(res_b);
59
60         bundle_free(kb);
61
62         return 0;
63 }
64
65 static void prt_bundle(const char *key, const char *value, void *d)
66 {
67         printf("bundle - key: %s, value: %s\n", key, value);
68 }
69
70 int do_start(void *data)
71 {
72         bundle *kb = data;
73         const char *tmp;
74         struct timeval tv;
75         struct timeval cur;
76         struct timeval res;
77         static int times = 0;
78
79         printf("=================================\n");
80         printf("start callback with glib - %d\n", times++);
81         printf("=================================\n");
82
83         tmp = bundle_get_val(kb, AUL_K_STARTTIME);
84         if (tmp != NULL) {
85                 sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
86                 gettimeofday(&cur, NULL);
87                 timersub(&cur, &tv, &res);
88                 printf("=================================\n");
89                 printf("launched time = %ld sec %ld msec\n", res.tv_sec,
90                        res.tv_usec / 1000);
91                 printf("=================================\n");
92         }
93         bundle_del(kb, AUL_K_STARTTIME);
94
95         bundle_iterate(kb, prt_bundle, NULL);
96
97         ecore_timer_add(5, send_result, bundle_dup(kb));
98
99         return 0;
100 }
101
102 static int aul_handler(aul_type type, bundle *kb, void *data)
103 {
104         bundle *b;
105
106         switch (type) {
107         case AUL_START:
108                 b = bundle_dup(kb);
109                 do_start((void *)b);
110                 bundle_free(b);
111                 break;
112         case AUL_RESUME:
113                 do_resume();
114                 break;
115         case AUL_TERMINATE:
116                 exit(0);
117                 break;
118         }
119         return 0;
120 }
121
122 int app_dead_handler(int pid, void *data)
123 {
124         printf("===> %s : %d\n", __FUNCTION__, pid);
125         return 0;
126 }
127
128 int app_launch_handler(int pid, void *data)
129 {
130         printf("===> %s : %d\n", __FUNCTION__, pid);
131         return 0;
132 }
133
134 __attribute__ ((visibility("default")))
135 int main(int argc, char **argv)
136 {
137         ecore_init();
138
139         do_create();
140
141         if (aul_launch_init(aul_handler, NULL) < 0)
142                 printf("error aul_init\n");
143         if (aul_launch_argv_handler(argc, argv) < 0)
144                 printf("error argv\n");
145
146         aul_listen_app_dead_signal(app_dead_handler, NULL);
147
148         aul_listen_app_launch_signal(app_launch_handler, NULL);
149
150         if (fork() == 0) {
151                 printf("child test\n");
152                 exit(0);
153         }
154
155         ecore_main_loop_begin();
156         return 0;
157 }
158
159 /* vi: set ts=8 sts=8 sw=8: */
160
161
162
163 /* vi: set ts=8 sts=8 sw=8: */