tizen 2.3 release
[framework/api/application.git] / app_common / app_event.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <string.h>
18
19 #include <vconf-internal-keys.h>
20 #include <app_common.h>
21 #include <app_internal.h>
22
23 app_device_orientation_e app_convert_appcore_rm(enum appcore_rm rm)
24 {
25         app_device_orientation_e dev_orientation;
26
27         switch (rm)
28         {
29         case APPCORE_RM_PORTRAIT_NORMAL:
30                 dev_orientation = APP_DEVICE_ORIENTATION_0;
31                 break;
32
33         case APPCORE_RM_PORTRAIT_REVERSE:
34                 dev_orientation = APP_DEVICE_ORIENTATION_180;
35                 break;
36
37         case APPCORE_RM_LANDSCAPE_NORMAL:
38                 dev_orientation = APP_DEVICE_ORIENTATION_270;
39                 break;
40
41         case APPCORE_RM_LANDSCAPE_REVERSE:
42                 dev_orientation = APP_DEVICE_ORIENTATION_90;
43                 break;
44
45         default:
46                 dev_orientation = APP_DEVICE_ORIENTATION_0;
47                 break;
48         }
49
50         return dev_orientation;
51 }
52
53 static int _app_convert_low_memory(void *val)
54 {
55         switch (*(int *)val) {
56         case VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL:
57                 return APP_EVENT_LOW_MEMORY_NORMAL;
58         case VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING:
59                 return APP_EVENT_LOW_MEMORY_SOFT_WARNING;
60         case VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING:
61                 return APP_EVENT_LOW_MEMORY_HARD_WARNING;
62         default:
63                 return -1;
64         }
65 }
66
67 static int _app_convert_low_battery(void *val)
68 {
69         switch (*(int *)val) {
70         case VCONFKEY_SYSMAN_BAT_POWER_OFF:
71                 return APP_EVENT_LOW_BATTERY_POWER_OFF;
72         case VCONFKEY_SYSMAN_BAT_CRITICAL_LOW:
73                 return APP_EVENT_LOW_BATTERY_CRITICAL_LOW;
74         default:
75                 return -1;
76         }
77 }
78
79 int app_event_get_low_memory_status(app_event_info_h event_info, app_event_low_memory_status_e *status)
80 {
81         int ret;
82
83         if (event_info == NULL || status == NULL)
84                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
85
86         if (event_info->type != APP_EVENT_LOW_MEMORY)
87                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "event type mismatching");
88
89         ret = _app_convert_low_memory(event_info->value);
90         if (ret < 0)
91                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "invalid event info");
92
93         *status = ret;
94
95         return APP_ERROR_NONE;
96 }
97
98 int app_event_get_low_battery_status(app_event_info_h event_info, app_event_low_battery_status_e *status)
99 {
100         int ret;
101
102         if (event_info == NULL || status == NULL)
103                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
104
105         if (event_info->type != APP_EVENT_LOW_BATTERY)
106                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "event type mismatching");
107
108         ret = _app_convert_low_battery(event_info->value);
109         if (ret < 0)
110                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "invalid event info");
111
112         *status = ret;
113
114         return APP_ERROR_NONE;
115 }
116
117 int app_event_get_language(app_event_info_h event_info, char **lang)
118 {
119         if (event_info == NULL || lang == NULL)
120                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
121
122         if (event_info->type != APP_EVENT_LANGUAGE_CHANGED)
123                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
124
125         *lang = strdup(event_info->value);
126
127         return APP_ERROR_NONE;
128 }
129
130 int app_event_get_region_format(app_event_info_h event_info, char **region)
131 {
132         if (event_info == NULL || region == NULL)
133                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
134
135         if (event_info->type != APP_EVENT_REGION_FORMAT_CHANGED)
136                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
137
138         *region = strdup(event_info->value);
139
140         return APP_ERROR_NONE;
141 }
142
143 int app_event_get_device_orientation(app_event_info_h event_info, app_device_orientation_e *orientation)
144 {
145         if (event_info == NULL || orientation == NULL)
146                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
147
148         if (event_info->type != APP_EVENT_DEVICE_ORIENTATION_CHANGED)
149                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
150
151         *orientation = app_convert_appcore_rm(*(enum appcore_rm *)(event_info->value));
152
153         return APP_ERROR_NONE;
154 }
155