1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/*
* media-key
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <aul.h>
#include <media_key.h>
#include <string.h>
#if X11
#include <utilX.h>
#endif
#include <dlog.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "CAPI_SYSTEM_MEDIA_KEY"
static void (*_media_key_event_cb)(media_key_e key, media_key_event_e status, void* user_data) = NULL;
static void *_media_key_data = NULL;
static int _media_key_initialized = 0;
extern int aul_key_reserve();
extern int aul_key_release();
extern int aul_key_init(int (*aul_handler) (bundle *, void *), void *data);
static int __aul_key_handler(bundle *b, void *data)
{
int ret = MEDIA_KEY_ERROR_NONE;
char *key_str;
char *event_str;
media_key_e key = MEDIA_KEY_UNKNOWN;
media_key_event_e event = MEDIA_KEY_STATUS_UNKNOWN;
key_str = (char *)bundle_get_val(b, AUL_K_MULTI_KEY);
event_str = (char *)bundle_get_val(b, AUL_K_MULTI_KEY_EVENT);
#if X11
if (!strcmp(key_str, KEY_PLAYCD)) {
key = MEDIA_KEY_PLAY;
} else if (!strcmp(key_str, KEY_STOPCD)) {
key = MEDIA_KEY_STOP;
} else if (!strcmp(key_str, KEY_PAUSECD)) {
key = MEDIA_KEY_PAUSE;
} else if (!strcmp(key_str, KEY_NEXTSONG)) {
key = MEDIA_KEY_NEXT;
} else if (!strcmp(key_str, KEY_PREVIOUSSONG)) {
key = MEDIA_KEY_PREVIOUS;
} else if (!strcmp(key_str, KEY_REWIND)) {
key = MEDIA_KEY_REWIND;
} else if (!strcmp(key_str, KEY_FASTFORWARD)) {
key = MEDIA_KEY_FASTFORWARD;
}
#else
LOGE("[%s] not implemented for wayland", __FUNCTION__);
#endif
if (!strcmp(event_str, AUL_V_KEY_RELEASED)) {
event = MEDIA_KEY_STATUS_RELEASED;
} else if (!strcmp(event_str, AUL_V_KEY_PRESSED)) {
event = MEDIA_KEY_STATUS_PRESSED;
}
LOGD("[%s] media_key [%s][%d]", __FUNCTION__, key_str, key);
LOGD("[%s] media_key_event [%s][%d]", __FUNCTION__, event_str, event);
if(_media_key_event_cb)
_media_key_event_cb(key, event, _media_key_data);
return ret;
}
int media_key_reserve(media_key_event_cb callback, void* user_data)
{
int ret;
if(!_media_key_initialized) {
aul_key_init(__aul_key_handler, NULL);
_media_key_initialized = 1;
}
_media_key_event_cb = callback;
_media_key_data = user_data;
ret = aul_key_reserve();
if(ret < 0) {
LOGE("[%s] aul_key_set_event error [%d]", __FUNCTION__, ret);
return MEDIA_KEY_ERROR_INVALID_PARAMETER;
}
return MEDIA_KEY_ERROR_NONE;
}
int media_key_release()
{
int ret;
ret = aul_key_release();
if(ret < 0) {
LOGE("[%s] aul_key_unset_event error [%d]", __FUNCTION__, ret);
return MEDIA_KEY_ERROR_INVALID_PARAMETER;
}
_media_key_event_cb = NULL;
_media_key_data = NULL;
return MEDIA_KEY_ERROR_NONE;
}
|