Git init
[framework/appfw/aul-1.git] / test / app_test.c
1 /*
2 Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
3 PROPRIETARY/CONFIDENTIAL
4 This software is the confidential and proprietary information of 
5 SAMSUNG ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
6 this software is owned by Samsung and you 
7 shall not disclose such Confidential Information and shall 
8 use it only in accordance with the terms of the license agreement 
9 you entered into with SAMSUNG ELECTRONICS.  SAMSUNG make no 
10 representations or warranties about the suitability 
11 of the software, either express or implied, including but not 
12 limited to the implied warranties of merchantability, fitness for 
13 a particular purpose, or non-infringement. 
14 SAMSUNG shall not be liable for any damages suffered by licensee arising out of or 
15 related to this software.
16 */
17
18 #include <poll.h>
19 #include <stdio.h>
20 #include <unistd.h>
21 #include "aul.h"
22
23 /* ecore-glib integration */
24
25 #include <Ecore.h>
26
27 void do_create()
28 {
29         /* call real create callback*/
30 }
31
32 void do_resume()
33 {
34         /* call real resume callback*/
35         static int times = 0;
36         printf("=================================\n");
37         printf("resumed - %d\n", times++);
38         printf("=================================\n");
39 }
40
41 static Eina_Bool send_result(void *data)
42 {
43         bundle *kb;
44         bundle *res_b;
45         kb = (bundle *) data;
46
47         aul_create_result_bundle(kb, &res_b);
48         if (res_b == NULL)
49                 return 0;
50
51         aul_send_service_result(res_b);
52         bundle_free(res_b);
53
54         bundle_free(kb);
55
56         return 0;
57 }
58
59 static void prt_bundle(const char *key, const char *value, void *d)
60 {
61         printf("bundle - key: %s, value: %s\n", key, value);
62 }
63
64 int do_start(void *data)
65 {
66         bundle *kb = data;
67         const char *tmp;
68         struct timeval tv;
69         struct timeval cur;
70         struct timeval res;
71         static int times = 0;
72
73         printf("=================================\n");
74         printf("start callback with glib - %d\n", times++);
75         printf("=================================\n");
76
77         tmp = bundle_get_val(kb, AUL_K_STARTTIME);
78         if (tmp != NULL) {
79                 sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec);
80                 gettimeofday(&cur, NULL);
81                 timersub(&cur, &tv, &res);
82                 printf("=================================\n");
83                 printf("launched time = %ld sec %ld msec\n", res.tv_sec,
84                        res.tv_usec / 1000);
85                 printf("=================================\n");
86         }
87         bundle_del(kb, AUL_K_STARTTIME);
88
89         bundle_iterate(kb, prt_bundle, NULL);
90
91         ecore_timer_add(5, send_result, bundle_dup(kb));
92
93         return 0;
94 }
95
96 static int aul_handler(aul_type type, bundle *kb, void *data)
97 {
98         bundle *b;
99
100         switch (type) {
101         case AUL_START:
102                 b = bundle_dup(kb);
103                 do_start((void *)b);
104                 bundle_free(b);
105                 break;
106         case AUL_RESUME:
107                 do_resume();
108                 break;
109         case AUL_TERMINATE:
110                 exit(0);
111                 break;
112         }
113         return 0;
114 }
115
116 int app_dead_handler(int pid, void *data)
117 {
118         printf("===> %s : %d\n", __FUNCTION__, pid);
119         return 0;
120 }
121
122 __attribute__ ((visibility("default")))
123 int main(int argc, char **argv)
124 {
125         ecore_init();
126
127         do_create();
128
129         if (aul_launch_init(aul_handler, NULL) < 0)
130                 printf("error aul_init\n");
131         if (aul_launch_argv_handler(argc, argv) < 0)
132                 printf("error argv\n");
133
134         aul_listen_app_dead_signal(app_dead_handler, NULL);
135
136         if (fork() == 0) {
137                 printf("child test\n");
138                 exit(0);
139         }
140
141         ecore_main_loop_begin();
142         return 0;
143 }
144
145 /* vi: set ts=8 sts=8 sw=8: */
146
147
148
149 /* vi: set ts=8 sts=8 sw=8: */