- update source.
[platform/framework/web/crosswalk.git] / src / xwalk / application / tools / linux / xwalk_launcher_tizen.cc
1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #if defined(OS_TIZEN_MOBILE)
9 #include <appcore/appcore-common.h>
10 #endif
11 #include "xwalk/application/tools/linux/xwalk_launcher_tizen.h"
12
13 enum app_event {
14   AE_UNKNOWN,
15   AE_CREATE,
16   AE_TERMINATE,
17   AE_PAUSE,
18   AE_RESUME,
19   AE_RESET,
20   AE_LOWMEM_POST,
21   AE_MEM_FLUSH,
22   AE_MAX
23 };
24
25 // Private struct from appcore-internal, necessary to get events from
26 // the system.
27 struct ui_ops {
28   void* data;
29   void (*cb_app)(enum app_event evnt, void* data, bundle* b);
30 };
31
32 static struct ui_ops appcore_ops;
33
34 static const char* event2str(enum app_event event) {
35   switch (event) {
36     case AE_UNKNOWN:
37       return "AE_UNKNOWN";
38     case AE_CREATE:
39       return "AE_CREATE";
40     case AE_TERMINATE:
41       return "AE_TERMINATE";
42     case AE_PAUSE:
43       return "AE_PAUSE";
44     case AE_RESUME:
45       return "AE_RESUME";
46     case AE_RESET:
47       return "AE_RESET";
48     case AE_LOWMEM_POST:
49       return "AE_LOWMEM_POST";
50     case AE_MEM_FLUSH:
51       return "AE_MEM_FLUSH";
52     case AE_MAX:
53       return "AE_MAX";
54   }
55
56   return "INVALID EVENT";
57 }
58
59 static void application_event_cb(enum app_event event, void* data, bundle* b) {
60   fprintf(stderr, "event '%s'\n", event2str(event));
61
62   if (event == AE_TERMINATE) {
63     exit(0);
64   }
65 }
66
67 int xwalk_appcore_init(int argc, char** argv, const char* name) {
68   appcore_ops.cb_app = application_event_cb;
69   appcore_ops.data = NULL;
70
71   return appcore_init(name, &appcore_ops, argc, argv);
72 }