Upload Tizen2.0 source
[framework/appfw/aul-1.git] / src / key.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
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <utilX.h>
27 #include <glib.h>
28 #include <poll.h>
29 #include <bundle.h>
30
31 #include "aul.h"
32 #include "aul_api.h"
33 #include "menu_db_util.h"
34 #include "simple_util.h"
35 #include "app_sock.h"
36 #include "aul_util.h"
37 #include "launch.h"
38
39
40 static int (*_aul_key_handler) (bundle *kb, void *data) = NULL;
41 static void *_aul_key_data = NULL;
42
43 extern GSourceFuncs funcs;
44
45 int app_key_event(bundle *kb)
46 {
47         if (_aul_key_handler)
48                 _aul_key_handler(kb, _aul_key_data);
49         return 0;
50 }
51
52 int aul_register_key_init_callback(
53         int (*aul_handler) (bundle *, void *), void *data)
54 {
55         /* Save start handler function in static var */
56         _aul_key_handler = aul_handler;
57         _aul_key_data = data;
58         return 0;
59 }
60
61 SLPAPI int aul_key_init(int (*aul_handler) (bundle *, void *), void *data)
62 {
63         int fd;
64         GPollFD *gpollfd;
65         GSource *src;
66         int ret;
67
68         if (aul_handler != NULL)
69                 aul_register_key_init_callback(aul_handler, data);
70
71         fd = aul_initialize();
72         if (fd < 0)
73                 return fd;
74
75         src = g_source_new(&funcs, sizeof(GSource));
76
77         gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
78         gpollfd->events = POLLIN;
79         gpollfd->fd = fd;
80
81         g_source_add_poll(src, gpollfd);
82         g_source_set_callback(src, (GSourceFunc) __aul_glib_handler,
83                               (gpointer) gpollfd, NULL);
84         g_source_set_priority(src, G_PRIORITY_LOW);
85
86         ret = g_source_attach(src, NULL);
87         if (ret == 0)
88                 return AUL_R_ERROR;
89
90         g_source_unref(src);
91
92         return AUL_R_OK;
93 }
94
95 SLPAPI int aul_key_reserve()
96 {
97         bundle *kb;
98         int ret;
99
100         kb = bundle_create();
101         ret = app_send_cmd(AUL_UTIL_PID, APP_KEY_RESERVE, kb);
102         bundle_free(kb);
103
104         return ret;
105 }
106
107 SLPAPI int aul_key_release()
108 {
109         bundle *kb;
110         int ret;
111
112         kb = bundle_create();
113         ret = app_send_cmd(AUL_UTIL_PID, APP_KEY_RELEASE, kb);
114         bundle_free(kb);
115
116         return ret;
117 }
118
119
120