# 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;
+}
*/
#include <system_info.h>
-#include "device_provider_base.h"
+#include "DeviceProviderBase.h"
-ctx::device_provider_base::device_provider_base()
- : being_subscribed(false)
+ctx::DeviceProviderBase::DeviceProviderBase()
+ : __beingSubscribed(false)
{
}
-int ctx::device_provider_base::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult)
+int ctx::DeviceProviderBase::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult)
{
- IF_FAIL_RETURN(!being_subscribed, ERR_NONE);
+ IF_FAIL_RETURN(!__beingSubscribed, ERR_NONE);
int ret = subscribe();
if (ret == ERR_NONE)
- being_subscribed = true;
+ __beingSubscribed = true;
else
- destroy_self();
+ destroySelf();
return ret;
}
-int ctx::device_provider_base::unsubscribe(const char *subject, ctx::Json option)
+int ctx::DeviceProviderBase::unsubscribe(const char *subject, ctx::Json option)
{
int ret = ERR_NONE;
- if (being_subscribed)
+ if (__beingSubscribed)
ret = unsubscribe();
- destroy_self();
+ destroySelf();
return ret;
}
-int ctx::device_provider_base::read(const char *subject, ctx::Json option, ctx::Json *requestResult)
+int ctx::DeviceProviderBase::read(const char *subject, ctx::Json option, ctx::Json *requestResult)
{
int ret = read();
- if (!being_subscribed)
- destroy_self();
+ if (!__beingSubscribed)
+ destroySelf();
return ret;
}
-int ctx::device_provider_base::write(const char *subject, ctx::Json data, ctx::Json *requestResult)
+int ctx::DeviceProviderBase::write(const char *subject, ctx::Json data, ctx::Json *requestResult)
{
int ret = write();
- if (!being_subscribed)
- destroy_self();
+ if (!__beingSubscribed)
+ destroySelf();
return ret;
}
-int ctx::device_provider_base::subscribe()
+int ctx::DeviceProviderBase::subscribe()
{
return ERR_NOT_SUPPORTED;
}
-int ctx::device_provider_base::unsubscribe()
+int ctx::DeviceProviderBase::unsubscribe()
{
return ERR_NOT_SUPPORTED;
}
-int ctx::device_provider_base::read()
+int ctx::DeviceProviderBase::read()
{
return ERR_NOT_SUPPORTED;
}
-int ctx::device_provider_base::write()
+int ctx::DeviceProviderBase::write()
{
return ERR_NOT_SUPPORTED;
}
-bool ctx::device_provider_base::get_system_info_bool(const char *key)
+bool ctx::DeviceProviderBase::getSystemInfoBool(const char *key)
{
bool supported = false;
int ret = system_info_get_platform_bool(key, &supported);
* limitations under the License.
*/
-#ifndef __CONTEXT_DEVICE_PROVIDER_BASE_H__
-#define __CONTEXT_DEVICE_PROVIDER_BASE_H__
+#ifndef _CONTEXT_DEVICE_PROVIDER_BASE_H_
+#define _CONTEXT_DEVICE_PROVIDER_BASE_H_
#include <types_internal.h>
#include <Json.h>
static ContextProviderBase *create(void *data); \
static void destroy(void *data); \
protected: \
- void destroy_self(); \
+ void destroySelf(); \
private: \
static prvd *__instance; \
{ \
DESTROY_INSTANCE(); \
} \
- void ctx::prvd::destroy_self() \
+ void ctx::prvd::destroySelf() \
{ \
destroy(NULL); \
} \
namespace ctx {
- class device_provider_base : public ContextProviderBase {
+ 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 write(const char *subject, ctx::Json data, ctx::Json *requestResult);
protected:
- bool being_subscribed;
+ bool __beingSubscribed;
- device_provider_base();
- virtual ~device_provider_base() {}
+ DeviceProviderBase();
+ virtual ~DeviceProviderBase() {}
virtual int subscribe();
virtual int unsubscribe();
virtual int read();
virtual int write();
- virtual void destroy_self() = 0;
+ virtual void destroySelf() = 0;
- static bool get_system_info_bool(const char *key);
+ static bool getSystemInfoBool(const char *key);
};
}
-#endif
+#endif // _CONTEXT_DEVICE_PROVIDER_BASE_H_
* limitations under the License.
*/
-#ifndef _DEVICE_STATUS_ACTIVITY_H_
-#define _DEVICE_STATUS_ACTIVITY_H_
+#ifndef _DEVICE_ACTIVITY_STATUS_H_
+#define _DEVICE_ACTIVITY_STATUS_H_
#include <system_info.h>
-#include "activity_base.h"
+#include "ActivityBase.h"
-#define GENERATE_ACTIVITY_PROVIDER(act_prvd, act_subj, act_type) \
- class act_prvd : public user_activity_base { \
+#define GENERATE_ACTIVITY_PROVIDER(actPrvd, actSubj, actType) \
+ class actPrvd : public UserActivityBase { \
public: \
static ContextProviderBase *create(void *data) \
{ \
- CREATE_INSTANCE(ctx::act_prvd); \
+ CREATE_INSTANCE(ctx::actPrvd); \
} \
static void destroy(void *data) \
{ \
DESTROY_INSTANCE(); \
} \
- static bool is_supported() \
+ static bool isSupported() \
{ \
- return get_system_info_bool("tizen.org/feature/sensor.activity_recognition"); \
+ return getSystemInfoBool("tizen.org/feature/sensor.activity_recognition"); \
} \
- static void submit_trigger_item() \
+ static void submitTriggerItem() \
{ \
- context_manager::registerTriggerItem((act_subj), OPS_SUBSCRIBE, \
+ context_manager::registerTriggerItem((actSubj), OPS_SUBSCRIBE, \
"{\"Event\":{\"type\":\"string\", \"values\":[\"Detected\"]}}", \
"{\"Accuracy\":{\"type\":\"string\", \"values\":[\"Low\", \"Normal\", \"High\"]}}" \
); \
} \
protected: \
- void destroy_self() \
+ void destroySelf() \
{ \
destroy(NULL); \
} \
private: \
- static act_prvd *__instance; \
- act_prvd() : user_activity_base((act_subj), (act_type)) {} \
+ static actPrvd *__instance; \
+ actPrvd() : UserActivityBase((actSubj), (actType)) {} \
}; \
- ctx::act_prvd *ctx::act_prvd::__instance = NULL; \
+ ctx::actPrvd *ctx::actPrvd::__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);
+ 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_STATUS_ACTIVITY_H_
+#endif // _DEVICE_ACTIVITY_STATUS_H_
#include <types_internal.h>
#include <ContextManager.h>
-#include "activity_types.h"
-#include "activity_base.h"
+#include "ActivityTypes.h"
+#include "ActivityBase.h"
-ctx::user_activity_base::user_activity_base(const char *subj, activity_type_e type)
- : activity_type(type)
- , activity_handle(NULL)
- , subject(subj)
+ctx::UserActivityBase::UserActivityBase(const char *subj, activity_type_e type) :
+ __activityType(type),
+ __activityHandle(NULL),
+ __subject(subj)
{
}
-ctx::user_activity_base::~user_activity_base()
+ctx::UserActivityBase::~UserActivityBase()
{
- if (activity_handle)
- activity_release(activity_handle);
+ if (__activityHandle)
+ activity_release(__activityHandle);
}
-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)
+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);
- user_activity_base *instance = static_cast<user_activity_base*>(user_data);
- instance->handle_event(activity, data, timestamp);
+ UserActivityBase *instance = static_cast<UserActivityBase*>(userData);
+ instance->__handleUpdate(activity, data, timestamp);
}
-void ctx::user_activity_base::handle_event(activity_type_e activity, const activity_data_h data, double timestamp)
+void ctx::UserActivityBase::__handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp)
{
- IF_FAIL_VOID_TAG(activity == activity_type, _E, "Invalid activity: %d", activity);
+ IF_FAIL_VOID_TAG(activity == __activityType, _E, "Invalid activity: %d", activity);
ctx::Json dataRead;
dataRead.set(NULL, USER_ACT_EVENT, USER_ACT_DETECTED);
break;
}
- context_manager::publish(subject.c_str(), NULL, ERR_NONE, dataRead);
+ context_manager::publish(__subject.c_str(), NULL, ERR_NONE, dataRead);
}
-int ctx::user_activity_base::subscribe()
+int ctx::UserActivityBase::subscribe()
{
- IF_FAIL_RETURN(activity_handle == NULL, ERR_NONE);
+ IF_FAIL_RETURN(__activityHandle == NULL, ERR_NONE);
- _D("Starting to monitor %s", subject.c_str());
+ _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");
+ activity_create(&__activityHandle);
+ IF_FAIL_RETURN_TAG(__activityHandle, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
- int ret = activity_start_recognition(activity_handle, activity_type, event_cb, this);
+ int ret = activity_start_recognition(__activityHandle, __activityType, __updateCb, this);
if (ret != ACTIVITY_ERROR_NONE) {
_E("Recognition starting failed");
- activity_release(activity_handle);
- activity_handle = NULL;
+ activity_release(__activityHandle);
+ __activityHandle = NULL;
return ERR_OPERATION_FAILED;
}
return ERR_NONE;
}
-int ctx::user_activity_base::unsubscribe()
+int ctx::UserActivityBase::unsubscribe()
{
- IF_FAIL_RETURN(activity_handle, ERR_NONE);
+ IF_FAIL_RETURN(__activityHandle, ERR_NONE);
- _D("Stop monitoring %s", subject.c_str());
+ _D("Stop monitoring %s", __subject.c_str());
- activity_stop_recognition(activity_handle);
- activity_release(activity_handle);
- activity_handle = NULL;
+ activity_stop_recognition(__activityHandle);
+ activity_release(__activityHandle);
+ __activityHandle = NULL;
return ERR_NONE;
}
* limitations under the License.
*/
-#ifndef _DEVICE_STATUS_ACTIVITY_BASE_H_
-#define _DEVICE_STATUS_ACTIVITY_BASE_H_
+#ifndef _DEVICE_ACTIVITY_STATUS_BASE_H_
+#define _DEVICE_ACTIVITY_STATUS_BASE_H_
#include <string>
#include <activity_recognition.h>
-#include "../device_provider_base.h"
+#include "../DeviceProviderBase.h"
namespace ctx {
- class user_activity_base : public device_provider_base {
+ class UserActivityBase : public DeviceProviderBase {
public:
int subscribe();
int unsubscribe();
protected:
- activity_type_e activity_type;
- activity_h activity_handle;
- std::string subject;
+ activity_type_e __activityType;
+ activity_h __activityHandle;
+ std::string __subject;
- user_activity_base(const char *subj, activity_type_e type);
- virtual ~user_activity_base();
+ UserActivityBase(const char *subj, activity_type_e type);
+ virtual ~UserActivityBase();
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);
+ 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_STATUS_ACTIVITY_BASE_H_
+#endif // _DEVICE_ACTIVITY_STATUS_BASE_H_
* limitations under the License.
*/
-#ifndef __CONTEXT_USER_ACTIVITY_TYPES_H__
-#define __CONTEXT_USER_ACTIVITY_TYPES_H__
+#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_NORMAL "Normal"
#define USER_ACT_HIGH "High"
-#endif //__CONTEXT_USER_ACTIVITY_TYPES_H__
+#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.
- */
-
-#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;
-}
#include <stdlib.h>
#include <Json.h>
#include <ContextManager.h>
-#include "social_types.h"
-#include "call.h"
+#include "SocialTypes.h"
+#include "Call.h"
#define TELEPHONY_NOTI_ID_CNT 8
-GENERATE_PROVIDER_COMMON_IMPL(social_status_call);
+GENERATE_PROVIDER_COMMON_IMPL(SocialStatusCall);
-static bool telephony_initialized = false;
-static telephony_noti_e call_noti_ids[] =
+static bool __telephonyInitialized = false;
+static telephony_noti_e __callNotiIds[] =
{
TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE,
TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE,
TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING,
TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING,
};
-static ctx::Json latest;
+static ctx::Json __latest;
-ctx::social_status_call::social_status_call()
+ctx::SocialStatusCall::SocialStatusCall()
{
- handle_list.count = 0;
- handle_list.handle = NULL;
+ __handleList.count = 0;
+ __handleList.handle = NULL;
}
-ctx::social_status_call::~social_status_call()
+ctx::SocialStatusCall::~SocialStatusCall()
{
}
-bool ctx::social_status_call::is_supported()
+bool ctx::SocialStatusCall::isSupported()
{
- return get_system_info_bool("tizen.org/feature/network.telephony");
+ return getSystemInfoBool("tizen.org/feature/network.telephony");
}
-void ctx::social_status_call::submit_trigger_item()
+void ctx::SocialStatusCall::submitTriggerItem()
{
context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CALL, OPS_SUBSCRIBE | OPS_READ,
"{"
//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)
+void ctx::SocialStatusCall::__updateCb(telephony_h handle, telephony_noti_e notiId, void *data, void *userData)
{
- social_status_call *instance = static_cast<social_status_call*>(user_data);
- instance->handle_call_event(handle, noti_id, data);
+ SocialStatusCall *instance = static_cast<SocialStatusCall*>(userData);
+ instance->__handleUpdate(handle, notiId, data);
}
-void ctx::social_status_call::handle_call_event(telephony_h handle, telephony_noti_e noti_id, void* id)
+void ctx::SocialStatusCall::__handleUpdate(telephony_h handle, telephony_noti_e notiId, void* id)
{
-
Json data;
unsigned int count;
- telephony_call_h *call_list;
+ telephony_call_h *callList;
// Call state
- switch (noti_id) {
+ 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);
case TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING:
case TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING:*/
default:
- _E("Unkown noti id: %d", noti_id);
+ _E("Unkown noti id: %d", notiId);
return;
}
// Call type
- switch (noti_id) {
+ 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_DIALING:
case TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING:*/
default:
- _E("Unkown noti id: %d", noti_id);
+ _E("Unkown noti id: %d", notiId);
return;
}
- int err = telephony_call_get_call_list(handle, &count, &call_list);
+ 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 call_id = *static_cast<unsigned int *>(id);
+ unsigned int callId = *static_cast<unsigned int *>(id);
for (unsigned int i = 0; i < count; i++) {
- unsigned int tmp_id;
+ unsigned int tempId;
// Handle id
- if (!get_call_handle_id(call_list[i], tmp_id)) {
+ if (!__getCallHandleId(callList[i], tempId)) {
continue;
}
- if (call_id != tmp_id) {
+ if (callId != tempId) {
continue;
}
// Address
std::string address;
- if (get_call_address(call_list[i], address)) {
+ if (__getCallAddress(callList[i], address)) {
data.set(NULL, SOCIAL_ST_ADDRESS, address);
break;
}
}
- if (latest != data) {
+ if (__latest != data) {
context_manager::publish(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data);
- latest = data.str();
+ __latest = data.str();
}
- telephony_call_release_call_list(count, &call_list);
+ telephony_call_release_call_list(count, &callList);
}
-bool ctx::social_status_call::init_telephony()
+bool ctx::SocialStatusCall::__initTelephony()
{
- IF_FAIL_RETURN(!telephony_initialized, true);
+ IF_FAIL_RETURN(!__telephonyInitialized, true);
- int err = telephony_init(&handle_list);
+ int err = telephony_init(&__handleList);
IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Initialization failed");
- telephony_initialized = true;
+ __telephonyInitialized = true;
return true;
}
-void ctx::social_status_call::release_telephony()
+void ctx::SocialStatusCall::__releaseTelephony()
{
- IF_FAIL_VOID(telephony_initialized);
+ IF_FAIL_VOID(__telephonyInitialized);
- telephony_deinit(&handle_list);
+ telephony_deinit(&__handleList);
- telephony_initialized = false;
+ __telephonyInitialized = false;
}
-bool ctx::social_status_call::set_callback()
+bool ctx::SocialStatusCall::__setCallback()
{
//TODO: Consider dual-sim devices
- IF_FAIL_RETURN_TAG(init_telephony(), false, _E, "Initialization failed");
+ IF_FAIL_RETURN_TAG(__initTelephony(), false, _E, "Initialization failed");
int err;
- for (unsigned int i = 0; i < handle_list.count; i++) {
+ 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(handle_list.handle[i], call_noti_ids[j], call_event_cb, this);
+ err = telephony_set_noti_cb(__handleList.handle[i], __callNotiIds[j], __updateCb, this);
IF_FAIL_CATCH(err == TELEPHONY_ERROR_NONE);
}
}
CATCH:
_E("Initialization failed");
- release_telephony();
+ __releaseTelephony();
return false;
}
-void ctx::social_status_call::unset_callback()
+void ctx::SocialStatusCall::__unsetCallback()
{
- for (unsigned int i = 0; i < handle_list.count; i++) {
+ for (unsigned int i = 0; i < __handleList.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]);
+ telephony_unset_noti_cb(__handleList.handle[i], __callNotiIds[j]);
}
}
- release_telephony();
+ __releaseTelephony();
}
-bool ctx::social_status_call::get_call_state(telephony_call_h& handle, std::string& state)
+bool ctx::SocialStatusCall::__getCallState(telephony_call_h& handle, std::string& state)
{
state.clear();
return true;
}
-bool ctx::social_status_call::get_call_type(telephony_call_h& handle, std::string& type)
+bool ctx::SocialStatusCall::__getCallType(telephony_call_h& handle, std::string& type)
{
type.clear();
return true;
}
-bool ctx::social_status_call::get_call_address(telephony_call_h& handle, std::string& address)
+bool ctx::SocialStatusCall::__getCallAddress(telephony_call_h& handle, std::string& address)
{
address.clear();
return true;
}
-bool ctx::social_status_call::get_call_handle_id(telephony_call_h& handle, unsigned int& id)
+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::social_status_call::subscribe()
+int ctx::SocialStatusCall::subscribe()
{
- bool ret = set_callback();
+ bool ret = __setCallback();
IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
return ERR_NONE;
}
-int ctx::social_status_call::unsubscribe()
+int ctx::SocialStatusCall::unsubscribe()
{
- unset_callback();
+ __unsetCallback();
return ERR_NONE;
}
-bool ctx::social_status_call::read_current_status(telephony_h& handle, ctx::Json& data)
+bool ctx::SocialStatusCall::__readCurrentStatus(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);
+ telephony_call_h *callList = NULL;
+ telephony_call_get_call_list(handle, &count, &callList);
// Default data
- data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE);
+ 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)) {
+ 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);
+ 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);
+ if (__getCallType(callList[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 (__getCallAddress(callList[i], address)) {
+ data->set(NULL, SOCIAL_ST_ADDRESS, address);
}
if (state == SOCIAL_ST_ACTIVE) {
}
}
- telephony_call_release_call_list(count, &call_list);
+ telephony_call_release_call_list(count, &callList);
return true;
}
-int ctx::social_status_call::read()
+int ctx::SocialStatusCall::read()
{
- bool temporary_handle = false;
- if (!telephony_initialized) {
- IF_FAIL_RETURN(init_telephony(), ERR_OPERATION_FAILED);
- temporary_handle = true;
+ 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 < handle_list.count; i++) {
+ for (unsigned int i = 0; i < __handleList.count; i++) {
telephony_sim_state_e state;
- int err = telephony_sim_get_state(handle_list.handle[i], &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 = read_current_status(handle_list.handle[i], data);
+ ret = __readCurrentStatus(__handleList.handle[i], &data);
break;
}
- if (temporary_handle)
- release_telephony();
+ if (temporaryHandle)
+ __releaseTelephony();
if (ret) {
ctx::context_manager::replyToRead(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, 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_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_
#include <Json.h>
#include <ContextManager.h>
-#include "social_types.h"
-#include "contacts.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(social_status_contacts);
+GENERATE_PROVIDER_COMMON_IMPL(SocialStatusContacts);
-ctx::social_status_contacts::social_status_contacts()
- : latest_my_profile(0)
- , latest_person(0)
+ctx::SocialStatusContacts::SocialStatusContacts() :
+ __latestMyProfile(0),
+ __latestPerson(0)
{
}
-ctx::social_status_contacts::~social_status_contacts()
+ctx::SocialStatusContacts::~SocialStatusContacts()
{
}
-bool ctx::social_status_contacts::is_supported()
+bool ctx::SocialStatusContacts::isSupported()
{
return true;
}
-void ctx::social_status_contacts::submit_trigger_item()
+void ctx::SocialStatusContacts::submitTriggerItem()
{
context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CONTACTS, OPS_SUBSCRIBE,
"{"
NULL);
}
-void ctx::social_status_contacts::db_change_cb(const char* view_uri, void* user_data)
+void ctx::SocialStatusContacts::__updateCb(const char* viewUri, void* userData)
{
- social_status_contacts *instance = static_cast<social_status_contacts*>(user_data);
- instance->handle_db_change(view_uri);
+ SocialStatusContacts *instance = static_cast<SocialStatusContacts*>(userData);
+ instance->__handleUpdate(viewUri);
}
-void ctx::social_status_contacts::handle_db_change(const char* view_uri)
+void ctx::SocialStatusContacts::__handleUpdate(const char* viewUri)
{
- if (!STR_EQ(view_uri, _contacts_my_profile._uri) && !STR_EQ(view_uri, _contacts_person._uri)) {
+ if (!STR_EQ(viewUri, _contacts_my_profile._uri) && !STR_EQ(viewUri, _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());
+ 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);
context_manager::publish(SOCIAL_ST_SUBJ_CONTACTS, NULL, ERR_NONE, data);
}
-bool ctx::social_status_contacts::is_consecutive_change(const char* view_uri)
+bool ctx::SocialStatusContacts::__isConsecutiveChange(const char* viewUri)
{
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 (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 false;
}
-bool ctx::social_status_contacts::set_callback()
+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, db_change_cb, this);
+ 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, db_change_cb, this);
+ 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;
return false;
}
-void ctx::social_status_contacts::unset_callback()
+void ctx::SocialStatusContacts::__unsetCallback()
{
- contacts_db_remove_changed_cb(MY_PROFILE_VIEW, db_change_cb, this);
- contacts_db_remove_changed_cb(PERSON_VIEW, db_change_cb, this);
+ contacts_db_remove_changed_cb(MY_PROFILE_VIEW, __updateCb, this);
+ contacts_db_remove_changed_cb(PERSON_VIEW, __updateCb, this);
contacts_disconnect();
- latest_my_profile = 0;
- latest_person = 0;
+ __latestMyProfile = 0;
+ __latestPerson = 0;
}
-int ctx::social_status_contacts::subscribe()
+int ctx::SocialStatusContacts::subscribe()
{
- bool ret = set_callback();
+ bool ret = __setCallback();
IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
return ERR_NONE;
}
-int ctx::social_status_contacts::unsubscribe()
+int ctx::SocialStatusContacts::unsubscribe()
{
- unset_callback();
+ __unsetCallback();
return ERR_NONE;
}
#define _CONTEXT_SOCIAL_STATUS_CONTACTS_H_
#include <contacts.h>
-#include "../device_provider_base.h"
+#include "../DeviceProviderBase.h"
namespace ctx {
- class social_status_contacts : public device_provider_base {
+ class SocialStatusContacts : public DeviceProviderBase {
- GENERATE_PROVIDER_COMMON_DECL(social_status_contacts);
+ GENERATE_PROVIDER_COMMON_DECL(SocialStatusContacts);
public:
int subscribe();
int unsubscribe();
- static bool is_supported();
- static void submit_trigger_item();
+ static bool isSupported();
+ static void submitTriggerItem();
private:
- time_t latest_my_profile;
- time_t latest_person;
+ time_t __latestMyProfile;
+ time_t __latestPerson;
- social_status_contacts();
- ~social_status_contacts();
+ SocialStatusContacts();
+ ~SocialStatusContacts();
- 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);
+ bool __setCallback();
+ void __unsetCallback();
+ void __handleUpdate(const char* viewUri);
+ static void __updateCb(const char* viewUri, void* userData);
+ bool __isConsecutiveChange(const char* viewUri);
};
}
#include <email-api-etc.h>
#include <ContextManager.h>
-#include "social_types.h"
-#include "email.h"
+#include "SocialTypes.h"
+#include "Email.h"
-GENERATE_PROVIDER_COMMON_IMPL(social_status_email);
+GENERATE_PROVIDER_COMMON_IMPL(SocialStatusEmail);
-ctx::social_status_email::social_status_email()
- : dbus_signal_id(-1)
- , __dbusWatcher(DBusType::SESSION)
+ctx::SocialStatusEmail::SocialStatusEmail() :
+ __dbusSignalId(-1),
+ __dbusWatcher(DBusType::SESSION)
{
}
-ctx::social_status_email::~social_status_email()
+ctx::SocialStatusEmail::~SocialStatusEmail()
{
}
-bool ctx::social_status_email::is_supported()
+bool ctx::SocialStatusEmail::isSupported()
{
- return get_system_info_bool("tizen.org/feature/network.telephony");
+ return getSystemInfoBool("tizen.org/feature/network.telephony");
}
-void ctx::social_status_email::submit_trigger_item()
+void ctx::SocialStatusEmail::submitTriggerItem()
{
context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_EMAIL, OPS_SUBSCRIBE,
"{"
NULL);
}
-void ctx::social_status_email::onSignal(const char* sender, const char* path, const char* iface, const char* name, GVariant* param)
+void ctx::SocialStatusEmail::onSignal(const char* sender, const char* path, const char* iface, const char* name, GVariant* param)
{
- gint sub_type = 0;
+ gint subType = 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);
+ g_variant_get(param, "(ii&sii)", &subType, &gi1, &gc, &gi2, &gi3);
- if (sub_type == NOTI_DOWNLOAD_FINISH) {
+ 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", sub_type, gi1, gc, gi2, gi3);
+ _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 (sub_type == NOTI_SEND_FINISH) {
- _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", sub_type, gi1, gc, gi2, gi3);
+ } 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::social_status_email::subscribe()
+int ctx::SocialStatusEmail::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");
+ __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::social_status_email::unsubscribe()
+int ctx::SocialStatusEmail::unsubscribe()
{
- __dbusWatcher.unwatch(dbus_signal_id);
+ __dbusWatcher.unwatch(__dbusSignalId);
return ERR_NONE;
}
#define _CONTEXT_SOCIAL_STATUS_EMAIL_H_
#include <DBusSignalWatcher.h>
-#include "../device_provider_base.h"
+#include "../DeviceProviderBase.h"
namespace ctx {
- class social_status_email : public device_provider_base, public IDBusSignalListener {
+ class SocialStatusEmail : public DeviceProviderBase, public IDBusSignalListener {
- GENERATE_PROVIDER_COMMON_DECL(social_status_email);
+ 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 is_supported();
- static void submit_trigger_item();
+ static bool isSupported();
+ static void submitTriggerItem();
private:
- int64_t dbus_signal_id;
+ int64_t __dbusSignalId;
DBusSignalWatcher __dbusWatcher;
- social_status_email();
- ~social_status_email();
+ SocialStatusEmail();
+ ~SocialStatusEmail();
};
}
#include <Json.h>
#include <ContextManager.h>
-#include "social_types.h"
-#include "message.h"
+#include "SocialTypes.h"
+#include "Message.h"
#define MAX_ADDR_SIZE 20
-GENERATE_PROVIDER_COMMON_IMPL(social_status_message);
+GENERATE_PROVIDER_COMMON_IMPL(SocialStatusMessage);
-ctx::social_status_message::social_status_message()
- : message_handle(NULL)
+ctx::SocialStatusMessage::SocialStatusMessage() :
+ __messageHandle(NULL)
{
}
-ctx::social_status_message::~social_status_message()
+ctx::SocialStatusMessage::~SocialStatusMessage()
{
}
-bool ctx::social_status_message::is_supported()
+bool ctx::SocialStatusMessage::isSupported()
{
- return get_system_info_bool("tizen.org/feature/network.telephony");
+ return getSystemInfoBool("tizen.org/feature/network.telephony");
}
-void ctx::social_status_message::submit_trigger_item()
+void ctx::SocialStatusMessage::submitTriggerItem()
{
context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_MESSAGE, OPS_SUBSCRIBE,
"{"
NULL);
}
-void ctx::social_status_message::state_change_cb(msg_handle_t handle, msg_struct_t msg, void* user_data)
+void ctx::SocialStatusMessage::__updateCb(msg_handle_t handle, msg_struct_t msg, void* userData)
{
- social_status_message *instance = static_cast<social_status_message*>(user_data);
- instance->handle_state_change(msg);
+ SocialStatusMessage *instance = static_cast<SocialStatusMessage*>(userData);
+ instance->__handleUpdate(msg);
}
-void ctx::social_status_message::handle_state_change(msg_struct_t msg)
+void ctx::SocialStatusMessage::__handleUpdate(msg_struct_t msg)
{
int err;
int type;
context_manager::publish(SOCIAL_ST_SUBJ_MESSAGE, NULL, ERR_NONE, data);
}
-bool ctx::social_status_message::set_callback()
+bool ctx::SocialStatusMessage::__setCallback()
{
int err;
- err = msg_open_msg_handle(&message_handle);
+ err = msg_open_msg_handle(&__messageHandle);
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);
+ err = msg_reg_sms_message_callback(__messageHandle, __updateCb, 0, this);
if (err != MSG_SUCCESS) {
- msg_close_msg_handle(&message_handle);
+ msg_close_msg_handle(&__messageHandle);
_E("Setting SMS event callback failed");
return false;
}
- msg_reg_mms_conf_message_callback(message_handle, state_change_cb, NULL, this);
+ msg_reg_mms_conf_message_callback(__messageHandle, __updateCb, NULL, this);
return true;
}
-void ctx::social_status_message::unset_callback()
+void ctx::SocialStatusMessage::__unsetCallback()
{
- if (message_handle)
- msg_close_msg_handle(&message_handle);
+ if (__messageHandle)
+ msg_close_msg_handle(&__messageHandle);
- message_handle = NULL;
+ __messageHandle = NULL;
}
-int ctx::social_status_message::subscribe()
+int ctx::SocialStatusMessage::subscribe()
{
- bool ret = set_callback();
+ bool ret = __setCallback();
IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
return ERR_NONE;
}
-int ctx::social_status_message::unsubscribe()
+int ctx::SocialStatusMessage::unsubscribe()
{
- unset_callback();
+ __unsetCallback();
return ERR_NONE;
}
#include <msg.h>
#include <msg_transport.h>
-#include "../device_provider_base.h"
+#include "../DeviceProviderBase.h"
namespace ctx {
- class social_status_message : public device_provider_base {
+ class SocialStatusMessage : public DeviceProviderBase {
- GENERATE_PROVIDER_COMMON_DECL(social_status_message);
+ GENERATE_PROVIDER_COMMON_DECL(SocialStatusMessage);
public:
int subscribe();
int unsubscribe();
- static bool is_supported();
- static void submit_trigger_item();
+ static bool isSupported();
+ static void submitTriggerItem();
private:
- msg_handle_t message_handle;
- bool being_subscribed;
+ msg_handle_t __messageHandle;
+ bool __beingSubscribed;
- social_status_message();
- ~social_status_message();
+ SocialStatusMessage();
+ ~SocialStatusMessage();
- 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);
+ bool __setCallback();
+ void __unsetCallback();
+ void __handleUpdate(msg_struct_t msg);
+ static void __updateCb(msg_handle_t handle, msg_struct_t msg, void* userData);
};
}
* limitations under the License.
*/
-#ifndef __CONTEXT_SOCIAL_STATUS_TYPES_INTERNAL_H__
-#define __CONTEXT_SOCIAL_STATUS_TYPES_INTERNAL_H__
+#ifndef _CONTEXT_SOCIAL_STATUS_TYPES_H_
+#define _CONTEXT_SOCIAL_STATUS_TYPES_H_
// Subject
#define SOCIAL_ST_SUBJ_CALL "social/call"
#define SOCIAL_ST_PERSON "Person"
#define SOCIAL_ST_CHANGED "Changed"
-#endif
+#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.
- */
-
-#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) 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_
*/
#include <ContextManager.h>
-#include "system_types.h"
-#include "battery.h"
+#include "SystemTypes.h"
+#include "Battery.h"
-GENERATE_PROVIDER_COMMON_IMPL(device_status_battery);
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusBattery);
-ctx::device_status_battery::device_status_battery()
+ctx::DeviceStatusBattery::DeviceStatusBattery()
{
}
-ctx::device_status_battery::~device_status_battery()
+ctx::DeviceStatusBattery::~DeviceStatusBattery()
{
}
-bool ctx::device_status_battery::is_supported()
+bool ctx::DeviceStatusBattery::isSupported()
{
return true;
}
-void ctx::device_status_battery::submit_trigger_item()
+void ctx::DeviceStatusBattery::submitTriggerItem()
{
context_manager::registerTriggerItem(DEVICE_ST_SUBJ_BATTERY, OPS_SUBSCRIBE | OPS_READ,
"{"
NULL);
}
-void ctx::device_status_battery::update_cb(device_callback_e device_type, void* value, void* user_data)
+void ctx::DeviceStatusBattery::__updateCb(device_callback_e deviceType, void* value, void* userData)
{
- IF_FAIL_VOID(device_type == DEVICE_CALLBACK_BATTERY_LEVEL);
+ IF_FAIL_VOID(deviceType == DEVICE_CALLBACK_BATTERY_LEVEL);
- device_status_battery *instance = static_cast<device_status_battery*>(user_data);
- instance->handle_update(device_type, value);
+ DeviceStatusBattery *instance = static_cast<DeviceStatusBattery*>(userData);
+ instance->__handleUpdate(deviceType, value);
}
-void ctx::device_status_battery::handle_update(device_callback_e device_type, void* value)
+void ctx::DeviceStatusBattery::__handleUpdate(device_callback_e deviceType, void* value)
{
intptr_t level = (intptr_t)value;
- const char* level_string = trans_to_string(level);
- IF_FAIL_VOID(level_string);
+ const char* levelString = __transToString(level);
+ IF_FAIL_VOID(levelString);
ctx::Json dataRead;
- dataRead.set(NULL, DEVICE_ST_LEVEL, level_string);
+ dataRead.set(NULL, DEVICE_ST_LEVEL, levelString);
- bool charging_state = false;
- int ret = device_battery_is_charging(&charging_state);
+ 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, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+ 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::device_status_battery::trans_to_string(intptr_t level)
+const char* ctx::DeviceStatusBattery::__transToString(intptr_t level)
{
switch (level) {
case DEVICE_BATTERY_LEVEL_EMPTY:
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;
- }
+ {
+ 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");
}
}
-int ctx::device_status_battery::subscribe()
+int ctx::DeviceStatusBattery::subscribe()
{
- int ret = device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, update_cb, this);
+ 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::device_status_battery::unsubscribe()
+int ctx::DeviceStatusBattery::unsubscribe()
{
- int ret = device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, update_cb);
+ 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::device_status_battery::read()
+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* level_string = trans_to_string(level);
- IF_FAIL_RETURN(level_string, ERR_OPERATION_FAILED);
+ const char* levelString = __transToString(level);
+ IF_FAIL_RETURN(levelString, ERR_OPERATION_FAILED);
- dataRead.set(NULL, DEVICE_ST_LEVEL, level_string);
+ dataRead.set(NULL, DEVICE_ST_LEVEL, levelString);
- bool charging_state = false;
- ret = device_battery_is_charging(&charging_state);
+ 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, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+ 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;
* limitations under the License.
*/
-#ifndef _DEVICE_STATUS_BATTERY_LEVEL_H_
-#define _DEVICE_STATUS_BATTERY_LEVEL_H_
+#ifndef _DEVICE_SYSTEM_STATUS_BATTERY_H_
+#define _DEVICE_SYSTEM_STATUS_BATTERY_H_
#include <device/callback.h>
#include <device/battery.h>
-#include "../device_provider_base.h"
+#include "../DeviceProviderBase.h"
namespace ctx {
- class device_status_battery : public device_provider_base {
+ class DeviceStatusBattery : public DeviceProviderBase {
- GENERATE_PROVIDER_COMMON_DECL(device_status_battery);
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusBattery);
public:
int subscribe();
int unsubscribe();
int read();
- static bool is_supported();
- static void submit_trigger_item();
+ static bool isSupported();
+ static void submitTriggerItem();
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);
+ 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_STATUS_BATTERY_LEVEL_H_
+#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_
*/
#include <ContextManager.h>
-#include "system_types.h"
-#include "psmode.h"
+#include "SystemTypes.h"
+#include "Psmode.h"
-GENERATE_PROVIDER_COMMON_IMPL(device_status_psmode);
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusPsmode);
-ctx::device_status_psmode::device_status_psmode()
+ctx::DeviceStatusPsmode::DeviceStatusPsmode()
{
}
-ctx::device_status_psmode::~device_status_psmode()
+ctx::DeviceStatusPsmode::~DeviceStatusPsmode()
{
}
-bool ctx::device_status_psmode::is_supported()
+bool ctx::DeviceStatusPsmode::isSupported()
{
return true;
}
-void ctx::device_status_psmode::submit_trigger_item()
+void ctx::DeviceStatusPsmode::submitTriggerItem()
{
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)
+void ctx::DeviceStatusPsmode::__updateCb(keynode_t *node, void* userData)
{
- device_status_psmode *instance = static_cast<device_status_psmode*>(user_data);
- instance->handle_update(node);
+ DeviceStatusPsmode *instance = static_cast<DeviceStatusPsmode*>(userData);
+ instance->__handleUpdate(node);
}
-void ctx::device_status_psmode::handle_update(keynode_t *node)
+void ctx::DeviceStatusPsmode::__handleUpdate(keynode_t *node)
{
int status;
ctx::Json dataRead;
context_manager::publish(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, dataRead);
}
-int ctx::device_status_psmode::subscribe()
+int ctx::DeviceStatusPsmode::subscribe()
{
- int ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, update_cb, this);
+ 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::device_status_psmode::unsubscribe()
+int ctx::DeviceStatusPsmode::unsubscribe()
{
- int ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, update_cb);
+ int ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, __updateCb);
IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED);
return ERR_NONE;
}
-int ctx::device_status_psmode::read()
+int ctx::DeviceStatusPsmode::read()
{
int mode;
int ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &mode);
* limitations under the License.
*/
-#ifndef _DEVICE_STATUS_POWER_SAVING_MODE_H_
-#define _DEVICE_STATUS_POWER_SAVING_MODE_H_
+#ifndef _DEVICE_SYSTEM_STATUS_POWER_SAVING_MODE_H_
+#define _DEVICE_SYSTEM_STATUS_POWER_SAVING_MODE_H_
#include <vconf.h>
-#include "../device_provider_base.h"
+#include "../DeviceProviderBase.h"
namespace ctx {
- class device_status_psmode : public device_provider_base {
+ class DeviceStatusPsmode : public DeviceProviderBase {
- GENERATE_PROVIDER_COMMON_DECL(device_status_psmode);
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusPsmode);
public:
int subscribe();
int unsubscribe();
int read();
- static bool is_supported();
- static void submit_trigger_item();
+ static bool isSupported();
+ static void submitTriggerItem();
private:
- device_status_psmode();
- ~device_status_psmode();
- void handle_update(keynode_t *node);
- static void update_cb(keynode_t *node, void* user_data);
+ DeviceStatusPsmode();
+ ~DeviceStatusPsmode();
+ void __handleUpdate(keynode_t *node);
+ static void __updateCb(keynode_t *node, void* userData);
};
}
-#endif // _DEVICE_STATUS_POWER_SAVING_H_
+#endif // _DEVICE_SYSTEM_STATUS_POWER_SAVING_MODE_H_
* limitations under the License.
*/
-#ifndef __CONTEXT_DEVICESTATUS_TYPES_H__
-#define __CONTEXT_DEVICESTATUS_TYPES_H__
+#ifndef _DEVICE_SYSTEM_STATUS_TYPES_H_
+#define _DEVICE_SYSTEM_STATUS_TYPES_H_
// Subject
#define DEVICE_ST_SUBJ_BATTERY "system/battery"
#define TRIG_BOOL_ITEM_DEF(sbj) "\"" sbj "\":{\"type\":\"integer\",\"min\":0,\"max\":1}"
-#endif //__CONTEXT_DEVICESTATUS_TYPES_H__
+#endif //_DEVICE_SYSTEM_STATUS_TYPES_H_
#include <ContextManager.h>
#include <TimerManager.h>
-#include "system_types.h"
-#include "time.h"
+#include "SystemTypes.h"
+#include "Time.h"
-GENERATE_PROVIDER_COMMON_IMPL(device_status_time);
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusTime);
-ctx::device_status_time::device_status_time()
+ctx::DeviceStatusTime::DeviceStatusTime()
{
}
-ctx::device_status_time::~device_status_time()
+ctx::DeviceStatusTime::~DeviceStatusTime()
{
}
-bool ctx::device_status_time::is_supported()
+bool ctx::DeviceStatusTime::isSupported()
{
return true;
}
-void ctx::device_status_time::submit_trigger_item()
+void ctx::DeviceStatusTime::submitTriggerItem()
{
context_manager::registerTriggerItem(DEVICE_ST_SUBJ_TIME, OPS_READ,
"{"
NULL);
}
-int ctx::device_status_time::subscribe()
+int ctx::DeviceStatusTime::subscribe()
{
return ERR_NOT_SUPPORTED;
}
-int ctx::device_status_time::unsubscribe()
+int ctx::DeviceStatusTime::unsubscribe()
{
return ERR_NOT_SUPPORTED;
}
-int ctx::device_status_time::read()
+int ctx::DeviceStatusTime::read()
{
time_t rawtime;
- struct tm timeinfo;
+ struct tm timeInfo;
time(&rawtime);
tzset();
- localtime_r(&rawtime, &timeinfo);
+ 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);
+ 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, 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);
+ 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, day_of_week.c_str(), day_of_month);
+ _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);
* limitations under the License.
*/
-#ifndef _DEVICE_STATUS_TIME_H_
-#define _DEVICE_STATUS_TIME_H_
+#ifndef _DEVICE_SYSTEM_STATUS_TIME_H_
+#define _DEVICE_SYSTEM_STATUS_TIME_H_
-#include "../device_provider_base.h"
+#include "../DeviceProviderBase.h"
namespace ctx {
- class device_status_time : public device_provider_base {
+ class DeviceStatusTime : public DeviceProviderBase {
- GENERATE_PROVIDER_COMMON_DECL(device_status_time);
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusTime);
public:
int subscribe();
int unsubscribe();
int read();
- static bool is_supported();
- static void submit_trigger_item();
+ static bool isSupported();
+ static void submitTriggerItem();
private:
- device_status_time();
- ~device_status_time();
+ DeviceStatusTime();
+ ~DeviceStatusTime();
};
}
-#endif // _DEVICE_STATUS_TIME_H_
+#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 "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_
*/
#include <ContextManager.h>
-#include "../system_types.h"
-#include "charger.h"
+#include "../SystemTypes.h"
+#include "Charger.h"
-GENERATE_PROVIDER_COMMON_IMPL(device_status_charger);
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusCharger);
-ctx::device_status_charger::device_status_charger()
- : device_status_runtime_info(RUNTIME_INFO_KEY_CHARGER_CONNECTED)
+ctx::DeviceStatusCharger::DeviceStatusCharger() :
+ DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_CHARGER_CONNECTED)
{
}
-ctx::device_status_charger::~device_status_charger()
+ctx::DeviceStatusCharger::~DeviceStatusCharger()
{
}
-bool ctx::device_status_charger::is_supported()
+bool ctx::DeviceStatusCharger::isSupported()
{
return true;
}
-void ctx::device_status_charger::submit_trigger_item()
+void ctx::DeviceStatusCharger::submitTriggerItem()
{
context_manager::registerTriggerItem(DEVICE_ST_SUBJ_CHARGER, OPS_SUBSCRIBE | OPS_READ,
"{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL);
}
-void ctx::device_status_charger::handle_update()
+void ctx::DeviceStatusCharger::handleUpdate()
{
- bool charger_status = false;
+ bool chargerStatus = false;
- int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &charger_status);
+ 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, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+ 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::device_status_charger::read()
+int ctx::DeviceStatusCharger::read()
{
- bool charger_status = false;
+ bool chargerStatus = false;
ctx::Json dataRead;
- int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &charger_status);
+ 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, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
+ 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;
* limitations under the License.
*/
-#ifndef _DEVICE_STATUS_CHARGER_H_
-#define _DEVICE_STATUS_CHARGER_H_
+#ifndef _DEVICE_SYSTEM_STATUS_CHARGER_
+#define _DEVICE_SYSTEM_STATUS_CHARGER_
-#include "base_rtinfo.h"
+#include "RuntimeInfoBase.h"
namespace ctx {
- class device_status_charger : public device_status_runtime_info {
+ class DeviceStatusCharger : public DeviceStatusRuntimeInfo {
- GENERATE_PROVIDER_COMMON_DECL(device_status_charger);
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusCharger);
public:
int read();
- static bool is_supported();
- static void submit_trigger_item();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ protected:
+ void handleUpdate();
private:
- device_status_charger();
- ~device_status_charger();
- void handle_update();
+ DeviceStatusCharger();
+ ~DeviceStatusCharger();
};
}
-#endif // _DEVICE_STATUS_CHARGER_H_
+#endif // _DEVICE_SYSTEM_STATUS_CHARGER_H_
*/
#include <ContextManager.h>
-#include "../system_types.h"
-#include "gps.h"
+#include "../SystemTypes.h"
+#include "Gps.h"
-GENERATE_PROVIDER_COMMON_IMPL(device_status_gps);
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusGps);
-static const char* get_state_string(int gps_state)
+static const char* __getStatusString(int gpsStatus)
{
- switch (gps_state) {
+ switch (gpsStatus) {
case RUNTIME_INFO_GPS_STATUS_DISABLED:
return DEVICE_ST_DISABLED;
return DEVICE_ST_CONNECTED;
default:
- _E("Unknown GPS status: %d", gps_state);
+ _E("Unknown GPS status: %d", gpsStatus);
return NULL;
}
}
-ctx::device_status_gps::device_status_gps()
- : device_status_runtime_info(RUNTIME_INFO_KEY_GPS_STATUS)
+ctx::DeviceStatusGps::DeviceStatusGps() :
+ DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_GPS_STATUS)
{
}
-ctx::device_status_gps::~device_status_gps()
+ctx::DeviceStatusGps::~DeviceStatusGps()
{
}
-bool ctx::device_status_gps::is_supported()
+bool ctx::DeviceStatusGps::isSupported()
{
- return get_system_info_bool("tizen.org/feature/location.gps");
+ return getSystemInfoBool("tizen.org/feature/location.gps");
}
-void ctx::device_status_gps::submit_trigger_item()
+void ctx::DeviceStatusGps::submitTriggerItem()
{
context_manager::registerTriggerItem(DEVICE_ST_SUBJ_GPS, OPS_SUBSCRIBE | OPS_READ,
"{"
NULL);
}
-void ctx::device_status_gps::handle_update()
+void ctx::DeviceStatusGps::handleUpdate()
{
- int gps_status;
- int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gps_status);
+ 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* state_str = get_state_string(gps_status);
- IF_FAIL_VOID(state_str);
+ const char* stateStr = __getStatusString(gpsStatus);
+ IF_FAIL_VOID(stateStr);
- dataRead.set(NULL, DEVICE_ST_STATE, state_str);
+ dataRead.set(NULL, DEVICE_ST_STATE, stateStr);
context_manager::publish(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead);
}
-int ctx::device_status_gps::read()
+int ctx::DeviceStatusGps::read()
{
- int gps_status;
+ int gpsStatus;
ctx::Json dataRead;
- int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gps_status);
+ 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* state_str = get_state_string(gps_status);
- IF_FAIL_RETURN(state_str, ERR_OPERATION_FAILED);
+ const char* stateStr = __getStatusString(gpsStatus);
+ IF_FAIL_RETURN(stateStr, ERR_OPERATION_FAILED);
- dataRead.set(NULL, DEVICE_ST_STATE, state_str);
+ dataRead.set(NULL, DEVICE_ST_STATE, stateStr);
ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead);
return ERR_NONE;
* limitations under the License.
*/
-#ifndef _DEVICE_STATUS_USB_H_
-#define _DEVICE_STATUS_USB_H_
+#ifndef _DEVICE_SYSTEM_STATUS_GPS_H_
+#define _DEVICE_SYSTEM_STATUS_GPS_H_
-#include "base_rtinfo.h"
+#include "RuntimeInfoBase.h"
namespace ctx {
- class device_status_usb : public device_status_runtime_info {
+ class DeviceStatusGps : public DeviceStatusRuntimeInfo {
- GENERATE_PROVIDER_COMMON_DECL(device_status_usb);
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusGps);
public:
int read();
- static bool is_supported();
- static void submit_trigger_item();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ protected:
+ void handleUpdate();
private:
- device_status_usb();
- ~device_status_usb();
- void handle_update();
+ DeviceStatusGps();
+ ~DeviceStatusGps();
};
}
-#endif // _DEVICE_STATUS_USB_H_
+#endif // _DEVICE_SYSTEM_STATUS_GPS_H_
* limitations under the License.
*/
-#include "base_rtinfo.h"
+#include "RuntimeInfoBase.h"
-ctx::device_status_runtime_info::device_status_runtime_info(runtime_info_key_e key)
- : info_key(key)
+ctx::DeviceStatusRuntimeInfo::DeviceStatusRuntimeInfo(runtime_info_key_e key) :
+ __infoKey(key)
{
}
-runtime_info_key_e ctx::device_status_runtime_info::get_info_key()
+runtime_info_key_e ctx::DeviceStatusRuntimeInfo::__getInfoKey()
{
- return info_key;
+ return __infoKey;
}
-void ctx::device_status_runtime_info::update_cb(runtime_info_key_e key, void* user_data)
+void ctx::DeviceStatusRuntimeInfo::updateCb(runtime_info_key_e runtimeKey, void* userData)
{
- 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();
+ DeviceStatusRuntimeInfo *instance = static_cast<DeviceStatusRuntimeInfo*>(userData);
+ IF_FAIL_VOID_TAG(runtimeKey == instance->__getInfoKey(), _W, "Runtime info key mismatch");
+ instance->handleUpdate();
}
-int ctx::device_status_runtime_info::subscribe()
+int ctx::DeviceStatusRuntimeInfo::subscribe()
{
- int ret = runtime_info_set_changed_cb(info_key, update_cb, this);
+ 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::device_status_runtime_info::unsubscribe()
+int ctx::DeviceStatusRuntimeInfo::unsubscribe()
{
- int ret = runtime_info_unset_changed_cb(info_key);
+ int ret = runtime_info_unset_changed_cb(__infoKey);
IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
return ERR_NONE;
}
* limitations under the License.
*/
-#ifndef __CONTEXT_DEVICE_STATUS_RUNTIME_INFO_H__
-#define __CONTEXT_DEVICE_STATUS_RUNTIME_INFO_H__
+#ifndef _DEVICE_SYSTEM_STATUS_RUNTIME_INFO_BASE_H_
+#define _DEVICE_SYSTEM_STATUS_RUNTIME_INFO_BASE_H_
#include <runtime_info.h>
-#include "../../device_provider_base.h"
+#include "../../DeviceProviderBase.h"
namespace ctx {
- class device_status_runtime_info : public device_provider_base {
+ class DeviceStatusRuntimeInfo : public DeviceProviderBase {
public:
- device_status_runtime_info(runtime_info_key_e key);
+ DeviceStatusRuntimeInfo(runtime_info_key_e key);
int subscribe();
int unsubscribe();
virtual int read() = 0;
protected:
- runtime_info_key_e info_key;
+ runtime_info_key_e __infoKey;
- virtual ~device_status_runtime_info(){}
- static void update_cb(runtime_info_key_e runtime_key, void* user_data);
- virtual void handle_update() = 0;
+ virtual ~DeviceStatusRuntimeInfo(){}
+ static void updateCb(runtime_info_key_e runtimeKey, void* userData);
+ virtual void handleUpdate() = 0;
private:
- runtime_info_key_e get_info_key();
+ runtime_info_key_e __getInfoKey();
};
}
-#endif
+#endif // _DEVICE_SYSTEM_STATUS_RUNTIME_INFO_BASE_H_
*/
#include <ContextManager.h>
-#include "../system_types.h"
-#include "usb.h"
+#include "../SystemTypes.h"
+#include "Usb.h"
-GENERATE_PROVIDER_COMMON_IMPL(device_status_usb);
+GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusUsb);
-ctx::device_status_usb::device_status_usb()
- : device_status_runtime_info(RUNTIME_INFO_KEY_USB_CONNECTED)
+ctx::DeviceStatusUsb::DeviceStatusUsb() :
+ DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_USB_CONNECTED)
{
}
-ctx::device_status_usb::~device_status_usb()
+ctx::DeviceStatusUsb::~DeviceStatusUsb()
{
}
-bool ctx::device_status_usb::is_supported()
+bool ctx::DeviceStatusUsb::isSupported()
{
- return get_system_info_bool("tizen.org/feature/usb.host");
+ return getSystemInfoBool("tizen.org/feature/usb.host");
}
-void ctx::device_status_usb::submit_trigger_item()
+void ctx::DeviceStatusUsb::submitTriggerItem()
{
context_manager::registerTriggerItem(DEVICE_ST_SUBJ_USB, OPS_SUBSCRIBE | OPS_READ,
"{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL);
}
-void ctx::device_status_usb::handle_update()
+void ctx::DeviceStatusUsb::handleUpdate()
{
bool status = false;
context_manager::publish(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, dataRead);
}
-int ctx::device_status_usb::read()
+int ctx::DeviceStatusUsb::read()
{
bool status = false;
ctx::Json dataRead;
* limitations under the License.
*/
-#ifndef _DEVICE_STATUS_GPS_H_
-#define _DEVICE_STATUS_GPS_H_
+#ifndef _DEVICE_SYSTEM_STATUS_USB_H_
+#define _DEVICE_SYSTEM_STATUS_USB_H_
-#include "base_rtinfo.h"
+#include "RuntimeInfoBase.h"
namespace ctx {
- class device_status_gps : public device_status_runtime_info {
+ class DeviceStatusUsb : public DeviceStatusRuntimeInfo {
- GENERATE_PROVIDER_COMMON_DECL(device_status_gps);
+ GENERATE_PROVIDER_COMMON_DECL(DeviceStatusUsb);
public:
int read();
- static bool is_supported();
- static void submit_trigger_item();
+ static bool isSupported();
+ static void submitTriggerItem();
+
+ protected:
+ void handleUpdate();
private:
- device_status_gps();
- ~device_status_gps();
- void handle_update();
+ DeviceStatusUsb();
+ ~DeviceStatusUsb();
};
}
-#endif // _DEVICE_STATUS_GPS_H_
+#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.
- */
-
-#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