fix doxygen comments
[platform/core/api/application.git] / app_common / app_event.c
1 /*
2  * Copyright (c) 2011 - 2016 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         case APPCORE_RM_PORTRAIT_NORMAL:
29                 dev_orientation = APP_DEVICE_ORIENTATION_0;
30                 break;
31         case APPCORE_RM_PORTRAIT_REVERSE:
32                 dev_orientation = APP_DEVICE_ORIENTATION_180;
33                 break;
34         case APPCORE_RM_LANDSCAPE_NORMAL:
35                 dev_orientation = APP_DEVICE_ORIENTATION_270;
36                 break;
37         case APPCORE_RM_LANDSCAPE_REVERSE:
38                 dev_orientation = APP_DEVICE_ORIENTATION_90;
39                 break;
40         default:
41                 dev_orientation = APP_DEVICE_ORIENTATION_0;
42                 break;
43         }
44
45         return dev_orientation;
46 }
47
48 static int _app_convert_low_memory(void *val)
49 {
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;
57         default:
58                 return -1;
59         }
60 }
61
62 static int _app_convert_low_battery(void *val)
63 {
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;
69         default:
70                 return -1;
71         }
72 }
73
74 int app_event_get_low_memory_status(app_event_info_h event_info, app_event_low_memory_status_e *status)
75 {
76         int ret;
77
78         if (event_info == NULL || status == NULL)
79                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
80
81         if (event_info->type != APP_EVENT_LOW_MEMORY)
82                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "event type mismatching");
83
84         ret = _app_convert_low_memory(event_info->value);
85         if (ret < 0)
86                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "invalid event info");
87
88         *status = ret;
89
90         return APP_ERROR_NONE;
91 }
92
93 int app_event_get_low_battery_status(app_event_info_h event_info, app_event_low_battery_status_e *status)
94 {
95         int ret;
96
97         if (event_info == NULL || status == NULL)
98                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
99
100         if (event_info->type != APP_EVENT_LOW_BATTERY)
101                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "event type mismatching");
102
103         ret = _app_convert_low_battery(event_info->value);
104         if (ret < 0)
105                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "invalid event info");
106
107         *status = ret;
108
109         return APP_ERROR_NONE;
110 }
111
112 int app_event_get_language(app_event_info_h event_info, char **lang)
113 {
114         if (event_info == NULL || lang == NULL)
115                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
116
117         if (event_info->type != APP_EVENT_LANGUAGE_CHANGED)
118                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
119
120         *lang = strdup(event_info->value);
121
122         return APP_ERROR_NONE;
123 }
124
125 int app_event_get_region_format(app_event_info_h event_info, char **region)
126 {
127         if (event_info == NULL || region == NULL)
128                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
129
130         if (event_info->type != APP_EVENT_REGION_FORMAT_CHANGED)
131                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
132
133         *region = strdup(event_info->value);
134
135         return APP_ERROR_NONE;
136 }
137
138 int app_event_get_device_orientation(app_event_info_h event_info, app_device_orientation_e *orientation)
139 {
140         if (event_info == NULL || orientation == NULL)
141                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
142
143         if (event_info->type != APP_EVENT_DEVICE_ORIENTATION_CHANGED)
144                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
145
146         *orientation = app_convert_appcore_rm(*(enum appcore_rm *)(event_info->value));
147
148         return APP_ERROR_NONE;
149 }
150
151 int app_event_get_suspended_state(app_event_info_h event_info, app_suspended_state_e *state)
152 {
153         if (event_info == NULL || state == NULL)
154                 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "null parameter");
155
156         if (event_info->type != APP_EVENT_SUSPENDED_STATE_CHANGED)
157                 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "event type mismatching");
158
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;
163
164         return APP_ERROR_NONE;
165 }
166