2 * Copyright (c) 2011 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <vconf-internal-keys.h>
20 #include <app_common.h>
21 #include <app_internal.h>
23 app_device_orientation_e app_convert_appcore_rm(enum appcore_rm rm)
25 app_device_orientation_e dev_orientation;
28 case APPCORE_RM_PORTRAIT_NORMAL:
29 dev_orientation = APP_DEVICE_ORIENTATION_0;
31 case APPCORE_RM_PORTRAIT_REVERSE:
32 dev_orientation = APP_DEVICE_ORIENTATION_180;
34 case APPCORE_RM_LANDSCAPE_NORMAL:
35 dev_orientation = APP_DEVICE_ORIENTATION_270;
37 case APPCORE_RM_LANDSCAPE_REVERSE:
38 dev_orientation = APP_DEVICE_ORIENTATION_90;
41 dev_orientation = APP_DEVICE_ORIENTATION_0;
45 return dev_orientation;
48 static int _app_convert_low_memory(void *val)
50 switch (*(int *)val) {
51 case VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL:
52 return APP_EVENT_LOW_MEMORY_NORMAL;
53 case VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING:
54 return APP_EVENT_LOW_MEMORY_SOFT_WARNING;
55 case VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING:
56 return APP_EVENT_LOW_MEMORY_HARD_WARNING;
62 static int _app_convert_low_battery(void *val)
64 switch (*(int *)val) {
65 case VCONFKEY_SYSMAN_BAT_POWER_OFF:
66 return APP_EVENT_LOW_BATTERY_POWER_OFF;
67 case VCONFKEY_SYSMAN_BAT_CRITICAL_LOW:
68 return APP_EVENT_LOW_BATTERY_CRITICAL_LOW;
74 int app_event_get_low_memory_status(app_event_info_h event_info, app_event_low_memory_status_e *status)
78 if (event_info == NULL || status == NULL)
79 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
81 if (event_info->type != APP_EVENT_LOW_MEMORY)
82 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "event type mismatching");
84 ret = _app_convert_low_memory(event_info->value);
86 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "invalid event info");
90 return APP_ERROR_NONE;
93 int app_event_get_low_battery_status(app_event_info_h event_info, app_event_low_battery_status_e *status)
97 if (event_info == NULL || status == NULL)
98 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
100 if (event_info->type != APP_EVENT_LOW_BATTERY)
101 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "event type mismatching");
103 ret = _app_convert_low_battery(event_info->value);
105 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "invalid event info");
109 return APP_ERROR_NONE;
112 int app_event_get_language(app_event_info_h event_info, char **lang)
114 if (event_info == NULL || lang == NULL)
115 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
117 if (event_info->type != APP_EVENT_LANGUAGE_CHANGED)
118 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
120 *lang = strdup(event_info->value);
122 return APP_ERROR_NONE;
125 int app_event_get_region_format(app_event_info_h event_info, char **region)
127 if (event_info == NULL || region == NULL)
128 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
130 if (event_info->type != APP_EVENT_REGION_FORMAT_CHANGED)
131 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
133 *region = strdup(event_info->value);
135 return APP_ERROR_NONE;
138 int app_event_get_device_orientation(app_event_info_h event_info, app_device_orientation_e *orientation)
140 if (event_info == NULL || orientation == NULL)
141 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
143 if (event_info->type != APP_EVENT_DEVICE_ORIENTATION_CHANGED)
144 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
146 *orientation = app_convert_appcore_rm(*(enum appcore_rm *)(event_info->value));
148 return APP_ERROR_NONE;
151 int app_event_get_suspended_state(app_event_info_h event_info, app_suspended_state_e *state)
153 if (event_info == NULL || state == NULL)
154 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
156 if (event_info->type != APP_EVENT_SUSPENDED_STATE_CHANGED)
157 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
159 if (*(enum appcore_suspended_state *)(event_info->value) == APPCORE_SUSPENDED_STATE_WILL_ENTER_SUSPEND)
160 *state = APP_SUSPENDED_STATE_WILL_ENTER;
161 else if (*(enum appcore_suspended_state *)(event_info->value) == APPCORE_SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND)
162 *state = APP_SUSPENDED_STATE_DID_EXIT;
164 return APP_ERROR_NONE;