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 "ActivityProxy.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 {
33 EXTAPI int activity_is_supported(activity_type_e activity, bool* supported)
38 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
39 ASSERT_NOT_NULL(supported);
40 IF_FAIL_RETURN(IS_VALID_ACTIVITY(activity), ERR_INVALID_PARAMETER);
42 *supported = ActivityProxy::isSupported(activity);
46 EXTAPI int activity_create(activity_h *handle)
48 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
49 ASSERT_NOT_NULL(handle);
51 _activity_handle_s *hdl = static_cast<activity_h>(malloc(sizeof(_activity_handle_s)));
52 IF_FAIL_RETURN_TAG(hdl, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
54 hdl->proxy = new(std::nothrow) ActivityProxy();
55 if (hdl->proxy == NULL) {
56 _E("Memory allocation failed");
58 return ERR_OPERATION_FAILED;
65 EXTAPI int activity_release(activity_h handle)
67 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
68 ASSERT_NOT_NULL(handle);
76 EXTAPI int activity_start_recognition(activity_h handle, activity_type_e activity, activity_recognition_cb callback, void *user_data)
78 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
79 ASSERT_NOT_NULL(handle);
80 ASSERT_NOT_NULL(callback);
81 IF_FAIL_RETURN(IS_VALID_ACTIVITY(activity), ERR_INVALID_PARAMETER);
83 if (!handle->proxy->setActivity(activity)) {
84 return ERR_INVALID_PARAMETER;
87 handle->proxy->setPowerSave(false);
88 handle->proxy->setCb(callback);
89 handle->proxy->setUserData(user_data);
91 if (!handle->proxy->start()) {
92 return ERR_OPERATION_FAILED;
98 EXTAPI int activity_stop_recognition(activity_h handle)
100 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
101 ASSERT_NOT_NULL(handle);
103 IF_FAIL_RETURN(handle->proxy->stop(), ACTIVITY_ERROR_NOT_STARTED);
108 EXTAPI int activity_get_accuracy(const activity_data_h data, activity_accuracy_e *accuracy)
110 ASSERT_SUPPORTED(FEATURE_ACTIVITY);
111 ASSERT_NOT_NULL(data);
112 ASSERT_NOT_NULL(accuracy);
114 *accuracy = static_cast<activity_accuracy_e>(data->accuracy);