revise gcov option on rpm spec
[platform/core/api/motion.git] / src / Activity.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
18 #include <stdlib.h>
19 #include "ActivitySensor.h"
20
21 #define FEATURE_ACTIVITY "tizen.org/feature/sensor.activity_recognition"
22
23 #define ACTIVITY_FIRST  ACTIVITY_STATIONARY
24 #define ACTIVITY_LAST   ACTIVITY_IN_VEHICLE
25 #define IS_VALID_ACTIVITY(X)    (ACTIVITY_FIRST <= (X) && (X) <= ACTIVITY_LAST)
26
27 using namespace motion;
28
29 struct _activity_handle_s {
30         ActivitySensor *sensor;
31 };
32
33 EXPORT_API int activity_is_supported(activity_type_e activity, bool* supported)
34 {
35         _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
36         if (supported)
37                 *supported = false;
38
39         ASSERT_SUPPORTED(FEATURE_ACTIVITY);
40         //LCOV_EXCL_START
41         ASSERT_NOT_NULL(supported);
42         IF_FAIL_RETURN(IS_VALID_ACTIVITY(activity), ERR_INVALID_PARAMETER);
43
44         *supported = ActivitySensor::isSupported(activity);
45         return ERR_NONE;
46         //LCOV_EXCL_STOP
47 }
48
49 EXPORT_API int activity_create(activity_h *handle)
50 {
51         _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
52         ASSERT_SUPPORTED(FEATURE_ACTIVITY);
53         //LCOV_EXCL_START
54         ASSERT_NOT_NULL(handle);
55
56         _activity_handle_s *hdl = static_cast<activity_h>(malloc(sizeof(_activity_handle_s)));
57         IF_FAIL_RETURN_TAG(hdl, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
58
59         hdl->sensor = new(std::nothrow) ActivitySensor();
60         if (hdl->sensor == NULL) {
61                 _E("Memory allocation failed");
62                 free(hdl);
63                 return ERR_OPERATION_FAILED;
64         }
65
66         *handle = hdl;
67         return ERR_NONE;
68         //LCOV_EXCL_STOP
69 }
70
71 EXPORT_API int activity_release(activity_h handle)
72 {
73         _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
74         ASSERT_SUPPORTED(FEATURE_ACTIVITY);
75         //LCOV_EXCL_START
76         ASSERT_NOT_NULL(handle);
77
78         delete handle->sensor;
79         free(handle);
80
81         return ERR_NONE;
82         //LCOV_EXCL_STOP
83 }
84
85 EXPORT_API int activity_start_recognition(activity_h handle, activity_type_e activity, activity_recognition_cb callback, void *user_data)
86 {
87         _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
88         ASSERT_SUPPORTED(FEATURE_ACTIVITY);
89         //LCOV_EXCL_START
90         ASSERT_NOT_NULL(handle);
91         ASSERT_NOT_NULL(callback);
92         IF_FAIL_RETURN(IS_VALID_ACTIVITY(activity), ERR_INVALID_PARAMETER);
93
94         if (!handle->sensor->setActivity(activity)) {
95                 return ERR_INVALID_PARAMETER;
96         }
97
98         handle->sensor->setCallback(callback);
99         handle->sensor->setUserData(user_data);
100
101         if (!handle->sensor->start()) {
102                 return ERR_OPERATION_FAILED;
103         }
104
105         return ERR_NONE;
106         //LCOV_EXCL_STOP
107 }
108
109 EXPORT_API int activity_stop_recognition(activity_h handle)
110 {
111         _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
112         ASSERT_SUPPORTED(FEATURE_ACTIVITY);
113         //LCOV_EXCL_START
114         ASSERT_NOT_NULL(handle);
115
116         IF_FAIL_RETURN(handle->sensor->stop(), ACTIVITY_ERROR_NOT_STARTED);
117
118         return ERR_NONE;
119         //LCOV_EXCL_STOP
120 }
121
122 EXPORT_API int activity_get_accuracy(const activity_data_h data, activity_accuracy_e *accuracy)
123 {
124         _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
125         ASSERT_SUPPORTED(FEATURE_ACTIVITY);
126         //LCOV_EXCL_START
127         ASSERT_NOT_NULL(data);
128         ASSERT_NOT_NULL(accuracy);
129
130         *accuracy = static_cast<activity_accuracy_e>(data->accuracy);
131
132         return ERR_NONE;
133         //LCOV_EXCL_STOP
134 }