2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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 "ActivitySensor.h"
21 #define FEATURE_ACTIVITY "tizen.org/feature/sensor.activity_recognition"
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)
27 using namespace motion;
29 struct _activity_handle_s {
30 ActivitySensor *sensor;
33 EXPORT_API int activity_is_supported(activity_type_e activity, bool* supported)
35 _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
39 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
41 ASSERT_NOT_NULL(supported);
42 IF_FAIL_RETURN(IS_VALID_ACTIVITY(activity), ERR_INVALID_PARAMETER);
44 *supported = ActivitySensor::isSupported(activity);
49 EXPORT_API int activity_create(activity_h *handle)
51 _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
52 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
54 ASSERT_NOT_NULL(handle);
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");
59 hdl->sensor = new(std::nothrow) ActivitySensor();
60 if (hdl->sensor == NULL) {
61 _E("Memory allocation failed");
63 return ERR_OPERATION_FAILED;
71 EXPORT_API int activity_release(activity_h handle)
73 _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
74 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
76 ASSERT_NOT_NULL(handle);
78 delete handle->sensor;
85 EXPORT_API int activity_start_recognition(activity_h handle, activity_type_e activity, activity_recognition_cb callback, void *user_data)
87 _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
88 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
90 ASSERT_NOT_NULL(handle);
91 ASSERT_NOT_NULL(callback);
92 IF_FAIL_RETURN(IS_VALID_ACTIVITY(activity), ERR_INVALID_PARAMETER);
94 if (!handle->sensor->setActivity(activity)) {
95 return ERR_INVALID_PARAMETER;
98 handle->sensor->setCallback(callback);
99 handle->sensor->setUserData(user_data);
101 if (!handle->sensor->start()) {
102 return ERR_OPERATION_FAILED;
109 EXPORT_API int activity_stop_recognition(activity_h handle)
111 _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
112 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
114 ASSERT_NOT_NULL(handle);
116 IF_FAIL_RETURN(handle->sensor->stop(), ACTIVITY_ERROR_NOT_STARTED);
122 EXPORT_API int activity_get_accuracy(const activity_data_h data, activity_accuracy_e *accuracy)
124 _W("DEPRECATION WARNING: %s() is deprecated and will be removed from next release.", __func__);
125 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
127 ASSERT_NOT_NULL(data);
128 ASSERT_NOT_NULL(accuracy);
130 *accuracy = static_cast<activity_accuracy_e>(data->accuracy);