# prvd_cdef, prvd_deps, and prvd_srcs need to be set properly
# Common Profile
-FILE(GLOB prvd_srcs ./*.cpp system/alarm.cpp system/time.cpp)
+FILE(GLOB prvd_srcs ./*.cpp system/Alarm.cpp system/Time.cpp)
SET(prvd_deps vconf capi-system-info capi-system-device capi-system-runtime-info)
# Mobile Profile
SET(prvd_deps ${prvd_deps} capi-telephony tapi msg-service motion)
FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} activity/*.cpp)
FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} system/*.cpp)
- FILE(GLOB prvd_srcs ${prvd_srcs} social/call.cpp social/message.cpp)
+ FILE(GLOB prvd_srcs ${prvd_srcs} social/Call.cpp social/Message.cpp)
ENDIF("${PROFILE}" STREQUAL "wearable")
# TV Profile
IF("${PROFILE}" STREQUAL "tv")
SET(prvd_deps ${prvd_deps} capi-network-bluetooth capi-network-wifi)
- FILE(GLOB prvd_srcs ${prvd_srcs} system/headphone.cpp system/wifi.cpp)
+ FILE(GLOB prvd_srcs ${prvd_srcs} system/Headphone.cpp system/Wifi.cpp)
ENDIF("${PROFILE}" STREQUAL "tv")
--- /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 <types_internal.h>
+#include <ContextManager.h>
+#include <ContextProviderBase.h>
+#include <DeviceContextProvider.h>
+
+#include "system/SystemTypes.h"
+#include "social/SocialTypes.h"
+#include "activity/ActivityTypes.h"
+
+#include "system/Alarm.h"
+#include "system/Time.h"
+
+#ifdef _MOBILE_
+#include "system/runtime_info/Charger.h"
+#include "system/runtime_info/Gps.h"
+#include "system/runtime_info/Usb.h"
+#include "system/Wifi.h"
+#include "system/Headphone.h"
+#include "system/Battery.h"
+#include "system/Psmode.h"
+#include "social/Call.h"
+#include "social/Email.h"
+#include "social/Message.h"
+#include "social/Contacts.h"
+#include "activity/Activity.h"
+#endif
+
+#ifdef _WEARABLE_
+#include "system/runtime_info/Charger.h"
+#include "system/runtime_info/Gps.h"
+#include "system/runtime_info/Usb.h"
+#include "system/Wifi.h"
+#include "system/Headphone.h"
+#include "system/Battery.h"
+#include "system/Psmode.h"
+#include "social/Call.h"
+#include "social/Message.h"
+#include "activity/Activity.h"
+#endif
+
+#ifdef _TV_
+#include "system/Wifi.h"
+#include "system/Headphone.h"
+#endif
+
+#define PRIV_NETWORK "network.get"
+#define PRIV_TELEPHONY "telephony"
+#define PRIV_MESSAGE "message.read"
+#define PRIV_CONTACT "contact.read"
+
+template<typename Provider>
+void registerProvider(const char *subject, const char *privilege)
+{
+ if (!Provider::isSupported())
+ return;
+
+ ctx::ContextProviderInfo providerInfo(Provider::create, Provider::destroy, NULL, privilege);
+ ctx::context_manager::registerProvider(subject, providerInfo);
+ Provider::submitTriggerItem();
+}
+
+EXTAPI bool ctx::initDeviceContextProvider()
+{
+ registerProvider<DeviceStatusAlarm>(DEVICE_ST_SUBJ_ALARM, NULL);
+ registerProvider<DeviceStatusTime>(DEVICE_ST_SUBJ_TIME, NULL);
+
+#ifdef _MOBILE_
+ registerProvider<DeviceStatusWifi>(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK);
+ registerProvider<DeviceStatusHeadphone>(DEVICE_ST_SUBJ_HEADPHONE, NULL);
+
+ registerProvider<DeviceStatusCharger>(DEVICE_ST_SUBJ_CHARGER, NULL);
+ registerProvider<DeviceStatusGps>(DEVICE_ST_SUBJ_GPS, NULL);
+ registerProvider<DeviceStatusUsb>(DEVICE_ST_SUBJ_USB, NULL);
+ registerProvider<DeviceStatusBattery>(DEVICE_ST_SUBJ_BATTERY, NULL);
+ registerProvider<DeviceStatusPsmode>(DEVICE_ST_SUBJ_PSMODE, NULL);
+
+ registerProvider<SocialStatusCall>(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY);
+ registerProvider<SocialStatusEmail>(SOCIAL_ST_SUBJ_EMAIL, NULL);
+ registerProvider<SocialStatusMessage>(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE);
+ registerProvider<SocialStatusContacts>(SOCIAL_ST_SUBJ_CONTACTS, PRIV_CONTACT);
+
+ 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);
+
+ /* Create context providers, which need to be initiated before being subscribed */
+ if (DeviceStatusWifi::isSupported())
+ DeviceStatusWifi::create(NULL);
+#endif
+
+#ifdef _WEARABLE_
+ registerProvider<DeviceStatusWifi>(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK);
+ registerProvider<DeviceStatusHeadphone>(DEVICE_ST_SUBJ_HEADPHONE, NULL);
+
+ registerProvider<DeviceStatusCharger>(DEVICE_ST_SUBJ_CHARGER, NULL);
+ registerProvider<DeviceStatusGps>(DEVICE_ST_SUBJ_GPS, NULL);
+ registerProvider<DeviceStatusUsb>(DEVICE_ST_SUBJ_USB, NULL);
+ registerProvider<DeviceStatusBattery>(DEVICE_ST_SUBJ_BATTERY, NULL);
+ registerProvider<DeviceStatusPsmode>(DEVICE_ST_SUBJ_PSMODE, NULL);
+
+ registerProvider<SocialStatusCall>(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY);
+ registerProvider<SocialStatusMessage>(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE);
+
+ 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);
+
+ /* Create context providers, which need to be initiated before being subscribed */
+ if (DeviceStatusWifi::isSupported())
+ DeviceStatusWifi::create(NULL);
+#endif
+
+#ifdef _TV_
+ registerProvider<DeviceStatusWifi>(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK);
+ registerProvider<DeviceStatusHeadphone>(DEVICE_ST_SUBJ_HEADPHONE, NULL);
+
+ /* Create context providers, which need to be initiated before being subscribed */
+ if (DeviceStatusWifi::isSupported())
+ DeviceStatusWifi::create(NULL);
+#endif
+
+ return true;
+}
--- /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 <system_info.h>
+#include "DeviceProviderBase.h"
+
+ctx::DeviceProviderBase::DeviceProviderBase()
+ : __beingSubscribed(false)
+{
+}
+
+int ctx::DeviceProviderBase::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult)
+{
+ IF_FAIL_RETURN(!__beingSubscribed, ERR_NONE);
+
+ int ret = subscribe();
+
+ if (ret == ERR_NONE)
+ __beingSubscribed = true;
+ else
+ destroySelf();
+
+ return ret;
+}
+
+int ctx::DeviceProviderBase::unsubscribe(const char *subject, ctx::Json option)
+{
+ int ret = ERR_NONE;
+
+ if (__beingSubscribed)
+ ret = unsubscribe();
+
+ destroySelf();
+ return ret;
+}
+
+int ctx::DeviceProviderBase::read(const char *subject, ctx::Json option, ctx::Json *requestResult)
+{
+ int ret = read();
+
+ if (!__beingSubscribed)
+ destroySelf();
+
+ return ret;
+}
+
+int ctx::DeviceProviderBase::write(const char *subject, ctx::Json data, ctx::Json *requestResult)
+{
+ int ret = write();
+
+ if (!__beingSubscribed)
+ destroySelf();
+
+ return ret;
+}
+
+int ctx::DeviceProviderBase::subscribe()
+{
+ return ERR_NOT_SUPPORTED;
+}
+
+int ctx::DeviceProviderBase::unsubscribe()
+{
+ return ERR_NOT_SUPPORTED;
+}
+
+int ctx::DeviceProviderBase::read()
+{
+ return ERR_NOT_SUPPORTED;
+}
+
+int ctx::DeviceProviderBase::write()
+{
+ return ERR_NOT_SUPPORTED;
+}
+
+bool ctx::DeviceProviderBase::getSystemInfoBool(const char *key)
+{
+ bool supported = false;
+ int ret = system_info_get_platform_bool(key, &supported);
+ IF_FAIL_RETURN_TAG(ret == SYSTEM_INFO_ERROR_NONE, false, _E, "system_info_get_platform_bool() failed");
+ return supported;
+}
--- /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 _CONTEXT_DEVICE_PROVIDER_BASE_H_
+#define _CONTEXT_DEVICE_PROVIDER_BASE_H_
+
+#include <types_internal.h>
+#include <Json.h>
+#include <ContextProviderBase.h>
+
+#define CREATE_INSTANCE(prvd) \
+ do { \
+ IF_FAIL_RETURN(!__instance, __instance); \
+ __instance = new(std::nothrow) prvd(); \
+ IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); \
+ _I(BLUE("Created")); \
+ return __instance; \
+ } while (0) \
+
+#define DESTROY_INSTANCE() \
+ do { \
+ IF_FAIL_VOID(__instance); \
+ delete __instance; \
+ __instance = NULL; \
+ _I(BLUE("Destroyed")); \
+ } while (0) \
+
+#define GENERATE_PROVIDER_COMMON_DECL(prvd) \
+ public: \
+ static ContextProviderBase *create(void *data); \
+ static void destroy(void *data); \
+ protected: \
+ void destroySelf(); \
+ private: \
+ static prvd *__instance; \
+
+#define GENERATE_PROVIDER_COMMON_IMPL(prvd) \
+ ctx::prvd *ctx::prvd::__instance = NULL; \
+ ctx::ContextProviderBase *ctx::prvd::create(void *data) \
+ { \
+ CREATE_INSTANCE(prvd); \
+ } \
+ void ctx::prvd::destroy(void *data) \
+ { \
+ DESTROY_INSTANCE(); \
+ } \
+ void ctx::prvd::destroySelf() \
+ { \
+ destroy(NULL); \
+ } \
+
+namespace ctx {
+
+ class DeviceProviderBase : public ContextProviderBase {
+ public:
+ int subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult);
+ int unsubscribe(const char *subject, ctx::Json option);
+ int read(const char *subject, ctx::Json option, ctx::Json *requestResult);
+ int write(const char *subject, ctx::Json data, ctx::Json *requestResult);
+
+ protected:
+ bool __beingSubscribed;
+
+ DeviceProviderBase();
+ virtual ~DeviceProviderBase() {}
+
+ virtual int subscribe();
+ virtual int unsubscribe();
+ virtual int read();
+ virtual int write();
+ virtual void destroySelf() = 0;
+
+ static bool getSystemInfoBool(const char *key);
+ };
+}
+
+#endif // _CONTEXT_DEVICE_PROVIDER_BASE_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.
+ */
+
+#ifndef _DEVICE_ACTIVITY_STATUS_H_
+#define _DEVICE_ACTIVITY_STATUS_H_
+
+#include <system_info.h>
+#include "ActivityBase.h"
+
+#define GENERATE_ACTIVITY_PROVIDER(actPrvd, actSubj, actType) \
+ class actPrvd : public UserActivityBase { \
+ public: \
+ static ContextProviderBase *create(void *data) \
+ { \
+ CREATE_INSTANCE(ctx::actPrvd); \
+ } \
+ static void destroy(void *data) \
+ { \
+ DESTROY_INSTANCE(); \
+ } \
+ static bool isSupported() \
+ { \
+ return getSystemInfoBool("tizen.org/feature/sensor.activity_recognition"); \
+ } \
+ static void submitTriggerItem() \
+ { \
+ context_manager::registerTriggerItem((actSubj), OPS_SUBSCRIBE, \
+ "{\"Event\":{\"type\":\"string\", \"values\":[\"Detected\"]}}", \
+ "{\"Accuracy\":{\"type\":\"string\", \"values\":[\"Low\", \"Normal\", \"High\"]}}" \
+ ); \
+ } \
+ protected: \
+ void destroySelf() \
+ { \
+ destroy(NULL); \
+ } \
+ private: \
+ static actPrvd *__instance; \
+ actPrvd() : UserActivityBase((actSubj), (actType)) {} \
+ }; \
+ ctx::actPrvd *ctx::actPrvd::__instance = NULL; \
+
+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);
+}
+
+#endif // _DEVICE_ACTIVITY_STATUS_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 <types_internal.h>
+#include <ContextManager.h>
+#include "ActivityTypes.h"
+#include "ActivityBase.h"
+
+ctx::UserActivityBase::UserActivityBase(const char *subj, activity_type_e type) :
+ __activityType(type),
+ __activityHandle(NULL),
+ __subject(subj)
+{
+}
+
+ctx::UserActivityBase::~UserActivityBase()
+{
+ if (__activityHandle)
+ activity_release(__activityHandle);
+}
+
+void ctx::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 ctx::UserActivityBase::__handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp)
+{
+ IF_FAIL_VOID_TAG(activity == __activityType, _E, "Invalid activity: %d", activity);
+
+ ctx::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;
+ }
+
+ context_manager::publish(__subject.c_str(), NULL, ERR_NONE, dataRead);
+}
+
+int ctx::UserActivityBase::subscribe()
+{
+ IF_FAIL_RETURN(__activityHandle == NULL, ERR_NONE);
+
+ _D("Starting to monitor %s", __subject.c_str());
+
+ 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 ctx::UserActivityBase::unsubscribe()
+{
+ IF_FAIL_RETURN(__activityHandle, ERR_NONE);
+
+ _D("Stop monitoring %s", __subject.c_str());
+
+ 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 "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class UserActivityBase : public DeviceProviderBase {
+ public:
+ int subscribe();
+ int unsubscribe();
+
+ protected:
+ activity_type_e __activityType;
+ activity_h __activityHandle;
+ std::string __subject;
+
+ UserActivityBase(const char *subj, activity_type_e type);
+ virtual ~UserActivityBase();
+
+ 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_
--- /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_TYPES_H_
+#define _DEVICE_ACTIVITY_STATUS_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"
+
+// Data Key
+#define USER_ACT_EVENT "Event"
+#define USER_ACT_ACCURACY "Accuracy"
+
+// Data Value
+#define USER_ACT_DETECTED "Detected"
+#define USER_ACT_LOW "Low"
+#define USER_ACT_NORMAL "Normal"
+#define USER_ACT_HIGH "High"
+
+#endif // _DEVICE_ACTIVITY_STATUS_TYPES_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.
- */
-
-#ifndef _DEVICE_STATUS_ACTIVITY_H_
-#define _DEVICE_STATUS_ACTIVITY_H_
-
-#include <system_info.h>
-#include "activity_base.h"
-
-#define GENERATE_ACTIVITY_PROVIDER(act_prvd, act_subj, act_type) \
- class act_prvd : public user_activity_base { \
- public: \
- static ContextProviderBase *create(void *data) \
- { \
- CREATE_INSTANCE(ctx::act_prvd); \
- } \
- static void destroy(void *data) \
- { \
- DESTROY_INSTANCE(); \
- } \
- static bool is_supported() \
- { \
- return get_system_info_bool("tizen.org/feature/sensor.activity_recognition"); \
- } \
- static void submit_trigger_item() \
- { \
- context_manager::registerTriggerItem((act_subj), OPS_SUBSCRIBE, \
- "{\"Event\":{\"type\":\"string\", \"values\":[\"Detected\"]}}", \
- "{\"Accuracy\":{\"type\":\"string\", \"values\":[\"Low\", \"Normal\", \"High\"]}}" \
- ); \
- } \
- protected: \
- void destroy_self() \
- { \
- destroy(NULL); \
- } \
- private: \
- static act_prvd *__instance; \
- act_prvd() : user_activity_base((act_subj), (act_type)) {} \
- }; \
- ctx::act_prvd *ctx::act_prvd::__instance = NULL; \
-
-namespace ctx {
- GENERATE_ACTIVITY_PROVIDER(user_activity_stationary, USER_ACT_SUBJ_STATIONARY, ACTIVITY_STATIONARY);
- GENERATE_ACTIVITY_PROVIDER(user_activity_walking, USER_ACT_SUBJ_WALKING, ACTIVITY_WALK);
- GENERATE_ACTIVITY_PROVIDER(user_activity_running, USER_ACT_SUBJ_RUNNING, ACTIVITY_RUN);
- GENERATE_ACTIVITY_PROVIDER(user_activity_in_vehicle, USER_ACT_SUBJ_IN_VEHICLE, ACTIVITY_IN_VEHICLE);
-}
-
-#endif // _DEVICE_STATUS_ACTIVITY_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 <types_internal.h>
-#include <ContextManager.h>
-#include "activity_types.h"
-#include "activity_base.h"
-
-ctx::user_activity_base::user_activity_base(const char *subj, activity_type_e type)
- : activity_type(type)
- , activity_handle(NULL)
- , subject(subj)
-{
-}
-
-ctx::user_activity_base::~user_activity_base()
-{
- if (activity_handle)
- activity_release(activity_handle);
-}
-
-void ctx::user_activity_base::event_cb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* user_data)
-{
- IF_FAIL_VOID_TAG(error == ACTIVITY_ERROR_NONE, _E, "Error: %d", error);
-
- user_activity_base *instance = static_cast<user_activity_base*>(user_data);
- instance->handle_event(activity, data, timestamp);
-}
-
-void ctx::user_activity_base::handle_event(activity_type_e activity, const activity_data_h data, double timestamp)
-{
- IF_FAIL_VOID_TAG(activity == activity_type, _E, "Invalid activity: %d", activity);
-
- ctx::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;
- }
-
- context_manager::publish(subject.c_str(), NULL, ERR_NONE, dataRead);
-}
-
-int ctx::user_activity_base::subscribe()
-{
- IF_FAIL_RETURN(activity_handle == NULL, ERR_NONE);
-
- _D("Starting to monitor %s", subject.c_str());
-
- activity_create(&activity_handle);
- IF_FAIL_RETURN_TAG(activity_handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
-
- int ret = activity_start_recognition(activity_handle, activity_type, event_cb, this);
- if (ret != ACTIVITY_ERROR_NONE) {
- _E("Recognition starting failed");
- activity_release(activity_handle);
- activity_handle = NULL;
- return ERR_OPERATION_FAILED;
- }
-
- return ERR_NONE;
-}
-
-int ctx::user_activity_base::unsubscribe()
-{
- IF_FAIL_RETURN(activity_handle, ERR_NONE);
-
- _D("Stop monitoring %s", subject.c_str());
-
- activity_stop_recognition(activity_handle);
- activity_release(activity_handle);
- activity_handle = 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_STATUS_ACTIVITY_BASE_H_
-#define _DEVICE_STATUS_ACTIVITY_BASE_H_
-
-#include <string>
-#include <activity_recognition.h>
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class user_activity_base : public device_provider_base {
- public:
- int subscribe();
- int unsubscribe();
-
- protected:
- activity_type_e activity_type;
- activity_h activity_handle;
- std::string subject;
-
- user_activity_base(const char *subj, activity_type_e type);
- virtual ~user_activity_base();
-
- private:
- void handle_event(activity_type_e activity, const activity_data_h data, double timestamp);
- static void event_cb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* user_data);
- };
-
-}
-
-#endif // _DEVICE_STATUS_ACTIVITY_BASE_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.
- */
-
-#ifndef __CONTEXT_USER_ACTIVITY_TYPES_H__
-#define __CONTEXT_USER_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"
-
-// Data Key
-#define USER_ACT_EVENT "Event"
-#define USER_ACT_ACCURACY "Accuracy"
-
-// Data Value
-#define USER_ACT_DETECTED "Detected"
-#define USER_ACT_LOW "Low"
-#define USER_ACT_NORMAL "Normal"
-#define USER_ACT_HIGH "High"
-
-#endif //__CONTEXT_USER_ACTIVITY_TYPES_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 <types_internal.h>
-#include <ContextManager.h>
-#include <ContextProviderBase.h>
-#include <DeviceContextProvider.h>
-
-#include "system/system_types.h"
-#include "social/social_types.h"
-#include "activity/activity_types.h"
-
-#include "system/alarm.h"
-#include "system/time.h"
-
-#ifdef _MOBILE_
-#include "system/runtime-info/charger.h"
-#include "system/runtime-info/gps.h"
-#include "system/runtime-info/usb.h"
-#include "system/wifi.h"
-#include "system/headphone.h"
-#include "system/battery.h"
-#include "system/psmode.h"
-#include "social/call.h"
-#include "social/email.h"
-#include "social/message.h"
-#include "social/contacts.h"
-#include "activity/activity.h"
-#endif
-
-#ifdef _WEARABLE_
-#include "system/runtime-info/charger.h"
-#include "system/runtime-info/gps.h"
-#include "system/runtime-info/usb.h"
-#include "system/wifi.h"
-#include "system/headphone.h"
-#include "system/battery.h"
-#include "system/psmode.h"
-#include "social/call.h"
-#include "social/message.h"
-#include "activity/activity.h"
-#endif
-
-#ifdef _TV_
-#include "system/wifi.h"
-#include "system/headphone.h"
-#endif
-
-#define PRIV_NETWORK "network.get"
-#define PRIV_TELEPHONY "telephony"
-#define PRIV_MESSAGE "message.read"
-#define PRIV_CONTACT "contact.read"
-
-template<typename provider>
-void registerProvider(const char *subject, const char *privilege)
-{
- if (!provider::is_supported())
- return;
-
- ctx::ContextProviderInfo providerInfo(provider::create, provider::destroy, NULL, privilege);
- ctx::context_manager::registerProvider(subject, providerInfo);
- provider::submit_trigger_item();
-}
-
-EXTAPI bool ctx::initDeviceContextProvider()
-{
- registerProvider<device_status_alarm>(DEVICE_ST_SUBJ_ALARM, NULL);
- registerProvider<device_status_time>(DEVICE_ST_SUBJ_TIME, NULL);
-
-#ifdef _MOBILE_
- registerProvider<device_status_wifi>(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK);
- registerProvider<device_status_headphone>(DEVICE_ST_SUBJ_HEADPHONE, NULL);
-
- registerProvider<device_status_charger>(DEVICE_ST_SUBJ_CHARGER, NULL);
- registerProvider<device_status_gps>(DEVICE_ST_SUBJ_GPS, NULL);
- registerProvider<device_status_usb>(DEVICE_ST_SUBJ_USB, NULL);
- registerProvider<device_status_battery>(DEVICE_ST_SUBJ_BATTERY, NULL);
- registerProvider<device_status_psmode>(DEVICE_ST_SUBJ_PSMODE, NULL);
-
- registerProvider<social_status_call>(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY);
- registerProvider<social_status_email>(SOCIAL_ST_SUBJ_EMAIL, NULL);
- registerProvider<social_status_message>(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE);
- registerProvider<social_status_contacts>(SOCIAL_ST_SUBJ_CONTACTS, PRIV_CONTACT);
-
- registerProvider<user_activity_stationary>(USER_ACT_SUBJ_STATIONARY, NULL);
- registerProvider<user_activity_walking>(USER_ACT_SUBJ_WALKING, NULL);
- registerProvider<user_activity_running>(USER_ACT_SUBJ_RUNNING, NULL);
- registerProvider<user_activity_in_vehicle>(USER_ACT_SUBJ_IN_VEHICLE, NULL);
-
- /* Create context providers, which need to be initiated before being subscribed */
- if (device_status_wifi::is_supported())
- device_status_wifi::create(NULL);
-#endif
-
-#ifdef _WEARABLE_
- registerProvider<device_status_wifi>(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK);
- registerProvider<device_status_headphone>(DEVICE_ST_SUBJ_HEADPHONE, NULL);
-
- registerProvider<device_status_charger>(DEVICE_ST_SUBJ_CHARGER, NULL);
- registerProvider<device_status_gps>(DEVICE_ST_SUBJ_GPS, NULL);
- registerProvider<device_status_usb>(DEVICE_ST_SUBJ_USB, NULL);
- registerProvider<device_status_battery>(DEVICE_ST_SUBJ_BATTERY, NULL);
- registerProvider<device_status_psmode>(DEVICE_ST_SUBJ_PSMODE, NULL);
-
- registerProvider<social_status_call>(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY);
- registerProvider<social_status_message>(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE);
-
- registerProvider<user_activity_stationary>(USER_ACT_SUBJ_STATIONARY, NULL);
- registerProvider<user_activity_walking>(USER_ACT_SUBJ_WALKING, NULL);
- registerProvider<user_activity_running>(USER_ACT_SUBJ_RUNNING, NULL);
- registerProvider<user_activity_in_vehicle>(USER_ACT_SUBJ_IN_VEHICLE, NULL);
-
- /* Create context providers, which need to be initiated before being subscribed */
- if (device_status_wifi::is_supported())
- device_status_wifi::create(NULL);
-#endif
-
-#ifdef _TV_
- registerProvider<device_status_wifi>(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK);
- registerProvider<device_status_headphone>(DEVICE_ST_SUBJ_HEADPHONE, NULL);
-
- /* Create context providers, which need to be initiated before being subscribed */
- if (device_status_wifi::is_supported())
- device_status_wifi::create(NULL);
-#endif
-
- return true;
-}
+++ /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 <system_info.h>
-#include "device_provider_base.h"
-
-ctx::device_provider_base::device_provider_base()
- : being_subscribed(false)
-{
-}
-
-int ctx::device_provider_base::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult)
-{
- IF_FAIL_RETURN(!being_subscribed, ERR_NONE);
-
- int ret = subscribe();
-
- if (ret == ERR_NONE)
- being_subscribed = true;
- else
- destroy_self();
-
- return ret;
-}
-
-int ctx::device_provider_base::unsubscribe(const char *subject, ctx::Json option)
-{
- int ret = ERR_NONE;
-
- if (being_subscribed)
- ret = unsubscribe();
-
- destroy_self();
- return ret;
-}
-
-int ctx::device_provider_base::read(const char *subject, ctx::Json option, ctx::Json *requestResult)
-{
- int ret = read();
-
- if (!being_subscribed)
- destroy_self();
-
- return ret;
-}
-
-int ctx::device_provider_base::write(const char *subject, ctx::Json data, ctx::Json *requestResult)
-{
- int ret = write();
-
- if (!being_subscribed)
- destroy_self();
-
- return ret;
-}
-
-int ctx::device_provider_base::subscribe()
-{
- return ERR_NOT_SUPPORTED;
-}
-
-int ctx::device_provider_base::unsubscribe()
-{
- return ERR_NOT_SUPPORTED;
-}
-
-int ctx::device_provider_base::read()
-{
- return ERR_NOT_SUPPORTED;
-}
-
-int ctx::device_provider_base::write()
-{
- return ERR_NOT_SUPPORTED;
-}
-
-bool ctx::device_provider_base::get_system_info_bool(const char *key)
-{
- bool supported = false;
- int ret = system_info_get_platform_bool(key, &supported);
- IF_FAIL_RETURN_TAG(ret == SYSTEM_INFO_ERROR_NONE, false, _E, "system_info_get_platform_bool() failed");
- return supported;
-}
+++ /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 __CONTEXT_DEVICE_PROVIDER_BASE_H__
-#define __CONTEXT_DEVICE_PROVIDER_BASE_H__
-
-#include <types_internal.h>
-#include <Json.h>
-#include <ContextProviderBase.h>
-
-#define CREATE_INSTANCE(prvd) \
- do { \
- IF_FAIL_RETURN(!__instance, __instance); \
- __instance = new(std::nothrow) prvd(); \
- IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); \
- _I(BLUE("Created")); \
- return __instance; \
- } while (0) \
-
-#define DESTROY_INSTANCE() \
- do { \
- IF_FAIL_VOID(__instance); \
- delete __instance; \
- __instance = NULL; \
- _I(BLUE("Destroyed")); \
- } while (0) \
-
-#define GENERATE_PROVIDER_COMMON_DECL(prvd) \
- public: \
- static ContextProviderBase *create(void *data); \
- static void destroy(void *data); \
- protected: \
- void destroy_self(); \
- private: \
- static prvd *__instance; \
-
-#define GENERATE_PROVIDER_COMMON_IMPL(prvd) \
- ctx::prvd *ctx::prvd::__instance = NULL; \
- ctx::ContextProviderBase *ctx::prvd::create(void *data) \
- { \
- CREATE_INSTANCE(prvd); \
- } \
- void ctx::prvd::destroy(void *data) \
- { \
- DESTROY_INSTANCE(); \
- } \
- void ctx::prvd::destroy_self() \
- { \
- destroy(NULL); \
- } \
-
-namespace ctx {
-
- class device_provider_base : public ContextProviderBase {
- public:
- int subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult);
- int unsubscribe(const char *subject, ctx::Json option);
- int read(const char *subject, ctx::Json option, ctx::Json *requestResult);
- int write(const char *subject, ctx::Json data, ctx::Json *requestResult);
-
- protected:
- bool being_subscribed;
-
- device_provider_base();
- virtual ~device_provider_base() {}
-
- virtual int subscribe();
- virtual int unsubscribe();
- virtual int read();
- virtual int write();
- virtual void destroy_self() = 0;
-
- static bool get_system_info_bool(const char *key);
- };
-}
-
-#endif
--- /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 <stdlib.h>
+#include <Json.h>
+#include <ContextManager.h>
+#include "SocialTypes.h"
+#include "Call.h"
+
+#define TELEPHONY_NOTI_ID_CNT 8
+GENERATE_PROVIDER_COMMON_IMPL(SocialStatusCall);
+
+static bool __telephonyInitialized = false;
+static telephony_noti_e __callNotiIds[] =
+{
+ TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE,
+ TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE,
+// TELEPHONY_NOTI_VOICE_CALL_STATUS_HELD,
+// TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING,
+ TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING,
+ TELEPHONY_NOTI_VOICE_CALL_STATUS_INCOMING,
+ TELEPHONY_NOTI_VIDEO_CALL_STATUS_IDLE,
+ TELEPHONY_NOTI_VIDEO_CALL_STATUS_ACTIVE,
+// TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING,
+ TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING,
+ TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING,
+};
+static ctx::Json __latest;
+
+ctx::SocialStatusCall::SocialStatusCall()
+{
+ __handleList.count = 0;
+ __handleList.handle = NULL;
+}
+
+ctx::SocialStatusCall::~SocialStatusCall()
+{
+}
+
+bool ctx::SocialStatusCall::isSupported()
+{
+ return getSystemInfoBool("tizen.org/feature/network.telephony");
+}
+
+void ctx::SocialStatusCall::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CALL, OPS_SUBSCRIBE | OPS_READ,
+ "{"
+ "\"Medium\":{\"type\":\"string\",\"values\":[\"Voice\",\"Video\"]},"
+ "\"State\":{\"type\":\"string\",\"values\":[\"Idle\",\"Connecting\",\"Connected\"]},"
+ "\"Address\":{\"type\":\"string\"}"
+ "}",
+ NULL);
+ //TODO remove Connecting, Connected
+}
+
+void ctx::SocialStatusCall::__updateCb(telephony_h handle, telephony_noti_e notiId, void *data, void *userData)
+{
+ SocialStatusCall *instance = static_cast<SocialStatusCall*>(userData);
+ instance->__handleUpdate(handle, notiId, data);
+}
+
+void ctx::SocialStatusCall::__handleUpdate(telephony_h handle, telephony_noti_e notiId, void* id)
+{
+ Json data;
+ unsigned int count;
+ telephony_call_h *callList;
+
+ // Call state
+ switch (notiId) {
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE:
+ case TELEPHONY_NOTI_VIDEO_CALL_STATUS_IDLE:
+ data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE);
+ break;
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE:
+ case TELEPHONY_NOTI_VIDEO_CALL_STATUS_ACTIVE:
+ data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_ACTIVE);
+ break;
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING:
+ case TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING:
+ data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_ALERTING);
+ break;
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_INCOMING:
+ case TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING:
+ data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_INCOMING);
+ break;
+/* // Ignore below cases
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_HELD:
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING:
+ case TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING:*/
+ default:
+ _E("Unkown noti id: %d", notiId);
+ return;
+ }
+
+ // Call type
+ switch (notiId) {
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE:
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE:
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING:
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_INCOMING:
+ data.set(NULL, SOCIAL_ST_TYPE, SOCIAL_ST_VOICE);
+ break;
+ case TELEPHONY_NOTI_VIDEO_CALL_STATUS_IDLE:
+ case TELEPHONY_NOTI_VIDEO_CALL_STATUS_ACTIVE:
+ case TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING:
+ case TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING:
+ data.set(NULL, SOCIAL_ST_TYPE, SOCIAL_ST_VIDEO);
+ break;
+/* // Ignore below cases
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_HELD:
+ case TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING:
+ case TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING:*/
+ default:
+ _E("Unkown noti id: %d", notiId);
+ return;
+ }
+
+ int err = telephony_call_get_call_list(handle, &count, &callList);
+ IF_FAIL_VOID_TAG(err == TELEPHONY_ERROR_NONE, _E, "Getting call list failed");
+
+ unsigned int callId = *static_cast<unsigned int *>(id);
+ for (unsigned int i = 0; i < count; i++) {
+ unsigned int tempId;
+ // Handle id
+ if (!__getCallHandleId(callList[i], tempId)) {
+ continue;
+ }
+
+ if (callId != tempId) {
+ continue;
+ }
+
+ // Address
+ std::string address;
+ if (__getCallAddress(callList[i], address)) {
+ data.set(NULL, SOCIAL_ST_ADDRESS, address);
+ break;
+ }
+ }
+
+ if (__latest != data) {
+ context_manager::publish(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data);
+ __latest = data.str();
+ }
+ telephony_call_release_call_list(count, &callList);
+}
+
+bool ctx::SocialStatusCall::__initTelephony()
+{
+ IF_FAIL_RETURN(!__telephonyInitialized, true);
+
+ int err = telephony_init(&__handleList);
+ IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Initialization failed");
+
+ __telephonyInitialized = true;
+ return true;
+}
+
+void ctx::SocialStatusCall::__releaseTelephony()
+{
+ IF_FAIL_VOID(__telephonyInitialized);
+
+ telephony_deinit(&__handleList);
+
+ __telephonyInitialized = false;
+}
+
+bool ctx::SocialStatusCall::__setCallback()
+{
+ //TODO: Consider dual-sim devices
+ IF_FAIL_RETURN_TAG(__initTelephony(), false, _E, "Initialization failed");
+
+ int err;
+
+ for (unsigned int i = 0; i < __handleList.count; i++) {
+ for (unsigned int j = 0; j < TELEPHONY_NOTI_ID_CNT; j++) {
+ err = telephony_set_noti_cb(__handleList.handle[i], __callNotiIds[j], __updateCb, this);
+ IF_FAIL_CATCH(err == TELEPHONY_ERROR_NONE);
+ }
+ }
+
+ return true;
+
+CATCH:
+ _E("Initialization failed");
+ __releaseTelephony();
+ return false;
+}
+
+void ctx::SocialStatusCall::__unsetCallback()
+{
+ for (unsigned int i = 0; i < __handleList.count; i++) {
+ for (unsigned int j = 0; j < TELEPHONY_NOTI_ID_CNT; j++) {
+ telephony_unset_noti_cb(__handleList.handle[i], __callNotiIds[j]);
+ }
+ }
+
+ __releaseTelephony();
+}
+
+bool ctx::SocialStatusCall::__getCallState(telephony_call_h& handle, std::string& state)
+{
+ state.clear();
+
+ telephony_call_status_e st;
+ int err = telephony_call_get_status(handle, &st);
+ IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Getting state failed");
+
+ switch (st) {
+ case TELEPHONY_CALL_STATUS_ACTIVE:
+ state = SOCIAL_ST_ACTIVE;
+ break;
+ case TELEPHONY_CALL_STATUS_HELD:
+ state = SOCIAL_ST_HELD;
+ break;
+ case TELEPHONY_CALL_STATUS_DIALING:
+ state = SOCIAL_ST_DIALING;
+ break;
+ case TELEPHONY_CALL_STATUS_ALERTING:
+ state = SOCIAL_ST_ALERTING;
+ break;
+ case TELEPHONY_CALL_STATUS_INCOMING:
+ state = SOCIAL_ST_INCOMING;
+ break;
+ default:
+ state = SOCIAL_ST_IDLE;
+ }
+
+ IF_FAIL_RETURN_TAG(!state.empty(), false, _W, "State is empty");
+
+ return true;
+}
+
+bool ctx::SocialStatusCall::__getCallType(telephony_call_h& handle, std::string& type)
+{
+ type.clear();
+
+ telephony_call_type_e t;
+ int err = telephony_call_get_type(handle, &t);
+ IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Getting type failed");
+
+ switch (t) {
+ case TELEPHONY_CALL_TYPE_VOICE:
+ type = SOCIAL_ST_VOICE;
+ break;
+ case TELEPHONY_CALL_TYPE_VIDEO:
+ type = SOCIAL_ST_VIDEO;
+ break;
+ default:
+ _E("Unknown type: %d", t);
+ return false;
+ }
+
+ IF_FAIL_RETURN_TAG(!type.empty(), false, _W, "Type is empty");
+
+ return true;
+}
+
+bool ctx::SocialStatusCall::__getCallAddress(telephony_call_h& handle, std::string& address)
+{
+ address.clear();
+
+ char* number = NULL;
+ int err = telephony_call_get_number(handle, &number);
+ IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Getting address failed");
+
+ if (number) {
+ address = number;
+ free(number);
+ number = NULL;
+ }
+
+ IF_FAIL_RETURN_TAG(!address.empty(), false, _W, "Address is empty");
+
+ return true;
+}
+
+bool ctx::SocialStatusCall::__getCallHandleId(telephony_call_h& handle, unsigned int& id)
+{
+ int err = telephony_call_get_handle_id(handle, &id);
+ IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Getting handle id failed");
+
+ return true;
+}
+
+int ctx::SocialStatusCall::subscribe()
+{
+ bool ret = __setCallback();
+ IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
+ return ERR_NONE;
+}
+
+int ctx::SocialStatusCall::unsubscribe()
+{
+ __unsetCallback();
+ return ERR_NONE;
+}
+
+bool ctx::SocialStatusCall::__readCurrentStatus(telephony_h& handle, ctx::Json* data)
+{
+ unsigned int count = 0;
+ telephony_call_h *callList = NULL;
+ telephony_call_get_call_list(handle, &count, &callList);
+
+ // Default data
+ data->set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE);
+
+ // Held & Dialing are ignored
+ for (unsigned int i = 0; i < count; i++) {
+ // Call state
+ std::string state;
+ if (__getCallState(callList[i], state)) {
+ // Skip Held & Dialing
+ if (state.compare(SOCIAL_ST_HELD) == 0 || state.compare(SOCIAL_ST_DIALING) == 0)
+ continue;
+
+ data->set(NULL, SOCIAL_ST_STATE, state);
+ }
+
+ // Call type
+ std::string type;
+ if (__getCallType(callList[i], type)) {
+ data->set(NULL, SOCIAL_ST_MEDIUM, type);
+ }
+
+ // Address
+ std::string address;
+ if (__getCallAddress(callList[i], address)) {
+ data->set(NULL, SOCIAL_ST_ADDRESS, address);
+ }
+
+ if (state == SOCIAL_ST_ACTIVE) {
+ break;
+ }
+ }
+
+ telephony_call_release_call_list(count, &callList);
+ return true;
+}
+
+int ctx::SocialStatusCall::read()
+{
+ bool temporaryHandle = false;
+ if (!__telephonyInitialized) {
+ IF_FAIL_RETURN(__initTelephony(), ERR_OPERATION_FAILED);
+ temporaryHandle = true;
+ }
+
+ bool ret = true;
+ Json data;
+ data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE);
+
+ for (unsigned int i = 0; i < __handleList.count; i++) {
+ telephony_sim_state_e state;
+ int err = telephony_sim_get_state(__handleList.handle[i], &state);
+ IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting SIM status failed");
+
+ if (state != TELEPHONY_SIM_STATE_AVAILABLE)
+ continue;
+
+ ret = __readCurrentStatus(__handleList.handle[i], &data);
+ break;
+ }
+
+ if (temporaryHandle)
+ __releaseTelephony();
+
+ if (ret) {
+ ctx::context_manager::replyToRead(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data);
+ return ERR_NONE;
+ }
+
+ return ERR_OPERATION_FAILED;
+}
--- /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 _CONTEXT_SOCIAL_STATUS_CALL_H_
+#define _CONTEXT_SOCIAL_STATUS_CALL_H_
+
+#include <telephony.h>
+#include "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class SocialStatusCall : public DeviceProviderBase {
+
+ GENERATE_PROVIDER_COMMON_DECL(SocialStatusCall);
+
+ public:
+ int subscribe();
+ int unsubscribe();
+ int read();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ private:
+ telephony_handle_list_s __handleList;
+
+ SocialStatusCall();
+ ~SocialStatusCall();
+
+ bool __initTelephony();
+ void __releaseTelephony();
+ bool __setCallback();
+ void __unsetCallback();
+ bool __readCurrentStatus(telephony_h& handle, ctx::Json* data);
+
+ bool __getCallState(telephony_call_h& handle, std::string& state);
+ bool __getCallType(telephony_call_h& handle, std::string& type);
+ bool __getCallAddress(telephony_call_h& handle, std::string& address);
+ bool __getCallHandleId(telephony_call_h& handle, unsigned int& id);
+
+ void __handleUpdate(telephony_h handle, telephony_noti_e notiId, void* id);
+ static void __updateCb(telephony_h handle, telephony_noti_e notiId, void *data, void *userData);
+ };
+}
+
+#endif // _CONTEXT_SOCIAL_STATUS_CALL_H_
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <Json.h>
+#include <ContextManager.h>
+#include "SocialTypes.h"
+#include "Contacts.h"
+
+#define MY_PROFILE_VIEW _contacts_my_profile._uri
+#define PERSON_VIEW _contacts_person._uri
+#define TIME_INTERVAL 1
+
+GENERATE_PROVIDER_COMMON_IMPL(SocialStatusContacts);
+
+ctx::SocialStatusContacts::SocialStatusContacts() :
+ __latestMyProfile(0),
+ __latestPerson(0)
+{
+}
+
+ctx::SocialStatusContacts::~SocialStatusContacts()
+{
+}
+
+bool ctx::SocialStatusContacts::isSupported()
+{
+ return true;
+}
+
+void ctx::SocialStatusContacts::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CONTACTS, OPS_SUBSCRIBE,
+ "{"
+ "\"Event\":{\"type\":\"string\",\"values\":[\"Changed\"]},"
+ "\"Type\":{\"type\":\"string\",\"values\":[\"MyProfile\",\"Person\"]}"
+ "}",
+ NULL);
+}
+
+void ctx::SocialStatusContacts::__updateCb(const char* viewUri, void* userData)
+{
+ SocialStatusContacts *instance = static_cast<SocialStatusContacts*>(userData);
+ instance->__handleUpdate(viewUri);
+}
+
+void ctx::SocialStatusContacts::__handleUpdate(const char* viewUri)
+{
+ if (!STR_EQ(viewUri, _contacts_my_profile._uri) && !STR_EQ(viewUri, _contacts_person._uri)) {
+ _W("Unknown view uri");
+ return;
+ }
+
+ std::string view = (STR_EQ(viewUri, _contacts_my_profile._uri)? SOCIAL_ST_MY_PROFILE : SOCIAL_ST_PERSON);
+ IF_FAIL_VOID_TAG(!__isConsecutiveChange(viewUri), _D, "Ignore consecutive db change: %s", view.c_str());
+
+ ctx::Json data;
+ data.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_CHANGED);
+ data.set(NULL, SOCIAL_ST_TYPE, view);
+ context_manager::publish(SOCIAL_ST_SUBJ_CONTACTS, NULL, ERR_NONE, data);
+}
+
+bool ctx::SocialStatusContacts::__isConsecutiveChange(const char* viewUri)
+{
+ time_t now = time(NULL);
+ double diff = 0;
+
+ if (STR_EQ(viewUri, MY_PROFILE_VIEW)) {
+ diff = difftime(now, __latestMyProfile);
+ __latestMyProfile = now;
+ } else if (STR_EQ(viewUri, PERSON_VIEW)) {
+ diff = difftime(now, __latestPerson);
+ __latestPerson = now;
+ }
+
+ if (diff < TIME_INTERVAL)
+ return true;
+
+ return false;
+}
+
+bool ctx::SocialStatusContacts::__setCallback()
+{
+ int err;
+
+ err = contacts_connect();
+ IF_FAIL_RETURN_TAG(err == CONTACTS_ERROR_NONE, false, _E, "Connecting contacts failed");
+
+ err = contacts_db_add_changed_cb(MY_PROFILE_VIEW, __updateCb, this);
+ IF_FAIL_CATCH_TAG(err == CONTACTS_ERROR_NONE, _E, "Setting my profile view changed callback failed");
+
+ err = contacts_db_add_changed_cb(PERSON_VIEW, __updateCb, this);
+ IF_FAIL_CATCH_TAG(err == CONTACTS_ERROR_NONE, _E, "Setting person view changed callback failed");
+
+ return true;
+
+CATCH:
+ contacts_disconnect();
+ return false;
+}
+
+void ctx::SocialStatusContacts::__unsetCallback()
+{
+ contacts_db_remove_changed_cb(MY_PROFILE_VIEW, __updateCb, this);
+ contacts_db_remove_changed_cb(PERSON_VIEW, __updateCb, this);
+
+ contacts_disconnect();
+
+ __latestMyProfile = 0;
+ __latestPerson = 0;
+}
+
+int ctx::SocialStatusContacts::subscribe()
+{
+ bool ret = __setCallback();
+ IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
+ return ERR_NONE;
+}
+
+int ctx::SocialStatusContacts::unsubscribe()
+{
+ __unsetCallback();
+ return ERR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 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 _CONTEXT_SOCIAL_STATUS_CONTACTS_H_
+#define _CONTEXT_SOCIAL_STATUS_CONTACTS_H_
+
+#include <contacts.h>
+#include "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class SocialStatusContacts : public DeviceProviderBase {
+
+ GENERATE_PROVIDER_COMMON_DECL(SocialStatusContacts);
+
+ public:
+ int subscribe();
+ int unsubscribe();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ private:
+ time_t __latestMyProfile;
+ time_t __latestPerson;
+
+ SocialStatusContacts();
+ ~SocialStatusContacts();
+
+ bool __setCallback();
+ void __unsetCallback();
+ void __handleUpdate(const char* viewUri);
+ static void __updateCb(const char* viewUri, void* userData);
+ bool __isConsecutiveChange(const char* viewUri);
+ };
+}
+
+#endif // _CONTEXT_SOCIAL_STATUS_CONTACTS_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 <gio/gio.h>
+#include <email-api-etc.h>
+
+#include <ContextManager.h>
+#include "SocialTypes.h"
+#include "Email.h"
+
+GENERATE_PROVIDER_COMMON_IMPL(SocialStatusEmail);
+
+ctx::SocialStatusEmail::SocialStatusEmail() :
+ __dbusSignalId(-1),
+ __dbusWatcher(DBusType::SESSION)
+{
+}
+
+ctx::SocialStatusEmail::~SocialStatusEmail()
+{
+}
+
+bool ctx::SocialStatusEmail::isSupported()
+{
+ return getSystemInfoBool("tizen.org/feature/network.telephony");
+}
+
+void ctx::SocialStatusEmail::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_EMAIL, OPS_SUBSCRIBE,
+ "{"
+ "\"Event\":{\"type\":\"string\",\"values\":[\"Received\",\"Sent\"]}"
+ "}",
+ NULL);
+}
+
+void ctx::SocialStatusEmail::onSignal(const char* sender, const char* path, const char* iface, const char* name, GVariant* param)
+{
+ gint subType = 0;
+ gint gi1 = 0;
+ const gchar *gc = NULL;
+ gint gi2 = 0;
+ gint gi3 = 0;
+
+ g_variant_get(param, "(ii&sii)", &subType, &gi1, &gc, &gi2, &gi3);
+
+ if (subType == NOTI_DOWNLOAD_FINISH) {
+ //TODO: Check if this signal actually means that there are new mails
+ _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", subType, gi1, gc, gi2, gi3);
+ ctx::Json dataUpdated;
+ dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED);
+ context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, dataUpdated);
+
+ } else if (subType == NOTI_SEND_FINISH) {
+ _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", subType, gi1, gc, gi2, gi3);
+ ctx::Json dataUpdated;
+ dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_SENT);
+ context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, dataUpdated);
+ }
+}
+
+
+int ctx::SocialStatusEmail::subscribe()
+{
+ __dbusSignalId = __dbusWatcher.watch(NULL, NULL, "User.Email.NetworkStatus", "email", this);
+ IF_FAIL_RETURN_TAG(__dbusSignalId >= 0, ERR_OPERATION_FAILED, _E, "Email dbus signal subscription failed");
+ return ERR_NONE;
+}
+
+
+int ctx::SocialStatusEmail::unsubscribe()
+{
+ __dbusWatcher.unwatch(__dbusSignalId);
+ 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 _CONTEXT_SOCIAL_STATUS_EMAIL_H_
+#define _CONTEXT_SOCIAL_STATUS_EMAIL_H_
+
+#include <DBusSignalWatcher.h>
+#include "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class SocialStatusEmail : public DeviceProviderBase, public IDBusSignalListener {
+
+ GENERATE_PROVIDER_COMMON_DECL(SocialStatusEmail);
+
+ public:
+ int subscribe();
+ int unsubscribe();
+ void onSignal(const char *sender, const char *path, const char *iface, const char *name, GVariant *param);
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ private:
+ int64_t __dbusSignalId;
+ DBusSignalWatcher __dbusWatcher;
+
+ SocialStatusEmail();
+ ~SocialStatusEmail();
+ };
+}
+
+#endif // _CONTEXT_SOCIAL_STATUS_EMAIL_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 <Json.h>
+#include <ContextManager.h>
+#include "SocialTypes.h"
+#include "Message.h"
+
+#define MAX_ADDR_SIZE 20
+
+GENERATE_PROVIDER_COMMON_IMPL(SocialStatusMessage);
+
+ctx::SocialStatusMessage::SocialStatusMessage() :
+ __messageHandle(NULL)
+{
+}
+
+ctx::SocialStatusMessage::~SocialStatusMessage()
+{
+}
+
+bool ctx::SocialStatusMessage::isSupported()
+{
+ return getSystemInfoBool("tizen.org/feature/network.telephony");
+}
+
+void ctx::SocialStatusMessage::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_MESSAGE, OPS_SUBSCRIBE,
+ "{"
+ "\"Event\":{\"type\":\"string\",\"values\":[\"Received\"]},"
+ "\"Type\":{\"type\":\"string\",\"values\":[\"SMS\",\"MMS\"]},"
+ "\"Address\":{\"type\":\"string\"}"
+ "}",
+ NULL);
+}
+
+void ctx::SocialStatusMessage::__updateCb(msg_handle_t handle, msg_struct_t msg, void* userData)
+{
+ SocialStatusMessage *instance = static_cast<SocialStatusMessage*>(userData);
+ instance->__handleUpdate(msg);
+}
+
+void ctx::SocialStatusMessage::__handleUpdate(msg_struct_t msg)
+{
+ int err;
+ int type;
+ char address[MAX_ADDR_SIZE];
+ ctx::Json data;
+
+ err = msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &type);
+ IF_FAIL_VOID_TAG(err == MSG_SUCCESS, _W, "Getting message type failed");
+
+ err = msg_get_str_value(msg, MSG_MESSAGE_REPLY_ADDR_STR, address, MAX_ADDR_SIZE);
+ IF_FAIL_VOID_TAG(err == MSG_SUCCESS, _W, "Getting reply address failed");
+
+ switch (type) {
+ case MSG_TYPE_SMS_CB :
+ case MSG_TYPE_SMS_JAVACB :
+ case MSG_TYPE_SMS_WAPPUSH :
+ case MSG_TYPE_SMS_MWI :
+ case MSG_TYPE_SMS_SYNCML :
+ case MSG_TYPE_SMS_REJECT :
+ case MSG_TYPE_SMS_ETWS_PRIMARY :
+ case MSG_TYPE_SMS :
+ data.set(NULL, SOCIAL_ST_TYPE, SOCIAL_ST_SMS);
+ break;
+ case MSG_TYPE_MMS_NOTI :
+ case MSG_TYPE_MMS_JAVA :
+ case MSG_TYPE_MMS :
+ data.set(NULL, SOCIAL_ST_TYPE, SOCIAL_ST_MMS);
+ break;
+ default :
+ _W("Unknown message type");
+ return;
+ }
+
+ data.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED);
+ data.set(NULL, SOCIAL_ST_ADDRESS, address);
+
+ context_manager::publish(SOCIAL_ST_SUBJ_MESSAGE, NULL, ERR_NONE, data);
+}
+
+bool ctx::SocialStatusMessage::__setCallback()
+{
+ int err;
+
+ err = msg_open_msg_handle(&__messageHandle);
+ IF_FAIL_RETURN_TAG(err == MSG_SUCCESS, false, _E, "Handle creation failed");
+
+ err = msg_reg_sms_message_callback(__messageHandle, __updateCb, 0, this);
+ if (err != MSG_SUCCESS) {
+ msg_close_msg_handle(&__messageHandle);
+ _E("Setting SMS event callback failed");
+ return false;
+ }
+
+ msg_reg_mms_conf_message_callback(__messageHandle, __updateCb, NULL, this);
+ return true;
+}
+
+void ctx::SocialStatusMessage::__unsetCallback()
+{
+ if (__messageHandle)
+ msg_close_msg_handle(&__messageHandle);
+
+ __messageHandle = NULL;
+}
+
+int ctx::SocialStatusMessage::subscribe()
+{
+ bool ret = __setCallback();
+ IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
+ return ERR_NONE;
+}
+
+int ctx::SocialStatusMessage::unsubscribe()
+{
+ __unsetCallback();
+ 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 _CONTEXT_SOCIAL_STATUS_SMS_H_
+#define _CONTEXT_SOCIAL_STATUS_SMS_H_
+
+#include <msg.h>
+#include <msg_transport.h>
+#include "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class SocialStatusMessage : public DeviceProviderBase {
+
+ GENERATE_PROVIDER_COMMON_DECL(SocialStatusMessage);
+
+ public:
+ int subscribe();
+ int unsubscribe();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ private:
+ msg_handle_t __messageHandle;
+ bool __beingSubscribed;
+
+ SocialStatusMessage();
+ ~SocialStatusMessage();
+
+ bool __setCallback();
+ void __unsetCallback();
+ void __handleUpdate(msg_struct_t msg);
+ static void __updateCb(msg_handle_t handle, msg_struct_t msg, void* userData);
+ };
+}
+
+#endif // _CONTEXT_SOCIAL_STATUS_SMS_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.
+ */
+
+#ifndef _CONTEXT_SOCIAL_STATUS_TYPES_H_
+#define _CONTEXT_SOCIAL_STATUS_TYPES_H_
+
+// Subject
+#define SOCIAL_ST_SUBJ_CALL "social/call"
+#define SOCIAL_ST_SUBJ_EMAIL "social/email"
+#define SOCIAL_ST_SUBJ_MESSAGE "social/message"
+#define SOCIAL_ST_SUBJ_CONTACTS "social/contacts"
+
+// Data Key
+#define SOCIAL_ST_STATE "State"
+#define SOCIAL_ST_EVENT "Event"
+#define SOCIAL_ST_TYPE "Type"
+#define SOCIAL_ST_MEDIUM "Medium"
+#define SOCIAL_ST_ADDRESS "Address"
+
+// Data Values
+#define SOCIAL_ST_IDLE "Idle"
+#define SOCIAL_ST_CONNECTING "Connecting"
+#define SOCIAL_ST_CONNECTED "Connected"
+#define SOCIAL_ST_ACTIVE SOCIAL_ST_CONNECTED
+#define SOCIAL_ST_HELD "Held"
+#define SOCIAL_ST_DIALING "Dialing"
+#define SOCIAL_ST_ALERTING SOCIAL_ST_CONNECTING
+#define SOCIAL_ST_INCOMING SOCIAL_ST_CONNECTING
+#define SOCIAL_ST_VOICE "Voice"
+#define SOCIAL_ST_VIDEO "Video"
+#define SOCIAL_ST_SENT "Sent"
+#define SOCIAL_ST_RECEIVED "Received"
+#define SOCIAL_ST_SMS "SMS"
+#define SOCIAL_ST_MMS "MMS"
+#define SOCIAL_ST_MY_PROFILE "MyProfile"
+#define SOCIAL_ST_PERSON "Person"
+#define SOCIAL_ST_CHANGED "Changed"
+
+#endif //_CONTEXT_SOCIAL_STATUS_TYPES_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 <stdlib.h>
-#include <Json.h>
-#include <ContextManager.h>
-#include "social_types.h"
-#include "call.h"
-
-#define TELEPHONY_NOTI_ID_CNT 8
-GENERATE_PROVIDER_COMMON_IMPL(social_status_call);
-
-static bool telephony_initialized = false;
-static telephony_noti_e call_noti_ids[] =
-{
- TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE,
- TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE,
-// TELEPHONY_NOTI_VOICE_CALL_STATUS_HELD,
-// TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING,
- TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING,
- TELEPHONY_NOTI_VOICE_CALL_STATUS_INCOMING,
- TELEPHONY_NOTI_VIDEO_CALL_STATUS_IDLE,
- TELEPHONY_NOTI_VIDEO_CALL_STATUS_ACTIVE,
-// TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING,
- TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING,
- TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING,
-};
-static ctx::Json latest;
-
-ctx::social_status_call::social_status_call()
-{
- handle_list.count = 0;
- handle_list.handle = NULL;
-}
-
-ctx::social_status_call::~social_status_call()
-{
-}
-
-bool ctx::social_status_call::is_supported()
-{
- return get_system_info_bool("tizen.org/feature/network.telephony");
-}
-
-void ctx::social_status_call::submit_trigger_item()
-{
- context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CALL, OPS_SUBSCRIBE | OPS_READ,
- "{"
- "\"Medium\":{\"type\":\"string\",\"values\":[\"Voice\",\"Video\"]},"
- "\"State\":{\"type\":\"string\",\"values\":[\"Idle\",\"Connecting\",\"Connected\"]},"
- "\"Address\":{\"type\":\"string\"}"
- "}",
- NULL);
- //TODO remove Connecting, Connected
-}
-
-void ctx::social_status_call::call_event_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data)
-{
- social_status_call *instance = static_cast<social_status_call*>(user_data);
- instance->handle_call_event(handle, noti_id, data);
-}
-
-void ctx::social_status_call::handle_call_event(telephony_h handle, telephony_noti_e noti_id, void* id)
-{
-
- Json data;
- unsigned int count;
- telephony_call_h *call_list;
-
- // Call state
- switch (noti_id) {
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE:
- case TELEPHONY_NOTI_VIDEO_CALL_STATUS_IDLE:
- data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE);
- break;
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE:
- case TELEPHONY_NOTI_VIDEO_CALL_STATUS_ACTIVE:
- data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_ACTIVE);
- break;
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING:
- case TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING:
- data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_ALERTING);
- break;
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_INCOMING:
- case TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING:
- data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_INCOMING);
- break;
-/* // Ignore below cases
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_HELD:
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING:
- case TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING:*/
- default:
- _E("Unkown noti id: %d", noti_id);
- return;
- }
-
- // Call type
- switch (noti_id) {
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE:
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE:
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING:
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_INCOMING:
- data.set(NULL, SOCIAL_ST_TYPE, SOCIAL_ST_VOICE);
- break;
- case TELEPHONY_NOTI_VIDEO_CALL_STATUS_IDLE:
- case TELEPHONY_NOTI_VIDEO_CALL_STATUS_ACTIVE:
- case TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING:
- case TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING:
- data.set(NULL, SOCIAL_ST_TYPE, SOCIAL_ST_VIDEO);
- break;
-/* // Ignore below cases
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_HELD:
- case TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING:
- case TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING:*/
- default:
- _E("Unkown noti id: %d", noti_id);
- return;
- }
-
- int err = telephony_call_get_call_list(handle, &count, &call_list);
- IF_FAIL_VOID_TAG(err == TELEPHONY_ERROR_NONE, _E, "Getting call list failed");
-
- unsigned int call_id = *static_cast<unsigned int *>(id);
- for (unsigned int i = 0; i < count; i++) {
- unsigned int tmp_id;
- // Handle id
- if (!get_call_handle_id(call_list[i], tmp_id)) {
- continue;
- }
-
- if (call_id != tmp_id) {
- continue;
- }
-
- // Address
- std::string address;
- if (get_call_address(call_list[i], address)) {
- data.set(NULL, SOCIAL_ST_ADDRESS, address);
- break;
- }
- }
-
- if (latest != data) {
- context_manager::publish(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data);
- latest = data.str();
- }
- telephony_call_release_call_list(count, &call_list);
-}
-
-bool ctx::social_status_call::init_telephony()
-{
- IF_FAIL_RETURN(!telephony_initialized, true);
-
- int err = telephony_init(&handle_list);
- IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Initialization failed");
-
- telephony_initialized = true;
- return true;
-}
-
-void ctx::social_status_call::release_telephony()
-{
- IF_FAIL_VOID(telephony_initialized);
-
- telephony_deinit(&handle_list);
-
- telephony_initialized = false;
-}
-
-bool ctx::social_status_call::set_callback()
-{
- //TODO: Consider dual-sim devices
- IF_FAIL_RETURN_TAG(init_telephony(), false, _E, "Initialization failed");
-
- int err;
-
- for (unsigned int i = 0; i < handle_list.count; i++) {
- for (unsigned int j = 0; j < TELEPHONY_NOTI_ID_CNT; j++) {
- err = telephony_set_noti_cb(handle_list.handle[i], call_noti_ids[j], call_event_cb, this);
- IF_FAIL_CATCH(err == TELEPHONY_ERROR_NONE);
- }
- }
-
- return true;
-
-CATCH:
- _E("Initialization failed");
- release_telephony();
- return false;
-}
-
-void ctx::social_status_call::unset_callback()
-{
- for (unsigned int i = 0; i < handle_list.count; i++) {
- for (unsigned int j = 0; j < TELEPHONY_NOTI_ID_CNT; j++) {
- telephony_unset_noti_cb(handle_list.handle[i], call_noti_ids[j]);
- }
- }
-
- release_telephony();
-}
-
-bool ctx::social_status_call::get_call_state(telephony_call_h& handle, std::string& state)
-{
- state.clear();
-
- telephony_call_status_e st;
- int err = telephony_call_get_status(handle, &st);
- IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Getting state failed");
-
- switch (st) {
- case TELEPHONY_CALL_STATUS_ACTIVE:
- state = SOCIAL_ST_ACTIVE;
- break;
- case TELEPHONY_CALL_STATUS_HELD:
- state = SOCIAL_ST_HELD;
- break;
- case TELEPHONY_CALL_STATUS_DIALING:
- state = SOCIAL_ST_DIALING;
- break;
- case TELEPHONY_CALL_STATUS_ALERTING:
- state = SOCIAL_ST_ALERTING;
- break;
- case TELEPHONY_CALL_STATUS_INCOMING:
- state = SOCIAL_ST_INCOMING;
- break;
- default:
- state = SOCIAL_ST_IDLE;
- }
-
- IF_FAIL_RETURN_TAG(!state.empty(), false, _W, "State is empty");
-
- return true;
-}
-
-bool ctx::social_status_call::get_call_type(telephony_call_h& handle, std::string& type)
-{
- type.clear();
-
- telephony_call_type_e t;
- int err = telephony_call_get_type(handle, &t);
- IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Getting type failed");
-
- switch (t) {
- case TELEPHONY_CALL_TYPE_VOICE:
- type = SOCIAL_ST_VOICE;
- break;
- case TELEPHONY_CALL_TYPE_VIDEO:
- type = SOCIAL_ST_VIDEO;
- break;
- default:
- _E("Unknown type: %d", t);
- return false;
- }
-
- IF_FAIL_RETURN_TAG(!type.empty(), false, _W, "Type is empty");
-
- return true;
-}
-
-bool ctx::social_status_call::get_call_address(telephony_call_h& handle, std::string& address)
-{
- address.clear();
-
- char* number = NULL;
- int err = telephony_call_get_number(handle, &number);
- IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Getting address failed");
-
- if (number) {
- address = number;
- free(number);
- number = NULL;
- }
-
- IF_FAIL_RETURN_TAG(!address.empty(), false, _W, "Address is empty");
-
- return true;
-}
-
-bool ctx::social_status_call::get_call_handle_id(telephony_call_h& handle, unsigned int& id)
-{
- int err = telephony_call_get_handle_id(handle, &id);
- IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Getting handle id failed");
-
- return true;
-}
-
-int ctx::social_status_call::subscribe()
-{
- bool ret = set_callback();
- IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
- return ERR_NONE;
-}
-
-int ctx::social_status_call::unsubscribe()
-{
- unset_callback();
- return ERR_NONE;
-}
-
-bool ctx::social_status_call::read_current_status(telephony_h& handle, ctx::Json& data)
-{
- unsigned int count = 0;
- telephony_call_h *call_list = NULL;
- telephony_call_get_call_list(handle, &count, &call_list);
-
- // Default data
- data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE);
-
- // Held & Dialing are ignored
- for (unsigned int i = 0; i < count; i++) {
- // Call state
- std::string state;
- if (get_call_state(call_list[i], state)) {
- // Skip Held & Dialing
- if (state.compare(SOCIAL_ST_HELD) == 0 || state.compare(SOCIAL_ST_DIALING) == 0)
- continue;
-
- data.set(NULL, SOCIAL_ST_STATE, state);
- }
-
- // Call type
- std::string type;
- if (get_call_type(call_list[i], type)) {
- data.set(NULL, SOCIAL_ST_MEDIUM, type);
- }
-
- // Address
- std::string address;
- if (get_call_address(call_list[i], address)) {
- data.set(NULL, SOCIAL_ST_ADDRESS, address);
- }
-
- if (state == SOCIAL_ST_ACTIVE) {
- break;
- }
- }
-
- telephony_call_release_call_list(count, &call_list);
- return true;
-}
-
-int ctx::social_status_call::read()
-{
- bool temporary_handle = false;
- if (!telephony_initialized) {
- IF_FAIL_RETURN(init_telephony(), ERR_OPERATION_FAILED);
- temporary_handle = true;
- }
-
- bool ret = true;
- Json data;
- data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE);
-
- for (unsigned int i = 0; i < handle_list.count; i++) {
- telephony_sim_state_e state;
- int err = telephony_sim_get_state(handle_list.handle[i], &state);
- IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting SIM status failed");
-
- if (state != TELEPHONY_SIM_STATE_AVAILABLE)
- continue;
-
- ret = read_current_status(handle_list.handle[i], data);
- break;
- }
-
- if (temporary_handle)
- release_telephony();
-
- if (ret) {
- ctx::context_manager::replyToRead(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data);
- return ERR_NONE;
- }
-
- return ERR_OPERATION_FAILED;
-}
+++ /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 _CONTEXT_SOCIAL_STATUS_CALL_H_
-#define _CONTEXT_SOCIAL_STATUS_CALL_H_
-
-#include <telephony.h>
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class social_status_call : public device_provider_base {
-
- GENERATE_PROVIDER_COMMON_DECL(social_status_call);
-
- public:
- int subscribe();
- int unsubscribe();
- int read();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- telephony_handle_list_s handle_list;
-
- social_status_call();
- ~social_status_call();
-
- bool init_telephony();
- void release_telephony();
- bool set_callback();
- void unset_callback();
- bool read_current_status(telephony_h& handle, ctx::Json& data);
-
- bool get_call_state(telephony_call_h& handle, std::string& state);
- bool get_call_type(telephony_call_h& handle, std::string& type);
- bool get_call_address(telephony_call_h& handle, std::string& address);
- bool get_call_handle_id(telephony_call_h& handle, unsigned int& id);
-
- void handle_call_event(telephony_h handle, telephony_noti_e noti_id, void* id);
- static void call_event_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data);
- };
-}
-
-#endif // _CONTEXT_SOCIAL_STATUS_CALL_H_
+++ /dev/null
-/*
- * Copyright (c) 2016 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 <Json.h>
-#include <ContextManager.h>
-#include "social_types.h"
-#include "contacts.h"
-
-#define MY_PROFILE_VIEW _contacts_my_profile._uri
-#define PERSON_VIEW _contacts_person._uri
-#define TIME_INTERVAL 1
-
-GENERATE_PROVIDER_COMMON_IMPL(social_status_contacts);
-
-ctx::social_status_contacts::social_status_contacts()
- : latest_my_profile(0)
- , latest_person(0)
-{
-}
-
-ctx::social_status_contacts::~social_status_contacts()
-{
-}
-
-bool ctx::social_status_contacts::is_supported()
-{
- return true;
-}
-
-void ctx::social_status_contacts::submit_trigger_item()
-{
- context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CONTACTS, OPS_SUBSCRIBE,
- "{"
- "\"Event\":{\"type\":\"string\",\"values\":[\"Changed\"]},"
- "\"Type\":{\"type\":\"string\",\"values\":[\"MyProfile\",\"Person\"]}"
- "}",
- NULL);
-}
-
-void ctx::social_status_contacts::db_change_cb(const char* view_uri, void* user_data)
-{
- social_status_contacts *instance = static_cast<social_status_contacts*>(user_data);
- instance->handle_db_change(view_uri);
-}
-
-void ctx::social_status_contacts::handle_db_change(const char* view_uri)
-{
- if (!STR_EQ(view_uri, _contacts_my_profile._uri) && !STR_EQ(view_uri, _contacts_person._uri)) {
- _W("Unknown view uri");
- return;
- }
-
- std::string view = (STR_EQ(view_uri, _contacts_my_profile._uri)? SOCIAL_ST_MY_PROFILE : SOCIAL_ST_PERSON);
- IF_FAIL_VOID_TAG(!is_consecutive_change(view_uri), _D, "Ignore consecutive db change: %s", view.c_str());
-
- ctx::Json data;
- data.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_CHANGED);
- data.set(NULL, SOCIAL_ST_TYPE, view);
- context_manager::publish(SOCIAL_ST_SUBJ_CONTACTS, NULL, ERR_NONE, data);
-}
-
-bool ctx::social_status_contacts::is_consecutive_change(const char* view_uri)
-{
- time_t now = time(NULL);
- double diff = 0;
-
- if (STR_EQ(view_uri, MY_PROFILE_VIEW)) {
- diff = difftime(now, latest_my_profile);
- latest_my_profile = now;
- } else if (STR_EQ(view_uri, PERSON_VIEW)) {
- diff = difftime(now, latest_person);
- latest_person = now;
- }
-
- if (diff < TIME_INTERVAL)
- return true;
-
- return false;
-}
-
-bool ctx::social_status_contacts::set_callback()
-{
- int err;
-
- err = contacts_connect();
- IF_FAIL_RETURN_TAG(err == CONTACTS_ERROR_NONE, false, _E, "Connecting contacts failed");
-
- err = contacts_db_add_changed_cb(MY_PROFILE_VIEW, db_change_cb, this);
- IF_FAIL_CATCH_TAG(err == CONTACTS_ERROR_NONE, _E, "Setting my profile view changed callback failed");
-
- err = contacts_db_add_changed_cb(PERSON_VIEW, db_change_cb, this);
- IF_FAIL_CATCH_TAG(err == CONTACTS_ERROR_NONE, _E, "Setting person view changed callback failed");
-
- return true;
-
-CATCH:
- contacts_disconnect();
- return false;
-}
-
-void ctx::social_status_contacts::unset_callback()
-{
- contacts_db_remove_changed_cb(MY_PROFILE_VIEW, db_change_cb, this);
- contacts_db_remove_changed_cb(PERSON_VIEW, db_change_cb, this);
-
- contacts_disconnect();
-
- latest_my_profile = 0;
- latest_person = 0;
-}
-
-int ctx::social_status_contacts::subscribe()
-{
- bool ret = set_callback();
- IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
- return ERR_NONE;
-}
-
-int ctx::social_status_contacts::unsubscribe()
-{
- unset_callback();
- return ERR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 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 _CONTEXT_SOCIAL_STATUS_CONTACTS_H_
-#define _CONTEXT_SOCIAL_STATUS_CONTACTS_H_
-
-#include <contacts.h>
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class social_status_contacts : public device_provider_base {
-
- GENERATE_PROVIDER_COMMON_DECL(social_status_contacts);
-
- public:
- int subscribe();
- int unsubscribe();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- time_t latest_my_profile;
- time_t latest_person;
-
- social_status_contacts();
- ~social_status_contacts();
-
- bool set_callback();
- void unset_callback();
- void handle_db_change(const char* view_uri);
- static void db_change_cb(const char* view_uri, void* user_data);
- bool is_consecutive_change(const char* view_uri);
- };
-}
-
-#endif // _CONTEXT_SOCIAL_STATUS_CONTACTS_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 <gio/gio.h>
-#include <email-api-etc.h>
-
-#include <ContextManager.h>
-#include "social_types.h"
-#include "email.h"
-
-GENERATE_PROVIDER_COMMON_IMPL(social_status_email);
-
-ctx::social_status_email::social_status_email()
- : dbus_signal_id(-1)
- , __dbusWatcher(DBusType::SESSION)
-{
-}
-
-ctx::social_status_email::~social_status_email()
-{
-}
-
-bool ctx::social_status_email::is_supported()
-{
- return get_system_info_bool("tizen.org/feature/network.telephony");
-}
-
-void ctx::social_status_email::submit_trigger_item()
-{
- context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_EMAIL, OPS_SUBSCRIBE,
- "{"
- "\"Event\":{\"type\":\"string\",\"values\":[\"Received\",\"Sent\"]}"
- "}",
- NULL);
-}
-
-void ctx::social_status_email::onSignal(const char* sender, const char* path, const char* iface, const char* name, GVariant* param)
-{
- gint sub_type = 0;
- gint gi1 = 0;
- const gchar *gc = NULL;
- gint gi2 = 0;
- gint gi3 = 0;
-
- g_variant_get(param, "(ii&sii)", &sub_type, &gi1, &gc, &gi2, &gi3);
-
- if (sub_type == NOTI_DOWNLOAD_FINISH) {
- //TODO: Check if this signal actually means that there are new mails
- _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", sub_type, gi1, gc, gi2, gi3);
- ctx::Json dataUpdated;
- dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED);
- context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, dataUpdated);
-
- } else if (sub_type == NOTI_SEND_FINISH) {
- _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", sub_type, gi1, gc, gi2, gi3);
- ctx::Json dataUpdated;
- dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_SENT);
- context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, dataUpdated);
- }
-}
-
-
-int ctx::social_status_email::subscribe()
-{
- dbus_signal_id = __dbusWatcher.watch(NULL, NULL, "User.Email.NetworkStatus", "email", this);
- IF_FAIL_RETURN_TAG(dbus_signal_id >= 0, ERR_OPERATION_FAILED, _E, "Email dbus signal subscription failed");
- return ERR_NONE;
-}
-
-
-int ctx::social_status_email::unsubscribe()
-{
- __dbusWatcher.unwatch(dbus_signal_id);
- 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 _CONTEXT_SOCIAL_STATUS_EMAIL_H_
-#define _CONTEXT_SOCIAL_STATUS_EMAIL_H_
-
-#include <DBusSignalWatcher.h>
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class social_status_email : public device_provider_base, public IDBusSignalListener {
-
- GENERATE_PROVIDER_COMMON_DECL(social_status_email);
-
- public:
- int subscribe();
- int unsubscribe();
- void onSignal(const char *sender, const char *path, const char *iface, const char *name, GVariant *param);
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- int64_t dbus_signal_id;
- DBusSignalWatcher __dbusWatcher;
-
- social_status_email();
- ~social_status_email();
- };
-}
-
-#endif // _CONTEXT_SOCIAL_STATUS_EMAIL_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 <Json.h>
-#include <ContextManager.h>
-#include "social_types.h"
-#include "message.h"
-
-#define MAX_ADDR_SIZE 20
-
-GENERATE_PROVIDER_COMMON_IMPL(social_status_message);
-
-ctx::social_status_message::social_status_message()
- : message_handle(NULL)
-{
-}
-
-ctx::social_status_message::~social_status_message()
-{
-}
-
-bool ctx::social_status_message::is_supported()
-{
- return get_system_info_bool("tizen.org/feature/network.telephony");
-}
-
-void ctx::social_status_message::submit_trigger_item()
-{
- context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_MESSAGE, OPS_SUBSCRIBE,
- "{"
- "\"Event\":{\"type\":\"string\",\"values\":[\"Received\"]},"
- "\"Type\":{\"type\":\"string\",\"values\":[\"SMS\",\"MMS\"]},"
- "\"Address\":{\"type\":\"string\"}"
- "}",
- NULL);
-}
-
-void ctx::social_status_message::state_change_cb(msg_handle_t handle, msg_struct_t msg, void* user_data)
-{
- social_status_message *instance = static_cast<social_status_message*>(user_data);
- instance->handle_state_change(msg);
-}
-
-void ctx::social_status_message::handle_state_change(msg_struct_t msg)
-{
- int err;
- int type;
- char address[MAX_ADDR_SIZE];
- ctx::Json data;
-
- err = msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &type);
- IF_FAIL_VOID_TAG(err == MSG_SUCCESS, _W, "Getting message type failed");
-
- err = msg_get_str_value(msg, MSG_MESSAGE_REPLY_ADDR_STR, address, MAX_ADDR_SIZE);
- IF_FAIL_VOID_TAG(err == MSG_SUCCESS, _W, "Getting reply address failed");
-
- switch (type) {
- case MSG_TYPE_SMS_CB :
- case MSG_TYPE_SMS_JAVACB :
- case MSG_TYPE_SMS_WAPPUSH :
- case MSG_TYPE_SMS_MWI :
- case MSG_TYPE_SMS_SYNCML :
- case MSG_TYPE_SMS_REJECT :
- case MSG_TYPE_SMS_ETWS_PRIMARY :
- case MSG_TYPE_SMS :
- data.set(NULL, SOCIAL_ST_TYPE, SOCIAL_ST_SMS);
- break;
- case MSG_TYPE_MMS_NOTI :
- case MSG_TYPE_MMS_JAVA :
- case MSG_TYPE_MMS :
- data.set(NULL, SOCIAL_ST_TYPE, SOCIAL_ST_MMS);
- break;
- default :
- _W("Unknown message type");
- return;
- }
-
- data.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED);
- data.set(NULL, SOCIAL_ST_ADDRESS, address);
-
- context_manager::publish(SOCIAL_ST_SUBJ_MESSAGE, NULL, ERR_NONE, data);
-}
-
-bool ctx::social_status_message::set_callback()
-{
- int err;
-
- err = msg_open_msg_handle(&message_handle);
- IF_FAIL_RETURN_TAG(err == MSG_SUCCESS, false, _E, "Handle creation failed");
-
- err = msg_reg_sms_message_callback(message_handle, state_change_cb, 0, this);
- if (err != MSG_SUCCESS) {
- msg_close_msg_handle(&message_handle);
- _E("Setting SMS event callback failed");
- return false;
- }
-
- msg_reg_mms_conf_message_callback(message_handle, state_change_cb, NULL, this);
- return true;
-}
-
-void ctx::social_status_message::unset_callback()
-{
- if (message_handle)
- msg_close_msg_handle(&message_handle);
-
- message_handle = NULL;
-}
-
-int ctx::social_status_message::subscribe()
-{
- bool ret = set_callback();
- IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
- return ERR_NONE;
-}
-
-int ctx::social_status_message::unsubscribe()
-{
- unset_callback();
- 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 _CONTEXT_SOCIAL_STATUS_SMS_H_
-#define _CONTEXT_SOCIAL_STATUS_SMS_H_
-
-#include <msg.h>
-#include <msg_transport.h>
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class social_status_message : public device_provider_base {
-
- GENERATE_PROVIDER_COMMON_DECL(social_status_message);
-
- public:
- int subscribe();
- int unsubscribe();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- msg_handle_t message_handle;
- bool being_subscribed;
-
- social_status_message();
- ~social_status_message();
-
- bool set_callback();
- void unset_callback();
- void handle_state_change(msg_struct_t msg);
- static void state_change_cb(msg_handle_t handle, msg_struct_t msg, void* user_data);
- };
-}
-
-#endif // _CONTEXT_SOCIAL_STATUS_SMS_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.
- */
-
-#ifndef __CONTEXT_SOCIAL_STATUS_TYPES_INTERNAL_H__
-#define __CONTEXT_SOCIAL_STATUS_TYPES_INTERNAL_H__
-
-// Subject
-#define SOCIAL_ST_SUBJ_CALL "social/call"
-#define SOCIAL_ST_SUBJ_EMAIL "social/email"
-#define SOCIAL_ST_SUBJ_MESSAGE "social/message"
-#define SOCIAL_ST_SUBJ_CONTACTS "social/contacts"
-
-// Data Key
-#define SOCIAL_ST_STATE "State"
-#define SOCIAL_ST_EVENT "Event"
-#define SOCIAL_ST_TYPE "Type"
-#define SOCIAL_ST_MEDIUM "Medium"
-#define SOCIAL_ST_ADDRESS "Address"
-
-// Data Values
-#define SOCIAL_ST_IDLE "Idle"
-#define SOCIAL_ST_CONNECTING "Connecting"
-#define SOCIAL_ST_CONNECTED "Connected"
-#define SOCIAL_ST_ACTIVE SOCIAL_ST_CONNECTED
-#define SOCIAL_ST_HELD "Held"
-#define SOCIAL_ST_DIALING "Dialing"
-#define SOCIAL_ST_ALERTING SOCIAL_ST_CONNECTING
-#define SOCIAL_ST_INCOMING SOCIAL_ST_CONNECTING
-#define SOCIAL_ST_VOICE "Voice"
-#define SOCIAL_ST_VIDEO "Video"
-#define SOCIAL_ST_SENT "Sent"
-#define SOCIAL_ST_RECEIVED "Received"
-#define SOCIAL_ST_SMS "SMS"
-#define SOCIAL_ST_MMS "MMS"
-#define SOCIAL_ST_MY_PROFILE "MyProfile"
-#define SOCIAL_ST_PERSON "Person"
-#define SOCIAL_ST_CHANGED "Changed"
-
-#endif
--- /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 <ContextManager.h>
+#include "SystemTypes.h"
+#include "Alarm.h"
+
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusAlarm);
+
+ctx::DeviceStatusAlarm::DeviceStatusAlarm()
+{
+}
+
+ctx::DeviceStatusAlarm::~DeviceStatusAlarm()
+{
+ __clear();
+
+ for (auto it = __optionSet.begin(); it != __optionSet.end(); ++it) {
+ delete *it;
+ }
+ __optionSet.clear();
+}
+
+bool ctx::DeviceStatusAlarm::isSupported()
+{
+ return true;
+}
+
+void ctx::DeviceStatusAlarm::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(DEVICE_ST_SUBJ_ALARM, OPS_SUBSCRIBE,
+ "{"
+ "\"TimeOfDay\":{\"type\":\"integer\",\"min\":0,\"max\":1439},"
+ "\"DayOfWeek\":{\"type\":\"string\",\"values\":[\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\",\"Weekday\",\"Weekend\"]}"
+ "}",
+ NULL);
+}
+
+int ctx::DeviceStatusAlarm::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult)
+{
+ int ret = subscribe(option);
+ __destroyIfUnused();
+ return ret;
+}
+
+int ctx::DeviceStatusAlarm::unsubscribe(const char *subject, ctx::Json option)
+{
+ int ret = unsubscribe(option);
+ __destroyIfUnused();
+ return ret;
+}
+
+int ctx::DeviceStatusAlarm::read(const char *subject, ctx::Json option, ctx::Json *requestResult)
+{
+ __destroyIfUnused();
+ return ERR_NOT_SUPPORTED;
+}
+
+int ctx::DeviceStatusAlarm::write(const char *subject, ctx::Json data, ctx::Json *requestResult)
+{
+ __destroyIfUnused();
+ return ERR_NOT_SUPPORTED;
+}
+
+int ctx::DeviceStatusAlarm::subscribe(ctx::Json option)
+{
+ int dow = __getArrangedDayOfWeek(option);
+
+ int time;
+ for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) {
+ __add(time, dow);
+ }
+
+ ctx::Json* elem = new(std::nothrow) ctx::Json(option);
+ if (elem) {
+ __optionSet.insert(elem);
+ } else {
+ unsubscribe(option);
+ _E("Memory allocation failed");
+ return ERR_OUT_OF_MEMORY;
+ }
+
+ return ERR_NONE;
+}
+
+int ctx::DeviceStatusAlarm::unsubscribe(ctx::Json option)
+{
+ int dow = __getArrangedDayOfWeek(option);
+
+ int time;
+ for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) {
+ __remove(time, dow);
+ }
+
+ OptionSet::iterator target = __findOption(option);
+ if (target != __optionSet.end()) {
+ delete (*target);
+ __optionSet.erase(target);
+ }
+
+ return ERR_NONE;
+}
+
+int ctx::DeviceStatusAlarm::__getArrangedDayOfWeek(ctx::Json& option)
+{
+ int dow = 0;
+
+ std::string tempDay;
+ for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &tempDay); i++) {
+ dow |= ctx::TimerManager::dowToInt(tempDay);
+ }
+ _D("Requested day of week (%#x)", dow);
+
+ return dow;
+}
+
+ctx::DeviceStatusAlarm::RefCountArray::RefCountArray()
+{
+ memset(count, 0, sizeof(int) * DAYS_PER_WEEK);
+}
+
+int ctx::DeviceStatusAlarm::__mergeDayOfWeek(int* refCnt)
+{
+ int dayOfWeek = 0;
+
+ for (int d = 0; d < DAYS_PER_WEEK; ++d) {
+ if (refCnt[d] > 0) {
+ dayOfWeek |= (0x01 << d);
+ }
+ }
+
+ return dayOfWeek;
+}
+
+bool ctx::DeviceStatusAlarm::__add(int minute, int dayOfWeek)
+{
+ IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 &&
+ dayOfWeek > 0 && dayOfWeek <= static_cast<int>(DayOfWeek::EVERYDAY),
+ false, _E, "Invalid parameter");
+
+ RefCountArray &ref = __refCountMap[minute];
+
+ for (int d = 0; d < DAYS_PER_WEEK; ++d) {
+ if ((dayOfWeek & (0x01 << d)) != 0) {
+ ref.count[d] += 1;
+ }
+ }
+
+ return __resetTimer(minute);
+}
+
+bool ctx::DeviceStatusAlarm::__remove(int minute, int dayOfWeek)
+{
+ IF_FAIL_RETURN_TAG(minute >= 0 && minute < 1440 &&
+ dayOfWeek > 0 && dayOfWeek <= static_cast<int>(DayOfWeek::EVERYDAY),
+ false, _E, "Invalid parameter");
+
+ RefCountArray &ref = __refCountMap[minute];
+
+ for (int d = 0; d < DAYS_PER_WEEK; ++d) {
+ if ((dayOfWeek & (0x01 << d)) != 0 && ref.count[d] > 0) {
+ ref.count[d] -= 1;
+ }
+ }
+
+ return __resetTimer(minute);
+}
+
+bool ctx::DeviceStatusAlarm::__resetTimer(int minute)
+{
+ int dayOfWeek = __mergeDayOfWeek(__refCountMap[minute].count);
+ TimerState &timer = __timerStateMap[minute];
+
+ if (dayOfWeek == timer.dayOfWeek) {
+ /* Necessary timers are already running... */
+ return true;
+ }
+
+ if (dayOfWeek == 0 && timer.timerId > 0) {
+ /* Turn off the timer at hour, if it is not necessray anymore. */
+ __timerManager.remove(timer.timerId);
+ __timerStateMap.erase(minute);
+ __refCountMap.erase(minute);
+ return true;
+ }
+
+ if (timer.timerId > 0) {
+ /* Turn off the current timer, to set a new one. */
+ __timerManager.remove(timer.timerId);
+ timer.timerId = -1;
+ timer.dayOfWeek = 0;
+ }
+
+ /* Create a new timer, w.r.t. the new dayOfWeek value. */
+ int h = minute / 60;
+ int m = minute - h * 60;
+ int tid = __timerManager.setAt(h, m, static_cast<DayOfWeek>(dayOfWeek), this);
+ IF_FAIL_RETURN_TAG(tid > 0, false, _E, "Timer setting failed");
+
+ timer.timerId = tid;
+ timer.dayOfWeek = dayOfWeek;
+
+ return true;
+}
+
+void ctx::DeviceStatusAlarm::__clear()
+{
+ for (auto it = __timerStateMap.begin(); it != __timerStateMap.end(); ++it) {
+ if (it->second.timerId > 0) {
+ __timerManager.remove(it->second.timerId);
+ }
+ }
+
+ __timerStateMap.clear();
+ __refCountMap.clear();
+}
+
+bool ctx::DeviceStatusAlarm::onTimerExpired(int timerId)
+{
+ time_t rawTime;
+ struct tm timeInfo;
+
+ time(&rawTime);
+ tzset();
+ localtime_r(&rawTime, &timeInfo);
+
+ int hour = timeInfo.tm_hour;
+ int min = timeInfo.tm_min;
+ int dayOfWeek = (0x01 << timeInfo.tm_wday);
+
+ __handleUpdate(hour, min, dayOfWeek);
+
+ return true;
+}
+
+void ctx::DeviceStatusAlarm::__handleUpdate(int hour, int min, int dayOfWeek)
+{
+ _I("Time: %02d:%02d, Day of Week: %#x", hour, min, dayOfWeek);
+
+ ctx::Json dataRead;
+ int resultTime = hour * 60 + min;
+ std::string resultDay = ctx::TimerManager::dowToStr(dayOfWeek);
+ dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, resultTime);
+ dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, resultDay);
+
+ for (auto it = __optionSet.begin(); it != __optionSet.end(); ++it) {
+ ctx::Json option = (**it);
+ if (__isMatched(option, resultTime, resultDay)) {
+ context_manager::publish(DEVICE_ST_SUBJ_ALARM, option, ERR_NONE, dataRead);
+ }
+ }
+}
+
+bool ctx::DeviceStatusAlarm::__isMatched(ctx::Json& option, int time, std::string day)
+{
+ bool ret = false;
+ int optionTime;
+ for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &optionTime); i++){
+ if (time == optionTime) {
+ ret = true;
+ break;
+ }
+ }
+ IF_FAIL_RETURN(ret, false);
+
+ std::string optionDay;
+ for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &optionDay); i++){
+ if (day == optionDay) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+ctx::DeviceStatusAlarm::OptionSet::iterator ctx::DeviceStatusAlarm::__findOption(ctx::Json& option)
+{
+ for (auto it = __optionSet.begin(); it != __optionSet.end(); ++it) {
+ if (option == (**it))
+ return it;
+ }
+ return __optionSet.end();
+}
+
+void ctx::DeviceStatusAlarm::__destroyIfUnused()
+{
+ IF_FAIL_VOID(__optionSet.empty());
+ destroy(NULL);
+}
--- /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_SYSTEM_STATUS_ALARM_H_
+#define _DEVICE_SYSTEM_STATUS_ALARM_H_
+
+#include <map>
+#include <set>
+#include <ContextProviderBase.h>
+#include <TimerManager.h>
+#include "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class DeviceStatusAlarm : public ContextProviderBase, ITimerListener {
+
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusAlarm);
+
+ public:
+ int subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult);
+ int unsubscribe(const char *subject, ctx::Json option);
+ int read(const char *subject, ctx::Json option, ctx::Json *requestResult);
+ int write(const char *subject, ctx::Json data, ctx::Json *requestResult);
+
+ int subscribe(ctx::Json option);
+ int unsubscribe(ctx::Json option);
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ protected:
+ bool onTimerExpired(int timerId);
+
+ private:
+ DeviceStatusAlarm();
+ ~DeviceStatusAlarm();
+
+ struct RefCountArray {
+ int count[7]; /* reference counts for days of week*/
+ RefCountArray();
+ };
+
+ struct TimerState {
+ int timerId;
+ int dayOfWeek; /* day of week, merged into one integer */
+ TimerState() : timerId(-1), dayOfWeek(0) {}
+ };
+
+ typedef std::map<int, RefCountArray> RefCountMap;
+ typedef std::map<int, TimerState> TimerStateMap;
+ typedef std::set<ctx::Json*> OptionSet;
+
+ RefCountMap __refCountMap;
+ TimerStateMap __timerStateMap;
+ OptionSet __optionSet;
+ TimerManager __timerManager;
+
+ bool __add(int minute, int dayOfWeek);
+ bool __remove(int minute, int dayOfWeek);
+ bool __resetTimer(int hour);
+ void __clear();
+ void __handleUpdate(int hour, int min, int dayOfWeek);
+
+ int __getArrangedDayOfWeek(ctx::Json& option);
+ int __mergeDayOfWeek(int *refCnt);
+
+ bool __isMatched(ctx::Json& option, int time, std::string day);
+ OptionSet::iterator __findOption(ctx::Json& option);
+
+ void __destroyIfUnused();
+
+ };
+}
+
+#endif // _DEVICE_SYSTEM_STATUS_ALARM_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 <ContextManager.h>
+#include "SystemTypes.h"
+#include "Battery.h"
+
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusBattery);
+
+ctx::DeviceStatusBattery::DeviceStatusBattery()
+{
+}
+
+ctx::DeviceStatusBattery::~DeviceStatusBattery()
+{
+}
+
+bool ctx::DeviceStatusBattery::isSupported()
+{
+ return true;
+}
+
+void ctx::DeviceStatusBattery::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(DEVICE_ST_SUBJ_BATTERY, OPS_SUBSCRIBE | OPS_READ,
+ "{"
+ "\"Level\":{\"type\":\"string\",\"values\":[\"Empty\",\"Critical\",\"Low\",\"Normal\",\"High\",\"Full\"]},"
+ TRIG_BOOL_ITEM_DEF("IsCharging")
+ "}",
+ NULL);
+}
+
+void ctx::DeviceStatusBattery::__updateCb(device_callback_e deviceType, void* value, void* userData)
+{
+ IF_FAIL_VOID(deviceType == DEVICE_CALLBACK_BATTERY_LEVEL);
+
+ DeviceStatusBattery *instance = static_cast<DeviceStatusBattery*>(userData);
+ instance->__handleUpdate(deviceType, value);
+}
+
+void ctx::DeviceStatusBattery::__handleUpdate(device_callback_e deviceType, void* value)
+{
+ intptr_t level = (intptr_t)value;
+
+ const char* levelString = __transToString(level);
+ IF_FAIL_VOID(levelString);
+
+ ctx::Json dataRead;
+ dataRead.set(NULL, DEVICE_ST_LEVEL, levelString);
+
+ bool chargingState = false;
+ int ret = device_battery_is_charging(&chargingState);
+ IF_FAIL_VOID_TAG(ret == DEVICE_ERROR_NONE, _E, "Getting state failed");
+
+ dataRead.set(NULL, DEVICE_ST_IS_CHARGING, chargingState ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+ ctx::context_manager::publish(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, dataRead);
+}
+
+const char* ctx::DeviceStatusBattery::__transToString(intptr_t level)
+{
+ switch (level) {
+ case DEVICE_BATTERY_LEVEL_EMPTY:
+ return DEVICE_ST_EMPTY;
+
+ case DEVICE_BATTERY_LEVEL_CRITICAL:
+ return DEVICE_ST_CRITICAL;
+
+ case DEVICE_BATTERY_LEVEL_LOW:
+ return DEVICE_ST_LOW;
+
+ case DEVICE_BATTERY_LEVEL_HIGH:
+ return DEVICE_ST_NORMAL;
+
+ case DEVICE_BATTERY_LEVEL_FULL:
+ {
+ int percent;
+ device_battery_get_percent(&percent);
+
+ if (percent == 100) {
+ return DEVICE_ST_FULL;
+ } else {
+ return DEVICE_ST_HIGH;
+ }
+ break;
+ }
+
+ default:
+ _E("Invalid battery level");
+ return NULL;
+ }
+}
+
+int ctx::DeviceStatusBattery::subscribe()
+{
+ int ret = device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, __updateCb, this);
+ IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
+ return ERR_NONE;
+}
+
+int ctx::DeviceStatusBattery::unsubscribe()
+{
+ int ret = device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, __updateCb);
+ IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
+ return ERR_NONE;
+}
+
+int ctx::DeviceStatusBattery::read()
+{
+ device_battery_level_e level;
+ ctx::Json dataRead;
+
+ int ret = device_battery_get_level_status(&level);
+ IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
+
+ const char* levelString = __transToString(level);
+ IF_FAIL_RETURN(levelString, ERR_OPERATION_FAILED);
+
+ dataRead.set(NULL, DEVICE_ST_LEVEL, levelString);
+
+ bool chargingState = false;
+ ret = device_battery_is_charging(&chargingState);
+ IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
+
+ dataRead.set(NULL, DEVICE_ST_IS_CHARGING, chargingState ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+
+ ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, dataRead);
+ 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_SYSTEM_STATUS_BATTERY_H_
+#define _DEVICE_SYSTEM_STATUS_BATTERY_H_
+
+#include <device/callback.h>
+#include <device/battery.h>
+#include "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class DeviceStatusBattery : public DeviceProviderBase {
+
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusBattery);
+
+ public:
+ int subscribe();
+ int unsubscribe();
+ int read();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ private:
+ DeviceStatusBattery();
+ ~DeviceStatusBattery();
+ const char* __transToString(intptr_t level);
+ void __handleUpdate(device_callback_e deviceType, void* value);
+ static void __updateCb(device_callback_e deviceType, void* value, void* userData);
+ };
+}
+
+#endif // _DEVICE_SYSTEM_STATUS_BATTERY_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 <ContextManager.h>
+#include "SystemTypes.h"
+#include "Headphone.h"
+
+#define HANDLING_DELAY 2000
+#define MAX_HANDLING_COUNT 3
+
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusHeadphone);
+
+ctx::DeviceStatusHeadphone::DeviceStatusHeadphone() :
+ __connected(false),
+ __audioJackState(RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED),
+ __btAudioState(false),
+ __btAudioCallbackOn(false),
+ __btEventHandlerAdded(false),
+ __btEventHandlingCount(0)
+{
+}
+
+ctx::DeviceStatusHeadphone::~DeviceStatusHeadphone()
+{
+}
+
+bool ctx::DeviceStatusHeadphone::isSupported()
+{
+ return true;
+}
+
+void ctx::DeviceStatusHeadphone::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(DEVICE_ST_SUBJ_HEADPHONE, OPS_SUBSCRIBE | OPS_READ,
+ "{"
+ TRIG_BOOL_ITEM_DEF("IsConnected") ","
+ "\"Type\":{\"type\":\"string\",\"values\":[\"Normal\",\"Headset\",\"Bluetooth\"]}"
+ "}",
+ NULL);
+}
+
+int ctx::DeviceStatusHeadphone::subscribe()
+{
+ __connected = __getCurrentStatus();
+
+ // Wired headphone
+ int ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, __onAudioJackStateChanged, this);
+ IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
+
+ // Bluetooth headphone
+ __setBtAudioCallback();
+
+ return ERR_NONE;
+}
+
+int ctx::DeviceStatusHeadphone::unsubscribe()
+{
+ runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS);
+ __unsetBtAudioCallback();
+
+ return ERR_NONE;
+}
+
+int ctx::DeviceStatusHeadphone::read()
+{
+ if (!__beingSubscribed)
+ __connected = __getCurrentStatus();
+
+ Json data;
+ __generateDataPacket(&data);
+ ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data);
+
+ return ERR_NONE;
+}
+
+void ctx::DeviceStatusHeadphone::__setBtAudioCallback()
+{
+ IF_FAIL_VOID(!__btAudioCallbackOn);
+ int ret;
+
+ ret = bt_initialize();
+ if (ret != BT_ERROR_NONE) {
+ _W("Bluetooth initialization failed");
+ return;
+ }
+
+ ret = bt_device_set_connection_state_changed_cb(__onBtConnectionChanged, this);
+ if (ret != BT_ERROR_NONE) {
+ bt_deinitialize();
+ return;
+ }
+
+ __btAudioCallbackOn = true;
+}
+
+void ctx::DeviceStatusHeadphone::__unsetBtAudioCallback()
+{
+ IF_FAIL_VOID(__btAudioCallbackOn);
+
+ bt_device_unset_connection_state_changed_cb();
+ bt_deinitialize();
+
+ __btAudioCallbackOn = false;
+}
+
+void ctx::DeviceStatusHeadphone::__setBtAudioState(bool state)
+{
+ __btAudioState = state;
+}
+
+bool ctx::DeviceStatusHeadphone::__getCurrentStatus()
+{
+ int ret;
+
+ // Wired audio
+ ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, &__audioJackState);
+ IF_FAIL_RETURN(ret == ERR_NONE, __connected);
+
+ // Bluetooth audio
+ __btAudioState = false;
+ ret = bt_initialize();
+ if (ret == BT_ERROR_NONE) {
+ bt_adapter_foreach_bonded_device(__onBtBond, this);
+ bt_deinitialize();
+ }
+
+ return ((__audioJackState != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || __btAudioState);
+}
+
+void ctx::DeviceStatusHeadphone::__generateDataPacket(ctx::Json* data)
+{
+ data->set(NULL, DEVICE_ST_IS_CONNECTED, __connected ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+
+ switch (__audioJackState) {
+ case RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_3WIRE:
+ data->set(NULL, DEVICE_ST_TYPE, DEVICE_ST_NORMAL);
+ break;
+ case RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_4WIRE:
+ data->set(NULL, DEVICE_ST_TYPE, DEVICE_ST_HEADSET);
+ break;
+ default:
+ if (__btAudioState)
+ data->set(NULL, DEVICE_ST_TYPE, DEVICE_ST_BLUETOOTH);
+ break;
+ }
+}
+
+bool ctx::DeviceStatusHeadphone::__handleUpdate()
+{
+ bool prevState = __connected;
+ __connected = ((__audioJackState != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || __btAudioState);
+
+ IF_FAIL_RETURN(prevState != __connected, false);
+
+ ctx::Json data;
+ __generateDataPacket(&data);
+ ctx::context_manager::publish(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data);
+ return true;
+}
+
+void ctx::DeviceStatusHeadphone::__handleAudioJackEvent()
+{
+ int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, &__audioJackState);
+ IF_FAIL_VOID_TAG(ret == ERR_NONE, _E, "Getting runtime info failed");
+ __handleUpdate();
+}
+
+void ctx::DeviceStatusHeadphone::__onAudioJackStateChanged(runtime_info_key_e runtimeKey, void* userData)
+{
+ _D("EarJack");
+ ctx::DeviceStatusHeadphone *instance = static_cast<ctx::DeviceStatusHeadphone*>(userData);
+ instance->__handleAudioJackEvent();
+}
+
+void ctx::DeviceStatusHeadphone::__onBtConnectionChanged(bool connected, bt_device_connection_info_s *connInfo, void *userData)
+{
+ ctx::DeviceStatusHeadphone *instance = static_cast<ctx::DeviceStatusHeadphone*>(userData);
+ IF_FAIL_VOID(connected != instance->__btAudioState);
+ IF_FAIL_VOID(!instance->__btEventHandlerAdded);
+
+ if (connected) {
+ _D("BT state checking scheduled");
+ instance->__btEventHandlerAdded = true;
+ instance->__btEventHandlingCount = 0;
+ g_timeout_add(HANDLING_DELAY, __handleBtEvent, userData);
+ } else {
+ __handleBtEvent(userData);
+ }
+}
+
+gboolean ctx::DeviceStatusHeadphone::__handleBtEvent(gpointer data)
+{
+ _D("BT state checking started");
+ ctx::DeviceStatusHeadphone *instance = static_cast<ctx::DeviceStatusHeadphone*>(data);
+ instance->__btEventHandlerAdded = false;
+
+ instance->__setBtAudioState(false);
+ int err = bt_adapter_foreach_bonded_device(__onBtBond, data);
+ IF_FAIL_RETURN_TAG(err == BT_ERROR_NONE, FALSE, _E, "bt_adapter_foreach_bonded_device() failed");
+
+ instance->__btEventHandlingCount++;
+
+ if (instance->__handleUpdate() || instance->__btEventHandlingCount >= MAX_HANDLING_COUNT)
+ return FALSE;
+
+ return TRUE;
+}
+
+bool ctx::DeviceStatusHeadphone::__onBtBond(bt_device_info_s *deviceInfo, void* userData)
+{
+ if (deviceInfo->bt_class.major_device_class != BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO)
+ return true;
+
+ bool st = false;
+ int err = bt_device_is_profile_connected(deviceInfo->remote_address, BT_PROFILE_A2DP, &st);
+ IF_FAIL_RETURN_TAG(err == BT_ERROR_NONE, false, _E, "bt_device_is_profile_connected() failed");
+
+ if (st) {
+ ctx::DeviceStatusHeadphone *instance = static_cast<ctx::DeviceStatusHeadphone*>(userData);
+ instance->__setBtAudioState(true);
+ return false;
+ }
+
+ return true;
+}
--- /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_SYSTEM_STATUS_HEADPHONE_H_
+#define _DEVICE_STATUS_HEADPNOHE_H_
+
+#include <glib.h>
+#include <runtime_info.h>
+#include <bluetooth.h>
+#include "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class DeviceStatusHeadphone : public DeviceProviderBase {
+
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusHeadphone);
+
+ public:
+ int subscribe();
+ int unsubscribe();
+ int read();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ private:
+ bool __connected;
+ int __audioJackState;
+ bool __btAudioState;
+ bool __btAudioCallbackOn;
+ bool __btEventHandlerAdded;
+ int __btEventHandlingCount;
+
+ DeviceStatusHeadphone();
+ ~DeviceStatusHeadphone();
+
+ bool __getCurrentStatus();
+ void __setBtAudioCallback();
+ void __unsetBtAudioCallback();
+ void __setBtAudioState(bool state);
+
+ void __generateDataPacket(Json* data);
+ bool __handleUpdate();
+ void __handleAudioJackEvent();
+ static gboolean __handleBtEvent(gpointer data);
+
+ static void __onAudioJackStateChanged(runtime_info_key_e runtimeKey, void* userData);
+ static void __onBtConnectionChanged(bool connected, bt_device_connection_info_s *connInfo, void *userData);
+ static bool __onBtBond(bt_device_info_s *deviceInfo, void* userData);
+ };
+}
+
+#endif // _DEVICE_SYSTEM_STATUS_HEADPHONE_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 <ContextManager.h>
+#include "SystemTypes.h"
+#include "Psmode.h"
+
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusPsmode);
+
+ctx::DeviceStatusPsmode::DeviceStatusPsmode()
+{
+}
+
+ctx::DeviceStatusPsmode::~DeviceStatusPsmode()
+{
+}
+
+bool ctx::DeviceStatusPsmode::isSupported()
+{
+ return true;
+}
+
+void ctx::DeviceStatusPsmode::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(DEVICE_ST_SUBJ_PSMODE, OPS_SUBSCRIBE | OPS_READ,
+ "{" TRIG_BOOL_ITEM_DEF("IsEnabled") "}", NULL);
+}
+
+void ctx::DeviceStatusPsmode::__updateCb(keynode_t *node, void* userData)
+{
+ DeviceStatusPsmode *instance = static_cast<DeviceStatusPsmode*>(userData);
+ instance->__handleUpdate(node);
+}
+
+void ctx::DeviceStatusPsmode::__handleUpdate(keynode_t *node)
+{
+ int status;
+ ctx::Json dataRead;
+
+ status = vconf_keynode_get_int(node);
+ IF_FAIL_VOID_TAG(status >= 0, _E, "Getting state failed");
+
+ dataRead.set(NULL, DEVICE_ST_IS_ENABLED, status == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE);
+
+ context_manager::publish(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, dataRead);
+}
+
+int ctx::DeviceStatusPsmode::subscribe()
+{
+ int ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, __updateCb, this);
+ IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED);
+ return ERR_NONE;
+}
+
+int ctx::DeviceStatusPsmode::unsubscribe()
+{
+ int ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, __updateCb);
+ IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED);
+ return ERR_NONE;
+}
+
+int ctx::DeviceStatusPsmode::read()
+{
+ int mode;
+ int ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &mode);
+ IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED);
+
+ ctx::Json dataRead;
+ dataRead.set(NULL, DEVICE_ST_IS_ENABLED, mode == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE);
+
+ ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, dataRead);
+ 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_SYSTEM_STATUS_POWER_SAVING_MODE_H_
+#define _DEVICE_SYSTEM_STATUS_POWER_SAVING_MODE_H_
+
+#include <vconf.h>
+#include "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class DeviceStatusPsmode : public DeviceProviderBase {
+
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusPsmode);
+
+ public:
+ int subscribe();
+ int unsubscribe();
+ int read();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ private:
+ DeviceStatusPsmode();
+ ~DeviceStatusPsmode();
+ void __handleUpdate(keynode_t *node);
+ static void __updateCb(keynode_t *node, void* userData);
+ };
+}
+
+#endif // _DEVICE_SYSTEM_STATUS_POWER_SAVING_MODE_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.
+ */
+
+#ifndef _DEVICE_SYSTEM_STATUS_TYPES_H_
+#define _DEVICE_SYSTEM_STATUS_TYPES_H_
+
+// Subject
+#define DEVICE_ST_SUBJ_BATTERY "system/battery"
+#define DEVICE_ST_SUBJ_CHARGER "system/charger"
+#define DEVICE_ST_SUBJ_HEADPHONE "system/headphone"
+#define DEVICE_ST_SUBJ_WIFI "system/wifi"
+#define DEVICE_ST_SUBJ_USB "system/usb"
+#define DEVICE_ST_SUBJ_GPS "system/gps"
+#define DEVICE_ST_SUBJ_PSMODE "system/psmode"
+#define DEVICE_ST_SUBJ_ALARM "device/alarm"
+#define DEVICE_ST_SUBJ_TIME "device/time"
+
+// Data Key
+#define DEVICE_ST_EVENT "Event"
+#define DEVICE_ST_STATE "State"
+#define DEVICE_ST_TYPE "Type"
+#define DEVICE_ST_LEVEL "Level"
+#define DEVICE_ST_BSSID "BSSID"
+#define DEVICE_ST_IS_CONNECTED "IsConnected"
+#define DEVICE_ST_IS_ENABLED "IsEnabled"
+#define DEVICE_ST_IS_CHARGING "IsCharging"
+#define DEVICE_ST_DETECTED "Detected"
+#define DEVICE_ST_TIME_OF_DAY "TimeOfDay"
+#define DEVICE_ST_DAY_OF_WEEK "DayOfWeek"
+#define DEVICE_ST_DAY_OF_MONTH "DayOfMonth"
+
+// Data Value
+#define DEVICE_ST_TRUE 1
+#define DEVICE_ST_FALSE 0
+#define DEVICE_ST_ENTER "Enter"
+#define DEVICE_ST_EXIT "Exit"
+#define DEVICE_ST_DISABLED "Disabled"
+#define DEVICE_ST_CONNECTED "Connected"
+#define DEVICE_ST_UNCONNECTED "Unconnected"
+#define DEVICE_ST_SEARCHING "Searching"
+#define DEVICE_ST_EMPTY "Empty"
+#define DEVICE_ST_CRITICAL "Critical"
+#define DEVICE_ST_LOW "Low"
+#define DEVICE_ST_NORMAL "Normal"
+#define DEVICE_ST_HIGH "High"
+#define DEVICE_ST_FULL "Full"
+#define DEVICE_ST_HEADSET "Headset"
+#define DEVICE_ST_BLUETOOTH "Bluetooth"
+
+#define TRIG_BOOL_ITEM_DEF(sbj) "\"" sbj "\":{\"type\":\"integer\",\"min\":0,\"max\":1}"
+
+#endif //_DEVICE_SYSTEM_STATUS_TYPES_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 <ContextManager.h>
+#include <TimerManager.h>
+#include "SystemTypes.h"
+#include "Time.h"
+
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusTime);
+
+ctx::DeviceStatusTime::DeviceStatusTime()
+{
+}
+
+ctx::DeviceStatusTime::~DeviceStatusTime()
+{
+}
+
+bool ctx::DeviceStatusTime::isSupported()
+{
+ return true;
+}
+
+void ctx::DeviceStatusTime::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(DEVICE_ST_SUBJ_TIME, OPS_READ,
+ "{"
+ "\"TimeOfDay\":{\"type\":\"integer\",\"min\":0,\"max\":1439},"
+ "\"DayOfWeek\":{\"type\":\"string\",\"values\":[\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\",\"Weekday\",\"Weekend\"]},"
+ "\"DayOfMonth\":{\"type\":\"integer\",\"min\":1,\"max\":31}"
+ "}",
+ NULL);
+}
+
+int ctx::DeviceStatusTime::subscribe()
+{
+ return ERR_NOT_SUPPORTED;
+}
+
+int ctx::DeviceStatusTime::unsubscribe()
+{
+ return ERR_NOT_SUPPORTED;
+}
+
+int ctx::DeviceStatusTime::read()
+{
+ time_t rawtime;
+ struct tm timeInfo;
+
+ time(&rawtime);
+ tzset();
+ localtime_r(&rawtime, &timeInfo);
+
+ int dayOfMonth = timeInfo.tm_mday;
+ int minuteOfDay = timeInfo.tm_hour * 60 + timeInfo.tm_min;
+ std::string dayOfWeek = ctx::TimerManager::dowToStr(0x01 << timeInfo.tm_wday);
+
+ ctx::Json dataRead;
+ dataRead.set(NULL, DEVICE_ST_DAY_OF_MONTH, dayOfMonth);
+ dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, dayOfWeek);
+ dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, minuteOfDay);
+
+ _I("Time: %02d:%02d, Day of Week: %s, Day of Month: %d", timeInfo.tm_hour, timeInfo.tm_min, dayOfWeek.c_str(), dayOfMonth);
+
+ ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_TIME, NULL, ERR_NONE, dataRead);
+
+ 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_SYSTEM_STATUS_TIME_H_
+#define _DEVICE_SYSTEM_STATUS_TIME_H_
+
+#include "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class DeviceStatusTime : public DeviceProviderBase {
+
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusTime);
+
+ public:
+ int subscribe();
+ int unsubscribe();
+ int read();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ private:
+ DeviceStatusTime();
+ ~DeviceStatusTime();
+ };
+}
+
+#endif // _DEVICE_SYSTEM_STATUS_TIME_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 <SharedVars.h>
+#include <ContextManager.h>
+#include "SystemTypes.h"
+#include "Wifi.h"
+
+ctx::DeviceStatusWifi *ctx::DeviceStatusWifi::__instance = NULL;
+
+ctx::DeviceStatusWifi::DeviceStatusWifi() :
+ __lastState(UNKNOWN),
+ __isInitialized(false),
+ __isActivated(false),
+ __connState(WIFI_CONNECTION_STATE_FAILURE)
+{
+ IF_FAIL_VOID_TAG(__startMonitor(), _W, "WiFi monitor initialization failed");
+
+ if (!__getCurrentState()) {
+ __stopMonitor();
+ _W("Getting current WiFi status failed");
+ }
+}
+
+ctx::DeviceStatusWifi::~DeviceStatusWifi()
+{
+}
+
+ctx::ContextProviderBase *ctx::DeviceStatusWifi::create(void *data)
+{
+ CREATE_INSTANCE(DeviceStatusWifi);
+}
+
+void ctx::DeviceStatusWifi::destroy(void *data)
+{
+ __instance->__stopMonitor();
+ DESTROY_INSTANCE();
+}
+
+void ctx::DeviceStatusWifi::destroySelf()
+{
+ /* WiFi status will be monitored continuously, even if no client is subscribing it */
+}
+
+bool ctx::DeviceStatusWifi::isSupported()
+{
+ return getSystemInfoBool("tizen.org/feature/network.wifi");
+}
+
+void ctx::DeviceStatusWifi::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(DEVICE_ST_SUBJ_WIFI, OPS_SUBSCRIBE | OPS_READ,
+ "{"
+ "\"State\":{\"type\":\"string\",\"values\":[\"Disabled\",\"Unconnected\",\"Connected\"]},"
+ "\"BSSID\":{\"type\":\"string\"}"
+ "}",
+ NULL);
+}
+
+bool ctx::DeviceStatusWifi::__getCurrentState()
+{
+ int err;
+
+ if (!__isInitialized) {
+ err = wifi_initialize();
+ IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_initialize() failed");
+ }
+
+ err = wifi_is_activated(&__isActivated);
+ IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_is_activated() failed");
+
+ err = wifi_get_connection_state(&__connState);
+ IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_get_connection_state() failed");
+
+ if (__isActivated) {
+ if (__connState == WIFI_CONNECTION_STATE_CONNECTED) {
+ __lastState = CONNECTED;
+ __getBssid();
+ } else {
+ __lastState = UNCONNECTED;
+ __clearBssid();
+ }
+ } else {
+ __lastState = DISABLED;
+ __clearBssid();
+ }
+
+ if (!__isInitialized)
+ wifi_deinitialize();
+
+ return true;
+}
+
+bool ctx::DeviceStatusWifi::__getBssid()
+{
+ int err;
+ char *strBuf = NULL;
+ wifi_ap_h ap = NULL;
+
+ err = wifi_get_connected_ap(&ap);
+ IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_get_connected_ap() failed");
+
+ wifi_ap_get_bssid(ap, &strBuf);
+ __bssid = (strBuf != NULL ? strBuf : "");
+ g_free(strBuf);
+
+ wifi_ap_destroy(ap);
+
+ if (__bssid.empty())
+ _W("Failed to get BSSID");
+
+ SharedVars().set(ctx::SharedVars::WIFI_BSSID, __bssid);
+ _D("BSSID: %s", __bssid.c_str());
+
+ return !__bssid.empty();
+}
+
+void ctx::DeviceStatusWifi::__clearBssid()
+{
+ __bssid.clear();
+ SharedVars().clear(ctx::SharedVars::WIFI_BSSID);
+ _D("No WiFi connection");
+}
+
+bool ctx::DeviceStatusWifi::__getResponsePacket(ctx::Json* data)
+{
+ switch (__lastState) {
+ case DISABLED:
+ data->set(NULL, DEVICE_ST_STATE, DEVICE_ST_DISABLED);
+ break;
+
+ case UNCONNECTED:
+ data->set(NULL, DEVICE_ST_STATE, DEVICE_ST_UNCONNECTED);
+ break;
+
+ case CONNECTED:
+ data->set(NULL, DEVICE_ST_STATE, DEVICE_ST_CONNECTED);
+ data->set(NULL, DEVICE_ST_BSSID, __bssid);
+ break;
+
+ default:
+ return false;
+ }
+
+ return true;
+}
+
+int ctx::DeviceStatusWifi::read()
+{
+ IF_FAIL_RETURN(__getCurrentState(), ERR_OPERATION_FAILED);
+
+ ctx::Json dataRead;
+ if (__getResponsePacket(&dataRead)) {
+ ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, dataRead);
+ return ERR_NONE;
+ }
+
+ return ERR_OPERATION_FAILED;
+}
+
+bool ctx::DeviceStatusWifi::__startMonitor()
+{
+ IF_FAIL_RETURN(!__isInitialized, true);
+
+ int err;
+ err = wifi_initialize();
+ IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_initialize() failed");
+
+ err = wifi_set_device_state_changed_cb(__deviceStateChangedCb, this);
+ IF_FAIL_CATCH_TAG(err == WIFI_ERROR_NONE, _E, "wifi_set_device_state_changed_cb() failed");
+
+ err = wifi_set_connection_state_changed_cb(__connectionStateChangedCb, this);
+ IF_FAIL_CATCH_TAG(err == WIFI_ERROR_NONE, _E, "wifi_set_connection_state_changed_cb() failed");
+
+ __isInitialized = true;
+ return true;
+
+CATCH:
+ wifi_deinitialize();
+ return false;
+}
+
+void ctx::DeviceStatusWifi::__stopMonitor()
+{
+ IF_FAIL_VOID(__isInitialized);
+
+ wifi_unset_device_state_changed_cb();
+ wifi_unset_connection_state_changed_cb();
+ wifi_deinitialize();
+ __isInitialized = false;
+}
+
+int ctx::DeviceStatusWifi::subscribe()
+{
+#if 0
+ IF_FAIL_RETURN(__startMonitor(), ERR_OPERATION_FAILED);
+ if (!__getCurrentState()) {
+ __stopMonitor();
+ return ERR_OPERATION_FAILED;
+ }
+#endif
+
+ return ERR_NONE;
+}
+
+int ctx::DeviceStatusWifi::unsubscribe()
+{
+#if 0
+ __stopMonitor();
+#endif
+ return ERR_NONE;
+}
+
+void ctx::DeviceStatusWifi::__handleUpdate()
+{
+ int prevState = __lastState;
+
+ if (__isActivated) {
+ if (__connState == WIFI_CONNECTION_STATE_CONNECTED) {
+ __lastState = CONNECTED;
+ } else {
+ __lastState = UNCONNECTED;
+ }
+ } else {
+ __lastState = DISABLED;
+ }
+
+ if (__lastState != prevState) {
+ if (__lastState == CONNECTED) {
+ __getBssid();
+ } else {
+ __clearBssid();
+ }
+
+ ctx::Json data;
+ if (__beingSubscribed && __getResponsePacket(&data))
+ context_manager::publish(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, data);
+ }
+}
+
+void ctx::DeviceStatusWifi::__deviceStateChangedCb(wifi_device_state_e state, void *userData)
+{
+ DeviceStatusWifi *instance = static_cast<DeviceStatusWifi*>(userData);
+ instance->__isActivated = (state == WIFI_DEVICE_STATE_ACTIVATED);
+ instance->__handleUpdate();
+}
+
+void ctx::DeviceStatusWifi::__connectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *userData)
+{
+ DeviceStatusWifi *instance = static_cast<DeviceStatusWifi*>(userData);
+ instance->__connState = state;
+ instance->__handleUpdate();
+}
--- /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_SYSTEM_STATUS_WIFI_H_
+#define _DEVICE_SYSTEM_STATUS_WIFI_H_
+
+#include <string>
+#include <wifi.h>
+#include "../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class DeviceStatusWifi : public DeviceProviderBase {
+
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusWifi);
+
+ public:
+ int subscribe();
+ int unsubscribe();
+ int read();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ private:
+ enum InternalState {
+ UNKNOWN = -1,
+ DISABLED = 0,
+ UNCONNECTED,
+ CONNECTED,
+ };
+
+ int __lastState;
+ bool __isInitialized;
+ bool __isActivated;
+ wifi_connection_state_e __connState;
+ std::string __bssid;
+
+ DeviceStatusWifi();
+ ~DeviceStatusWifi();
+
+ bool __getCurrentState();
+ bool __getBssid();
+ void __clearBssid();
+ bool __getResponsePacket(Json* data);
+ void __handleUpdate();
+ bool __startMonitor();
+ void __stopMonitor();
+ static void __deviceStateChangedCb(wifi_device_state_e state, void *userData);
+ static void __connectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *userData);
+ };
+}
+
+#endif // _CONTEXT_SYSTEM_STATUS_WIFI_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 <ContextManager.h>
-#include "system_types.h"
-#include "alarm.h"
-
-GENERATE_PROVIDER_COMMON_IMPL(device_status_alarm);
-
-ctx::device_status_alarm::device_status_alarm()
-{
-}
-
-ctx::device_status_alarm::~device_status_alarm()
-{
- clear();
-
- for (ctx::device_status_alarm::option_t::iterator it = option_set.begin(); it != option_set.end(); ++it) {
- delete *it;
- }
- option_set.clear();
-}
-
-bool ctx::device_status_alarm::is_supported()
-{
- return true;
-}
-
-void ctx::device_status_alarm::submit_trigger_item()
-{
- context_manager::registerTriggerItem(DEVICE_ST_SUBJ_ALARM, OPS_SUBSCRIBE,
- "{"
- "\"TimeOfDay\":{\"type\":\"integer\",\"min\":0,\"max\":1439},"
- "\"DayOfWeek\":{\"type\":\"string\",\"values\":[\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\",\"Weekday\",\"Weekend\"]}"
- "}",
- NULL);
-}
-
-int ctx::device_status_alarm::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult)
-{
- int ret = subscribe(option);
- destroy_if_unused();
- return ret;
-}
-
-int ctx::device_status_alarm::unsubscribe(const char *subject, ctx::Json option)
-{
- int ret = unsubscribe(option);
- destroy_if_unused();
- return ret;
-}
-
-int ctx::device_status_alarm::read(const char *subject, ctx::Json option, ctx::Json *requestResult)
-{
- destroy_if_unused();
- return ERR_NOT_SUPPORTED;
-}
-
-int ctx::device_status_alarm::write(const char *subject, ctx::Json data, ctx::Json *requestResult)
-{
- destroy_if_unused();
- return ERR_NOT_SUPPORTED;
-}
-
-int ctx::device_status_alarm::subscribe(ctx::Json option)
-{
- int dow = get_arranged_day_of_week(option);
-
- int time;
- for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) {
- add(time, dow);
- }
-
- ctx::Json* elem = new(std::nothrow) ctx::Json(option);
- if (elem) {
- option_set.insert(elem);
- } else {
- unsubscribe(option);
- _E("Memory allocation failed");
- return ERR_OUT_OF_MEMORY;
- }
-
- return ERR_NONE;
-}
-
-int ctx::device_status_alarm::unsubscribe(ctx::Json option)
-{
- int dow = get_arranged_day_of_week(option);
-
- int time;
- for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) {
- remove(time, dow);
- }
-
- option_t::iterator target = find_option(option);
- if (target != option_set.end()) {
- delete (*target);
- option_set.erase(target);
- }
-
- return ERR_NONE;
-}
-
-int ctx::device_status_alarm::get_arranged_day_of_week(ctx::Json& option)
-{
- int dow = 0;
-
- std::string tmp_d;
- for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &tmp_d); i++) {
- dow |= ctx::TimerManager::dowToInt(tmp_d);
- }
- _D("Requested day of week (%#x)", dow);
-
- return dow;
-}
-
-ctx::device_status_alarm::ref_count_array_s::ref_count_array_s()
-{
- memset(count, 0, sizeof(int) * DAYS_PER_WEEK);
-}
-
-int ctx::device_status_alarm::merge_day_of_week(int* ref_cnt)
-{
- int day_of_week = 0;
-
- for (int d = 0; d < DAYS_PER_WEEK; ++d) {
- if (ref_cnt[d] > 0) {
- day_of_week |= (0x01 << d);
- }
- }
-
- return day_of_week;
-}
-
-bool ctx::device_status_alarm::add(int minute, int day_of_week)
-{
- IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 &&
- day_of_week > 0 && day_of_week <= static_cast<int>(DayOfWeek::EVERYDAY),
- false, _E, "Invalid parameter");
-
- ref_count_array_s &ref = ref_count_map[minute];
-
- for (int d = 0; d < DAYS_PER_WEEK; ++d) {
- if ((day_of_week & (0x01 << d)) != 0) {
- ref.count[d] += 1;
- }
- }
-
- return reset_timer(minute);
-}
-
-bool ctx::device_status_alarm::remove(int minute, int day_of_week)
-{
- IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 &&
- day_of_week > 0 && day_of_week <= static_cast<int>(DayOfWeek::EVERYDAY),
- false, _E, "Invalid parameter");
-
- ref_count_array_s &ref = ref_count_map[minute];
-
- for (int d = 0; d < DAYS_PER_WEEK; ++d) {
- if ((day_of_week & (0x01 << d)) != 0 && ref.count[d] > 0) {
- ref.count[d] -= 1;
- }
- }
-
- return reset_timer(minute);
-}
-
-bool ctx::device_status_alarm::reset_timer(int minute)
-{
- int day_of_week = merge_day_of_week(ref_count_map[minute].count);
- timer_state_s &timer = timer_state_map[minute];
-
- if (day_of_week == timer.day_of_week) {
- /* Necessary timers are already running... */
- return true;
- }
-
- if (day_of_week == 0 && timer.timer_id > 0) {
- /* Turn off the timer at hour, if it is not necessray anymore. */
- __timerManager.remove(timer.timer_id);
- timer_state_map.erase(minute);
- ref_count_map.erase(minute);
- return true;
- }
-
- if (timer.timer_id > 0) {
- /* Turn off the current timer, to set a new one. */
- __timerManager.remove(timer.timer_id);
- timer.timer_id = -1;
- timer.day_of_week = 0;
- }
-
- /* Create a new timer, w.r.t. the new day_of_week value. */
- int h = minute / 60;
- int m = minute - h * 60;
- int tid = __timerManager.setAt(h, m, static_cast<DayOfWeek>(day_of_week), this);
- IF_FAIL_RETURN_TAG(tid > 0, false, _E, "Timer setting failed");
-
- timer.timer_id = tid;
- timer.day_of_week = day_of_week;
-
- return true;
-}
-
-void ctx::device_status_alarm::clear()
-{
- for (timer_state_map_t::iterator it = timer_state_map.begin(); it != timer_state_map.end(); ++it) {
- if (it->second.timer_id > 0) {
- __timerManager.remove(it->second.timer_id);
- }
- }
-
- timer_state_map.clear();
- ref_count_map.clear();
-}
-
-bool ctx::device_status_alarm::onTimerExpired(int timer_id)
-{
- time_t rawtime;
- struct tm timeinfo;
-
- time(&rawtime);
- tzset();
- localtime_r(&rawtime, &timeinfo);
-
- int hour = timeinfo.tm_hour;
- int min = timeinfo.tm_min;
- int day_of_week = (0x01 << timeinfo.tm_wday);
-
- on_timer_expired(hour, min, day_of_week);
-
- return true;
-}
-
-void ctx::device_status_alarm::on_timer_expired(int hour, int min, int day_of_week)
-{
- _I("Time: %02d:%02d, Day of Week: %#x", hour, min, day_of_week);
-
- ctx::Json dataRead;
- int result_time = hour * 60 + min;
- std::string result_day = ctx::TimerManager::dowToStr(day_of_week);
- dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, result_time);
- dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, result_day);
-
- for (option_t::iterator it = option_set.begin(); it != option_set.end(); ++it) {
- ctx::Json option = (**it);
- if (is_matched(option, result_time, result_day)) {
- context_manager::publish(DEVICE_ST_SUBJ_ALARM, option, ERR_NONE, dataRead);
- }
- }
-}
-
-bool ctx::device_status_alarm::is_matched(ctx::Json& option, int time, std::string day)
-{
- bool ret = false;
- int opt_time;
- for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &opt_time); i++){
- if (time == opt_time) {
- ret = true;
- break;
- }
- }
- IF_FAIL_RETURN(ret, false);
-
- std::string opt_day;
- for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &opt_day); i++){
- if (day == opt_day) {
- return true;
- }
- }
-
- return false;
-}
-
-ctx::device_status_alarm::option_t::iterator ctx::device_status_alarm::find_option(ctx::Json& option)
-{
- for (ctx::device_status_alarm::option_t::iterator it = option_set.begin(); it != option_set.end(); ++it) {
- if (option == (**it))
- return it;
- }
- return option_set.end();
-}
-
-void ctx::device_status_alarm::destroy_if_unused()
-{
- IF_FAIL_VOID(option_set.empty());
- destroy(NULL);
-}
+++ /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_STATUS_ALARM_H_
-#define _DEVICE_STATUS_ALARM_H_
-
-#include <map>
-#include <set>
-#include <ContextProviderBase.h>
-#include <TimerManager.h>
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class device_status_alarm : public ContextProviderBase, ITimerListener {
-
- GENERATE_PROVIDER_COMMON_DECL(device_status_alarm);
-
- public:
- int subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult);
- int unsubscribe(const char *subject, ctx::Json option);
- int read(const char *subject, ctx::Json option, ctx::Json *requestResult);
- int write(const char *subject, ctx::Json data, ctx::Json *requestResult);
-
- int subscribe(ctx::Json option);
- int unsubscribe(ctx::Json option);
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- device_status_alarm();
- ~device_status_alarm();
- void handle_update();
- static void update_cb(void* user_data);
- int get_arranged_day_of_week(ctx::Json& option);
-
- struct ref_count_array_s {
- int count[7]; /* reference counts for days of week*/
- ref_count_array_s();
- };
-
- struct timer_state_s {
- int timer_id;
- int day_of_week; /* day of week, merged into one integer */
- timer_state_s() : timer_id(-1), day_of_week(0) {}
- };
-
- typedef std::map<int, ref_count_array_s> ref_count_map_t;
- typedef std::map<int, timer_state_s> timer_state_map_t;
- typedef std::set<ctx::Json*> option_t;
-
- ref_count_map_t ref_count_map;
- timer_state_map_t timer_state_map;
- option_t option_set;
- TimerManager __timerManager;
-
- bool add(int minute, int day_of_week);
- bool remove(int minute, int day_of_week);
- void clear();
- bool empty();
-
- int merge_day_of_week(int *ref_cnt);
- bool reset_timer(int hour);
- void on_timer_expired(int hour, int min, int day_of_week);
- bool onTimerExpired(int timer_id);
-
- bool is_matched(ctx::Json& option, int time, std::string day);
- option_t::iterator find_option(ctx::Json& option);
-
- void destroy_if_unused();
-
- };
-}
-
-#endif // _DEVICE_STATUS_ALARM_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 <ContextManager.h>
-#include "system_types.h"
-#include "battery.h"
-
-GENERATE_PROVIDER_COMMON_IMPL(device_status_battery);
-
-ctx::device_status_battery::device_status_battery()
-{
-}
-
-ctx::device_status_battery::~device_status_battery()
-{
-}
-
-bool ctx::device_status_battery::is_supported()
-{
- return true;
-}
-
-void ctx::device_status_battery::submit_trigger_item()
-{
- context_manager::registerTriggerItem(DEVICE_ST_SUBJ_BATTERY, OPS_SUBSCRIBE | OPS_READ,
- "{"
- "\"Level\":{\"type\":\"string\",\"values\":[\"Empty\",\"Critical\",\"Low\",\"Normal\",\"High\",\"Full\"]},"
- TRIG_BOOL_ITEM_DEF("IsCharging")
- "}",
- NULL);
-}
-
-void ctx::device_status_battery::update_cb(device_callback_e device_type, void* value, void* user_data)
-{
- IF_FAIL_VOID(device_type == DEVICE_CALLBACK_BATTERY_LEVEL);
-
- device_status_battery *instance = static_cast<device_status_battery*>(user_data);
- instance->handle_update(device_type, value);
-}
-
-void ctx::device_status_battery::handle_update(device_callback_e device_type, void* value)
-{
- intptr_t level = (intptr_t)value;
-
- const char* level_string = trans_to_string(level);
- IF_FAIL_VOID(level_string);
-
- ctx::Json dataRead;
- dataRead.set(NULL, DEVICE_ST_LEVEL, level_string);
-
- bool charging_state = false;
- int ret = device_battery_is_charging(&charging_state);
- IF_FAIL_VOID_TAG(ret == DEVICE_ERROR_NONE, _E, "Getting state failed");
-
- dataRead.set(NULL, DEVICE_ST_IS_CHARGING, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
- ctx::context_manager::publish(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, dataRead);
-}
-
-const char* ctx::device_status_battery::trans_to_string(intptr_t level)
-{
- switch (level) {
- case DEVICE_BATTERY_LEVEL_EMPTY:
- return DEVICE_ST_EMPTY;
-
- case DEVICE_BATTERY_LEVEL_CRITICAL:
- return DEVICE_ST_CRITICAL;
-
- case DEVICE_BATTERY_LEVEL_LOW:
- return DEVICE_ST_LOW;
-
- case DEVICE_BATTERY_LEVEL_HIGH:
- return DEVICE_ST_NORMAL;
-
- case DEVICE_BATTERY_LEVEL_FULL:
- {
- int percent;
- device_battery_get_percent(&percent);
-
- if (percent == 100) {
- return DEVICE_ST_FULL;
- } else {
- return DEVICE_ST_HIGH;
- }
- }
- break;
-
- default:
- _E("Invalid battery level");
- return NULL;
- }
-}
-
-int ctx::device_status_battery::subscribe()
-{
- int ret = device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, update_cb, this);
- IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
- return ERR_NONE;
-}
-
-int ctx::device_status_battery::unsubscribe()
-{
- int ret = device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, update_cb);
- IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
- return ERR_NONE;
-}
-
-int ctx::device_status_battery::read()
-{
- device_battery_level_e level;
- ctx::Json dataRead;
-
- int ret = device_battery_get_level_status(&level);
- IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
-
- const char* level_string = trans_to_string(level);
- IF_FAIL_RETURN(level_string, ERR_OPERATION_FAILED);
-
- dataRead.set(NULL, DEVICE_ST_LEVEL, level_string);
-
- bool charging_state = false;
- ret = device_battery_is_charging(&charging_state);
- IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
-
- dataRead.set(NULL, DEVICE_ST_IS_CHARGING, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
-
- ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, dataRead);
- 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_STATUS_BATTERY_LEVEL_H_
-#define _DEVICE_STATUS_BATTERY_LEVEL_H_
-
-#include <device/callback.h>
-#include <device/battery.h>
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class device_status_battery : public device_provider_base {
-
- GENERATE_PROVIDER_COMMON_DECL(device_status_battery);
-
- public:
- int subscribe();
- int unsubscribe();
- int read();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- device_status_battery();
- ~device_status_battery();
- const char* trans_to_string(intptr_t level);
- void handle_update(device_callback_e device_type, void* value);
- static void update_cb(device_callback_e device_type, void* value, void* user_data);
- };
-}
-
-#endif // _DEVICE_STATUS_BATTERY_LEVEL_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 <ContextManager.h>
-#include "system_types.h"
-#include "headphone.h"
-
-#define HANDLING_DELAY 2000
-#define MAX_HANDLING_COUNT 3
-
-GENERATE_PROVIDER_COMMON_IMPL(device_status_headphone);
-
-ctx::device_status_headphone::device_status_headphone()
- : connected(false)
- , audio_jack_state(RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED)
- , bt_audio_state(false)
- , bt_audio_callback_on(false)
- , bt_event_handler_added(false)
- , bt_event_handling_count(0)
-{
-}
-
-ctx::device_status_headphone::~device_status_headphone()
-{
-}
-
-bool ctx::device_status_headphone::is_supported()
-{
- return true;
-}
-
-void ctx::device_status_headphone::submit_trigger_item()
-{
- context_manager::registerTriggerItem(DEVICE_ST_SUBJ_HEADPHONE, OPS_SUBSCRIBE | OPS_READ,
- "{"
- TRIG_BOOL_ITEM_DEF("IsConnected") ","
- "\"Type\":{\"type\":\"string\",\"values\":[\"Normal\",\"Headset\",\"Bluetooth\"]}"
- "}",
- NULL);
-}
-
-int ctx::device_status_headphone::subscribe()
-{
- connected = get_current_status();
-
- // Wired headphone
- int ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, on_audio_jack_state_changed, this);
- IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
-
- // Bluetooth headphone
- set_bt_audio_callback();
-
- return ERR_NONE;
-}
-
-int ctx::device_status_headphone::unsubscribe()
-{
- runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS);
- unset_bt_audio_callback();
-
- return ERR_NONE;
-}
-
-int ctx::device_status_headphone::read()
-{
- if (!being_subscribed)
- connected = get_current_status();
-
- Json data;
- generate_data_packet(data);
- ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data);
-
- return ERR_NONE;
-}
-
-void ctx::device_status_headphone::set_bt_audio_callback()
-{
- IF_FAIL_VOID(!bt_audio_callback_on);
- int ret;
-
- ret = bt_initialize();
- if (ret != BT_ERROR_NONE) {
- _W("Bluetooth initialization failed");
- return;
- }
-
- ret = bt_device_set_connection_state_changed_cb(on_bt_connection_changed, this);
- if (ret != BT_ERROR_NONE) {
- bt_deinitialize();
- return;
- }
-
- bt_audio_callback_on = true;
-}
-
-void ctx::device_status_headphone::unset_bt_audio_callback()
-{
- IF_FAIL_VOID(bt_audio_callback_on);
-
- bt_device_unset_connection_state_changed_cb();
- bt_deinitialize();
-
- bt_audio_callback_on = false;
-}
-
-void ctx::device_status_headphone::set_bt_audio_state(bool state)
-{
- bt_audio_state = state;
-}
-
-bool ctx::device_status_headphone::get_current_status()
-{
- int ret;
-
- // Wired audio
- ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, &audio_jack_state);
- IF_FAIL_RETURN(ret == ERR_NONE, connected);
-
- // Bluetooth audio
- bt_audio_state = false;
- ret = bt_initialize();
- if (ret == BT_ERROR_NONE) {
- bt_adapter_foreach_bonded_device(on_bt_bond, this);
- bt_deinitialize();
- }
-
- return ((audio_jack_state != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || bt_audio_state);
-}
-
-void ctx::device_status_headphone::generate_data_packet(ctx::Json &data)
-{
- data.set(NULL, DEVICE_ST_IS_CONNECTED, connected ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
-
- switch (audio_jack_state) {
- case RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_3WIRE:
- data.set(NULL, DEVICE_ST_TYPE, DEVICE_ST_NORMAL);
- break;
- case RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_4WIRE:
- data.set(NULL, DEVICE_ST_TYPE, DEVICE_ST_HEADSET);
- break;
- default:
- if (bt_audio_state)
- data.set(NULL, DEVICE_ST_TYPE, DEVICE_ST_BLUETOOTH);
- break;
- }
-}
-
-bool ctx::device_status_headphone::handle_event()
-{
- bool prev_state = connected;
- connected = ((audio_jack_state != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || bt_audio_state);
-
- IF_FAIL_RETURN(prev_state != connected, false);
-
- ctx::Json data;
- generate_data_packet(data);
- ctx::context_manager::publish(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data);
- return true;
-}
-
-void ctx::device_status_headphone::handle_audio_jack_event()
-{
- int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, &audio_jack_state);
- IF_FAIL_VOID_TAG(ret == ERR_NONE, _E, "Getting runtime info failed");
- handle_event();
-}
-
-void ctx::device_status_headphone::on_audio_jack_state_changed(runtime_info_key_e runtime_key, void* user_data)
-{
- _D("EarJack");
- ctx::device_status_headphone *instance = static_cast<ctx::device_status_headphone*>(user_data);
- instance->handle_audio_jack_event();
-}
-
-void ctx::device_status_headphone::on_bt_connection_changed(bool connected, bt_device_connection_info_s *conn_info, void *user_data)
-{
- ctx::device_status_headphone *instance = static_cast<ctx::device_status_headphone*>(user_data);
- IF_FAIL_VOID(connected != instance->bt_audio_state);
- IF_FAIL_VOID(!instance->bt_event_handler_added);
-
- if (connected) {
- _D("BT state checking scheduled");
- instance->bt_event_handler_added = true;
- instance->bt_event_handling_count = 0;
- g_timeout_add(HANDLING_DELAY, handle_bt_event, user_data);
- } else {
- handle_bt_event(user_data);
- }
-}
-
-gboolean ctx::device_status_headphone::handle_bt_event(gpointer data)
-{
- _D("BT state checking started");
- ctx::device_status_headphone *instance = static_cast<ctx::device_status_headphone*>(data);
- instance->bt_event_handler_added = false;
-
- instance->set_bt_audio_state(false);
- int err = bt_adapter_foreach_bonded_device(on_bt_bond, data);
- IF_FAIL_RETURN_TAG(err == BT_ERROR_NONE, FALSE, _E, "bt_adapter_foreach_bonded_device() failed");
-
- instance->bt_event_handling_count++;
-
- if (instance->handle_event() || instance->bt_event_handling_count >= MAX_HANDLING_COUNT)
- return FALSE;
-
- return TRUE;
-}
-
-bool ctx::device_status_headphone::on_bt_bond(bt_device_info_s *device_info, void* user_data)
-{
- if (device_info->bt_class.major_device_class != BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO)
- return true;
-
- bool st = false;
- int err = bt_device_is_profile_connected(device_info->remote_address, BT_PROFILE_A2DP, &st);
- IF_FAIL_RETURN_TAG(err == BT_ERROR_NONE, false, _E, "bt_device_is_profile_connected() failed");
-
- if (st) {
- ctx::device_status_headphone *instance = static_cast<ctx::device_status_headphone*>(user_data);
- instance->set_bt_audio_state(true);
- return false;
- }
-
- return true;
-}
+++ /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_STATUS_HEADPHONE_H_
-#define _DEVICE_STATUS_HEADPNOHE_H_
-
-#include <glib.h>
-#include <runtime_info.h>
-#include <bluetooth.h>
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class device_status_headphone : public device_provider_base {
-
- GENERATE_PROVIDER_COMMON_DECL(device_status_headphone);
-
- public:
- int subscribe();
- int unsubscribe();
- int read();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- bool connected;
- int audio_jack_state;
- bool bt_audio_state;
- bool bt_audio_callback_on;
- bool bt_event_handler_added;
- int bt_event_handling_count;
-
- device_status_headphone();
- ~device_status_headphone();
-
- bool get_current_status();
- void set_bt_audio_callback();
- void unset_bt_audio_callback();
- void set_bt_audio_state(bool state);
-
- void generate_data_packet(Json &data);
- bool handle_event();
- void handle_audio_jack_event();
-
- static gboolean handle_bt_event(gpointer data);
- static void on_audio_jack_state_changed(runtime_info_key_e runtime_key, void* user_data);
- static void on_bt_connection_changed(bool connected, bt_device_connection_info_s *conn_info, void *user_data);
- static bool on_bt_bond(bt_device_info_s *device_info, void* user_data);
- };
-}
-
-#endif // _DEVICE_STATUS_HEADPHONE_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 <ContextManager.h>
-#include "system_types.h"
-#include "psmode.h"
-
-GENERATE_PROVIDER_COMMON_IMPL(device_status_psmode);
-
-ctx::device_status_psmode::device_status_psmode()
-{
-}
-
-ctx::device_status_psmode::~device_status_psmode()
-{
-}
-
-bool ctx::device_status_psmode::is_supported()
-{
- return true;
-}
-
-void ctx::device_status_psmode::submit_trigger_item()
-{
- context_manager::registerTriggerItem(DEVICE_ST_SUBJ_PSMODE, OPS_SUBSCRIBE | OPS_READ,
- "{" TRIG_BOOL_ITEM_DEF("IsEnabled") "}", NULL);
-}
-
-void ctx::device_status_psmode::update_cb(keynode_t *node, void* user_data)
-{
- device_status_psmode *instance = static_cast<device_status_psmode*>(user_data);
- instance->handle_update(node);
-}
-
-void ctx::device_status_psmode::handle_update(keynode_t *node)
-{
- int status;
- ctx::Json dataRead;
-
- status = vconf_keynode_get_int(node);
- IF_FAIL_VOID_TAG(status >= 0, _E, "Getting state failed");
-
- dataRead.set(NULL, DEVICE_ST_IS_ENABLED, status == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE);
-
- context_manager::publish(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, dataRead);
-}
-
-int ctx::device_status_psmode::subscribe()
-{
- int ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, update_cb, this);
- IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED);
- return ERR_NONE;
-}
-
-int ctx::device_status_psmode::unsubscribe()
-{
- int ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, update_cb);
- IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED);
- return ERR_NONE;
-}
-
-int ctx::device_status_psmode::read()
-{
- int mode;
- int ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &mode);
- IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED);
-
- ctx::Json dataRead;
- dataRead.set(NULL, DEVICE_ST_IS_ENABLED, mode == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE);
-
- ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, dataRead);
- 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_STATUS_POWER_SAVING_MODE_H_
-#define _DEVICE_STATUS_POWER_SAVING_MODE_H_
-
-#include <vconf.h>
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class device_status_psmode : public device_provider_base {
-
- GENERATE_PROVIDER_COMMON_DECL(device_status_psmode);
-
- public:
- int subscribe();
- int unsubscribe();
- int read();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- device_status_psmode();
- ~device_status_psmode();
- void handle_update(keynode_t *node);
- static void update_cb(keynode_t *node, void* user_data);
- };
-}
-
-#endif // _DEVICE_STATUS_POWER_SAVING_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 "base_rtinfo.h"
-
-ctx::device_status_runtime_info::device_status_runtime_info(runtime_info_key_e key)
- : info_key(key)
-{
-}
-
-runtime_info_key_e ctx::device_status_runtime_info::get_info_key()
-{
- return info_key;
-}
-
-void ctx::device_status_runtime_info::update_cb(runtime_info_key_e key, void* user_data)
-{
- device_status_runtime_info *instance = static_cast<device_status_runtime_info*>(user_data);
- IF_FAIL_VOID_TAG(key == instance->get_info_key(), _W, "Runtime info key mismatch");
- instance->handle_update();
-}
-
-int ctx::device_status_runtime_info::subscribe()
-{
- int ret = runtime_info_set_changed_cb(info_key, update_cb, this);
- IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
- return ERR_NONE;
-}
-
-int ctx::device_status_runtime_info::unsubscribe()
-{
- int ret = runtime_info_unset_changed_cb(info_key);
- IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
- 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 __CONTEXT_DEVICE_STATUS_RUNTIME_INFO_H__
-#define __CONTEXT_DEVICE_STATUS_RUNTIME_INFO_H__
-
-#include <runtime_info.h>
-#include "../../device_provider_base.h"
-
-namespace ctx {
-
- class device_status_runtime_info : public device_provider_base {
- public:
- device_status_runtime_info(runtime_info_key_e key);
-
- int subscribe();
- int unsubscribe();
- virtual int read() = 0;
-
- protected:
- runtime_info_key_e info_key;
-
- virtual ~device_status_runtime_info(){}
- static void update_cb(runtime_info_key_e runtime_key, void* user_data);
- virtual void handle_update() = 0;
-
- private:
- runtime_info_key_e get_info_key();
- };
-}
-
-#endif
+++ /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 <ContextManager.h>
-#include "../system_types.h"
-#include "charger.h"
-
-GENERATE_PROVIDER_COMMON_IMPL(device_status_charger);
-
-ctx::device_status_charger::device_status_charger()
- : device_status_runtime_info(RUNTIME_INFO_KEY_CHARGER_CONNECTED)
-{
-}
-
-ctx::device_status_charger::~device_status_charger()
-{
-}
-
-bool ctx::device_status_charger::is_supported()
-{
- return true;
-}
-
-void ctx::device_status_charger::submit_trigger_item()
-{
- context_manager::registerTriggerItem(DEVICE_ST_SUBJ_CHARGER, OPS_SUBSCRIBE | OPS_READ,
- "{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL);
-}
-
-void ctx::device_status_charger::handle_update()
-{
- bool charger_status = false;
-
- int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &charger_status);
- IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed");
-
- ctx::Json dataRead;
- dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
-
- context_manager::publish(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, dataRead);
-}
-
-int ctx::device_status_charger::read()
-{
- bool charger_status = false;
- ctx::Json dataRead;
-
- int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &charger_status);
- IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed");
-
- dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
-
- ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, dataRead);
- 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_STATUS_CHARGER_H_
-#define _DEVICE_STATUS_CHARGER_H_
-
-#include "base_rtinfo.h"
-
-namespace ctx {
-
- class device_status_charger : public device_status_runtime_info {
-
- GENERATE_PROVIDER_COMMON_DECL(device_status_charger);
-
- public:
- int read();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- device_status_charger();
- ~device_status_charger();
- void handle_update();
- };
-}
-
-#endif // _DEVICE_STATUS_CHARGER_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 <ContextManager.h>
-#include "../system_types.h"
-#include "gps.h"
-
-GENERATE_PROVIDER_COMMON_IMPL(device_status_gps);
-
-static const char* get_state_string(int gps_state)
-{
- switch (gps_state) {
- case RUNTIME_INFO_GPS_STATUS_DISABLED:
- return DEVICE_ST_DISABLED;
-
- case RUNTIME_INFO_GPS_STATUS_SEARCHING:
- return DEVICE_ST_SEARCHING;
-
- case RUNTIME_INFO_GPS_STATUS_CONNECTED:
- return DEVICE_ST_CONNECTED;
-
- default:
- _E("Unknown GPS status: %d", gps_state);
- return NULL;
- }
-}
-
-ctx::device_status_gps::device_status_gps()
- : device_status_runtime_info(RUNTIME_INFO_KEY_GPS_STATUS)
-{
-}
-
-ctx::device_status_gps::~device_status_gps()
-{
-}
-
-bool ctx::device_status_gps::is_supported()
-{
- return get_system_info_bool("tizen.org/feature/location.gps");
-}
-
-void ctx::device_status_gps::submit_trigger_item()
-{
- context_manager::registerTriggerItem(DEVICE_ST_SUBJ_GPS, OPS_SUBSCRIBE | OPS_READ,
- "{"
- "\"State\":{\"type\":\"string\",\"values\":[\"Disabled\",\"Searching\",\"Connected\"]}"
- "}",
- NULL);
-}
-
-void ctx::device_status_gps::handle_update()
-{
- int gps_status;
- int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gps_status);
- IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed");
-
- ctx::Json dataRead;
-
- const char* state_str = get_state_string(gps_status);
- IF_FAIL_VOID(state_str);
-
- dataRead.set(NULL, DEVICE_ST_STATE, state_str);
-
- context_manager::publish(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead);
-}
-
-int ctx::device_status_gps::read()
-{
- int gps_status;
- ctx::Json dataRead;
-
- int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gps_status);
- IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed");
-
- const char* state_str = get_state_string(gps_status);
- IF_FAIL_RETURN(state_str, ERR_OPERATION_FAILED);
-
- dataRead.set(NULL, DEVICE_ST_STATE, state_str);
-
- ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead);
- 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_STATUS_GPS_H_
-#define _DEVICE_STATUS_GPS_H_
-
-#include "base_rtinfo.h"
-
-namespace ctx {
-
- class device_status_gps : public device_status_runtime_info {
-
- GENERATE_PROVIDER_COMMON_DECL(device_status_gps);
-
- public:
- int read();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- device_status_gps();
- ~device_status_gps();
- void handle_update();
- };
-}
-
-#endif // _DEVICE_STATUS_GPS_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 <ContextManager.h>
-#include "../system_types.h"
-#include "usb.h"
-
-GENERATE_PROVIDER_COMMON_IMPL(device_status_usb);
-
-ctx::device_status_usb::device_status_usb()
- : device_status_runtime_info(RUNTIME_INFO_KEY_USB_CONNECTED)
-{
-}
-
-ctx::device_status_usb::~device_status_usb()
-{
-}
-
-bool ctx::device_status_usb::is_supported()
-{
- return get_system_info_bool("tizen.org/feature/usb.host");
-}
-
-void ctx::device_status_usb::submit_trigger_item()
-{
- context_manager::registerTriggerItem(DEVICE_ST_SUBJ_USB, OPS_SUBSCRIBE | OPS_READ,
- "{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL);
-}
-
-void ctx::device_status_usb::handle_update()
-{
- bool status = false;
-
- int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_USB_CONNECTED, &status);
- IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed");
-
- ctx::Json dataRead;
- dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
-
- context_manager::publish(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, dataRead);
-}
-
-int ctx::device_status_usb::read()
-{
- bool status = false;
- ctx::Json dataRead;
-
- int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_USB_CONNECTED, &status);
- IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed");
-
- dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
-
- ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, dataRead);
- 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_STATUS_USB_H_
-#define _DEVICE_STATUS_USB_H_
-
-#include "base_rtinfo.h"
-
-namespace ctx {
-
- class device_status_usb : public device_status_runtime_info {
-
- GENERATE_PROVIDER_COMMON_DECL(device_status_usb);
-
- public:
- int read();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- device_status_usb();
- ~device_status_usb();
- void handle_update();
- };
-}
-
-#endif // _DEVICE_STATUS_USB_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 <ContextManager.h>
+#include "../SystemTypes.h"
+#include "Charger.h"
+
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusCharger);
+
+ctx::DeviceStatusCharger::DeviceStatusCharger() :
+ DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_CHARGER_CONNECTED)
+{
+}
+
+ctx::DeviceStatusCharger::~DeviceStatusCharger()
+{
+}
+
+bool ctx::DeviceStatusCharger::isSupported()
+{
+ return true;
+}
+
+void ctx::DeviceStatusCharger::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(DEVICE_ST_SUBJ_CHARGER, OPS_SUBSCRIBE | OPS_READ,
+ "{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL);
+}
+
+void ctx::DeviceStatusCharger::handleUpdate()
+{
+ bool chargerStatus = false;
+
+ int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &chargerStatus);
+ IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed");
+
+ ctx::Json dataRead;
+ dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, chargerStatus ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+
+ context_manager::publish(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, dataRead);
+}
+
+int ctx::DeviceStatusCharger::read()
+{
+ bool chargerStatus = false;
+ ctx::Json dataRead;
+
+ int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &chargerStatus);
+ IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed");
+
+ dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, chargerStatus ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+
+ ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, dataRead);
+ 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_SYSTEM_STATUS_CHARGER_
+#define _DEVICE_SYSTEM_STATUS_CHARGER_
+
+#include "RuntimeInfoBase.h"
+
+namespace ctx {
+
+ class DeviceStatusCharger : public DeviceStatusRuntimeInfo {
+
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusCharger);
+
+ public:
+ int read();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ protected:
+ void handleUpdate();
+
+ private:
+ DeviceStatusCharger();
+ ~DeviceStatusCharger();
+ };
+}
+
+#endif // _DEVICE_SYSTEM_STATUS_CHARGER_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 <ContextManager.h>
+#include "../SystemTypes.h"
+#include "Gps.h"
+
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusGps);
+
+static const char* __getStatusString(int gpsStatus)
+{
+ switch (gpsStatus) {
+ case RUNTIME_INFO_GPS_STATUS_DISABLED:
+ return DEVICE_ST_DISABLED;
+
+ case RUNTIME_INFO_GPS_STATUS_SEARCHING:
+ return DEVICE_ST_SEARCHING;
+
+ case RUNTIME_INFO_GPS_STATUS_CONNECTED:
+ return DEVICE_ST_CONNECTED;
+
+ default:
+ _E("Unknown GPS status: %d", gpsStatus);
+ return NULL;
+ }
+}
+
+ctx::DeviceStatusGps::DeviceStatusGps() :
+ DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_GPS_STATUS)
+{
+}
+
+ctx::DeviceStatusGps::~DeviceStatusGps()
+{
+}
+
+bool ctx::DeviceStatusGps::isSupported()
+{
+ return getSystemInfoBool("tizen.org/feature/location.gps");
+}
+
+void ctx::DeviceStatusGps::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(DEVICE_ST_SUBJ_GPS, OPS_SUBSCRIBE | OPS_READ,
+ "{"
+ "\"State\":{\"type\":\"string\",\"values\":[\"Disabled\",\"Searching\",\"Connected\"]}"
+ "}",
+ NULL);
+}
+
+void ctx::DeviceStatusGps::handleUpdate()
+{
+ int gpsStatus;
+ int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gpsStatus);
+ IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed");
+
+ ctx::Json dataRead;
+
+ const char* stateStr = __getStatusString(gpsStatus);
+ IF_FAIL_VOID(stateStr);
+
+ dataRead.set(NULL, DEVICE_ST_STATE, stateStr);
+
+ context_manager::publish(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead);
+}
+
+int ctx::DeviceStatusGps::read()
+{
+ int gpsStatus;
+ ctx::Json dataRead;
+
+ int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gpsStatus);
+ IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed");
+
+ const char* stateStr = __getStatusString(gpsStatus);
+ IF_FAIL_RETURN(stateStr, ERR_OPERATION_FAILED);
+
+ dataRead.set(NULL, DEVICE_ST_STATE, stateStr);
+
+ ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead);
+ 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_SYSTEM_STATUS_GPS_H_
+#define _DEVICE_SYSTEM_STATUS_GPS_H_
+
+#include "RuntimeInfoBase.h"
+
+namespace ctx {
+
+ class DeviceStatusGps : public DeviceStatusRuntimeInfo {
+
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusGps);
+
+ public:
+ int read();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ protected:
+ void handleUpdate();
+
+ private:
+ DeviceStatusGps();
+ ~DeviceStatusGps();
+ };
+}
+
+#endif // _DEVICE_SYSTEM_STATUS_GPS_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 "RuntimeInfoBase.h"
+
+ctx::DeviceStatusRuntimeInfo::DeviceStatusRuntimeInfo(runtime_info_key_e key) :
+ __infoKey(key)
+{
+}
+
+runtime_info_key_e ctx::DeviceStatusRuntimeInfo::__getInfoKey()
+{
+ return __infoKey;
+}
+
+void ctx::DeviceStatusRuntimeInfo::updateCb(runtime_info_key_e runtimeKey, void* userData)
+{
+ DeviceStatusRuntimeInfo *instance = static_cast<DeviceStatusRuntimeInfo*>(userData);
+ IF_FAIL_VOID_TAG(runtimeKey == instance->__getInfoKey(), _W, "Runtime info key mismatch");
+ instance->handleUpdate();
+}
+
+int ctx::DeviceStatusRuntimeInfo::subscribe()
+{
+ int ret = runtime_info_set_changed_cb(__infoKey, updateCb, this);
+ IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
+ return ERR_NONE;
+}
+
+int ctx::DeviceStatusRuntimeInfo::unsubscribe()
+{
+ int ret = runtime_info_unset_changed_cb(__infoKey);
+ IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
+ 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_SYSTEM_STATUS_RUNTIME_INFO_BASE_H_
+#define _DEVICE_SYSTEM_STATUS_RUNTIME_INFO_BASE_H_
+
+#include <runtime_info.h>
+#include "../../DeviceProviderBase.h"
+
+namespace ctx {
+
+ class DeviceStatusRuntimeInfo : public DeviceProviderBase {
+ public:
+ DeviceStatusRuntimeInfo(runtime_info_key_e key);
+
+ int subscribe();
+ int unsubscribe();
+ virtual int read() = 0;
+
+ protected:
+ runtime_info_key_e __infoKey;
+
+ virtual ~DeviceStatusRuntimeInfo(){}
+ static void updateCb(runtime_info_key_e runtimeKey, void* userData);
+ virtual void handleUpdate() = 0;
+
+ private:
+ runtime_info_key_e __getInfoKey();
+ };
+}
+
+#endif // _DEVICE_SYSTEM_STATUS_RUNTIME_INFO_BASE_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 <ContextManager.h>
+#include "../SystemTypes.h"
+#include "Usb.h"
+
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusUsb);
+
+ctx::DeviceStatusUsb::DeviceStatusUsb() :
+ DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_USB_CONNECTED)
+{
+}
+
+ctx::DeviceStatusUsb::~DeviceStatusUsb()
+{
+}
+
+bool ctx::DeviceStatusUsb::isSupported()
+{
+ return getSystemInfoBool("tizen.org/feature/usb.host");
+}
+
+void ctx::DeviceStatusUsb::submitTriggerItem()
+{
+ context_manager::registerTriggerItem(DEVICE_ST_SUBJ_USB, OPS_SUBSCRIBE | OPS_READ,
+ "{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL);
+}
+
+void ctx::DeviceStatusUsb::handleUpdate()
+{
+ bool status = false;
+
+ int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_USB_CONNECTED, &status);
+ IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed");
+
+ ctx::Json dataRead;
+ dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+
+ context_manager::publish(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, dataRead);
+}
+
+int ctx::DeviceStatusUsb::read()
+{
+ bool status = false;
+ ctx::Json dataRead;
+
+ int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_USB_CONNECTED, &status);
+ IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed");
+
+ dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+
+ ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, dataRead);
+ 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_SYSTEM_STATUS_USB_H_
+#define _DEVICE_SYSTEM_STATUS_USB_H_
+
+#include "RuntimeInfoBase.h"
+
+namespace ctx {
+
+ class DeviceStatusUsb : public DeviceStatusRuntimeInfo {
+
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusUsb);
+
+ public:
+ int read();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ protected:
+ void handleUpdate();
+
+ private:
+ DeviceStatusUsb();
+ ~DeviceStatusUsb();
+ };
+}
+
+#endif // _DEVICE_SYSTEM_STATUS_USB_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.
- */
-
-#ifndef __CONTEXT_DEVICESTATUS_TYPES_H__
-#define __CONTEXT_DEVICESTATUS_TYPES_H__
-
-// Subject
-#define DEVICE_ST_SUBJ_BATTERY "system/battery"
-#define DEVICE_ST_SUBJ_CHARGER "system/charger"
-#define DEVICE_ST_SUBJ_HEADPHONE "system/headphone"
-#define DEVICE_ST_SUBJ_WIFI "system/wifi"
-#define DEVICE_ST_SUBJ_USB "system/usb"
-#define DEVICE_ST_SUBJ_GPS "system/gps"
-#define DEVICE_ST_SUBJ_PSMODE "system/psmode"
-#define DEVICE_ST_SUBJ_ALARM "device/alarm"
-#define DEVICE_ST_SUBJ_TIME "device/time"
-
-// Data Key
-#define DEVICE_ST_EVENT "Event"
-#define DEVICE_ST_STATE "State"
-#define DEVICE_ST_TYPE "Type"
-#define DEVICE_ST_LEVEL "Level"
-#define DEVICE_ST_BSSID "BSSID"
-#define DEVICE_ST_IS_CONNECTED "IsConnected"
-#define DEVICE_ST_IS_ENABLED "IsEnabled"
-#define DEVICE_ST_IS_CHARGING "IsCharging"
-#define DEVICE_ST_DETECTED "Detected"
-#define DEVICE_ST_TIME_OF_DAY "TimeOfDay"
-#define DEVICE_ST_DAY_OF_WEEK "DayOfWeek"
-#define DEVICE_ST_DAY_OF_MONTH "DayOfMonth"
-
-// Data Value
-#define DEVICE_ST_TRUE 1
-#define DEVICE_ST_FALSE 0
-#define DEVICE_ST_ENTER "Enter"
-#define DEVICE_ST_EXIT "Exit"
-#define DEVICE_ST_DISABLED "Disabled"
-#define DEVICE_ST_CONNECTED "Connected"
-#define DEVICE_ST_UNCONNECTED "Unconnected"
-#define DEVICE_ST_SEARCHING "Searching"
-#define DEVICE_ST_EMPTY "Empty"
-#define DEVICE_ST_CRITICAL "Critical"
-#define DEVICE_ST_LOW "Low"
-#define DEVICE_ST_NORMAL "Normal"
-#define DEVICE_ST_HIGH "High"
-#define DEVICE_ST_FULL "Full"
-#define DEVICE_ST_HEADSET "Headset"
-#define DEVICE_ST_BLUETOOTH "Bluetooth"
-
-#define TRIG_BOOL_ITEM_DEF(sbj) "\"" sbj "\":{\"type\":\"integer\",\"min\":0,\"max\":1}"
-
-#endif //__CONTEXT_DEVICESTATUS_TYPES_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 <ContextManager.h>
-#include <TimerManager.h>
-#include "system_types.h"
-#include "time.h"
-
-GENERATE_PROVIDER_COMMON_IMPL(device_status_time);
-
-ctx::device_status_time::device_status_time()
-{
-}
-
-ctx::device_status_time::~device_status_time()
-{
-}
-
-bool ctx::device_status_time::is_supported()
-{
- return true;
-}
-
-void ctx::device_status_time::submit_trigger_item()
-{
- context_manager::registerTriggerItem(DEVICE_ST_SUBJ_TIME, OPS_READ,
- "{"
- "\"TimeOfDay\":{\"type\":\"integer\",\"min\":0,\"max\":1439},"
- "\"DayOfWeek\":{\"type\":\"string\",\"values\":[\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\",\"Weekday\",\"Weekend\"]},"
- "\"DayOfMonth\":{\"type\":\"integer\",\"min\":1,\"max\":31}"
- "}",
- NULL);
-}
-
-int ctx::device_status_time::subscribe()
-{
- return ERR_NOT_SUPPORTED;
-}
-
-int ctx::device_status_time::unsubscribe()
-{
- return ERR_NOT_SUPPORTED;
-}
-
-int ctx::device_status_time::read()
-{
- time_t rawtime;
- struct tm timeinfo;
-
- time(&rawtime);
- tzset();
- localtime_r(&rawtime, &timeinfo);
-
- int day_of_month = timeinfo.tm_mday;
- int minute_of_day = timeinfo.tm_hour * 60 + timeinfo.tm_min;
- std::string day_of_week = ctx::TimerManager::dowToStr(0x01 << timeinfo.tm_wday);
-
- ctx::Json dataRead;
- dataRead.set(NULL, DEVICE_ST_DAY_OF_MONTH, day_of_month);
- dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, day_of_week);
- dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, minute_of_day);
-
- _I("Time: %02d:%02d, Day of Week: %s, Day of Month: %d", timeinfo.tm_hour, timeinfo.tm_min, day_of_week.c_str(), day_of_month);
-
- ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_TIME, NULL, ERR_NONE, dataRead);
-
- 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_STATUS_TIME_H_
-#define _DEVICE_STATUS_TIME_H_
-
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class device_status_time : public device_provider_base {
-
- GENERATE_PROVIDER_COMMON_DECL(device_status_time);
-
- public:
- int subscribe();
- int unsubscribe();
- int read();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- device_status_time();
- ~device_status_time();
- };
-}
-
-#endif // _DEVICE_STATUS_TIME_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 <SharedVars.h>
-#include <ContextManager.h>
-#include "system_types.h"
-#include "wifi.h"
-
-ctx::device_status_wifi *ctx::device_status_wifi::__instance = NULL;
-
-ctx::device_status_wifi::device_status_wifi()
- : last_state(_UNKNOWN)
- , is_initialized(false)
- , is_activated(false)
- , conn_state(WIFI_CONNECTION_STATE_FAILURE)
-{
- IF_FAIL_VOID_TAG(start_monitor(), _W, "WiFi monitor initialization failed");
-
- if (!get_current_state()) {
- stop_monitor();
- _W("Getting current WiFi status failed");
- }
-}
-
-ctx::device_status_wifi::~device_status_wifi()
-{
-}
-
-ctx::ContextProviderBase *ctx::device_status_wifi::create(void *data)
-{
- CREATE_INSTANCE(device_status_wifi);
-}
-
-void ctx::device_status_wifi::destroy(void *data)
-{
- __instance->stop_monitor();
- DESTROY_INSTANCE();
-}
-
-void ctx::device_status_wifi::destroy_self()
-{
- /* WiFi status will be monitored continuously, even if no client is subscribing it */
-}
-
-bool ctx::device_status_wifi::is_supported()
-{
- return get_system_info_bool("tizen.org/feature/network.wifi");
-}
-
-void ctx::device_status_wifi::submit_trigger_item()
-{
- context_manager::registerTriggerItem(DEVICE_ST_SUBJ_WIFI, OPS_SUBSCRIBE | OPS_READ,
- "{"
- "\"State\":{\"type\":\"string\",\"values\":[\"Disabled\",\"Unconnected\",\"Connected\"]},"
- "\"BSSID\":{\"type\":\"string\"}"
- "}",
- NULL);
-}
-
-bool ctx::device_status_wifi::get_current_state()
-{
- int err;
-
- if (!is_initialized) {
- err = wifi_initialize();
- IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_initialize() failed");
- }
-
- err = wifi_is_activated(&is_activated);
- IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_is_activated() failed");
-
- err = wifi_get_connection_state(&conn_state);
- IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_get_connection_state() failed");
-
- if (is_activated) {
- if (conn_state == WIFI_CONNECTION_STATE_CONNECTED) {
- last_state = _CONNECTED;
- get_bssid();
- } else {
- last_state = _UNCONNECTED;
- clear_bssid();
- }
- } else {
- last_state = _DISABLED;
- clear_bssid();
- }
-
- if (!is_initialized)
- wifi_deinitialize();
-
- return true;
-}
-
-bool ctx::device_status_wifi::get_bssid()
-{
- int err;
- char *str_buf = NULL;
- wifi_ap_h ap = NULL;
-
- err = wifi_get_connected_ap(&ap);
- IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_get_connected_ap() failed");
-
- wifi_ap_get_bssid(ap, &str_buf);
- bssid = (str_buf != NULL ? str_buf : "");
- g_free(str_buf);
-
- wifi_ap_destroy(ap);
-
- if (bssid.empty())
- _W("Failed to get BSSID");
-
- SharedVars().set(ctx::SharedVars::WIFI_BSSID, bssid);
- _D("BSSID: %s", bssid.c_str());
-
- return !bssid.empty();
-}
-
-void ctx::device_status_wifi::clear_bssid()
-{
- bssid.clear();
- SharedVars().clear(ctx::SharedVars::WIFI_BSSID);
- _D("No WiFi connection");
-}
-
-bool ctx::device_status_wifi::get_response_packet(ctx::Json &data)
-{
- switch (last_state) {
- case _DISABLED:
- data.set(NULL, DEVICE_ST_STATE, DEVICE_ST_DISABLED);
- break;
-
- case _UNCONNECTED:
- data.set(NULL, DEVICE_ST_STATE, DEVICE_ST_UNCONNECTED);
- break;
-
- case _CONNECTED:
- data.set(NULL, DEVICE_ST_STATE, DEVICE_ST_CONNECTED);
- data.set(NULL, DEVICE_ST_BSSID, bssid);
- break;
-
- default:
- return false;
- }
-
- return true;
-}
-
-int ctx::device_status_wifi::read()
-{
- IF_FAIL_RETURN(get_current_state(), ERR_OPERATION_FAILED);
-
- ctx::Json dataRead;
-
- if (get_response_packet(dataRead)) {
- ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, dataRead);
- return ERR_NONE;
- }
-
- return ERR_OPERATION_FAILED;
-}
-
-bool ctx::device_status_wifi::start_monitor()
-{
- IF_FAIL_RETURN(!is_initialized, true);
-
- int err;
- err = wifi_initialize();
- IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_initialize() failed");
-
- err = wifi_set_device_state_changed_cb(device_state_changed_cb, this);
- IF_FAIL_CATCH_TAG(err == WIFI_ERROR_NONE, _E, "wifi_set_device_state_changed_cb() failed");
-
- err = wifi_set_connection_state_changed_cb(connection_state_changed_cb, this);
- IF_FAIL_CATCH_TAG(err == WIFI_ERROR_NONE, _E, "wifi_set_connection_state_changed_cb() failed");
-
- is_initialized = true;
- return true;
-
-CATCH:
- wifi_deinitialize();
- return false;
-}
-
-void ctx::device_status_wifi::stop_monitor()
-{
- IF_FAIL_VOID(is_initialized);
-
- wifi_unset_device_state_changed_cb();
- wifi_unset_connection_state_changed_cb();
- wifi_deinitialize();
- is_initialized = false;
-}
-
-int ctx::device_status_wifi::subscribe()
-{
-#if 0
- IF_FAIL_RETURN(start_monitor(), ERR_OPERATION_FAILED);
- if (!get_current_state()) {
- stop_monitor();
- return ERR_OPERATION_FAILED;
- }
-#endif
-
- return ERR_NONE;
-}
-
-int ctx::device_status_wifi::unsubscribe()
-{
-#if 0
- stop_monitor();
-#endif
- return ERR_NONE;
-}
-
-void ctx::device_status_wifi::aggregate_updated_data()
-{
- int prev_state = last_state;
-
- if (is_activated) {
- if (conn_state == WIFI_CONNECTION_STATE_CONNECTED) {
- last_state = _CONNECTED;
- } else {
- last_state = _UNCONNECTED;
- }
- } else {
- last_state = _DISABLED;
- }
-
- if (last_state != prev_state) {
- if (last_state == _CONNECTED) {
- get_bssid();
- } else {
- clear_bssid();
- }
-
- ctx::Json data;
- if (being_subscribed && get_response_packet(data))
- context_manager::publish(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, data);
- }
-}
-
-void ctx::device_status_wifi::device_state_changed_cb(wifi_device_state_e state, void *user_data)
-{
- device_status_wifi *instance = static_cast<device_status_wifi*>(user_data);
- instance->is_activated = (state == WIFI_DEVICE_STATE_ACTIVATED);
- instance->aggregate_updated_data();
-}
-
-void ctx::device_status_wifi::connection_state_changed_cb(wifi_connection_state_e state, wifi_ap_h ap, void *user_data)
-{
- device_status_wifi *instance = static_cast<device_status_wifi*>(user_data);
- instance->conn_state = state;
- instance->aggregate_updated_data();
-}
+++ /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 __CONTEXT_DEVICE_STATUS_WIFI_H__
-#define __CONTEXT_DEVICE_STATUS_WIFI_H__
-
-#include <string>
-#include <wifi.h>
-#include "../device_provider_base.h"
-
-namespace ctx {
-
- class device_status_wifi : public device_provider_base {
-
- GENERATE_PROVIDER_COMMON_DECL(device_status_wifi);
-
- public:
- int subscribe();
- int unsubscribe();
- int read();
- static bool is_supported();
- static void submit_trigger_item();
-
- private:
- enum _state_e {
- _UNKNOWN = -1,
- _DISABLED = 0,
- _UNCONNECTED,
- _CONNECTED,
- };
-
- int last_state;
- bool is_initialized;
- bool is_activated;
- wifi_connection_state_e conn_state;
- std::string bssid;
-
- device_status_wifi();
- ~device_status_wifi();
-
- bool get_current_state();
- bool get_bssid();
- void clear_bssid();
- bool get_response_packet(Json &data);
- void aggregate_updated_data();
- bool start_monitor();
- void stop_monitor();
- static void device_state_changed_cb(wifi_device_state_e state, void *user_data);
- static void connection_state_changed_cb(wifi_connection_state_e state, wifi_ap_h ap, void *user_data);
- };
-}
-
-#endif