--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <Util.h>
+#include "Activity.h"
+
+using namespace ctx;
+
+ActivityProvider::ActivityProvider(const char *subject, activity_type_e type) :
+ BasicProvider(subject),
+ __activityType(type),
+ __activityHandle(NULL)
+{
+}
+
+ActivityProvider::~ActivityProvider()
+{
+ if (__activityHandle)
+ activity_release(__activityHandle);
+}
+
+bool ActivityProvider::isSupported()
+{
+ return util::getSystemInfoBool("tizen.org/feature/sensor.activity_recognition");
+}
+
+void ActivityProvider::submitTriggerItem()
+{
+ registerTriggerItem(OPS_SUBSCRIBE,
+ "{\"Event\":{\"type\":\"string\", \"values\":[\"Detected\"]}}",
+ "{\"Accuracy\":{\"type\":\"string\", \"values\":[\"Low\", \"Normal\", \"High\"]}}"
+ );
+}
+
+void ActivityProvider::__updateCb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* userData)
+{
+ IF_FAIL_VOID_TAG(error == ACTIVITY_ERROR_NONE, _E, "Error: %d", error);
+
+ ActivityProvider *instance = static_cast<ActivityProvider*>(userData);
+ instance->__handleUpdate(activity, data, timestamp);
+}
+
+void ActivityProvider::__handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp)
+{
+ IF_FAIL_VOID_TAG(activity == __activityType, _E, "Invalid activity: %d", activity);
+
+ Json dataRead;
+ dataRead.set(NULL, CTX_ACTIVITY_EVENT, CTX_ACTIVITY_DETECTED);
+
+ activity_accuracy_e accuracy = ACTIVITY_ACCURACY_LOW;
+ activity_get_accuracy(data, &accuracy);
+
+ switch (accuracy) {
+ case ACTIVITY_ACCURACY_HIGH:
+ dataRead.set(NULL, CTX_ACTIVITY_ACCURACY, CTX_ACTIVITY_HIGH);
+ break;
+ case ACTIVITY_ACCURACY_MID:
+ dataRead.set(NULL, CTX_ACTIVITY_ACCURACY, CTX_ACTIVITY_NORMAL);
+ break;
+ default:
+ dataRead.set(NULL, CTX_ACTIVITY_ACCURACY, CTX_ACTIVITY_LOW);
+ break;
+ }
+
+ publish(NULL, ERR_NONE, dataRead);
+}
+
+int ActivityProvider::subscribe()
+{
+ IF_FAIL_RETURN(__activityHandle == NULL, ERR_NONE);
+
+ activity_create(&__activityHandle);
+ IF_FAIL_RETURN_TAG(__activityHandle, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
+
+ int ret = activity_start_recognition(__activityHandle, __activityType, __updateCb, this);
+ if (ret != ACTIVITY_ERROR_NONE) {
+ _E("Recognition starting failed");
+ activity_release(__activityHandle);
+ __activityHandle = NULL;
+ return ERR_OPERATION_FAILED;
+ }
+
+ return ERR_NONE;
+}
+
+int ActivityProvider::unsubscribe()
+{
+ IF_FAIL_RETURN(__activityHandle, ERR_NONE);
+
+ activity_stop_recognition(__activityHandle);
+ activity_release(__activityHandle);
+ __activityHandle = NULL;
+
+ return ERR_NONE;
+}
* limitations under the License.
*/
-#ifndef _DEVICE_ACTIVITY_STATUS_H_
-#define _DEVICE_ACTIVITY_STATUS_H_
+#ifndef _CONTEXT_ACTIVITY_PROVIDER_H_
+#define _CONTEXT_ACTIVITY_PROVIDER_H_
-#include "ActivityBase.h"
+#include <string>
+#include <activity_recognition.h>
+#include <BasicProvider.h>
#include "ActivityTypes.h"
#define GENERATE_ACTIVITY_PROVIDER(actPrvd, actSubj, actType) \
- class actPrvd : public UserActivityBase { \
+ class actPrvd : public ActivityProvider { \
public: \
- actPrvd() : UserActivityBase(actSubj, actType) {} \
+ actPrvd() : ActivityProvider(actSubj, actType) {} \
}; \
namespace ctx {
- GENERATE_ACTIVITY_PROVIDER(UserActivityStationary, USER_ACT_SUBJ_STATIONARY, ACTIVITY_STATIONARY);
- GENERATE_ACTIVITY_PROVIDER(UserActivityWalking, USER_ACT_SUBJ_WALKING, ACTIVITY_WALK);
- GENERATE_ACTIVITY_PROVIDER(UserActivityRunning, USER_ACT_SUBJ_RUNNING, ACTIVITY_RUN);
- GENERATE_ACTIVITY_PROVIDER(UserActivityInVehicle, USER_ACT_SUBJ_IN_VEHICLE, ACTIVITY_IN_VEHICLE);
+
+ class ActivityProvider : public BasicProvider {
+ public:
+ ActivityProvider(const char *subject, activity_type_e type);
+ virtual ~ActivityProvider();
+
+ int subscribe();
+ int unsubscribe();
+
+ bool isSupported();
+ void submitTriggerItem();
+
+ protected:
+ activity_type_e __activityType;
+ activity_h __activityHandle;
+
+ private:
+ void __handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp);
+ static void __updateCb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* userData);
+ };
+
+
+ GENERATE_ACTIVITY_PROVIDER(StationaryActivityProvider, CTX_ACTIVITY_SUBJ_STATIONARY, ACTIVITY_STATIONARY);
+ GENERATE_ACTIVITY_PROVIDER(WalkingActivityProvider, CTX_ACTIVITY_SUBJ_WALKING, ACTIVITY_WALK);
+ GENERATE_ACTIVITY_PROVIDER(RunningActivityProvider, CTX_ACTIVITY_SUBJ_RUNNING, ACTIVITY_RUN);
+ GENERATE_ACTIVITY_PROVIDER(InVehicleActivityProvider, CTX_ACTIVITY_SUBJ_IN_VEHICLE, ACTIVITY_IN_VEHICLE);
}
-#endif // _DEVICE_ACTIVITY_STATUS_H_
+#endif // _CONTEXT_ACTIVITY_PROVIDER_H_
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <Util.h>
-#include "ActivityTypes.h"
-#include "ActivityBase.h"
-
-using namespace ctx;
-
-UserActivityBase::UserActivityBase(const char *subject, activity_type_e type) :
- BasicProvider(subject),
- __activityType(type),
- __activityHandle(NULL)
-{
-}
-
-UserActivityBase::~UserActivityBase()
-{
- if (__activityHandle)
- activity_release(__activityHandle);
-}
-
-bool UserActivityBase::isSupported()
-{
- return util::getSystemInfoBool("tizen.org/feature/sensor.activity_recognition");
-}
-
-void UserActivityBase::submitTriggerItem()
-{
- registerTriggerItem(OPS_SUBSCRIBE,
- "{\"Event\":{\"type\":\"string\", \"values\":[\"Detected\"]}}",
- "{\"Accuracy\":{\"type\":\"string\", \"values\":[\"Low\", \"Normal\", \"High\"]}}"
- );
-}
-
-void UserActivityBase::__updateCb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* userData)
-{
- IF_FAIL_VOID_TAG(error == ACTIVITY_ERROR_NONE, _E, "Error: %d", error);
-
- UserActivityBase *instance = static_cast<UserActivityBase*>(userData);
- instance->__handleUpdate(activity, data, timestamp);
-}
-
-void UserActivityBase::__handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp)
-{
- IF_FAIL_VOID_TAG(activity == __activityType, _E, "Invalid activity: %d", activity);
-
- Json dataRead;
- dataRead.set(NULL, USER_ACT_EVENT, USER_ACT_DETECTED);
-
- activity_accuracy_e accuracy = ACTIVITY_ACCURACY_LOW;
- activity_get_accuracy(data, &accuracy);
-
- switch (accuracy) {
- case ACTIVITY_ACCURACY_HIGH:
- dataRead.set(NULL, USER_ACT_ACCURACY, USER_ACT_HIGH);
- break;
- case ACTIVITY_ACCURACY_MID:
- dataRead.set(NULL, USER_ACT_ACCURACY, USER_ACT_NORMAL);
- break;
- default:
- dataRead.set(NULL, USER_ACT_ACCURACY, USER_ACT_LOW);
- break;
- }
-
- publish(NULL, ERR_NONE, dataRead);
-}
-
-int UserActivityBase::subscribe()
-{
- IF_FAIL_RETURN(__activityHandle == NULL, ERR_NONE);
-
- activity_create(&__activityHandle);
- IF_FAIL_RETURN_TAG(__activityHandle, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
-
- int ret = activity_start_recognition(__activityHandle, __activityType, __updateCb, this);
- if (ret != ACTIVITY_ERROR_NONE) {
- _E("Recognition starting failed");
- activity_release(__activityHandle);
- __activityHandle = NULL;
- return ERR_OPERATION_FAILED;
- }
-
- return ERR_NONE;
-}
-
-int UserActivityBase::unsubscribe()
-{
- IF_FAIL_RETURN(__activityHandle, ERR_NONE);
-
- activity_stop_recognition(__activityHandle);
- activity_release(__activityHandle);
- __activityHandle = NULL;
-
- return ERR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _DEVICE_ACTIVITY_STATUS_BASE_H_
-#define _DEVICE_ACTIVITY_STATUS_BASE_H_
-
-#include <string>
-#include <activity_recognition.h>
-#include "../shared/BasicProvider.h"
-
-namespace ctx {
-
- class UserActivityBase : public BasicProvider {
- public:
- UserActivityBase(const char *subject, activity_type_e type);
- virtual ~UserActivityBase();
-
- int subscribe();
- int unsubscribe();
-
- bool isSupported();
- void submitTriggerItem();
-
- protected:
- activity_type_e __activityType;
- activity_h __activityHandle;
-
- private:
- void __handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp);
- static void __updateCb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* userData);
- };
-
-}
-
-#endif // _DEVICE_ACTIVITY_STATUS_BASE_H_
* limitations under the License.
*/
-#ifndef _DEVICE_ACTIVITY_STATUS_TYPES_H_
-#define _DEVICE_ACTIVITY_STATUS_TYPES_H_
+#ifndef _CONTEXT_ACTIVITY_TYPES_H_
+#define _CONTEXT_ACTIVITY_TYPES_H_
-// Subject
-#define USER_ACT_SUBJ_IN_VEHICLE "activity/in_vehicle"
-#define USER_ACT_SUBJ_RUNNING "activity/running"
-#define USER_ACT_SUBJ_STATIONARY "activity/stationary"
-#define USER_ACT_SUBJ_WALKING "activity/walking"
+/* Subject */
+#define CTX_ACTIVITY_SUBJ_IN_VEHICLE "activity/in_vehicle"
+#define CTX_ACTIVITY_SUBJ_RUNNING "activity/running"
+#define CTX_ACTIVITY_SUBJ_STATIONARY "activity/stationary"
+#define CTX_ACTIVITY_SUBJ_WALKING "activity/walking"
-// Data Key
-#define USER_ACT_EVENT "Event"
-#define USER_ACT_ACCURACY "Accuracy"
+/* Data Key */
+#define CTX_ACTIVITY_EVENT "Event"
+#define CTX_ACTIVITY_ACCURACY "Accuracy"
-// Data Value
-#define USER_ACT_DETECTED "Detected"
-#define USER_ACT_LOW "Low"
-#define USER_ACT_NORMAL "Normal"
-#define USER_ACT_HIGH "High"
+/* Data Value */
+#define CTX_ACTIVITY_DETECTED "Detected"
+#define CTX_ACTIVITY_LOW "Low"
+#define CTX_ACTIVITY_NORMAL "Normal"
+#define CTX_ACTIVITY_HIGH "High"
-#endif // _DEVICE_ACTIVITY_STATUS_TYPES_H_
+#endif /* _CONTEXT_ACTIVITY_TYPES_H_ */
registerProvider<DeviceStatusBattery>(DEVICE_ST_SUBJ_BATTERY, NULL);
registerProvider<DeviceStatusPsmode>(DEVICE_ST_SUBJ_PSMODE, NULL);
- registerProvider<UserActivityStationary>(USER_ACT_SUBJ_STATIONARY, NULL);
- registerProvider<UserActivityWalking>(USER_ACT_SUBJ_WALKING, NULL);
- registerProvider<UserActivityRunning>(USER_ACT_SUBJ_RUNNING, NULL);
- registerProvider<UserActivityInVehicle>(USER_ACT_SUBJ_IN_VEHICLE, NULL);
+ registerProvider<StationaryActivityProvider>(CTX_ACTIVITY_SUBJ_STATIONARY, NULL);
+ registerProvider<WalkingActivityProvider>(CTX_ACTIVITY_SUBJ_WALKING, NULL);
+ registerProvider<RunningActivityProvider>(CTX_ACTIVITY_SUBJ_RUNNING, NULL);
+ registerProvider<InVehicleActivityProvider>(CTX_ACTIVITY_SUBJ_IN_VEHICLE, NULL);
#ifdef _MOBILE_
registerProvider<SocialStatusCall>(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY);