From ffde390acc2e2ef89d44d1e037e87d284e59a457 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 18 Apr 2016 17:53:10 +0900 Subject: [PATCH] Refactor provider instance initialization routines Change-Id: I552e9278ebbfbc408ef76f6a5a5a913fa2d128f1 Signed-off-by: Mu-Woong Lee --- include/CustomContextProvider.h | 2 +- src/CMakeLists.txt | 2 +- src/custom/CustomBase.h | 4 +- src/custom/CustomContextProvider.cpp | 4 +- src/device/CMakeLists.txt | 2 +- src/device/DeviceContextProvider.cpp | 35 ++--- src/device/DeviceProviderBase.cpp | 49 ++++--- src/device/DeviceProviderBase.h | 61 ++------- src/device/activity/Activity.h | 30 +--- src/device/activity/ActivityBase.cpp | 42 +++--- src/device/activity/ActivityBase.h | 10 +- src/device/social/Call.cpp | 57 ++++---- src/device/social/Call.h | 16 +-- src/device/social/Contacts.cpp | 33 +++-- src/device/social/Contacts.h | 14 +- src/device/social/Email.cpp | 30 ++-- src/device/social/Email.h | 15 +- src/device/social/Message.cpp | 31 ++--- src/device/social/Message.h | 14 +- src/device/system/Alarm.cpp | 84 ++++-------- src/device/system/Alarm.h | 37 ++--- src/device/system/Battery.cpp | 34 ++--- src/device/system/Battery.h | 13 +- src/device/system/Headphone.cpp | 56 ++++---- src/device/system/Headphone.h | 14 +- src/device/system/Psmode.cpp | 32 ++--- src/device/system/Psmode.h | 13 +- src/device/system/Time.cpp | 26 ++-- src/device/system/Time.h | 13 +- src/device/system/Wifi.cpp | 67 ++++----- src/device/system/Wifi.h | 14 +- src/device/system/runtime_info/Charger.cpp | 27 ++-- src/device/system/runtime_info/Charger.h | 15 +- src/device/system/runtime_info/Gps.cpp | 27 ++-- src/device/system/runtime_info/Gps.h | 15 +- .../system/runtime_info/RuntimeInfoBase.cpp | 13 +- .../system/runtime_info/RuntimeInfoBase.h | 2 +- src/device/system/runtime_info/Usb.cpp | 27 ++-- src/device/system/runtime_info/Usb.h | 15 +- src/place/PlaceContextProvider.cpp | 15 +- src/place/geofence/GeofenceMonitorHandle.cpp | 84 ++++++------ src/place/geofence/GeofenceMonitorHandle.h | 6 +- src/place/geofence/PlaceGeofenceProvider.cpp | 78 ++--------- src/place/geofence/PlaceGeofenceProvider.h | 31 ++--- src/place/recognition/place_recognition.cpp | 32 +---- src/place/recognition/place_recognition.h | 29 ++-- src/statistics/CMakeLists.txt | 6 - src/statistics/StatisticsContextProvider.cpp | 75 +++++----- src/statistics/app/AppStatisticsProvider.cpp | 128 ------------------ src/statistics/app/AppStatisticsProvider.h | 48 ------- src/statistics/app/AppStatisticsTypes.h | 1 + src/statistics/app/AppStatsLogger.cpp | 57 ++++++++ src/statistics/app/AppStatsLogger.h | 45 ++++++ src/statistics/app/AppStatsProvider.cpp | 57 ++++++++ src/statistics/app/AppStatsProvider.h | 81 +++++++++++ src/statistics/app/DbHandle.cpp | 39 +++--- src/statistics/app/DbHandle.h | 20 +-- .../AppInactiveDetector.cpp | 2 +- .../AppInactiveDetector.h | 6 +- src/statistics/media/DbHandle.cpp | 37 ++--- src/statistics/media/DbHandle.h | 14 +- .../media/MediaStatisticsProvider.cpp | 113 ---------------- .../media/MediaStatisticsProvider.h | 48 ------- src/statistics/media/MediaStatisticsTypes.h | 1 + src/statistics/media/MediaStatsLogger.cpp | 39 ++++++ src/statistics/media/MediaStatsLogger.h | 42 ++++++ src/statistics/media/MediaStatsProvider.cpp | 67 +++++++++ src/statistics/media/MediaStatsProvider.h | 85 ++++++++++++ src/statistics/shared/DbHandleBase.cpp | 39 +++--- src/statistics/shared/DbHandleBase.h | 25 ++-- src/statistics/shared/SystemInfo.cpp | 10 +- src/statistics/social/DbHandle.cpp | 31 +++-- src/statistics/social/DbHandle.h | 12 +- .../social/SocialStatisticsProvider.cpp | 111 --------------- .../social/SocialStatisticsProvider.h | 48 ------- src/statistics/social/SocialStatisticsTypes.h | 1 + src/statistics/social/SocialStatsLogger.cpp | 39 ++++++ src/statistics/social/SocialStatsLogger.h | 42 ++++++ src/statistics/social/SocialStatsProvider.cpp | 63 +++++++++ src/statistics/social/SocialStatsProvider.h | 55 ++++++++ 80 files changed, 1348 insertions(+), 1409 deletions(-) delete mode 100644 src/statistics/app/AppStatisticsProvider.cpp delete mode 100644 src/statistics/app/AppStatisticsProvider.h create mode 100644 src/statistics/app/AppStatsLogger.cpp create mode 100644 src/statistics/app/AppStatsLogger.h create mode 100644 src/statistics/app/AppStatsProvider.cpp create mode 100644 src/statistics/app/AppStatsProvider.h delete mode 100644 src/statistics/media/MediaStatisticsProvider.cpp delete mode 100644 src/statistics/media/MediaStatisticsProvider.h create mode 100644 src/statistics/media/MediaStatsLogger.cpp create mode 100644 src/statistics/media/MediaStatsLogger.h create mode 100644 src/statistics/media/MediaStatsProvider.cpp create mode 100644 src/statistics/media/MediaStatsProvider.h delete mode 100644 src/statistics/social/SocialStatisticsProvider.cpp delete mode 100644 src/statistics/social/SocialStatisticsProvider.h create mode 100644 src/statistics/social/SocialStatsLogger.cpp create mode 100644 src/statistics/social/SocialStatsLogger.h create mode 100644 src/statistics/social/SocialStatsProvider.cpp create mode 100644 src/statistics/social/SocialStatsProvider.h diff --git a/include/CustomContextProvider.h b/include/CustomContextProvider.h index c75d63e..b000fa5 100644 --- a/include/CustomContextProvider.h +++ b/include/CustomContextProvider.h @@ -27,7 +27,7 @@ namespace ctx { int removeItem(std::string subject); int publishData(std::string subject, ctx::Json fact); - ContextProviderBase* create(void* data); + ContextProvider* create(void* data); void destroy(void* data); } /* namespace custom_context_provider */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ed647fd..5926ed8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,7 +14,7 @@ ENDFUNCTION(add_provider) add_provider(device) add_provider(statistics) add_provider(place) -add_provider(custom) +#add_provider(custom) LIST(REMOVE_DUPLICATES deps_collected) diff --git a/src/custom/CustomBase.h b/src/custom/CustomBase.h index 07504ec..13c9d99 100644 --- a/src/custom/CustomBase.h +++ b/src/custom/CustomBase.h @@ -18,12 +18,12 @@ #define _CONTEXT_CUSTOM_BASE_H_ #include -#include +#include #include namespace ctx { - class CustomBase : public ContextProviderBase { + class CustomBase : public ContextProvider { public: CustomBase(std::string subject, std::string name, ctx::Json tmpl, std::string owner); ~CustomBase(); diff --git a/src/custom/CustomContextProvider.cpp b/src/custom/CustomContextProvider.cpp index 61990b0..bcfb7bc 100644 --- a/src/custom/CustomContextProvider.cpp +++ b/src/custom/CustomContextProvider.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include "CustomBase.h" @@ -45,7 +45,7 @@ void unregisterProvider(const char* subject) ctx::context_manager::unregisterProvider(subject); } -SO_EXPORT ctx::ContextProviderBase* ctx::custom_context_provider::create(void *data) +SO_EXPORT ctx::ContextProvider* ctx::custom_context_provider::create(void *data) { // Already created in addItem() function. Return corresponding custom provider return __customMap[static_cast(data)]; diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt index 20276e3..16f436f 100644 --- a/src/device/CMakeLists.txt +++ b/src/device/CMakeLists.txt @@ -7,7 +7,7 @@ SET(prvd_deps vconf capi-system-info capi-system-device capi-system-runtime-info # Mobile Profile IF("${PROFILE}" STREQUAL "mobile") - SET(prvd_deps ${prvd_deps} capi-network-bluetooth capi-network-wifi) + SET(prvd_deps ${prvd_deps} capi-network-bluetooth capi-network-wifi contacts-service2) SET(prvd_deps ${prvd_deps} capi-telephony tapi msg-service capi-messaging-email motion) FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} activity/*.cpp) FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} system/*.cpp) diff --git a/src/device/DeviceContextProvider.cpp b/src/device/DeviceContextProvider.cpp index a6c2b85..332efdc 100644 --- a/src/device/DeviceContextProvider.cpp +++ b/src/device/DeviceContextProvider.cpp @@ -15,8 +15,7 @@ */ #include -#include -#include +#include #include #include "system/SystemTypes.h" @@ -54,11 +53,6 @@ #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" @@ -67,12 +61,16 @@ template void registerProvider(const char *subject, const char *privilege) { - if (!Provider::isSupported()) + Provider *provider = new(std::nothrow) Provider(); + IF_FAIL_VOID_TAG(provider, _E, "Memory allocation failed"); + + if (!provider->isSupported()) { + delete provider; return; + } - ctx::ContextProviderInfo providerInfo(Provider::create, Provider::destroy, NULL, privilege); - ctx::context_manager::registerProvider(subject, providerInfo); - Provider::submitTriggerItem(); + provider->registerProvider(privilege, provider); + provider->submitTriggerItem(); } SO_EXPORT bool ctx::initDeviceContextProvider() @@ -101,8 +99,10 @@ SO_EXPORT bool ctx::initDeviceContextProvider() registerProvider(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_ @@ -122,19 +122,6 @@ SO_EXPORT bool ctx::initDeviceContextProvider() registerProvider(USER_ACT_SUBJ_WALKING, NULL); registerProvider(USER_ACT_SUBJ_RUNNING, NULL); registerProvider(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(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); - registerProvider(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; diff --git a/src/device/DeviceProviderBase.cpp b/src/device/DeviceProviderBase.cpp index db8e069..1c5f5ef 100644 --- a/src/device/DeviceProviderBase.cpp +++ b/src/device/DeviceProviderBase.cpp @@ -17,12 +17,24 @@ #include #include "DeviceProviderBase.h" -ctx::DeviceProviderBase::DeviceProviderBase() : +using namespace ctx; + +DeviceProviderBase::DeviceProviderBase(const char *subject) : + ContextProvider(subject), __beingSubscribed(false) { } -int ctx::DeviceProviderBase::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) +bool DeviceProviderBase::isSupported() +{ + return true; +} + +void DeviceProviderBase::submitTriggerItem() +{ +} + +int DeviceProviderBase::subscribe(Json option, Json *requestResult) { IF_FAIL_RETURN(!__beingSubscribed, ERR_NONE); @@ -30,64 +42,51 @@ int ctx::DeviceProviderBase::subscribe(const char *subject, ctx::Json option, ct if (ret == ERR_NONE) __beingSubscribed = true; - else - destroySelf(); return ret; } -int ctx::DeviceProviderBase::unsubscribe(const char *subject, ctx::Json option) +int DeviceProviderBase::unsubscribe(Json option) { int ret = ERR_NONE; if (__beingSubscribed) ret = unsubscribe(); - destroySelf(); return ret; } -int ctx::DeviceProviderBase::read(const char *subject, ctx::Json option, ctx::Json *requestResult) +int DeviceProviderBase::read(Json option, Json *requestResult) { - int ret = read(); - - if (!__beingSubscribed) - destroySelf(); - - return ret; + return read(); } -int ctx::DeviceProviderBase::write(const char *subject, ctx::Json data, ctx::Json *requestResult) +int DeviceProviderBase::write(Json data, Json *requestResult) { - int ret = write(); - - if (!__beingSubscribed) - destroySelf(); - - return ret; + return write(); } -int ctx::DeviceProviderBase::subscribe() +int DeviceProviderBase::subscribe() { return ERR_NOT_SUPPORTED; } -int ctx::DeviceProviderBase::unsubscribe() +int DeviceProviderBase::unsubscribe() { return ERR_NOT_SUPPORTED; } -int ctx::DeviceProviderBase::read() +int DeviceProviderBase::read() { return ERR_NOT_SUPPORTED; } -int ctx::DeviceProviderBase::write() +int DeviceProviderBase::write() { return ERR_NOT_SUPPORTED; } -bool ctx::DeviceProviderBase::getSystemInfoBool(const char *key) +bool DeviceProviderBase::getSystemInfoBool(const char *key) { bool supported = false; int ret = system_info_get_platform_bool(key, &supported); diff --git a/src/device/DeviceProviderBase.h b/src/device/DeviceProviderBase.h index 323abe7..f5a55da 100644 --- a/src/device/DeviceProviderBase.h +++ b/src/device/DeviceProviderBase.h @@ -17,71 +17,30 @@ #ifndef _CONTEXT_DEVICE_PROVIDER_BASE_H_ #define _CONTEXT_DEVICE_PROVIDER_BASE_H_ -#include -#include -#include - -#define CREATE_INSTANCE(prvd) \ - do { \ - IF_FAIL_RETURN(!__instance, __instance); \ - __instance = new(std::nothrow) prvd(); \ - IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); \ - _I(BLUE("Created")); \ - return __instance; \ - } while (0) \ - -#define DESTROY_INSTANCE() \ - do { \ - IF_FAIL_VOID(__instance); \ - delete __instance; \ - __instance = NULL; \ - _I(BLUE("Destroyed")); \ - } while (0) \ - -#define GENERATE_PROVIDER_COMMON_DECL(prvd) \ - public: \ - static ContextProviderBase *create(void *data); \ - static void destroy(void *data); \ - protected: \ - void destroySelf(); \ - private: \ - static prvd *__instance; \ - -#define GENERATE_PROVIDER_COMMON_IMPL(prvd) \ - ctx::prvd *ctx::prvd::__instance = NULL; \ - ctx::ContextProviderBase *ctx::prvd::create(void *data) \ - { \ - CREATE_INSTANCE(prvd); \ - } \ - void ctx::prvd::destroy(void *data) \ - { \ - DESTROY_INSTANCE(); \ - } \ - void ctx::prvd::destroySelf() \ - { \ - destroy(NULL); \ - } \ +#include namespace ctx { - class DeviceProviderBase : public ContextProviderBase { + class DeviceProviderBase : public ContextProvider { 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(Json option, Json *requestResult); + int unsubscribe(Json option); + int read(Json option, Json *requestResult); + int write(Json data, Json *requestResult); + + virtual bool isSupported(); + virtual void submitTriggerItem(); protected: bool __beingSubscribed; - DeviceProviderBase(); + DeviceProviderBase(const char *subject); virtual ~DeviceProviderBase() {} virtual int subscribe(); virtual int unsubscribe(); virtual int read(); virtual int write(); - virtual void destroySelf() = 0; static bool getSystemInfoBool(const char *key); }; diff --git a/src/device/activity/Activity.h b/src/device/activity/Activity.h index b7bf49e..f50b283 100644 --- a/src/device/activity/Activity.h +++ b/src/device/activity/Activity.h @@ -17,41 +17,13 @@ #ifndef _DEVICE_ACTIVITY_STATUS_H_ #define _DEVICE_ACTIVITY_STATUS_H_ -#include #include "ActivityBase.h" #define GENERATE_ACTIVITY_PROVIDER(actPrvd, actSubj, actType) \ class actPrvd : public UserActivityBase { \ public: \ - static ContextProviderBase *create(void *data) \ - { \ - CREATE_INSTANCE(ctx::actPrvd); \ - } \ - static void destroy(void *data) \ - { \ - DESTROY_INSTANCE(); \ - } \ - static bool isSupported() \ - { \ - return getSystemInfoBool("tizen.org/feature/sensor.activity_recognition"); \ - } \ - static void submitTriggerItem() \ - { \ - context_manager::registerTriggerItem((actSubj), OPS_SUBSCRIBE, \ - "{\"Event\":{\"type\":\"string\", \"values\":[\"Detected\"]}}", \ - "{\"Accuracy\":{\"type\":\"string\", \"values\":[\"Low\", \"Normal\", \"High\"]}}" \ - ); \ - } \ - protected: \ - void destroySelf() \ - { \ - destroy(NULL); \ - } \ - private: \ - static actPrvd *__instance; \ - actPrvd() : UserActivityBase((actSubj), (actType)) {} \ + actPrvd() : UserActivityBase(actSubj, actType) {} \ }; \ - ctx::actPrvd *ctx::actPrvd::__instance = NULL; \ namespace ctx { GENERATE_ACTIVITY_PROVIDER(UserActivityStationary, USER_ACT_SUBJ_STATIONARY, ACTIVITY_STATIONARY); diff --git a/src/device/activity/ActivityBase.cpp b/src/device/activity/ActivityBase.cpp index 8b16c28..4abda04 100644 --- a/src/device/activity/ActivityBase.cpp +++ b/src/device/activity/ActivityBase.cpp @@ -14,25 +14,39 @@ * limitations under the License. */ -#include -#include +#include #include "ActivityTypes.h" #include "ActivityBase.h" -ctx::UserActivityBase::UserActivityBase(const char *subj, activity_type_e type) : +using namespace ctx; + +UserActivityBase::UserActivityBase(const char *subject, activity_type_e type) : + DeviceProviderBase(subject), __activityType(type), - __activityHandle(NULL), - __subject(subj) + __activityHandle(NULL) { } -ctx::UserActivityBase::~UserActivityBase() +UserActivityBase::~UserActivityBase() { if (__activityHandle) activity_release(__activityHandle); } -void ctx::UserActivityBase::__updateCb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* userData) +bool UserActivityBase::isSupported() +{ + return getSystemInfoBool("tizen.org/feature/sensor.activity_recognition"); +} + +void UserActivityBase::submitTriggerItem() +{ + registerTriggerItem(OPS_SUBSCRIBE, + "{\"Event\":{\"type\":\"string\", \"values\":[\"Detected\"]}}", + "{\"Accuracy\":{\"type\":\"string\", \"values\":[\"Low\", \"Normal\", \"High\"]}}" + ); +} + +void UserActivityBase::__updateCb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* userData) { IF_FAIL_VOID_TAG(error == ACTIVITY_ERROR_NONE, _E, "Error: %d", error); @@ -40,11 +54,11 @@ void ctx::UserActivityBase::__updateCb(activity_type_e activity, const activity_ instance->__handleUpdate(activity, data, timestamp); } -void ctx::UserActivityBase::__handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp) +void UserActivityBase::__handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp) { IF_FAIL_VOID_TAG(activity == __activityType, _E, "Invalid activity: %d", activity); - ctx::Json dataRead; + Json dataRead; dataRead.set(NULL, USER_ACT_EVENT, USER_ACT_DETECTED); activity_accuracy_e accuracy = ACTIVITY_ACCURACY_LOW; @@ -62,15 +76,13 @@ void ctx::UserActivityBase::__handleUpdate(activity_type_e activity, const activ break; } - context_manager::publish(__subject.c_str(), NULL, ERR_NONE, dataRead); + publish(NULL, ERR_NONE, dataRead); } -int ctx::UserActivityBase::subscribe() +int UserActivityBase::subscribe() { IF_FAIL_RETURN(__activityHandle == NULL, ERR_NONE); - _D("Starting to monitor %s", __subject.c_str()); - activity_create(&__activityHandle); IF_FAIL_RETURN_TAG(__activityHandle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); @@ -85,12 +97,10 @@ int ctx::UserActivityBase::subscribe() return ERR_NONE; } -int ctx::UserActivityBase::unsubscribe() +int UserActivityBase::unsubscribe() { IF_FAIL_RETURN(__activityHandle, ERR_NONE); - _D("Stop monitoring %s", __subject.c_str()); - activity_stop_recognition(__activityHandle); activity_release(__activityHandle); __activityHandle = NULL; diff --git a/src/device/activity/ActivityBase.h b/src/device/activity/ActivityBase.h index c7ce566..ef68d58 100644 --- a/src/device/activity/ActivityBase.h +++ b/src/device/activity/ActivityBase.h @@ -25,16 +25,18 @@ namespace ctx { class UserActivityBase : public DeviceProviderBase { public: + UserActivityBase(const char *subject, activity_type_e type); + virtual ~UserActivityBase(); + int subscribe(); int unsubscribe(); + bool isSupported(); + void submitTriggerItem(); + protected: activity_type_e __activityType; activity_h __activityHandle; - std::string __subject; - - UserActivityBase(const char *subj, activity_type_e type); - virtual ~UserActivityBase(); private: void __handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp); diff --git a/src/device/social/Call.cpp b/src/device/social/Call.cpp index d8bbebe..460c281 100644 --- a/src/device/social/Call.cpp +++ b/src/device/social/Call.cpp @@ -14,14 +14,12 @@ * limitations under the License. */ -#include -#include -#include #include "SocialTypes.h" #include "Call.h" #define TELEPHONY_NOTI_ID_CNT 8 -GENERATE_PROVIDER_COMMON_IMPL(SocialStatusCall); + +using namespace ctx; static bool __telephonyInitialized = false; static telephony_noti_e __callNotiIds[] = @@ -38,42 +36,43 @@ static telephony_noti_e __callNotiIds[] = TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING, TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING, }; -static ctx::Json __latest; +static Json __latest; -ctx::SocialStatusCall::SocialStatusCall() +SocialStatusCall::SocialStatusCall() : + DeviceProviderBase(SOCIAL_ST_SUBJ_CALL) { __handleList.count = 0; __handleList.handle = NULL; } -ctx::SocialStatusCall::~SocialStatusCall() +SocialStatusCall::~SocialStatusCall() { } -bool ctx::SocialStatusCall::isSupported() +bool SocialStatusCall::isSupported() { return getSystemInfoBool("tizen.org/feature/network.telephony"); } -void ctx::SocialStatusCall::submitTriggerItem() +void SocialStatusCall::submitTriggerItem() { - context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CALL, OPS_SUBSCRIBE | OPS_READ, + registerTriggerItem(OPS_SUBSCRIBE | OPS_READ, "{" "\"Medium\":{\"type\":\"string\",\"values\":[\"Voice\",\"Video\"]}," "\"State\":{\"type\":\"string\",\"values\":[\"Idle\",\"Connecting\",\"Connected\"]}," "\"Address\":{\"type\":\"string\"}" "}", NULL); - //TODO remove Connecting, Connected + /* TODO remove Connecting, Connected */ } -void ctx::SocialStatusCall::__updateCb(telephony_h handle, telephony_noti_e notiId, void *data, void *userData) +void SocialStatusCall::__updateCb(telephony_h handle, telephony_noti_e notiId, void *data, void *userData) { SocialStatusCall *instance = static_cast(userData); instance->__handleUpdate(handle, notiId, data); } -void ctx::SocialStatusCall::__handleUpdate(telephony_h handle, telephony_noti_e notiId, void* id) +void SocialStatusCall::__handleUpdate(telephony_h handle, telephony_noti_e notiId, void* id) { Json data; unsigned int count; @@ -153,13 +152,13 @@ void ctx::SocialStatusCall::__handleUpdate(telephony_h handle, telephony_noti_e } if (__latest != data) { - context_manager::publish(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data); + publish(NULL, ERR_NONE, data); __latest = data.str(); } telephony_call_release_call_list(count, &callList); } -bool ctx::SocialStatusCall::__initTelephony() +bool SocialStatusCall::__initTelephony() { IF_FAIL_RETURN(!__telephonyInitialized, true); @@ -170,7 +169,7 @@ bool ctx::SocialStatusCall::__initTelephony() return true; } -void ctx::SocialStatusCall::__releaseTelephony() +void SocialStatusCall::__releaseTelephony() { IF_FAIL_VOID(__telephonyInitialized); @@ -179,9 +178,9 @@ void ctx::SocialStatusCall::__releaseTelephony() __telephonyInitialized = false; } -bool ctx::SocialStatusCall::__setCallback() +bool SocialStatusCall::__setCallback() { - //TODO: Consider dual-sim devices + /* TODO: Consider dual-sim devices */ IF_FAIL_RETURN_TAG(__initTelephony(), false, _E, "Initialization failed"); int err; @@ -201,7 +200,7 @@ CATCH: return false; } -void ctx::SocialStatusCall::__unsetCallback() +void SocialStatusCall::__unsetCallback() { for (unsigned int i = 0; i < __handleList.count; i++) { for (unsigned int j = 0; j < TELEPHONY_NOTI_ID_CNT; j++) { @@ -212,7 +211,7 @@ void ctx::SocialStatusCall::__unsetCallback() __releaseTelephony(); } -bool ctx::SocialStatusCall::__getCallState(telephony_call_h& handle, std::string& state) +bool SocialStatusCall::__getCallState(telephony_call_h& handle, std::string& state) { state.clear(); @@ -245,7 +244,7 @@ bool ctx::SocialStatusCall::__getCallState(telephony_call_h& handle, std::string return true; } -bool ctx::SocialStatusCall::__getCallType(telephony_call_h& handle, std::string& type) +bool SocialStatusCall::__getCallType(telephony_call_h& handle, std::string& type) { type.clear(); @@ -270,7 +269,7 @@ bool ctx::SocialStatusCall::__getCallType(telephony_call_h& handle, std::string& return true; } -bool ctx::SocialStatusCall::__getCallAddress(telephony_call_h& handle, std::string& address) +bool SocialStatusCall::__getCallAddress(telephony_call_h& handle, std::string& address) { address.clear(); @@ -280,7 +279,7 @@ bool ctx::SocialStatusCall::__getCallAddress(telephony_call_h& handle, std::stri if (number) { address = number; - free(number); + g_free(number); number = NULL; } @@ -289,7 +288,7 @@ bool ctx::SocialStatusCall::__getCallAddress(telephony_call_h& handle, std::stri return true; } -bool ctx::SocialStatusCall::__getCallHandleId(telephony_call_h& handle, unsigned int& id) +bool 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"); @@ -297,20 +296,20 @@ bool ctx::SocialStatusCall::__getCallHandleId(telephony_call_h& handle, unsigned return true; } -int ctx::SocialStatusCall::subscribe() +int SocialStatusCall::subscribe() { bool ret = __setCallback(); IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::SocialStatusCall::unsubscribe() +int SocialStatusCall::unsubscribe() { __unsetCallback(); return ERR_NONE; } -bool ctx::SocialStatusCall::__readCurrentStatus(telephony_h& handle, ctx::Json* data) +bool SocialStatusCall::__readCurrentStatus(telephony_h& handle, Json* data) { unsigned int count = 0; telephony_call_h *callList = NULL; @@ -352,7 +351,7 @@ bool ctx::SocialStatusCall::__readCurrentStatus(telephony_h& handle, ctx::Json* return true; } -int ctx::SocialStatusCall::read() +int SocialStatusCall::read() { bool temporaryHandle = false; if (!__telephonyInitialized) { @@ -380,7 +379,7 @@ int ctx::SocialStatusCall::read() __releaseTelephony(); if (ret) { - ctx::context_manager::replyToRead(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data); + replyToRead(NULL, ERR_NONE, data); return ERR_NONE; } diff --git a/src/device/social/Call.h b/src/device/social/Call.h index 38fdab9..02a4eaa 100644 --- a/src/device/social/Call.h +++ b/src/device/social/Call.h @@ -23,27 +23,25 @@ namespace ctx { class SocialStatusCall : public DeviceProviderBase { - - GENERATE_PROVIDER_COMMON_DECL(SocialStatusCall); - public: + SocialStatusCall(); + ~SocialStatusCall(); + int subscribe(); int unsubscribe(); int read(); - static bool isSupported(); - static void submitTriggerItem(); + + bool isSupported(); + 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 __readCurrentStatus(telephony_h& handle, Json* data); bool __getCallState(telephony_call_h& handle, std::string& state); bool __getCallType(telephony_call_h& handle, std::string& type); diff --git a/src/device/social/Contacts.cpp b/src/device/social/Contacts.cpp index 4604c37..55ff19a 100644 --- a/src/device/social/Contacts.cpp +++ b/src/device/social/Contacts.cpp @@ -14,8 +14,6 @@ * limitations under the License. */ -#include -#include #include "SocialTypes.h" #include "Contacts.h" @@ -23,26 +21,27 @@ #define PERSON_VIEW _contacts_person._uri #define TIME_INTERVAL 1 -GENERATE_PROVIDER_COMMON_IMPL(SocialStatusContacts); +using namespace ctx; -ctx::SocialStatusContacts::SocialStatusContacts() : +SocialStatusContacts::SocialStatusContacts() : + DeviceProviderBase(SOCIAL_ST_SUBJ_CONTACTS), __latestMyProfile(0), __latestPerson(0) { } -ctx::SocialStatusContacts::~SocialStatusContacts() +SocialStatusContacts::~SocialStatusContacts() { } -bool ctx::SocialStatusContacts::isSupported() +bool SocialStatusContacts::isSupported() { return true; } -void ctx::SocialStatusContacts::submitTriggerItem() +void SocialStatusContacts::submitTriggerItem() { - context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CONTACTS, OPS_SUBSCRIBE, + registerTriggerItem(OPS_SUBSCRIBE, "{" "\"Event\":{\"type\":\"string\",\"values\":[\"Changed\"]}," "\"Type\":{\"type\":\"string\",\"values\":[\"MyProfile\",\"Person\"]}" @@ -50,13 +49,13 @@ void ctx::SocialStatusContacts::submitTriggerItem() NULL); } -void ctx::SocialStatusContacts::__updateCb(const char* viewUri, void* userData) +void SocialStatusContacts::__updateCb(const char* viewUri, void* userData) { SocialStatusContacts *instance = static_cast(userData); instance->__handleUpdate(viewUri); } -void ctx::SocialStatusContacts::__handleUpdate(const char* viewUri) +void SocialStatusContacts::__handleUpdate(const char* viewUri) { if (!STR_EQ(viewUri, _contacts_my_profile._uri) && !STR_EQ(viewUri, _contacts_person._uri)) { _W("Unknown view uri"); @@ -66,13 +65,13 @@ void ctx::SocialStatusContacts::__handleUpdate(const char* viewUri) 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; + Json data; data.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_CHANGED); data.set(NULL, SOCIAL_ST_TYPE, view); - context_manager::publish(SOCIAL_ST_SUBJ_CONTACTS, NULL, ERR_NONE, data); + publish(NULL, ERR_NONE, data); } -bool ctx::SocialStatusContacts::__isConsecutiveChange(const char* viewUri) +bool SocialStatusContacts::__isConsecutiveChange(const char* viewUri) { time_t now = time(NULL); double diff = 0; @@ -91,7 +90,7 @@ bool ctx::SocialStatusContacts::__isConsecutiveChange(const char* viewUri) return false; } -bool ctx::SocialStatusContacts::__setCallback() +bool SocialStatusContacts::__setCallback() { int err; @@ -111,7 +110,7 @@ CATCH: return false; } -void ctx::SocialStatusContacts::__unsetCallback() +void SocialStatusContacts::__unsetCallback() { contacts_db_remove_changed_cb(MY_PROFILE_VIEW, __updateCb, this); contacts_db_remove_changed_cb(PERSON_VIEW, __updateCb, this); @@ -122,14 +121,14 @@ void ctx::SocialStatusContacts::__unsetCallback() __latestPerson = 0; } -int ctx::SocialStatusContacts::subscribe() +int SocialStatusContacts::subscribe() { bool ret = __setCallback(); IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::SocialStatusContacts::unsubscribe() +int SocialStatusContacts::unsubscribe() { __unsetCallback(); return ERR_NONE; diff --git a/src/device/social/Contacts.h b/src/device/social/Contacts.h index b99929b..c5ced5a 100644 --- a/src/device/social/Contacts.h +++ b/src/device/social/Contacts.h @@ -23,22 +23,20 @@ namespace ctx { class SocialStatusContacts : public DeviceProviderBase { - - GENERATE_PROVIDER_COMMON_DECL(SocialStatusContacts); - public: + SocialStatusContacts(); + ~SocialStatusContacts(); + int subscribe(); int unsubscribe(); - static bool isSupported(); - static void submitTriggerItem(); + + bool isSupported(); + void submitTriggerItem(); private: time_t __latestMyProfile; time_t __latestPerson; - SocialStatusContacts(); - ~SocialStatusContacts(); - bool __setCallback(); void __unsetCallback(); void __handleUpdate(const char* viewUri); diff --git a/src/device/social/Email.cpp b/src/device/social/Email.cpp index c49f185..e67729e 100644 --- a/src/device/social/Email.cpp +++ b/src/device/social/Email.cpp @@ -14,40 +14,38 @@ * limitations under the License. */ -#include #include - -#include #include "SocialTypes.h" #include "Email.h" -GENERATE_PROVIDER_COMMON_IMPL(SocialStatusEmail); +using namespace ctx; -ctx::SocialStatusEmail::SocialStatusEmail() : +SocialStatusEmail::SocialStatusEmail() : + DeviceProviderBase(SOCIAL_ST_SUBJ_EMAIL), __dbusSignalId(-1), __dbusWatcher(DBusType::SESSION) { } -ctx::SocialStatusEmail::~SocialStatusEmail() +SocialStatusEmail::~SocialStatusEmail() { } -bool ctx::SocialStatusEmail::isSupported() +bool SocialStatusEmail::isSupported() { return getSystemInfoBool("tizen.org/feature/network.telephony"); } -void ctx::SocialStatusEmail::submitTriggerItem() +void SocialStatusEmail::submitTriggerItem() { - context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_EMAIL, OPS_SUBSCRIBE, + registerTriggerItem(OPS_SUBSCRIBE, "{" "\"Event\":{\"type\":\"string\",\"values\":[\"Received\",\"Sent\"]}" "}", NULL); } -void ctx::SocialStatusEmail::onSignal(const char* sender, const char* path, const char* iface, const char* name, GVariant* param) +void SocialStatusEmail::onSignal(const char* sender, const char* path, const char* iface, const char* name, GVariant* param) { gint subType = 0; gint gi1 = 0; @@ -60,20 +58,20 @@ void ctx::SocialStatusEmail::onSignal(const char* sender, const char* path, cons if (subType == NOTI_DOWNLOAD_FINISH) { //TODO: Check if this signal actually means that there are new mails _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", subType, gi1, gc, gi2, gi3); - ctx::Json dataUpdated; + Json dataUpdated; dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED); - context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, dataUpdated); + publish(NULL, ERR_NONE, dataUpdated); } else if (subType == NOTI_SEND_FINISH) { _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", subType, gi1, gc, gi2, gi3); - ctx::Json dataUpdated; + Json dataUpdated; dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_SENT); - context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, dataUpdated); + publish(NULL, ERR_NONE, dataUpdated); } } -int ctx::SocialStatusEmail::subscribe() +int SocialStatusEmail::subscribe() { __dbusSignalId = __dbusWatcher.watch(NULL, NULL, "User.Email.NetworkStatus", "email", this); IF_FAIL_RETURN_TAG(__dbusSignalId >= 0, ERR_OPERATION_FAILED, _E, "Email dbus signal subscription failed"); @@ -81,7 +79,7 @@ int ctx::SocialStatusEmail::subscribe() } -int ctx::SocialStatusEmail::unsubscribe() +int SocialStatusEmail::unsubscribe() { __dbusWatcher.unwatch(__dbusSignalId); return ERR_NONE; diff --git a/src/device/social/Email.h b/src/device/social/Email.h index 4daaea0..cf44ae7 100644 --- a/src/device/social/Email.h +++ b/src/device/social/Email.h @@ -23,22 +23,21 @@ namespace ctx { class SocialStatusEmail : public DeviceProviderBase, public IDBusSignalListener { - - GENERATE_PROVIDER_COMMON_DECL(SocialStatusEmail); - public: + SocialStatusEmail(); + ~SocialStatusEmail(); + int subscribe(); int unsubscribe(); + + bool isSupported(); + void submitTriggerItem(); + void onSignal(const char *sender, const char *path, const char *iface, const char *name, GVariant *param); - static bool isSupported(); - static void submitTriggerItem(); private: int64_t __dbusSignalId; DBusSignalWatcher __dbusWatcher; - - SocialStatusEmail(); - ~SocialStatusEmail(); }; } diff --git a/src/device/social/Message.cpp b/src/device/social/Message.cpp index 7643175..f55b3e6 100644 --- a/src/device/social/Message.cpp +++ b/src/device/social/Message.cpp @@ -14,32 +14,31 @@ * limitations under the License. */ -#include -#include #include "SocialTypes.h" #include "Message.h" #define MAX_ADDR_SIZE 20 -GENERATE_PROVIDER_COMMON_IMPL(SocialStatusMessage); +using namespace ctx; -ctx::SocialStatusMessage::SocialStatusMessage() : +SocialStatusMessage::SocialStatusMessage() : + DeviceProviderBase(SOCIAL_ST_SUBJ_MESSAGE), __messageHandle(NULL) { } -ctx::SocialStatusMessage::~SocialStatusMessage() +SocialStatusMessage::~SocialStatusMessage() { } -bool ctx::SocialStatusMessage::isSupported() +bool SocialStatusMessage::isSupported() { return getSystemInfoBool("tizen.org/feature/network.telephony"); } -void ctx::SocialStatusMessage::submitTriggerItem() +void SocialStatusMessage::submitTriggerItem() { - context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_MESSAGE, OPS_SUBSCRIBE, + registerTriggerItem(OPS_SUBSCRIBE, "{" "\"Event\":{\"type\":\"string\",\"values\":[\"Received\"]}," "\"Type\":{\"type\":\"string\",\"values\":[\"SMS\",\"MMS\"]}," @@ -48,18 +47,18 @@ void ctx::SocialStatusMessage::submitTriggerItem() NULL); } -void ctx::SocialStatusMessage::__updateCb(msg_handle_t handle, msg_struct_t msg, void* userData) +void SocialStatusMessage::__updateCb(msg_handle_t handle, msg_struct_t msg, void* userData) { SocialStatusMessage *instance = static_cast(userData); instance->__handleUpdate(msg); } -void ctx::SocialStatusMessage::__handleUpdate(msg_struct_t msg) +void SocialStatusMessage::__handleUpdate(msg_struct_t msg) { int err; int type; char address[MAX_ADDR_SIZE]; - ctx::Json data; + Json data; err = msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &type); IF_FAIL_VOID_TAG(err == MSG_SUCCESS, _W, "Getting message type failed"); @@ -91,10 +90,10 @@ void ctx::SocialStatusMessage::__handleUpdate(msg_struct_t msg) data.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED); data.set(NULL, SOCIAL_ST_ADDRESS, address); - context_manager::publish(SOCIAL_ST_SUBJ_MESSAGE, NULL, ERR_NONE, data); + publish(NULL, ERR_NONE, data); } -bool ctx::SocialStatusMessage::__setCallback() +bool SocialStatusMessage::__setCallback() { int err; @@ -112,7 +111,7 @@ bool ctx::SocialStatusMessage::__setCallback() return true; } -void ctx::SocialStatusMessage::__unsetCallback() +void SocialStatusMessage::__unsetCallback() { if (__messageHandle) msg_close_msg_handle(&__messageHandle); @@ -120,14 +119,14 @@ void ctx::SocialStatusMessage::__unsetCallback() __messageHandle = NULL; } -int ctx::SocialStatusMessage::subscribe() +int SocialStatusMessage::subscribe() { bool ret = __setCallback(); IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::SocialStatusMessage::unsubscribe() +int SocialStatusMessage::unsubscribe() { __unsetCallback(); return ERR_NONE; diff --git a/src/device/social/Message.h b/src/device/social/Message.h index 91c33b3..78d006b 100644 --- a/src/device/social/Message.h +++ b/src/device/social/Message.h @@ -24,22 +24,20 @@ namespace ctx { class SocialStatusMessage : public DeviceProviderBase { - - GENERATE_PROVIDER_COMMON_DECL(SocialStatusMessage); - public: + SocialStatusMessage(); + ~SocialStatusMessage(); + int subscribe(); int unsubscribe(); - static bool isSupported(); - static void submitTriggerItem(); + + bool isSupported(); + void submitTriggerItem(); private: msg_handle_t __messageHandle; bool __beingSubscribed; - SocialStatusMessage(); - ~SocialStatusMessage(); - bool __setCallback(); void __unsetCallback(); void __handleUpdate(msg_struct_t msg); diff --git a/src/device/system/Alarm.cpp b/src/device/system/Alarm.cpp index fc7aa10..edc7bad 100644 --- a/src/device/system/Alarm.cpp +++ b/src/device/system/Alarm.cpp @@ -14,17 +14,17 @@ * limitations under the License. */ -#include #include "SystemTypes.h" #include "Alarm.h" -GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusAlarm); +using namespace ctx; -ctx::DeviceStatusAlarm::DeviceStatusAlarm() +DeviceStatusAlarm::DeviceStatusAlarm() + : ContextProvider(DEVICE_ST_SUBJ_ALARM) { } -ctx::DeviceStatusAlarm::~DeviceStatusAlarm() +DeviceStatusAlarm::~DeviceStatusAlarm() { __clear(); @@ -34,14 +34,14 @@ ctx::DeviceStatusAlarm::~DeviceStatusAlarm() __optionSet.clear(); } -bool ctx::DeviceStatusAlarm::isSupported() +bool DeviceStatusAlarm::isSupported() { return true; } -void ctx::DeviceStatusAlarm::submitTriggerItem() +void DeviceStatusAlarm::submitTriggerItem() { - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_ALARM, OPS_SUBSCRIBE, + registerTriggerItem(OPS_SUBSCRIBE, "{" "\"TimeOfDay\":{\"type\":\"integer\",\"min\":0,\"max\":1439}," "\"DayOfWeek\":{\"type\":\"string\",\"values\":[\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\",\"Weekday\",\"Weekend\"]}" @@ -49,33 +49,7 @@ void ctx::DeviceStatusAlarm::submitTriggerItem() 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 DeviceStatusAlarm::subscribe(Json option, Json *requestResult) { int dow = __getArrangedDayOfWeek(option); @@ -84,7 +58,7 @@ int ctx::DeviceStatusAlarm::subscribe(ctx::Json option) __add(time, dow); } - ctx::Json* elem = new(std::nothrow) ctx::Json(option); + Json* elem = new(std::nothrow) Json(option); if (elem) { __optionSet.insert(elem); } else { @@ -96,7 +70,7 @@ int ctx::DeviceStatusAlarm::subscribe(ctx::Json option) return ERR_NONE; } -int ctx::DeviceStatusAlarm::unsubscribe(ctx::Json option) +int DeviceStatusAlarm::unsubscribe(Json option) { int dow = __getArrangedDayOfWeek(option); @@ -114,25 +88,25 @@ int ctx::DeviceStatusAlarm::unsubscribe(ctx::Json option) return ERR_NONE; } -int ctx::DeviceStatusAlarm::__getArrangedDayOfWeek(ctx::Json& option) +int DeviceStatusAlarm::__getArrangedDayOfWeek(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); + dow |= TimerManager::dowToInt(tempDay); } _D("Requested day of week (%#x)", dow); return dow; } -ctx::DeviceStatusAlarm::RefCountArray::RefCountArray() +DeviceStatusAlarm::RefCountArray::RefCountArray() { memset(count, 0, sizeof(int) * DAYS_PER_WEEK); } -int ctx::DeviceStatusAlarm::__mergeDayOfWeek(int* refCnt) +int DeviceStatusAlarm::__mergeDayOfWeek(int* refCnt) { int dayOfWeek = 0; @@ -145,7 +119,7 @@ int ctx::DeviceStatusAlarm::__mergeDayOfWeek(int* refCnt) return dayOfWeek; } -bool ctx::DeviceStatusAlarm::__add(int minute, int dayOfWeek) +bool DeviceStatusAlarm::__add(int minute, int dayOfWeek) { IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 && dayOfWeek > 0 && dayOfWeek <= static_cast(DayOfWeek::EVERYDAY), @@ -162,7 +136,7 @@ bool ctx::DeviceStatusAlarm::__add(int minute, int dayOfWeek) return __resetTimer(minute); } -bool ctx::DeviceStatusAlarm::__remove(int minute, int dayOfWeek) +bool DeviceStatusAlarm::__remove(int minute, int dayOfWeek) { IF_FAIL_RETURN_TAG(minute >= 0 && minute < 1440 && dayOfWeek > 0 && dayOfWeek <= static_cast(DayOfWeek::EVERYDAY), @@ -179,7 +153,7 @@ bool ctx::DeviceStatusAlarm::__remove(int minute, int dayOfWeek) return __resetTimer(minute); } -bool ctx::DeviceStatusAlarm::__resetTimer(int minute) +bool DeviceStatusAlarm::__resetTimer(int minute) { int dayOfWeek = __mergeDayOfWeek(__refCountMap[minute].count); TimerState &timer = __timerStateMap[minute]; @@ -216,7 +190,7 @@ bool ctx::DeviceStatusAlarm::__resetTimer(int minute) return true; } -void ctx::DeviceStatusAlarm::__clear() +void DeviceStatusAlarm::__clear() { for (auto it = __timerStateMap.begin(); it != __timerStateMap.end(); ++it) { if (it->second.timerId > 0) { @@ -228,7 +202,7 @@ void ctx::DeviceStatusAlarm::__clear() __refCountMap.clear(); } -bool ctx::DeviceStatusAlarm::onTimerExpired(int timerId) +bool DeviceStatusAlarm::onTimerExpired(int timerId) { time_t rawTime; struct tm timeInfo; @@ -246,25 +220,25 @@ bool ctx::DeviceStatusAlarm::onTimerExpired(int timerId) return true; } -void ctx::DeviceStatusAlarm::__handleUpdate(int hour, int min, int dayOfWeek) +void DeviceStatusAlarm::__handleUpdate(int hour, int min, int dayOfWeek) { _I("Time: %02d:%02d, Day of Week: %#x", hour, min, dayOfWeek); - ctx::Json dataRead; + Json dataRead; int resultTime = hour * 60 + min; - std::string resultDay = ctx::TimerManager::dowToStr(dayOfWeek); + std::string resultDay = 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); + Json option = (**it); if (__isMatched(option, resultTime, resultDay)) { - context_manager::publish(DEVICE_ST_SUBJ_ALARM, option, ERR_NONE, dataRead); + publish(option, ERR_NONE, dataRead); } } } -bool ctx::DeviceStatusAlarm::__isMatched(ctx::Json& option, int time, std::string day) +bool DeviceStatusAlarm::__isMatched(Json& option, int time, std::string day) { bool ret = false; int optionTime; @@ -286,7 +260,7 @@ bool ctx::DeviceStatusAlarm::__isMatched(ctx::Json& option, int time, std::strin return false; } -ctx::DeviceStatusAlarm::OptionSet::iterator ctx::DeviceStatusAlarm::__findOption(ctx::Json& option) +DeviceStatusAlarm::OptionSet::iterator DeviceStatusAlarm::__findOption(Json& option) { for (auto it = __optionSet.begin(); it != __optionSet.end(); ++it) { if (option == (**it)) @@ -294,9 +268,3 @@ ctx::DeviceStatusAlarm::OptionSet::iterator ctx::DeviceStatusAlarm::__findOption } return __optionSet.end(); } - -void ctx::DeviceStatusAlarm::__destroyIfUnused() -{ - IF_FAIL_VOID(__optionSet.empty()); - destroy(NULL); -} diff --git a/src/device/system/Alarm.h b/src/device/system/Alarm.h index 0ae4fce..5535e5c 100644 --- a/src/device/system/Alarm.h +++ b/src/device/system/Alarm.h @@ -19,34 +19,26 @@ #include #include -#include #include -#include "../DeviceProviderBase.h" +#include namespace ctx { - class DeviceStatusAlarm : public ContextProviderBase, ITimerListener { - - GENERATE_PROVIDER_COMMON_DECL(DeviceStatusAlarm); - + class DeviceStatusAlarm : public ContextProvider, ITimerListener { 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); + DeviceStatusAlarm(); + ~DeviceStatusAlarm(); + + int subscribe(Json option, Json *requestResult); + int unsubscribe(Json option); - int subscribe(ctx::Json option); - int unsubscribe(ctx::Json option); - static bool isSupported(); - static void submitTriggerItem(); + bool isSupported(); + void submitTriggerItem(); protected: bool onTimerExpired(int timerId); private: - DeviceStatusAlarm(); - ~DeviceStatusAlarm(); - struct RefCountArray { int count[7]; /* reference counts for days of week*/ RefCountArray(); @@ -60,7 +52,7 @@ namespace ctx { typedef std::map RefCountMap; typedef std::map TimerStateMap; - typedef std::set OptionSet; + typedef std::set OptionSet; RefCountMap __refCountMap; TimerStateMap __timerStateMap; @@ -73,14 +65,11 @@ namespace ctx { void __clear(); void __handleUpdate(int hour, int min, int dayOfWeek); - int __getArrangedDayOfWeek(ctx::Json& option); + int __getArrangedDayOfWeek(Json& option); int __mergeDayOfWeek(int *refCnt); - bool __isMatched(ctx::Json& option, int time, std::string day); - OptionSet::iterator __findOption(ctx::Json& option); - - void __destroyIfUnused(); - + bool __isMatched(Json& option, int time, std::string day); + OptionSet::iterator __findOption(Json& option); }; } diff --git a/src/device/system/Battery.cpp b/src/device/system/Battery.cpp index 8313333..94c3d58 100644 --- a/src/device/system/Battery.cpp +++ b/src/device/system/Battery.cpp @@ -14,28 +14,28 @@ * limitations under the License. */ -#include #include "SystemTypes.h" #include "Battery.h" -GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusBattery); +using namespace ctx; -ctx::DeviceStatusBattery::DeviceStatusBattery() +DeviceStatusBattery::DeviceStatusBattery() + : DeviceProviderBase(DEVICE_ST_SUBJ_BATTERY) { } -ctx::DeviceStatusBattery::~DeviceStatusBattery() +DeviceStatusBattery::~DeviceStatusBattery() { } -bool ctx::DeviceStatusBattery::isSupported() +bool DeviceStatusBattery::isSupported() { return true; } -void ctx::DeviceStatusBattery::submitTriggerItem() +void DeviceStatusBattery::submitTriggerItem() { - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_BATTERY, OPS_SUBSCRIBE | OPS_READ, + registerTriggerItem(OPS_SUBSCRIBE | OPS_READ, "{" "\"Level\":{\"type\":\"string\",\"values\":[\"Empty\",\"Critical\",\"Low\",\"Normal\",\"High\",\"Full\"]}," TRIG_BOOL_ITEM_DEF("IsCharging") @@ -43,7 +43,7 @@ void ctx::DeviceStatusBattery::submitTriggerItem() NULL); } -void ctx::DeviceStatusBattery::__updateCb(device_callback_e deviceType, void* value, void* userData) +void DeviceStatusBattery::__updateCb(device_callback_e deviceType, void* value, void* userData) { IF_FAIL_VOID(deviceType == DEVICE_CALLBACK_BATTERY_LEVEL); @@ -51,14 +51,14 @@ void ctx::DeviceStatusBattery::__updateCb(device_callback_e deviceType, void* va instance->__handleUpdate(deviceType, value); } -void ctx::DeviceStatusBattery::__handleUpdate(device_callback_e deviceType, void* value) +void DeviceStatusBattery::__handleUpdate(device_callback_e deviceType, void* value) { intptr_t level = (intptr_t)value; const char* levelString = __transToString(level); IF_FAIL_VOID(levelString); - ctx::Json dataRead; + Json dataRead; dataRead.set(NULL, DEVICE_ST_LEVEL, levelString); bool chargingState = false; @@ -66,10 +66,10 @@ void ctx::DeviceStatusBattery::__handleUpdate(device_callback_e deviceType, void IF_FAIL_VOID_TAG(ret == DEVICE_ERROR_NONE, _E, "Getting state failed"); dataRead.set(NULL, DEVICE_ST_IS_CHARGING, chargingState ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - ctx::context_manager::publish(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, dataRead); + publish(NULL, ERR_NONE, dataRead); } -const char* ctx::DeviceStatusBattery::__transToString(intptr_t level) +const char* DeviceStatusBattery::__transToString(intptr_t level) { switch (level) { case DEVICE_BATTERY_LEVEL_EMPTY: @@ -103,24 +103,24 @@ const char* ctx::DeviceStatusBattery::__transToString(intptr_t level) } } -int ctx::DeviceStatusBattery::subscribe() +int DeviceStatusBattery::subscribe() { int ret = device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, __updateCb, this); IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::DeviceStatusBattery::unsubscribe() +int DeviceStatusBattery::unsubscribe() { int ret = device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, __updateCb); IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::DeviceStatusBattery::read() +int DeviceStatusBattery::read() { device_battery_level_e level; - ctx::Json dataRead; + Json dataRead; int ret = device_battery_get_level_status(&level); IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED); @@ -136,6 +136,6 @@ int ctx::DeviceStatusBattery::read() 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); + replyToRead(NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/Battery.h b/src/device/system/Battery.h index cbc11ba..d016798 100644 --- a/src/device/system/Battery.h +++ b/src/device/system/Battery.h @@ -24,19 +24,18 @@ namespace ctx { class DeviceStatusBattery : public DeviceProviderBase { - - GENERATE_PROVIDER_COMMON_DECL(DeviceStatusBattery); - public: + DeviceStatusBattery(); + ~DeviceStatusBattery(); + int subscribe(); int unsubscribe(); int read(); - static bool isSupported(); - static void submitTriggerItem(); + + bool isSupported(); + void submitTriggerItem(); private: - DeviceStatusBattery(); - ~DeviceStatusBattery(); const char* __transToString(intptr_t level); void __handleUpdate(device_callback_e deviceType, void* value); static void __updateCb(device_callback_e deviceType, void* value, void* userData); diff --git a/src/device/system/Headphone.cpp b/src/device/system/Headphone.cpp index 3ec1281..0093af9 100644 --- a/src/device/system/Headphone.cpp +++ b/src/device/system/Headphone.cpp @@ -14,16 +14,16 @@ * limitations under the License. */ -#include #include "SystemTypes.h" #include "Headphone.h" #define HANDLING_DELAY 2000 #define MAX_HANDLING_COUNT 3 -GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusHeadphone); +using namespace ctx; -ctx::DeviceStatusHeadphone::DeviceStatusHeadphone() : +DeviceStatusHeadphone::DeviceStatusHeadphone() : + DeviceProviderBase(DEVICE_ST_SUBJ_HEADPHONE), __connected(false), __audioJackState(RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED), __btAudioState(false), @@ -33,18 +33,18 @@ ctx::DeviceStatusHeadphone::DeviceStatusHeadphone() : { } -ctx::DeviceStatusHeadphone::~DeviceStatusHeadphone() +DeviceStatusHeadphone::~DeviceStatusHeadphone() { } -bool ctx::DeviceStatusHeadphone::isSupported() +bool DeviceStatusHeadphone::isSupported() { return true; } -void ctx::DeviceStatusHeadphone::submitTriggerItem() +void DeviceStatusHeadphone::submitTriggerItem() { - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_HEADPHONE, OPS_SUBSCRIBE | OPS_READ, + registerTriggerItem(OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsConnected") "," "\"Type\":{\"type\":\"string\",\"values\":[\"Normal\",\"Headset\",\"Bluetooth\"]}" @@ -52,7 +52,7 @@ void ctx::DeviceStatusHeadphone::submitTriggerItem() NULL); } -int ctx::DeviceStatusHeadphone::subscribe() +int DeviceStatusHeadphone::subscribe() { __connected = __getCurrentStatus(); @@ -66,7 +66,7 @@ int ctx::DeviceStatusHeadphone::subscribe() return ERR_NONE; } -int ctx::DeviceStatusHeadphone::unsubscribe() +int DeviceStatusHeadphone::unsubscribe() { runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS); __unsetBtAudioCallback(); @@ -74,19 +74,19 @@ int ctx::DeviceStatusHeadphone::unsubscribe() return ERR_NONE; } -int ctx::DeviceStatusHeadphone::read() +int DeviceStatusHeadphone::read() { if (!__beingSubscribed) __connected = __getCurrentStatus(); Json data; __generateDataPacket(&data); - ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data); + replyToRead(NULL, ERR_NONE, data); return ERR_NONE; } -void ctx::DeviceStatusHeadphone::__setBtAudioCallback() +void DeviceStatusHeadphone::__setBtAudioCallback() { IF_FAIL_VOID(!__btAudioCallbackOn); int ret; @@ -106,7 +106,7 @@ void ctx::DeviceStatusHeadphone::__setBtAudioCallback() __btAudioCallbackOn = true; } -void ctx::DeviceStatusHeadphone::__unsetBtAudioCallback() +void DeviceStatusHeadphone::__unsetBtAudioCallback() { IF_FAIL_VOID(__btAudioCallbackOn); @@ -116,12 +116,12 @@ void ctx::DeviceStatusHeadphone::__unsetBtAudioCallback() __btAudioCallbackOn = false; } -void ctx::DeviceStatusHeadphone::__setBtAudioState(bool state) +void DeviceStatusHeadphone::__setBtAudioState(bool state) { __btAudioState = state; } -bool ctx::DeviceStatusHeadphone::__getCurrentStatus() +bool DeviceStatusHeadphone::__getCurrentStatus() { int ret; @@ -140,7 +140,7 @@ bool ctx::DeviceStatusHeadphone::__getCurrentStatus() return ((__audioJackState != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || __btAudioState); } -void ctx::DeviceStatusHeadphone::__generateDataPacket(ctx::Json* data) +void DeviceStatusHeadphone::__generateDataPacket(Json* data) { data->set(NULL, DEVICE_ST_IS_CONNECTED, __connected ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); @@ -158,36 +158,36 @@ void ctx::DeviceStatusHeadphone::__generateDataPacket(ctx::Json* data) } } -bool ctx::DeviceStatusHeadphone::__handleUpdate() +bool DeviceStatusHeadphone::__handleUpdate() { bool prevState = __connected; __connected = ((__audioJackState != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || __btAudioState); IF_FAIL_RETURN(prevState != __connected, false); - ctx::Json data; + Json data; __generateDataPacket(&data); - ctx::context_manager::publish(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data); + publish(NULL, ERR_NONE, data); return true; } -void ctx::DeviceStatusHeadphone::__handleAudioJackEvent() +void 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) +void DeviceStatusHeadphone::__onAudioJackStateChanged(runtime_info_key_e runtimeKey, void* userData) { _D("EarJack"); - ctx::DeviceStatusHeadphone *instance = static_cast(userData); + DeviceStatusHeadphone *instance = static_cast(userData); instance->__handleAudioJackEvent(); } -void ctx::DeviceStatusHeadphone::__onBtConnectionChanged(bool connected, bt_device_connection_info_s *connInfo, void *userData) +void DeviceStatusHeadphone::__onBtConnectionChanged(bool connected, bt_device_connection_info_s *connInfo, void *userData) { - ctx::DeviceStatusHeadphone *instance = static_cast(userData); + DeviceStatusHeadphone *instance = static_cast(userData); IF_FAIL_VOID(connected != instance->__btAudioState); IF_FAIL_VOID(!instance->__btEventHandlerAdded); @@ -201,10 +201,10 @@ void ctx::DeviceStatusHeadphone::__onBtConnectionChanged(bool connected, bt_devi } } -gboolean ctx::DeviceStatusHeadphone::__handleBtEvent(gpointer data) +gboolean DeviceStatusHeadphone::__handleBtEvent(gpointer data) { _D("BT state checking started"); - ctx::DeviceStatusHeadphone *instance = static_cast(data); + DeviceStatusHeadphone *instance = static_cast(data); instance->__btEventHandlerAdded = false; instance->__setBtAudioState(false); @@ -219,7 +219,7 @@ gboolean ctx::DeviceStatusHeadphone::__handleBtEvent(gpointer data) return TRUE; } -bool ctx::DeviceStatusHeadphone::__onBtBond(bt_device_info_s *deviceInfo, void* userData) +bool DeviceStatusHeadphone::__onBtBond(bt_device_info_s *deviceInfo, void* userData) { if (deviceInfo->bt_class.major_device_class != BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO) return true; @@ -229,7 +229,7 @@ bool ctx::DeviceStatusHeadphone::__onBtBond(bt_device_info_s *deviceInfo, void* IF_FAIL_RETURN_TAG(err == BT_ERROR_NONE, false, _E, "bt_device_is_profile_connected() failed"); if (st) { - ctx::DeviceStatusHeadphone *instance = static_cast(userData); + DeviceStatusHeadphone *instance = static_cast(userData); instance->__setBtAudioState(true); return false; } diff --git a/src/device/system/Headphone.h b/src/device/system/Headphone.h index 394a6d9..00edcfd 100644 --- a/src/device/system/Headphone.h +++ b/src/device/system/Headphone.h @@ -25,15 +25,16 @@ namespace ctx { class DeviceStatusHeadphone : public DeviceProviderBase { - - GENERATE_PROVIDER_COMMON_DECL(DeviceStatusHeadphone); - public: + DeviceStatusHeadphone(); + ~DeviceStatusHeadphone(); + int subscribe(); int unsubscribe(); int read(); - static bool isSupported(); - static void submitTriggerItem(); + + bool isSupported(); + void submitTriggerItem(); private: bool __connected; @@ -43,9 +44,6 @@ namespace ctx { bool __btEventHandlerAdded; int __btEventHandlingCount; - DeviceStatusHeadphone(); - ~DeviceStatusHeadphone(); - bool __getCurrentStatus(); void __setBtAudioCallback(); void __unsetBtAudioCallback(); diff --git a/src/device/system/Psmode.cpp b/src/device/system/Psmode.cpp index 894faf0..c52b176 100644 --- a/src/device/system/Psmode.cpp +++ b/src/device/system/Psmode.cpp @@ -14,73 +14,73 @@ * limitations under the License. */ -#include #include "SystemTypes.h" #include "Psmode.h" -GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusPsmode); +using namespace ctx; -ctx::DeviceStatusPsmode::DeviceStatusPsmode() +DeviceStatusPsmode::DeviceStatusPsmode() : + DeviceProviderBase(DEVICE_ST_SUBJ_PSMODE) { } -ctx::DeviceStatusPsmode::~DeviceStatusPsmode() +DeviceStatusPsmode::~DeviceStatusPsmode() { } -bool ctx::DeviceStatusPsmode::isSupported() +bool DeviceStatusPsmode::isSupported() { return true; } -void ctx::DeviceStatusPsmode::submitTriggerItem() +void DeviceStatusPsmode::submitTriggerItem() { - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_PSMODE, OPS_SUBSCRIBE | OPS_READ, + registerTriggerItem(OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsEnabled") "}", NULL); } -void ctx::DeviceStatusPsmode::__updateCb(keynode_t *node, void* userData) +void DeviceStatusPsmode::__updateCb(keynode_t *node, void* userData) { DeviceStatusPsmode *instance = static_cast(userData); instance->__handleUpdate(node); } -void ctx::DeviceStatusPsmode::__handleUpdate(keynode_t *node) +void DeviceStatusPsmode::__handleUpdate(keynode_t *node) { int status; - ctx::Json dataRead; + Json dataRead; status = vconf_keynode_get_int(node); IF_FAIL_VOID_TAG(status >= 0, _E, "Getting state failed"); dataRead.set(NULL, DEVICE_ST_IS_ENABLED, status == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE); - context_manager::publish(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, dataRead); + publish(NULL, ERR_NONE, dataRead); } -int ctx::DeviceStatusPsmode::subscribe() +int DeviceStatusPsmode::subscribe() { int ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, __updateCb, this); IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::DeviceStatusPsmode::unsubscribe() +int DeviceStatusPsmode::unsubscribe() { int ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, __updateCb); IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::DeviceStatusPsmode::read() +int DeviceStatusPsmode::read() { int mode; int ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &mode); IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED); - ctx::Json dataRead; + Json dataRead; dataRead.set(NULL, DEVICE_ST_IS_ENABLED, mode == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE); - ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, dataRead); + replyToRead(NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/Psmode.h b/src/device/system/Psmode.h index d18201e..d324ac3 100644 --- a/src/device/system/Psmode.h +++ b/src/device/system/Psmode.h @@ -23,19 +23,18 @@ namespace ctx { class DeviceStatusPsmode : public DeviceProviderBase { - - GENERATE_PROVIDER_COMMON_DECL(DeviceStatusPsmode); - public: + DeviceStatusPsmode(); + ~DeviceStatusPsmode(); + int subscribe(); int unsubscribe(); int read(); - static bool isSupported(); - static void submitTriggerItem(); + + bool isSupported(); + void submitTriggerItem(); private: - DeviceStatusPsmode(); - ~DeviceStatusPsmode(); void __handleUpdate(keynode_t *node); static void __updateCb(keynode_t *node, void* userData); }; diff --git a/src/device/system/Time.cpp b/src/device/system/Time.cpp index af3ded1..6fa0c81 100644 --- a/src/device/system/Time.cpp +++ b/src/device/system/Time.cpp @@ -14,29 +14,29 @@ * limitations under the License. */ -#include #include #include "SystemTypes.h" #include "Time.h" -GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusTime); +using namespace ctx; -ctx::DeviceStatusTime::DeviceStatusTime() +DeviceStatusTime::DeviceStatusTime() : + DeviceProviderBase(DEVICE_ST_SUBJ_TIME) { } -ctx::DeviceStatusTime::~DeviceStatusTime() +DeviceStatusTime::~DeviceStatusTime() { } -bool ctx::DeviceStatusTime::isSupported() +bool DeviceStatusTime::isSupported() { return true; } -void ctx::DeviceStatusTime::submitTriggerItem() +void DeviceStatusTime::submitTriggerItem() { - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_TIME, OPS_READ, + registerTriggerItem(OPS_READ, "{" "\"TimeOfDay\":{\"type\":\"integer\",\"min\":0,\"max\":1439}," "\"DayOfWeek\":{\"type\":\"string\",\"values\":[\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\",\"Weekday\",\"Weekend\"]}," @@ -45,17 +45,17 @@ void ctx::DeviceStatusTime::submitTriggerItem() NULL); } -int ctx::DeviceStatusTime::subscribe() +int DeviceStatusTime::subscribe() { return ERR_NOT_SUPPORTED; } -int ctx::DeviceStatusTime::unsubscribe() +int DeviceStatusTime::unsubscribe() { return ERR_NOT_SUPPORTED; } -int ctx::DeviceStatusTime::read() +int DeviceStatusTime::read() { time_t rawtime; struct tm timeInfo; @@ -66,16 +66,16 @@ int ctx::DeviceStatusTime::read() int dayOfMonth = timeInfo.tm_mday; int minuteOfDay = timeInfo.tm_hour * 60 + timeInfo.tm_min; - std::string dayOfWeek = ctx::TimerManager::dowToStr(0x01 << timeInfo.tm_wday); + std::string dayOfWeek = TimerManager::dowToStr(0x01 << timeInfo.tm_wday); - ctx::Json dataRead; + Json dataRead; dataRead.set(NULL, DEVICE_ST_DAY_OF_MONTH, dayOfMonth); dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, dayOfWeek); dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, minuteOfDay); _I("Time: %02d:%02d, Day of Week: %s, Day of Month: %d", timeInfo.tm_hour, timeInfo.tm_min, dayOfWeek.c_str(), dayOfMonth); - ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_TIME, NULL, ERR_NONE, dataRead); + replyToRead(NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/Time.h b/src/device/system/Time.h index 2a97993..e5e1112 100644 --- a/src/device/system/Time.h +++ b/src/device/system/Time.h @@ -22,19 +22,16 @@ namespace ctx { class DeviceStatusTime : public DeviceProviderBase { - - GENERATE_PROVIDER_COMMON_DECL(DeviceStatusTime); - public: + DeviceStatusTime(); + ~DeviceStatusTime(); + int subscribe(); int unsubscribe(); int read(); - static bool isSupported(); - static void submitTriggerItem(); - private: - DeviceStatusTime(); - ~DeviceStatusTime(); + bool isSupported(); + void submitTriggerItem(); }; } diff --git a/src/device/system/Wifi.cpp b/src/device/system/Wifi.cpp index e3a8a3a..5f6cca7 100644 --- a/src/device/system/Wifi.cpp +++ b/src/device/system/Wifi.cpp @@ -15,13 +15,13 @@ */ #include -#include #include "SystemTypes.h" #include "Wifi.h" -ctx::DeviceStatusWifi *ctx::DeviceStatusWifi::__instance = NULL; +using namespace ctx; -ctx::DeviceStatusWifi::DeviceStatusWifi() : +DeviceStatusWifi::DeviceStatusWifi() : + DeviceProviderBase(DEVICE_ST_SUBJ_WIFI), __lastState(UNKNOWN), __isInitialized(false), __isActivated(false), @@ -35,34 +35,19 @@ ctx::DeviceStatusWifi::DeviceStatusWifi() : } } -ctx::DeviceStatusWifi::~DeviceStatusWifi() +DeviceStatusWifi::~DeviceStatusWifi() { + __stopMonitor(); } -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() +bool DeviceStatusWifi::isSupported() { return getSystemInfoBool("tizen.org/feature/network.wifi"); } -void ctx::DeviceStatusWifi::submitTriggerItem() +void DeviceStatusWifi::submitTriggerItem() { - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_WIFI, OPS_SUBSCRIBE | OPS_READ, + registerTriggerItem(OPS_SUBSCRIBE | OPS_READ, "{" "\"State\":{\"type\":\"string\",\"values\":[\"Disabled\",\"Unconnected\",\"Connected\"]}," "\"BSSID\":{\"type\":\"string\"}" @@ -70,7 +55,7 @@ void ctx::DeviceStatusWifi::submitTriggerItem() NULL); } -bool ctx::DeviceStatusWifi::__getCurrentState() +bool DeviceStatusWifi::__getCurrentState() { int err; @@ -104,7 +89,7 @@ bool ctx::DeviceStatusWifi::__getCurrentState() return true; } -bool ctx::DeviceStatusWifi::__getBssid() +bool DeviceStatusWifi::__getBssid() { int err; char *strBuf = NULL; @@ -122,20 +107,20 @@ bool ctx::DeviceStatusWifi::__getBssid() if (__bssid.empty()) _W("Failed to get BSSID"); - SharedVars().set(ctx::SharedVars::WIFI_BSSID, __bssid); + SharedVars().set(SharedVars::WIFI_BSSID, __bssid); _D("BSSID: %s", __bssid.c_str()); return !__bssid.empty(); } -void ctx::DeviceStatusWifi::__clearBssid() +void DeviceStatusWifi::__clearBssid() { __bssid.clear(); - SharedVars().clear(ctx::SharedVars::WIFI_BSSID); + SharedVars().clear(SharedVars::WIFI_BSSID); _D("No WiFi connection"); } -bool ctx::DeviceStatusWifi::__getResponsePacket(ctx::Json* data) +bool DeviceStatusWifi::__getResponsePacket(Json* data) { switch (__lastState) { case DISABLED: @@ -158,20 +143,20 @@ bool ctx::DeviceStatusWifi::__getResponsePacket(ctx::Json* data) return true; } -int ctx::DeviceStatusWifi::read() +int DeviceStatusWifi::read() { IF_FAIL_RETURN(__getCurrentState(), ERR_OPERATION_FAILED); - ctx::Json dataRead; + Json dataRead; if (__getResponsePacket(&dataRead)) { - ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, dataRead); + replyToRead(NULL, ERR_NONE, dataRead); return ERR_NONE; } return ERR_OPERATION_FAILED; } -bool ctx::DeviceStatusWifi::__startMonitor() +bool DeviceStatusWifi::__startMonitor() { IF_FAIL_RETURN(!__isInitialized, true); @@ -193,7 +178,7 @@ CATCH: return false; } -void ctx::DeviceStatusWifi::__stopMonitor() +void DeviceStatusWifi::__stopMonitor() { IF_FAIL_VOID(__isInitialized); @@ -203,7 +188,7 @@ void ctx::DeviceStatusWifi::__stopMonitor() __isInitialized = false; } -int ctx::DeviceStatusWifi::subscribe() +int DeviceStatusWifi::subscribe() { #if 0 IF_FAIL_RETURN(__startMonitor(), ERR_OPERATION_FAILED); @@ -216,7 +201,7 @@ int ctx::DeviceStatusWifi::subscribe() return ERR_NONE; } -int ctx::DeviceStatusWifi::unsubscribe() +int DeviceStatusWifi::unsubscribe() { #if 0 __stopMonitor(); @@ -224,7 +209,7 @@ int ctx::DeviceStatusWifi::unsubscribe() return ERR_NONE; } -void ctx::DeviceStatusWifi::__handleUpdate() +void DeviceStatusWifi::__handleUpdate() { int prevState = __lastState; @@ -245,20 +230,20 @@ void ctx::DeviceStatusWifi::__handleUpdate() __clearBssid(); } - ctx::Json data; + Json data; if (__beingSubscribed && __getResponsePacket(&data)) - context_manager::publish(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, data); + publish(NULL, ERR_NONE, data); } } -void ctx::DeviceStatusWifi::__deviceStateChangedCb(wifi_device_state_e state, void *userData) +void DeviceStatusWifi::__deviceStateChangedCb(wifi_device_state_e state, void *userData) { DeviceStatusWifi *instance = static_cast(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) +void DeviceStatusWifi::__connectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *userData) { DeviceStatusWifi *instance = static_cast(userData); instance->__connState = state; diff --git a/src/device/system/Wifi.h b/src/device/system/Wifi.h index 59b721d..82cebb2 100644 --- a/src/device/system/Wifi.h +++ b/src/device/system/Wifi.h @@ -24,15 +24,16 @@ namespace ctx { class DeviceStatusWifi : public DeviceProviderBase { - - GENERATE_PROVIDER_COMMON_DECL(DeviceStatusWifi); - public: + DeviceStatusWifi(); + ~DeviceStatusWifi(); + int subscribe(); int unsubscribe(); int read(); - static bool isSupported(); - static void submitTriggerItem(); + + bool isSupported(); + void submitTriggerItem(); private: enum InternalState { @@ -48,9 +49,6 @@ namespace ctx { wifi_connection_state_e __connState; std::string __bssid; - DeviceStatusWifi(); - ~DeviceStatusWifi(); - bool __getCurrentState(); bool __getBssid(); void __clearBssid(); diff --git a/src/device/system/runtime_info/Charger.cpp b/src/device/system/runtime_info/Charger.cpp index 30802d9..8cdf40a 100644 --- a/src/device/system/runtime_info/Charger.cpp +++ b/src/device/system/runtime_info/Charger.cpp @@ -14,55 +14,54 @@ * limitations under the License. */ -#include #include "../SystemTypes.h" #include "Charger.h" -GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusCharger); +using namespace ctx; -ctx::DeviceStatusCharger::DeviceStatusCharger() : - DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_CHARGER_CONNECTED) +DeviceStatusCharger::DeviceStatusCharger() : + DeviceStatusRuntimeInfo(DEVICE_ST_SUBJ_CHARGER, RUNTIME_INFO_KEY_CHARGER_CONNECTED) { } -ctx::DeviceStatusCharger::~DeviceStatusCharger() +DeviceStatusCharger::~DeviceStatusCharger() { } -bool ctx::DeviceStatusCharger::isSupported() +bool DeviceStatusCharger::isSupported() { return true; } -void ctx::DeviceStatusCharger::submitTriggerItem() +void DeviceStatusCharger::submitTriggerItem() { - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_CHARGER, OPS_SUBSCRIBE | OPS_READ, + registerTriggerItem(OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL); } -void ctx::DeviceStatusCharger::handleUpdate() +void DeviceStatusCharger::handleUpdate() { bool chargerStatus = false; int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &chargerStatus); IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed"); - ctx::Json dataRead; + Json dataRead; dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, chargerStatus ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - context_manager::publish(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, dataRead); + publish(NULL, ERR_NONE, dataRead); } -int ctx::DeviceStatusCharger::read() +int DeviceStatusCharger::read() { bool chargerStatus = false; - ctx::Json dataRead; + Json dataRead; int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &chargerStatus); IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed"); dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, chargerStatus ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, dataRead); + replyToRead(NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/runtime_info/Charger.h b/src/device/system/runtime_info/Charger.h index 38cbca8..a6746a3 100644 --- a/src/device/system/runtime_info/Charger.h +++ b/src/device/system/runtime_info/Charger.h @@ -22,20 +22,17 @@ namespace ctx { class DeviceStatusCharger : public DeviceStatusRuntimeInfo { - - GENERATE_PROVIDER_COMMON_DECL(DeviceStatusCharger); - public: + DeviceStatusCharger(); + ~DeviceStatusCharger(); + int read(); - static bool isSupported(); - static void submitTriggerItem(); + + bool isSupported(); + void submitTriggerItem(); protected: void handleUpdate(); - - private: - DeviceStatusCharger(); - ~DeviceStatusCharger(); }; } diff --git a/src/device/system/runtime_info/Gps.cpp b/src/device/system/runtime_info/Gps.cpp index 9ec1c02..d2bc301 100644 --- a/src/device/system/runtime_info/Gps.cpp +++ b/src/device/system/runtime_info/Gps.cpp @@ -14,11 +14,10 @@ * limitations under the License. */ -#include #include "../SystemTypes.h" #include "Gps.h" -GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusGps); +using namespace ctx; static const char* __getStatusString(int gpsStatus) { @@ -38,49 +37,49 @@ static const char* __getStatusString(int gpsStatus) } } -ctx::DeviceStatusGps::DeviceStatusGps() : - DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_GPS_STATUS) +DeviceStatusGps::DeviceStatusGps() : + DeviceStatusRuntimeInfo(DEVICE_ST_SUBJ_GPS, RUNTIME_INFO_KEY_GPS_STATUS) { } -ctx::DeviceStatusGps::~DeviceStatusGps() +DeviceStatusGps::~DeviceStatusGps() { } -bool ctx::DeviceStatusGps::isSupported() +bool DeviceStatusGps::isSupported() { return getSystemInfoBool("tizen.org/feature/location.gps"); } -void ctx::DeviceStatusGps::submitTriggerItem() +void DeviceStatusGps::submitTriggerItem() { - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_GPS, OPS_SUBSCRIBE | OPS_READ, + registerTriggerItem(OPS_SUBSCRIBE | OPS_READ, "{" "\"State\":{\"type\":\"string\",\"values\":[\"Disabled\",\"Searching\",\"Connected\"]}" "}", NULL); } -void ctx::DeviceStatusGps::handleUpdate() +void DeviceStatusGps::handleUpdate() { int gpsStatus; int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gpsStatus); IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed"); - ctx::Json dataRead; + Json dataRead; const char* stateStr = __getStatusString(gpsStatus); IF_FAIL_VOID(stateStr); dataRead.set(NULL, DEVICE_ST_STATE, stateStr); - context_manager::publish(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead); + publish(NULL, ERR_NONE, dataRead); } -int ctx::DeviceStatusGps::read() +int DeviceStatusGps::read() { int gpsStatus; - ctx::Json dataRead; + Json dataRead; int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gpsStatus); IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed"); @@ -90,6 +89,6 @@ int ctx::DeviceStatusGps::read() dataRead.set(NULL, DEVICE_ST_STATE, stateStr); - ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead); + replyToRead(NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/runtime_info/Gps.h b/src/device/system/runtime_info/Gps.h index 38bc8e8..87acd1b 100644 --- a/src/device/system/runtime_info/Gps.h +++ b/src/device/system/runtime_info/Gps.h @@ -22,20 +22,17 @@ namespace ctx { class DeviceStatusGps : public DeviceStatusRuntimeInfo { - - GENERATE_PROVIDER_COMMON_DECL(DeviceStatusGps); - public: + DeviceStatusGps(); + ~DeviceStatusGps(); + int read(); - static bool isSupported(); - static void submitTriggerItem(); + + bool isSupported(); + void submitTriggerItem(); protected: void handleUpdate(); - - private: - DeviceStatusGps(); - ~DeviceStatusGps(); }; } diff --git a/src/device/system/runtime_info/RuntimeInfoBase.cpp b/src/device/system/runtime_info/RuntimeInfoBase.cpp index 61b117f..1f745ad 100644 --- a/src/device/system/runtime_info/RuntimeInfoBase.cpp +++ b/src/device/system/runtime_info/RuntimeInfoBase.cpp @@ -16,31 +16,34 @@ #include "RuntimeInfoBase.h" -ctx::DeviceStatusRuntimeInfo::DeviceStatusRuntimeInfo(runtime_info_key_e key) : +using namespace ctx; + +DeviceStatusRuntimeInfo::DeviceStatusRuntimeInfo(const char *subject, runtime_info_key_e key) : + DeviceProviderBase(subject), __infoKey(key) { } -runtime_info_key_e ctx::DeviceStatusRuntimeInfo::__getInfoKey() +runtime_info_key_e DeviceStatusRuntimeInfo::__getInfoKey() { return __infoKey; } -void ctx::DeviceStatusRuntimeInfo::updateCb(runtime_info_key_e runtimeKey, void* userData) +void DeviceStatusRuntimeInfo::updateCb(runtime_info_key_e runtimeKey, void* userData) { DeviceStatusRuntimeInfo *instance = static_cast(userData); IF_FAIL_VOID_TAG(runtimeKey == instance->__getInfoKey(), _W, "Runtime info key mismatch"); instance->handleUpdate(); } -int ctx::DeviceStatusRuntimeInfo::subscribe() +int DeviceStatusRuntimeInfo::subscribe() { int ret = runtime_info_set_changed_cb(__infoKey, updateCb, this); IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::DeviceStatusRuntimeInfo::unsubscribe() +int DeviceStatusRuntimeInfo::unsubscribe() { int ret = runtime_info_unset_changed_cb(__infoKey); IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED); diff --git a/src/device/system/runtime_info/RuntimeInfoBase.h b/src/device/system/runtime_info/RuntimeInfoBase.h index a0e2c20..a2e4a88 100644 --- a/src/device/system/runtime_info/RuntimeInfoBase.h +++ b/src/device/system/runtime_info/RuntimeInfoBase.h @@ -24,7 +24,7 @@ namespace ctx { class DeviceStatusRuntimeInfo : public DeviceProviderBase { public: - DeviceStatusRuntimeInfo(runtime_info_key_e key); + DeviceStatusRuntimeInfo(const char *subject, runtime_info_key_e key); int subscribe(); int unsubscribe(); diff --git a/src/device/system/runtime_info/Usb.cpp b/src/device/system/runtime_info/Usb.cpp index 929a03f..e0aa6af 100644 --- a/src/device/system/runtime_info/Usb.cpp +++ b/src/device/system/runtime_info/Usb.cpp @@ -14,55 +14,54 @@ * limitations under the License. */ -#include #include "../SystemTypes.h" #include "Usb.h" -GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusUsb); +using namespace ctx; -ctx::DeviceStatusUsb::DeviceStatusUsb() : - DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_USB_CONNECTED) +DeviceStatusUsb::DeviceStatusUsb() : + DeviceStatusRuntimeInfo(DEVICE_ST_SUBJ_USB, RUNTIME_INFO_KEY_USB_CONNECTED) { } -ctx::DeviceStatusUsb::~DeviceStatusUsb() +DeviceStatusUsb::~DeviceStatusUsb() { } -bool ctx::DeviceStatusUsb::isSupported() +bool DeviceStatusUsb::isSupported() { return getSystemInfoBool("tizen.org/feature/usb.host"); } -void ctx::DeviceStatusUsb::submitTriggerItem() +void DeviceStatusUsb::submitTriggerItem() { - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_USB, OPS_SUBSCRIBE | OPS_READ, + registerTriggerItem(OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL); } -void ctx::DeviceStatusUsb::handleUpdate() +void DeviceStatusUsb::handleUpdate() { bool status = false; int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_USB_CONNECTED, &status); IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed"); - ctx::Json dataRead; + Json dataRead; dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - context_manager::publish(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, dataRead); + publish(NULL, ERR_NONE, dataRead); } -int ctx::DeviceStatusUsb::read() +int DeviceStatusUsb::read() { bool status = false; - ctx::Json dataRead; + Json dataRead; int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_USB_CONNECTED, &status); IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed"); dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, dataRead); + replyToRead(NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/runtime_info/Usb.h b/src/device/system/runtime_info/Usb.h index 4602752..fc8678c 100644 --- a/src/device/system/runtime_info/Usb.h +++ b/src/device/system/runtime_info/Usb.h @@ -22,20 +22,17 @@ namespace ctx { class DeviceStatusUsb : public DeviceStatusRuntimeInfo { - - GENERATE_PROVIDER_COMMON_DECL(DeviceStatusUsb); - public: + DeviceStatusUsb(); + ~DeviceStatusUsb(); + int read(); - static bool isSupported(); - static void submitTriggerItem(); + + bool isSupported(); + void submitTriggerItem(); protected: void handleUpdate(); - - private: - DeviceStatusUsb(); - ~DeviceStatusUsb(); }; } diff --git a/src/place/PlaceContextProvider.cpp b/src/place/PlaceContextProvider.cpp index 363ed86..349000a 100644 --- a/src/place/PlaceContextProvider.cpp +++ b/src/place/PlaceContextProvider.cpp @@ -15,8 +15,6 @@ */ #include -#include -#include #include #ifdef _MOBILE_ @@ -29,21 +27,24 @@ template void registerProvider(const char *subject, const char *privilege) { - if (!Provider::isSupported()) + Provider *provider = new(std::nothrow) Provider(); + IF_FAIL_VOID_TAG(provider, _E, "Memory allocation failed"); + + if (!provider->isSupported()) { + delete provider; return; + } - ctx::ContextProviderInfo providerInfo(Provider::create, Provider::destroy, NULL, privilege); - ctx::context_manager::registerProvider(subject, providerInfo); + provider->registerProvider(privilege, provider); + provider->submitTriggerItem(); } SO_EXPORT bool ctx::initPlaceContextProvider() { #ifdef _MOBILE_ registerProvider(PLACE_SUBJ_GEOFENCE, PLACE_PRIV_GEOFENCE); - PlaceGeofenceProvider::submitTriggerItem(); #ifndef _DISABLE_RECOG_ENGINE_ - PlaceRecognitionProvider::create(NULL); registerProvider(PLACE_SUBJ_RECOGNITION, PLACE_PRIV_RECOGNITION); #endif /* _DISABLE_RECOG_ENGINE_ */ diff --git a/src/place/geofence/GeofenceMonitorHandle.cpp b/src/place/geofence/GeofenceMonitorHandle.cpp index 0e031bf..868966a 100644 --- a/src/place/geofence/GeofenceMonitorHandle.cpp +++ b/src/place/geofence/GeofenceMonitorHandle.cpp @@ -16,23 +16,25 @@ #include #include -#include -#include "PlaceGeofenceTypes.h" +#include "PlaceGeofenceProvider.h" #include "GeofenceMonitorHandle.h" -ctx::GeofenceMonitorHandle::GeofenceMonitorHandle() : +using namespace ctx; + +GeofenceMonitorHandle::GeofenceMonitorHandle(PlaceGeofenceProvider *provider) : + __provider(provider), __placeId(-1), __prevState(GEOFENCE_STATE_UNCERTAIN), __geoHandle(NULL) { } -ctx::GeofenceMonitorHandle::~GeofenceMonitorHandle() +GeofenceMonitorHandle::~GeofenceMonitorHandle() { __stopMonitor(); } -bool ctx::GeofenceMonitorHandle::startMonitor(int placeId) +bool GeofenceMonitorHandle::startMonitor(int placeId) { _D("Starts to monitor Place-%d", placeId); @@ -61,12 +63,12 @@ CATCH: return false; } -int ctx::GeofenceMonitorHandle::getPlaceId() +int GeofenceMonitorHandle::getPlaceId() { return __placeId; } -void ctx::GeofenceMonitorHandle::__stopMonitor() +void GeofenceMonitorHandle::__stopMonitor() { _D("Stops monitoring Place-%d", __placeId); @@ -81,7 +83,7 @@ void ctx::GeofenceMonitorHandle::__stopMonitor() __prevState = GEOFENCE_STATE_UNCERTAIN; } -bool ctx::GeofenceMonitorHandle::__startFence(int fenceId) +bool GeofenceMonitorHandle::__startFence(int fenceId) { int ret; @@ -101,48 +103,48 @@ bool ctx::GeofenceMonitorHandle::__startFence(int fenceId) return true; } -void ctx::GeofenceMonitorHandle::__removeFence(int fenceId) +void GeofenceMonitorHandle::__removeFence(int fenceId) { geofence_manager_stop(__geoHandle, fenceId); __geoStateMap.erase(fenceId); } -void ctx::GeofenceMonitorHandle::__updateFence(int fenceId, geofence_manage_e manage) +void GeofenceMonitorHandle::__updateFence(int fenceId, geofence_manage_e manage) { switch (manage) { - case GEOFENCE_MANAGE_PLACE_REMOVED: - _W("[Place-%d] Removed", __placeId); - __stopMonitor(); - break; - case GEOFENCE_MANAGE_FENCE_ADDED: - _I("[Place %d] Fence-%d added", __placeId, fenceId); - __startFence(fenceId); - __emitStateChange(); - break; - case GEOFENCE_MANAGE_FENCE_REMOVED: - _I("[Place-%d] Fence-%d removed", __placeId, fenceId); - __removeFence(fenceId); - __emitStateChange(); - break; - case GEOFENCE_MANAGE_FENCE_STARTED: - _D("[Place-%d] Fence-%d started", __placeId, fenceId); - break; - case GEOFENCE_MANAGE_FENCE_STOPPED: - _D("[Place-%d] Fence-%d stopped", __placeId, fenceId); - //TODO: Do we need to restart this? - break; - default: - _D("[Place-%d] Ignoring the manage event %d", __placeId, manage); - break; + case GEOFENCE_MANAGE_PLACE_REMOVED: + _W("[Place-%d] Removed", __placeId); + __stopMonitor(); + break; + case GEOFENCE_MANAGE_FENCE_ADDED: + _I("[Place %d] Fence-%d added", __placeId, fenceId); + __startFence(fenceId); + __emitStateChange(); + break; + case GEOFENCE_MANAGE_FENCE_REMOVED: + _I("[Place-%d] Fence-%d removed", __placeId, fenceId); + __removeFence(fenceId); + __emitStateChange(); + break; + case GEOFENCE_MANAGE_FENCE_STARTED: + _D("[Place-%d] Fence-%d started", __placeId, fenceId); + break; + case GEOFENCE_MANAGE_FENCE_STOPPED: + _D("[Place-%d] Fence-%d stopped", __placeId, fenceId); + //TODO: Do we need to restart this? + break; + default: + _D("[Place-%d] Ignoring the manage event %d", __placeId, manage); + break; } } -void ctx::GeofenceMonitorHandle::__updateState(int fenceId, geofence_state_e state) +void GeofenceMonitorHandle::__updateState(int fenceId, geofence_state_e state) { __geoStateMap[fenceId] = state; } -void ctx::GeofenceMonitorHandle::__emitStateChange() +void GeofenceMonitorHandle::__emitStateChange() { geofence_state_e currentState = GEOFENCE_STATE_UNCERTAIN; int outCount = 0; @@ -173,10 +175,10 @@ void ctx::GeofenceMonitorHandle::__emitStateChange() data.set(NULL, PLACE_GEOFENCE_PLACE_ID, __placeId); data.set(NULL, PLACE_GEOFENCE_EVENT, __getStateString(currentState)); - context_manager::publish(PLACE_SUBJ_GEOFENCE, option, ERR_NONE, data); + __provider->publish(option, ERR_NONE, data); } -const char* ctx::GeofenceMonitorHandle::__getStateString(geofence_state_e state) +const char* GeofenceMonitorHandle::__getStateString(geofence_state_e state) { switch (state) { case GEOFENCE_STATE_IN: @@ -190,7 +192,7 @@ const char* ctx::GeofenceMonitorHandle::__getStateString(geofence_state_e state) } } -bool ctx::GeofenceMonitorHandle::__fenceListCb(int geofenceId, geofence_h fence, int fenceIndex, int fenceCount, void* userData) +bool GeofenceMonitorHandle::__fenceListCb(int geofenceId, geofence_h fence, int fenceIndex, int fenceCount, void* userData) { _D("FenceID: %d, Index: %d, Count: %d", geofenceId, fenceIndex, fenceCount); IF_FAIL_RETURN(fenceCount > 0, false); @@ -199,7 +201,7 @@ bool ctx::GeofenceMonitorHandle::__fenceListCb(int geofenceId, geofence_h fence, return handle->__startFence(geofenceId); } -void ctx::GeofenceMonitorHandle::__fenceEventCb(int placeId, int geofenceId, geofence_manager_error_e error, geofence_manage_e manage, void* userData) +void GeofenceMonitorHandle::__fenceEventCb(int placeId, int geofenceId, geofence_manager_error_e error, geofence_manage_e manage, void* userData) { IF_FAIL_VOID_TAG(error == GEOFENCE_MANAGER_ERROR_NONE, _W, "Geofence error: %d", error); @@ -210,7 +212,7 @@ void ctx::GeofenceMonitorHandle::__fenceEventCb(int placeId, int geofenceId, geo handle->__updateFence(geofenceId, manage); } -void ctx::GeofenceMonitorHandle::__fenceStateCb(int geofenceId, geofence_state_e state, void* userData) +void GeofenceMonitorHandle::__fenceStateCb(int geofenceId, geofence_state_e state, void* userData) { GeofenceMonitorHandle *handle = reinterpret_cast(userData); handle->__updateState(geofenceId, state); diff --git a/src/place/geofence/GeofenceMonitorHandle.h b/src/place/geofence/GeofenceMonitorHandle.h index 2dc17ff..6bdd301 100644 --- a/src/place/geofence/GeofenceMonitorHandle.h +++ b/src/place/geofence/GeofenceMonitorHandle.h @@ -23,16 +23,18 @@ namespace ctx { - class GeofenceMonitorHandle { + class PlaceGeofenceProvider; + class GeofenceMonitorHandle { public: - GeofenceMonitorHandle(); + GeofenceMonitorHandle(PlaceGeofenceProvider *provider); ~GeofenceMonitorHandle(); bool startMonitor(int placeId); int getPlaceId(); private: + PlaceGeofenceProvider *__provider; int __placeId; geofence_state_e __prevState; geofence_manager_h __geoHandle; diff --git a/src/place/geofence/PlaceGeofenceProvider.cpp b/src/place/geofence/PlaceGeofenceProvider.cpp index 91b0785..e7aff50 100644 --- a/src/place/geofence/PlaceGeofenceProvider.cpp +++ b/src/place/geofence/PlaceGeofenceProvider.cpp @@ -15,45 +15,26 @@ */ #include - -#include -#include -#include +#include "GeofenceMonitorHandle.h" #include "PlaceGeofenceProvider.h" -ctx::PlaceGeofenceProvider *ctx::PlaceGeofenceProvider::__instance = NULL; +using namespace ctx; -ctx::PlaceGeofenceProvider::PlaceGeofenceProvider() +PlaceGeofenceProvider::PlaceGeofenceProvider() : + ContextProvider(PLACE_SUBJ_GEOFENCE) { } -ctx::PlaceGeofenceProvider::~PlaceGeofenceProvider() +PlaceGeofenceProvider::~PlaceGeofenceProvider() { - for (auto it = __handleMap.begin(); it != __handleMap.end(); ++it) { - delete it->second; + for (auto& it : __handleMap) { + delete it.second; } __handleMap.clear(); } -ctx::ContextProviderBase *ctx::PlaceGeofenceProvider::create(void *data) -{ - IF_FAIL_RETURN(!__instance, __instance); - __instance = new(std::nothrow) PlaceGeofenceProvider(); - IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); - _I(BLUE("Created")); - return __instance; -} - -void ctx::PlaceGeofenceProvider::destroy(void *data) -{ - IF_FAIL_VOID(__instance); - delete __instance; - __instance = NULL; - _I(BLUE("Destroyed")); -} - -bool ctx::PlaceGeofenceProvider::isSupported() +bool PlaceGeofenceProvider::isSupported() { bool supported = false; int ret = geofence_manager_is_supported(&supported); @@ -61,9 +42,9 @@ bool ctx::PlaceGeofenceProvider::isSupported() return supported; } -void ctx::PlaceGeofenceProvider::submitTriggerItem() +void PlaceGeofenceProvider::submitTriggerItem() { - context_manager::registerTriggerItem(PLACE_SUBJ_GEOFENCE, OPS_SUBSCRIBE, + registerTriggerItem(OPS_SUBSCRIBE, "{" "\"Event\":{\"type\":\"string\",\"values\":[\"In\",\"Out\"]}" "}", @@ -72,40 +53,7 @@ void ctx::PlaceGeofenceProvider::submitTriggerItem() "}"); } -void ctx::PlaceGeofenceProvider::__destroyIfUnused() -{ - IF_FAIL_VOID(__handleMap.empty()); - destroy(NULL); -} - - -int ctx::PlaceGeofenceProvider::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) -{ - int ret = __subscribe(option); - __destroyIfUnused(); - return ret; -} - -int ctx::PlaceGeofenceProvider::unsubscribe(const char *subject, ctx::Json option) -{ - int ret = __unsubscribe(option); - __destroyIfUnused(); - return ret; -} - -int ctx::PlaceGeofenceProvider::read(const char *subject, ctx::Json option, ctx::Json *requestResult) -{ - __destroyIfUnused(); - return ERR_NOT_SUPPORTED; -} - -int ctx::PlaceGeofenceProvider::write(const char *subject, ctx::Json data, ctx::Json *requestResult) -{ - __destroyIfUnused(); - return ERR_NOT_SUPPORTED; -} - -int ctx::PlaceGeofenceProvider::__subscribe(ctx::Json option) +int PlaceGeofenceProvider::subscribe(Json option, Json *requestResult) { int placeId = -1; option.get(NULL, PLACE_GEOFENCE_PLACE_ID, &placeId); @@ -117,7 +65,7 @@ int ctx::PlaceGeofenceProvider::__subscribe(ctx::Json option) return ERR_NONE; } - GeofenceMonitorHandle *handle = new(std::nothrow) GeofenceMonitorHandle(); + GeofenceMonitorHandle *handle = new(std::nothrow) GeofenceMonitorHandle(this); ASSERT_ALLOC(handle); bool ret = handle->startMonitor(placeId); @@ -132,7 +80,7 @@ int ctx::PlaceGeofenceProvider::__subscribe(ctx::Json option) return ERR_NONE; } -int ctx::PlaceGeofenceProvider::__unsubscribe(ctx::Json option) +int PlaceGeofenceProvider::unsubscribe(Json option) { int placeId = -1; option.get(NULL, PLACE_GEOFENCE_PLACE_ID, &placeId); diff --git a/src/place/geofence/PlaceGeofenceProvider.h b/src/place/geofence/PlaceGeofenceProvider.h index a95f4c6..e6ebf2f 100644 --- a/src/place/geofence/PlaceGeofenceProvider.h +++ b/src/place/geofence/PlaceGeofenceProvider.h @@ -18,35 +18,26 @@ #define _CONTEXT_PLACE_GEOFENCE_PROVIDER_H_ #include -#include -#include "GeofenceMonitorHandle.h" +#include #include "PlaceGeofenceTypes.h" namespace ctx { - class PlaceGeofenceProvider : public ContextProviderBase { + class GeofenceMonitorHandle; + class PlaceGeofenceProvider : public ContextProvider { public: - static ContextProviderBase *create(void *data); - static void destroy(void *data); - static bool isSupported(); - static void submitTriggerItem(); - - 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); - - private: - static PlaceGeofenceProvider *__instance; - std::map __handleMap; - PlaceGeofenceProvider(); ~PlaceGeofenceProvider(); - int __subscribe(ctx::Json option); - int __unsubscribe(ctx::Json option); - void __destroyIfUnused(); + int subscribe(Json option, Json *requestResult); + int unsubscribe(Json option); + + bool isSupported(); + void submitTriggerItem(); + + private: + std::map __handleMap; }; } /* namespace ctx */ diff --git a/src/place/recognition/place_recognition.cpp b/src/place/recognition/place_recognition.cpp index bca18be..b736f1a 100644 --- a/src/place/recognition/place_recognition.cpp +++ b/src/place/recognition/place_recognition.cpp @@ -14,41 +14,20 @@ * limitations under the License. */ -#include -#include #include "place_recognition.h" #include "user_places/user_places.h" -ctx::PlaceRecognitionProvider *ctx::PlaceRecognitionProvider::__instance = NULL; - -ctx::ContextProviderBase *ctx::PlaceRecognitionProvider::create(void *data) -{ - IF_FAIL_RETURN(!__instance, __instance); - __instance = new(std::nothrow) PlaceRecognitionProvider(); - IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); - _I(BLUE("Created")); - return __instance; -} - -void ctx::PlaceRecognitionProvider::destroy(void *data) -{ - IF_FAIL_VOID(__instance); - delete __instance; - __instance = NULL; - _I(BLUE("Destroyed")); -} - -int ctx::PlaceRecognitionProvider::subscribe(const char *subject, ctx::Json option, ctx::Json* requestResult) +int ctx::PlaceRecognitionProvider::subscribe(ctx::Json option, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } -int ctx::PlaceRecognitionProvider::unsubscribe(const char *subject, ctx::Json option) +int ctx::PlaceRecognitionProvider::unsubscribe(ctx::Json option) { return ERR_NOT_SUPPORTED; } -int ctx::PlaceRecognitionProvider::read(const char *subject, ctx::Json option, ctx::Json* requestResult) +int ctx::PlaceRecognitionProvider::read(ctx::Json option, ctx::Json* requestResult) { _I(BLUE("Read")); _J("Option", option); @@ -63,17 +42,18 @@ int ctx::PlaceRecognitionProvider::read(const char *subject, ctx::Json option, c * Please just be sure that, the 2nd input parameter "option" should be the same to the * "option" parameter received via ctx::PlaceRecognitionProvider::read(). */ - ctx::context_manager::replyToRead(PLACE_SUBJ_RECOGNITION, option, ERR_NONE, dataRead); + replyToRead(option, ERR_NONE, dataRead); return ERR_NONE; } -int ctx::PlaceRecognitionProvider::write(const char *subject, ctx::Json data, ctx::Json* requestResult) +int ctx::PlaceRecognitionProvider::write(ctx::Json data, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } bool ctx::PlaceRecognitionProvider::isSupported() { + /* TODO: This function should be implemented properly */ return true; } diff --git a/src/place/recognition/place_recognition.h b/src/place/recognition/place_recognition.h index 545c953..814bb00 100644 --- a/src/place/recognition/place_recognition.h +++ b/src/place/recognition/place_recognition.h @@ -17,31 +17,30 @@ #ifndef _CONTEXT_PLACE_RECOGNITION_H_ #define _CONTEXT_PLACE_RECOGNITION_H_ -#include +#include #include "place_recognition_types.h" #include "user_places/user_places.h" namespace ctx { - class PlaceRecognitionProvider : public ContextProviderBase { - + class PlaceRecognitionProvider : public ContextProvider { public: - static ContextProviderBase *create(void *data); - static void destroy(void *data); - static bool isSupported(); + PlaceRecognitionProvider() : + ContextProvider(PLACE_SUBJ_RECOGNITION), + __engine(PLACE_RECOG_HIGH_ACCURACY_MODE) {} - 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); + ~PlaceRecognitionProvider() {} - private: - static PlaceRecognitionProvider *__instance; - UserPlaces __engine; + int subscribe(ctx::Json option, ctx::Json *requestResult); + int unsubscribe(ctx::Json option); + int read(ctx::Json option, ctx::Json *requestResult); + int write(ctx::Json data, ctx::Json *requestResult); - PlaceRecognitionProvider() : __engine(PLACE_RECOG_HIGH_ACCURACY_MODE) {} - ~PlaceRecognitionProvider() {} + bool isSupported(); + void submitTriggerItem() {} + private: + UserPlaces __engine; }; /* class PlaceRecognitionProvider */ } /* namespace ctx */ diff --git a/src/statistics/CMakeLists.txt b/src/statistics/CMakeLists.txt index 79ac9c5..6b35770 100644 --- a/src/statistics/CMakeLists.txt +++ b/src/statistics/CMakeLists.txt @@ -29,9 +29,3 @@ ENDIF("${PROFILE}" STREQUAL "mobile") # Wearable Profile #IF("${PROFILE}" STREQUAL "wearable") #ENDIF("${PROFILE}" STREQUAL "wearable") - -# TV Profile -IF("${PROFILE}" STREQUAL "tv") - FILE(GLOB prvd_srcs ${prvd_srcs} media/*.cpp) - SET(prvd_deps ${prvd_deps} capi-content-media-content) -ENDIF("${PROFILE}" STREQUAL "tv") diff --git a/src/statistics/StatisticsContextProvider.cpp b/src/statistics/StatisticsContextProvider.cpp index 7c3123d..0dba666 100644 --- a/src/statistics/StatisticsContextProvider.cpp +++ b/src/statistics/StatisticsContextProvider.cpp @@ -14,75 +14,64 @@ */ #include -#include -#include +#include #include -#include "app/AppStatisticsProvider.h" +#include "app/AppStatsProvider.h" +#include "app/AppStatsLogger.h" #ifndef _DISABLE_PREDICTION_ENGINE_ // include prediction engine header files here #endif #ifdef _MOBILE_ -#include "media/MediaStatisticsProvider.h" -#include "social/SocialStatisticsProvider.h" -#endif - -#ifdef _TV_ -#include "media/MediaStatisticsProvider.h" +#include "media/MediaStatsProvider.h" +#include "media/MediaStatsLogger.h" +#include "social/SocialStatsProvider.h" +#include "social/SocialStatsLogger.h" #endif template void registerProvider(const char *subject, const char *privilege) { - if (!Provider::isSupported(subject)) + Provider *provider = new(std::nothrow) Provider(); + IF_FAIL_VOID_TAG(provider, _E, "Memory allocation failed"); + + if (!provider->isSupported()) { + delete provider; return; + } - ctx::ContextProviderInfo providerInfo(Provider::create, Provider::destroy, NULL, privilege); - ctx::context_manager::registerProvider(subject, providerInfo); + provider->registerProvider(privilege, provider); + provider->submitTriggerItem(); } SO_EXPORT bool ctx::initStatisticsContextProvider() { - AppStatisticsProvider::create(NULL); - registerProvider(APP_SUBJ_RECENTLY_USED, APP_HISTORY_PRIV); - registerProvider(APP_SUBJ_FREQUENTLY_USED, APP_HISTORY_PRIV); - registerProvider(APP_SUBJ_RARELY_USED, APP_HISTORY_PRIV); - registerProvider(APP_SUBJ_PEAK_TIME, APP_HISTORY_PRIV); - registerProvider(APP_SUBJ_COMMON_SETTING, APP_HISTORY_PRIV); - registerProvider(APP_SUBJ_FREQUENCY, APP_HISTORY_PRIV); - AppStatisticsProvider::submitTriggerItem(); + registerProvider(APP_SUBJ_LOGGER, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_RECENTLY_USED, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_FREQUENTLY_USED, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_RARELY_USED, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_PEAK_TIME, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_COMMON_SETTING, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_FREQUENCY, APP_HISTORY_PRIV); #ifndef _DISABLE_PREDICTION_ENGINE_ // initialize the prediction engine here #endif #ifdef _MOBILE_ - MediaStatisticsProvider::create(NULL); - registerProvider(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC, MEDIA_HISTORY_PRIV); - registerProvider(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO, MEDIA_HISTORY_PRIV); - registerProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC, MEDIA_HISTORY_PRIV); - registerProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO, MEDIA_HISTORY_PRIV); - registerProvider(MEDIA_SUBJ_MUSIC_FREQUENCY, MEDIA_HISTORY_PRIV); - registerProvider(MEDIA_SUBJ_VIDEO_FREQUENCY, MEDIA_HISTORY_PRIV); - MediaStatisticsProvider::submitTriggerItem(); - - SocialStatisticsProvider::create(NULL); - registerProvider(SOCIAL_SUBJ_FREQ_ADDRESS, SOCIAL_HISTORY_PRIV); - registerProvider(SOCIAL_SUBJ_FREQUENCY, SOCIAL_HISTORY_PRIV); - SocialStatisticsProvider::submitTriggerItem(); -#endif + registerProvider(MEDIA_SUBJ_LOGGER, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_MUSIC_FREQUENCY, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_VIDEO_FREQUENCY, MEDIA_HISTORY_PRIV); -#ifdef _TV_ - MediaStatisticsProvider::create(NULL); - registerProvider(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC, MEDIA_HISTORY_PRIV); - registerProvider(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO, MEDIA_HISTORY_PRIV); - registerProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC, MEDIA_HISTORY_PRIV); - registerProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO, MEDIA_HISTORY_PRIV); - registerProvider(MEDIA_SUBJ_MUSIC_FREQUENCY, MEDIA_HISTORY_PRIV); - registerProvider(MEDIA_SUBJ_VIDEO_FREQUENCY, MEDIA_HISTORY_PRIV); - MediaStatisticsProvider::submitTriggerItem(); + registerProvider(SOCIAL_SUBJ_LOGGER, SOCIAL_HISTORY_PRIV); + registerProvider(SOCIAL_SUBJ_FREQUENCY, SOCIAL_HISTORY_PRIV); + registerProvider(SOCIAL_SUBJ_FREQ_ADDRESS, SOCIAL_HISTORY_PRIV); #endif return true; diff --git a/src/statistics/app/AppStatisticsProvider.cpp b/src/statistics/app/AppStatisticsProvider.cpp deleted file mode 100644 index a7d4211..0000000 --- a/src/statistics/app/AppStatisticsProvider.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 -#include -#include -#include "AppStatisticsProvider.h" -#include "DbHandle.h" - -#include "DbInit.h" -#include "InstallMonitor.h" -#include "ActiveWindowMonitor.h" - -static ctx::AppInstallMonitor *__installMon = NULL; -static ctx::AppUseMonitor *__launchMon = NULL; - -ctx::AppStatisticsProvider *ctx::AppStatisticsProvider::__instance = NULL; - -ctx::AppStatisticsProvider::AppStatisticsProvider() -{ -} - -ctx::AppStatisticsProvider::~AppStatisticsProvider() -{ - delete __installMon; - delete __launchMon; - __installMon = NULL; - __launchMon = NULL; -} - -ctx::ContextProviderBase *ctx::AppStatisticsProvider::create(void *data) -{ - IF_FAIL_RETURN(!__instance, __instance); - - __instance = new(std::nothrow) AppStatisticsProvider(); - IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); - - if (!__instance->__init()) { - destroy(data); - return NULL; - } - - _I(BLUE("Created")); - return __instance; -} - -void ctx::AppStatisticsProvider::destroy(void *data) -{ - IF_FAIL_VOID(__instance); - delete __instance; - __instance = NULL; - _I(BLUE("Destroyed")); -} - -bool ctx::AppStatisticsProvider::isSupported(const char* subject) -{ - return true; -} - -void ctx::AppStatisticsProvider::submitTriggerItem() -{ - context_manager::registerTriggerItem(APP_SUBJ_FREQUENCY, OPS_READ, - "{" TRIG_DEF_RANK "," TRIG_DEF_TOTAL_COUNT "}", - "{" - "\"AppId\":{\"type\":\"string\"}," - TRIG_DEF_TIME_OF_DAY "," TRIG_DEF_DAY_OF_WEEK - "}"); -} - -bool ctx::AppStatisticsProvider::__init() -{ - AppDbInitializer *initializer = new(std::nothrow) AppDbInitializer(); - IF_FAIL_RETURN_TAG(initializer, false, _E, "Memory allocation failed"); - - __installMon = new(std::nothrow) ctx::AppInstallMonitor(); - __launchMon = new(std::nothrow) ctx::AppUseMonitor(); - IF_FAIL_CATCH_TAG(__installMon && __launchMon, _E, "Memory allocation failed"); - return true; - -CATCH: - delete __installMon; - delete __launchMon; - __installMon = NULL; - __launchMon = NULL; - return false; -} - -int ctx::AppStatisticsProvider::subscribe(const char* subject, ctx::Json option, ctx::Json* requestResult) -{ - return ERR_NOT_SUPPORTED; -} - -int ctx::AppStatisticsProvider::unsubscribe(const char* subject, ctx::Json option) -{ - return ERR_NOT_SUPPORTED; -} - -int ctx::AppStatisticsProvider::read(const char* subject, ctx::Json option, ctx::Json* requestResult) -{ - ctx::AppDbHandle *handle = new(std::nothrow) ctx::AppDbHandle(); - IF_FAIL_RETURN_TAG(handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); - - int err = handle->read(subject, option); - if (err != ERR_NONE) { - delete handle; - return err; - } - - return ERR_NONE; -} - -int ctx::AppStatisticsProvider::write(const char* subject, ctx::Json data, ctx::Json* requestResult) -{ - return ERR_NOT_SUPPORTED; -} diff --git a/src/statistics/app/AppStatisticsProvider.h b/src/statistics/app/AppStatisticsProvider.h deleted file mode 100644 index 1d5bb2d..0000000 --- a/src/statistics/app/AppStatisticsProvider.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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_STATS_APP_STATS_PROVIDER_H_ -#define _CONTEXT_STATS_APP_STATS_PROVIDER_H_ - -#include -#include "AppStatisticsTypes.h" - -namespace ctx { - - class AppStatisticsProvider : public ContextProviderBase { - public: - static ContextProviderBase *create(void *data); - static void destroy(void *data); - static bool isSupported(const char *subject); - static void submitTriggerItem(); - - 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); - - private: - static AppStatisticsProvider *__instance; - - AppStatisticsProvider(); - ~AppStatisticsProvider(); - bool __init(); - - }; /* class AppStatisticsProvider */ - -} /* namespace ctx */ - -#endif /* End of _CONTEXT_STATS_APP_STATS_PROVIDER_H_ */ diff --git a/src/statistics/app/AppStatisticsTypes.h b/src/statistics/app/AppStatisticsTypes.h index aa8f2d2..42b049e 100644 --- a/src/statistics/app/AppStatisticsTypes.h +++ b/src/statistics/app/AppStatisticsTypes.h @@ -20,6 +20,7 @@ #include "../shared/CommonTypes.h" #define APP_HISTORY_PRIV "apphistory.read" +#define APP_SUBJ_LOGGER "stats/app/logger" #define APP_SUBJ_RECENTLY_USED "stats/app/recently" #define APP_SUBJ_FREQUENTLY_USED "stats/app/often" #define APP_SUBJ_RARELY_USED "stats/app/rarely" diff --git a/src/statistics/app/AppStatsLogger.cpp b/src/statistics/app/AppStatsLogger.cpp new file mode 100644 index 0000000..9bbb390 --- /dev/null +++ b/src/statistics/app/AppStatsLogger.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AppStatisticsTypes.h" +#include "AppStatsLogger.h" + +using namespace ctx; + +AppStatsLogger::AppStatsLogger() : + ContextProvider(APP_SUBJ_LOGGER), + __initializer(NULL), + __installMon(NULL), + __launchMon(NULL) +{ + __initializer = new(std::nothrow) AppDbInitializer(); + IF_FAIL_VOID_TAG(__initializer, _E, "Memory allocation failed"); + + __installMon = new(std::nothrow) AppInstallMonitor(); + __launchMon = new(std::nothrow) AppUseMonitor(); + IF_FAIL_CATCH_TAG(__installMon && __launchMon, _E, "Memory allocation failed"); + return; + +CATCH: + delete __installMon; + delete __launchMon; + __installMon = NULL; + __launchMon = NULL; +} + +AppStatsLogger::~AppStatsLogger() +{ + delete __installMon; + delete __launchMon; +} + +int AppStatsLogger::subscribe(Json option, Json* requestResult) +{ + return ERR_NONE; +} + +int AppStatsLogger::unsubscribe(Json option) +{ + return ERR_NONE; +} diff --git a/src/statistics/app/AppStatsLogger.h b/src/statistics/app/AppStatsLogger.h new file mode 100644 index 0000000..b2104dd --- /dev/null +++ b/src/statistics/app/AppStatsLogger.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CONTEXT_APP_STATS_LOGGER_H_ +#define _CONTEXT_APP_STATS_LOGGER_H_ + +#include +#include "DbInit.h" +#include "InstallMonitor.h" +#include "ActiveWindowMonitor.h" + +namespace ctx { + + class AppStatsLogger : public ContextProvider { + public: + AppStatsLogger(); + ~AppStatsLogger(); + + int subscribe(Json option, Json *requestResult); + int unsubscribe(Json option); + + void submitTriggerItem() {} + + private: + AppDbInitializer *__initializer; + AppInstallMonitor *__installMon; + AppUseMonitor *__launchMon; + }; + +} /* namespace ctx */ + +#endif /* _CONTEXT_APP_STATS_LOGGER_H_ */ diff --git a/src/statistics/app/AppStatsProvider.cpp b/src/statistics/app/AppStatsProvider.cpp new file mode 100644 index 0000000..7e18049 --- /dev/null +++ b/src/statistics/app/AppStatsProvider.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AppStatsProvider.h" +#include "DbHandle.h" + +using namespace ctx; + +AppStatsProvider::AppStatsProvider(const char *subject) : + ContextProvider(subject) +{ +} + +AppStatsProvider::~AppStatsProvider() +{ +} + +void AppStatsProvider::submitTriggerItem() +{ +} + +int AppStatsProvider::read(Json option, Json *requestResult) +{ + AppDbHandle *handle = new(std::nothrow) AppDbHandle(this); + IF_FAIL_RETURN_TAG(handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); + + int err = handle->read(option); + if (err != ERR_NONE) { + delete handle; + return err; + } + + return ERR_NONE; +} + +void AppFreqProvider::submitTriggerItem() +{ + registerTriggerItem(OPS_READ, + "{" TRIG_DEF_RANK "," TRIG_DEF_TOTAL_COUNT "}", + "{" + "\"AppId\":{\"type\":\"string\"}," + TRIG_DEF_TIME_OF_DAY "," TRIG_DEF_DAY_OF_WEEK + "}"); +} diff --git a/src/statistics/app/AppStatsProvider.h b/src/statistics/app/AppStatsProvider.h new file mode 100644 index 0000000..dccb66a --- /dev/null +++ b/src/statistics/app/AppStatsProvider.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CONTEXT_APP_STATS_PROVIDER_H_ +#define _CONTEXT_APP_STATS_PROVIDER_H_ + +#include +#include "AppStatisticsTypes.h" + +namespace ctx { + + class AppStatsProvider : public ContextProvider { + public: + int read(Json option, Json *requestResult); + virtual void submitTriggerItem(); + + protected: + AppStatsProvider(const char *subject); + virtual ~AppStatsProvider(); + }; + + + class RecentAppProvider : public AppStatsProvider { + public: + RecentAppProvider() : + AppStatsProvider(APP_SUBJ_RECENTLY_USED) {} + }; + + + class FrequentAppProvider : public AppStatsProvider { + public: + FrequentAppProvider() : + AppStatsProvider(APP_SUBJ_FREQUENTLY_USED) {} + }; + + + class RareAppProvider : public AppStatsProvider { + public: + RareAppProvider() : + AppStatsProvider(APP_SUBJ_RARELY_USED) {} + }; + + + class AppPeakTimeProvider : public AppStatsProvider { + public: + AppPeakTimeProvider() : + AppStatsProvider(APP_SUBJ_PEAK_TIME) {} + }; + + + class AppSettingProvider : public AppStatsProvider { + public: + AppSettingProvider() : + AppStatsProvider(APP_SUBJ_COMMON_SETTING) {} + }; + + + class AppFreqProvider : public AppStatsProvider { + public: + AppFreqProvider() : + AppStatsProvider(APP_SUBJ_FREQUENCY) {} + + void submitTriggerItem(); + }; + +} /* namespace ctx */ + +#endif /* _CONTEXT_APP_STATS_PROVIDER_H_ */ diff --git a/src/statistics/app/DbHandle.cpp b/src/statistics/app/DbHandle.cpp index b83c137..06021e3 100644 --- a/src/statistics/app/DbHandle.cpp +++ b/src/statistics/app/DbHandle.cpp @@ -16,21 +16,24 @@ #include #include -#include #include "AppStatisticsTypes.h" #include "DbHandle.h" -ctx::AppDbHandle::AppDbHandle() +using namespace ctx; + +AppDbHandle::AppDbHandle(ContextProvider *provider) : + StatsDbHandleBase(provider) { } -ctx::AppDbHandle::~AppDbHandle() +AppDbHandle::~AppDbHandle() { } -int ctx::AppDbHandle::read(const char* subject, ctx::Json filter) +int AppDbHandle::read(Json filter) { std::string query; + const char *subject = reqProvider->getSubject(); if (STR_EQ(subject, APP_SUBJ_RECENTLY_USED)) { query = createSqlRecentlyUsed(filter); @@ -48,19 +51,19 @@ int ctx::AppDbHandle::read(const char* subject, ctx::Json filter) query = createSqlCommonSetting(filter); } else if (STR_EQ(subject, APP_SUBJ_FREQUENCY)) { - __isTriggerItem = true; + isTriggerItem = true; query = createSqlFrequency(filter); } IF_FAIL_RETURN(!query.empty(), ERR_OPERATION_FAILED); - bool ret = executeQuery(subject, filter, query.c_str()); + bool ret = executeQuery(filter, query.c_str()); IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED); return ERR_NONE; } -std::string ctx::AppDbHandle::createWhereClauseWithDeviceStatus(ctx::Json filter) +std::string AppDbHandle::createWhereClauseWithDeviceStatus(Json filter) { std::stringstream whereClause; std::string bssid; @@ -77,19 +80,19 @@ std::string ctx::AppDbHandle::createWhereClauseWithDeviceStatus(ctx::Json filter return whereClause.str(); } -std::string ctx::AppDbHandle::createSqlPeakTime(ctx::Json filter) +std::string AppDbHandle::createSqlPeakTime(Json filter) { return StatsDbHandleBase::createSqlPeakTime(filter, APP_TABLE_USAGE_LOG, createWhereClause(filter)); } -std::string ctx::AppDbHandle::createSqlCommonSetting(ctx::Json filter) +std::string AppDbHandle::createSqlCommonSetting(Json filter) { return StatsDbHandleBase::createSqlCommonSetting(filter, APP_TABLE_USAGE_LOG, createWhereClause(filter)); } -std::string ctx::AppDbHandle::createSqlFrequency(ctx::Json filter) +std::string AppDbHandle::createSqlFrequency(Json filter) { - ctx::Json filterCleaned; + Json filterCleaned; std::string weekStr; std::string timeOfDay; std::string appId; @@ -133,7 +136,7 @@ std::string ctx::AppDbHandle::createSqlFrequency(ctx::Json filter) return query.str(); } -std::string ctx::AppDbHandle::createSqlRecentlyUsed(ctx::Json filter) +std::string AppDbHandle::createSqlRecentlyUsed(Json filter) { std::stringstream query; int limit = DEFAULT_LIMIT; @@ -154,7 +157,7 @@ std::string ctx::AppDbHandle::createSqlRecentlyUsed(ctx::Json filter) return query.str(); } -std::string ctx::AppDbHandle::createSqlFrequentlyUsed(ctx::Json filter) +std::string AppDbHandle::createSqlFrequentlyUsed(Json filter) { std::stringstream query; int limit = DEFAULT_LIMIT; @@ -175,7 +178,7 @@ std::string ctx::AppDbHandle::createSqlFrequentlyUsed(ctx::Json filter) return query.str(); } -std::string ctx::AppDbHandle::createSqlRarelyUsed(ctx::Json filter) +std::string AppDbHandle::createSqlRarelyUsed(Json filter) { std::stringstream query; int limit = DEFAULT_LIMIT; @@ -198,11 +201,11 @@ std::string ctx::AppDbHandle::createSqlRarelyUsed(ctx::Json filter) return query.str(); } -void ctx::AppDbHandle::replyTriggerItem(int error, ctx::Json &jsonResult) +void AppDbHandle::replyTriggerItem(int error, Json &jsonResult) { - IF_FAIL_VOID_TAG(STR_EQ(__reqSubject.c_str(), APP_SUBJ_FREQUENCY), _E, "Invalid subject"); + IF_FAIL_VOID_TAG(STR_EQ(reqProvider->getSubject(), APP_SUBJ_FREQUENCY), _E, "Invalid subject"); - ctx::Json results; + Json results; std::string valStr; int val; @@ -213,5 +216,5 @@ void ctx::AppDbHandle::replyTriggerItem(int error, ctx::Json &jsonResult) jsonResult.get(NULL, STATS_RANK, &val); results.set(NULL, STATS_RANK, val); - context_manager::replyToRead(__reqSubject.c_str(), __reqFilter, error, results); + reqProvider->replyToRead(reqFilter, error, results); } diff --git a/src/statistics/app/DbHandle.h b/src/statistics/app/DbHandle.h index ac2e7d5..9084d87 100644 --- a/src/statistics/app/DbHandle.h +++ b/src/statistics/app/DbHandle.h @@ -24,20 +24,20 @@ namespace ctx { class AppDbHandle : public StatsDbHandleBase { public: - AppDbHandle(); + AppDbHandle(ContextProvider *provider); ~AppDbHandle(); - int read(const char* subject, ctx::Json filter); + int read(Json filter); protected: - std::string createWhereClauseWithDeviceStatus(ctx::Json filter); - std::string createSqlRecentlyUsed(ctx::Json filter); - std::string createSqlFrequentlyUsed(ctx::Json filter); - std::string createSqlRarelyUsed(ctx::Json filter); - std::string createSqlPeakTime(ctx::Json filter); - std::string createSqlCommonSetting(ctx::Json filter); - std::string createSqlFrequency(ctx::Json filter); - void replyTriggerItem(int error, ctx::Json &jsonResult); + std::string createWhereClauseWithDeviceStatus(Json filter); + std::string createSqlRecentlyUsed(Json filter); + std::string createSqlFrequentlyUsed(Json filter); + std::string createSqlRarelyUsed(Json filter); + std::string createSqlPeakTime(Json filter); + std::string createSqlCommonSetting(Json filter); + std::string createSqlFrequency(Json filter); + void replyTriggerItem(int error, Json &jsonResult); }; } diff --git a/src/statistics/app/app_inactive_detector/AppInactiveDetector.cpp b/src/statistics/app/app_inactive_detector/AppInactiveDetector.cpp index 48dc313..148d655 100644 --- a/src/statistics/app/app_inactive_detector/AppInactiveDetector.cpp +++ b/src/statistics/app/app_inactive_detector/AppInactiveDetector.cpp @@ -32,7 +32,7 @@ ctx::app_inactive_detector_provider::~app_inactive_detector_provider() { } -ctx::ContextProviderBase *ctx::app_inactive_detector_provider::create(void *data) +ctx::ContextProvider *ctx::app_inactive_detector_provider::create(void *data) { IF_FAIL_RETURN(!__instance, __instance); __instance = new(std::nothrow) app_inactive_detector_provider(); diff --git a/src/statistics/app/app_inactive_detector/AppInactiveDetector.h b/src/statistics/app/app_inactive_detector/AppInactiveDetector.h index 2dd427d..588130a 100644 --- a/src/statistics/app/app_inactive_detector/AppInactiveDetector.h +++ b/src/statistics/app/app_inactive_detector/AppInactiveDetector.h @@ -17,16 +17,16 @@ #ifndef __CONTEXT_APP_INACTIVE_DETECTOR_H__ #define __CONTEXT_APP_INACTIVE_DETECTOR_H__ -#include +#include #include "AppInactiveDetectorTypes.h" #include "InactiveDetector.h" namespace ctx { - class app_inactive_detector_provider : public ContextProviderBase { + class app_inactive_detector_provider : public ContextProvider { public: - static ContextProviderBase *create(void *data); + static ContextProvider *create(void *data); static void destroy(void *data); static bool is_supported(); diff --git a/src/statistics/media/DbHandle.cpp b/src/statistics/media/DbHandle.cpp index ec1e252..e8f0f03 100644 --- a/src/statistics/media/DbHandle.cpp +++ b/src/statistics/media/DbHandle.cpp @@ -16,23 +16,26 @@ #include #include -#include #include "../shared/SystemInfo.h" #include "MediaStatisticsTypes.h" #include "DbHandle.h" -ctx::MediaDbHandle::MediaDbHandle() +using namespace ctx; + +MediaDbHandle::MediaDbHandle(ContextProvider *provider) : + StatsDbHandleBase(provider) { } -ctx::MediaDbHandle::~MediaDbHandle() +MediaDbHandle::~MediaDbHandle() { } -int ctx::MediaDbHandle::read(const char* subject, ctx::Json filter) +int MediaDbHandle::read(Json filter) { //TODO: filter validation (in the API side?) std::string query; + const char *subject = reqProvider->getSubject(); if (STR_EQ(subject, MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC)) { query = createSqlPeakTime(MEDIA_TYPE_MUSIC, filter); @@ -47,23 +50,23 @@ int ctx::MediaDbHandle::read(const char* subject, ctx::Json filter) query = createSqlCommonSetting(MEDIA_TYPE_VIDEO, filter); } else if (STR_EQ(subject, MEDIA_SUBJ_MUSIC_FREQUENCY)) { - __isTriggerItem = true; + isTriggerItem = true; query = createSqlFrequency(MEDIA_TYPE_MUSIC, filter); } else if (STR_EQ(subject, MEDIA_SUBJ_VIDEO_FREQUENCY)) { - __isTriggerItem = true; + isTriggerItem = true; query = createSqlFrequency(MEDIA_TYPE_VIDEO, filter); } IF_FAIL_RETURN(!query.empty(), ERR_OPERATION_FAILED); - bool ret = executeQuery(subject, filter, query.c_str()); + bool ret = executeQuery(filter, query.c_str()); IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED); return ERR_NONE; } -std::string ctx::MediaDbHandle::createWhereClause(int mediaType, ctx::Json filter) +std::string MediaDbHandle::createWhereClause(int mediaType, Json filter) { std::stringstream whereClause; @@ -73,21 +76,21 @@ std::string ctx::MediaDbHandle::createWhereClause(int mediaType, ctx::Json filte return whereClause.str(); } -std::string ctx::MediaDbHandle::createSqlPeakTime(int mediaType, ctx::Json filter) +std::string MediaDbHandle::createSqlPeakTime(int mediaType, Json filter) { std::string where = createWhereClause(mediaType, filter); return StatsDbHandleBase::createSqlPeakTime(filter, MEDIA_TABLE_NAME, where); } -std::string ctx::MediaDbHandle::createSqlCommonSetting(int mediaType, ctx::Json filter) +std::string MediaDbHandle::createSqlCommonSetting(int mediaType, Json filter) { std::string where = createWhereClause(mediaType, filter); return StatsDbHandleBase::createSqlCommonSetting(filter, MEDIA_TABLE_NAME, where); } -std::string ctx::MediaDbHandle::createSqlFrequency(int mediaType, ctx::Json filter) +std::string MediaDbHandle::createSqlFrequency(int mediaType, Json filter) { - ctx::Json filterCleaned; + Json filterCleaned; std::string weekStr; std::string timeOfDay; @@ -108,16 +111,16 @@ std::string ctx::MediaDbHandle::createSqlFrequency(int mediaType, ctx::Json filt return query.str(); } -void ctx::MediaDbHandle::replyTriggerItem(int error, ctx::Json &jsonResult) +void MediaDbHandle::replyTriggerItem(int error, Json &jsonResult) { - IF_FAIL_VOID_TAG(STR_EQ(__reqSubject.c_str(), MEDIA_SUBJ_MUSIC_FREQUENCY) || - STR_EQ(__reqSubject.c_str(), MEDIA_SUBJ_VIDEO_FREQUENCY), _E, "Invalid subject"); + IF_FAIL_VOID_TAG(STR_EQ(reqProvider->getSubject(), MEDIA_SUBJ_MUSIC_FREQUENCY) || + STR_EQ(reqProvider->getSubject(), MEDIA_SUBJ_VIDEO_FREQUENCY), _E, "Invalid subject"); - ctx::Json results; + Json results; int val; jsonResult.get(NULL, STATS_TOTAL_COUNT, &val); results.set(NULL, STATS_TOTAL_COUNT, val); - context_manager::replyToRead(__reqSubject.c_str(), __reqFilter, error, results); + reqProvider->replyToRead(reqFilter, error, results); } diff --git a/src/statistics/media/DbHandle.h b/src/statistics/media/DbHandle.h index 8a1f036..8b7f1c1 100644 --- a/src/statistics/media/DbHandle.h +++ b/src/statistics/media/DbHandle.h @@ -24,17 +24,17 @@ namespace ctx { class MediaDbHandle : public StatsDbHandleBase { public: - MediaDbHandle(); + MediaDbHandle(ContextProvider *provider); ~MediaDbHandle(); - int read(const char* subject, ctx::Json filter); + int read(Json filter); protected: - std::string createWhereClause(int mediaType, ctx::Json filter); - std::string createSqlPeakTime(int mediaType, ctx::Json filter); - std::string createSqlCommonSetting(int mediaType, ctx::Json filter); - std::string createSqlFrequency(int mediaType, ctx::Json filter); - void replyTriggerItem(int error, ctx::Json &jsonResult); + std::string createWhereClause(int mediaType, Json filter); + std::string createSqlPeakTime(int mediaType, Json filter); + std::string createSqlCommonSetting(int mediaType, Json filter); + std::string createSqlFrequency(int mediaType, Json filter); + void replyTriggerItem(int error, Json &jsonResult); }; } diff --git a/src/statistics/media/MediaStatisticsProvider.cpp b/src/statistics/media/MediaStatisticsProvider.cpp deleted file mode 100644 index 582d654..0000000 --- a/src/statistics/media/MediaStatisticsProvider.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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 -#include -#include -#include "MediaStatisticsProvider.h" -#include "DbHandle.h" -#include "MediaContentMonitor.h" - -static ctx::MediaContentMonitor *__contentMon = NULL; - -ctx::MediaStatisticsProvider *ctx::MediaStatisticsProvider::__instance = NULL; - -ctx::MediaStatisticsProvider::MediaStatisticsProvider() -{ -} - -ctx::MediaStatisticsProvider::~MediaStatisticsProvider() -{ - delete __contentMon; - __contentMon = NULL; -} - -ctx::ContextProviderBase *ctx::MediaStatisticsProvider::create(void *data) -{ - IF_FAIL_RETURN(!__instance, __instance); - - __instance = new(std::nothrow) MediaStatisticsProvider(); - IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); - - _I(BLUE("Created")); - - if (!__instance->__init()) { - destroy(data); - return NULL; - } - - return __instance; -} - -void ctx::MediaStatisticsProvider::destroy(void *data) -{ - IF_FAIL_VOID(__instance); - delete __instance; - __instance = NULL; - _I(BLUE("Destroyed")); -} - -bool ctx::MediaStatisticsProvider::isSupported(const char* subject) -{ - return true; -} - -void ctx::MediaStatisticsProvider::submitTriggerItem() -{ - context_manager::registerTriggerItem(MEDIA_SUBJ_MUSIC_FREQUENCY, OPS_READ, - "{" TRIG_DEF_TOTAL_COUNT "}", - "{" TRIG_DEF_TIME_OF_DAY "," TRIG_DEF_DAY_OF_WEEK "}"); - - context_manager::registerTriggerItem(MEDIA_SUBJ_VIDEO_FREQUENCY, OPS_READ, - "{" TRIG_DEF_TOTAL_COUNT "}", - "{" TRIG_DEF_TIME_OF_DAY "," TRIG_DEF_DAY_OF_WEEK "}"); -} - -bool ctx::MediaStatisticsProvider::__init() -{ - __contentMon = new(std::nothrow) ctx::MediaContentMonitor(); - IF_FAIL_RETURN_TAG(__contentMon, false, _E, "Memory allocation failed"); - return true; -} - -int ctx::MediaStatisticsProvider::subscribe(const char* subject, ctx::Json option, ctx::Json* requestResult) -{ - return ERR_NOT_SUPPORTED; -} - -int ctx::MediaStatisticsProvider::unsubscribe(const char* subject, ctx::Json option) -{ - return ERR_NOT_SUPPORTED; -} - -int ctx::MediaStatisticsProvider::read(const char* subject, ctx::Json option, ctx::Json* requestResult) -{ - MediaDbHandle *handle = new(std::nothrow) MediaDbHandle(); - IF_FAIL_RETURN_TAG(handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); - - int err = handle->read(subject, option); - if (err != ERR_NONE) { - delete handle; - return err; - } - - return ERR_NONE; -} - -int ctx::MediaStatisticsProvider::write(const char* subject, ctx::Json data, ctx::Json* requestResult) -{ - return ERR_NOT_SUPPORTED; -} diff --git a/src/statistics/media/MediaStatisticsProvider.h b/src/statistics/media/MediaStatisticsProvider.h deleted file mode 100644 index edcbc5a..0000000 --- a/src/statistics/media/MediaStatisticsProvider.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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_STATS_MEDIA_STATS_PROVIDER_H_ -#define _CONTEXT_STATS_MEDIA_STATS_PROVIDER_H_ - -#include -#include "MediaStatisticsTypes.h" - -namespace ctx { - - class MediaStatisticsProvider : public ContextProviderBase { - public: - static ContextProviderBase *create(void *data); - static void destroy(void *data); - static bool isSupported(const char *subject); - static void submitTriggerItem(); - - 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); - - private: - static MediaStatisticsProvider *__instance; - - MediaStatisticsProvider(); - ~MediaStatisticsProvider(); - bool __init(); - - }; /* class MediaStatisticsProvider */ - -} /* namespace ctx */ - -#endif /* End of _CONTEXT_STATS_MEDIA_STATS_PROVIDER_H_ */ diff --git a/src/statistics/media/MediaStatisticsTypes.h b/src/statistics/media/MediaStatisticsTypes.h index 71d1fa1..a71e553 100644 --- a/src/statistics/media/MediaStatisticsTypes.h +++ b/src/statistics/media/MediaStatisticsTypes.h @@ -20,6 +20,7 @@ #include "../shared/CommonTypes.h" #define MEDIA_HISTORY_PRIV "mediahistory.read" +#define MEDIA_SUBJ_LOGGER "stats/media/logger" #define MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC "stats/music/peak_time" #define MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO "stats/video/peak_time" #define MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC "stats/music/setting" diff --git a/src/statistics/media/MediaStatsLogger.cpp b/src/statistics/media/MediaStatsLogger.cpp new file mode 100644 index 0000000..9b1db7d --- /dev/null +++ b/src/statistics/media/MediaStatsLogger.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MediaStatisticsTypes.h" +#include "MediaStatsLogger.h" + +using namespace ctx; + +MediaStatsLogger::MediaStatsLogger() : + ContextProvider(MEDIA_SUBJ_LOGGER) +{ +} + +MediaStatsLogger::~MediaStatsLogger() +{ +} + +int MediaStatsLogger::subscribe(Json option, Json* requestResult) +{ + return ERR_NONE; +} + +int MediaStatsLogger::unsubscribe(Json option) +{ + return ERR_NONE; +} diff --git a/src/statistics/media/MediaStatsLogger.h b/src/statistics/media/MediaStatsLogger.h new file mode 100644 index 0000000..28e8aca --- /dev/null +++ b/src/statistics/media/MediaStatsLogger.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CONTEXT_MEDIA_STATS_LOGGER_H_ +#define _CONTEXT_MEDIA_STATS_LOGGER_H_ + +#include +#include "MediaContentMonitor.h" + +namespace ctx { + + class MediaStatsLogger : public ContextProvider { + public: + MediaStatsLogger(); + ~MediaStatsLogger(); + + int subscribe(Json option, Json *requestResult); + int unsubscribe(Json option); + + void submitTriggerItem() {} + + private: + MediaContentMonitor __contentMon; + }; + +} /* namespace ctx */ + +#endif /* _CONTEXT_MEDIA_STATS_LOGGER_H_ */ + diff --git a/src/statistics/media/MediaStatsProvider.cpp b/src/statistics/media/MediaStatsProvider.cpp new file mode 100644 index 0000000..b8ce482 --- /dev/null +++ b/src/statistics/media/MediaStatsProvider.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MediaStatsProvider.h" +#include "DbHandle.h" + +using namespace ctx; + +MediaStatsProvider::MediaStatsProvider(const char *subject) : + ContextProvider(subject) +{ +} + +MediaStatsProvider::~MediaStatsProvider() +{ +} + +bool MediaStatsProvider::isSupported() +{ + /* TODO */ + return true; +} + +void MediaStatsProvider::submitTriggerItem() +{ +} + +int MediaStatsProvider::read(Json option, Json* requestResult) +{ + MediaDbHandle *handle = new(std::nothrow) MediaDbHandle(this); + IF_FAIL_RETURN_TAG(handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); + + int err = handle->read(option); + if (err != ERR_NONE) { + delete handle; + return err; + } + + return ERR_NONE; +} + +void MusicFreqProvider::submitTriggerItem() +{ + registerTriggerItem(OPS_READ, + "{" TRIG_DEF_TOTAL_COUNT "}", + "{" TRIG_DEF_TIME_OF_DAY "," TRIG_DEF_DAY_OF_WEEK "}"); +} + +void VideoFreqProvider::submitTriggerItem() +{ + registerTriggerItem(OPS_READ, + "{" TRIG_DEF_TOTAL_COUNT "}", + "{" TRIG_DEF_TIME_OF_DAY "," TRIG_DEF_DAY_OF_WEEK "}"); +} diff --git a/src/statistics/media/MediaStatsProvider.h b/src/statistics/media/MediaStatsProvider.h new file mode 100644 index 0000000..5895c46 --- /dev/null +++ b/src/statistics/media/MediaStatsProvider.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CONTEXT_MEDIA_STATS_PROVIDER_H_ +#define _CONTEXT_MEDIA_STATS_PROVIDER_H_ + +#include +#include "MediaStatisticsTypes.h" + +namespace ctx { + + class MediaStatsProvider : public ContextProvider { + public: + int read(Json option, Json* requestResult); + + bool isSupported(); + virtual void submitTriggerItem(); + + protected: + MediaStatsProvider(const char *subject); + virtual ~MediaStatsProvider(); + }; /* class MediaStatsProvider */ + + + class MusicPeakTimeProvider : public MediaStatsProvider { + public: + MusicPeakTimeProvider() : + MediaStatsProvider(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC) {} + }; + + + class VideoPeakTimeProvider : public MediaStatsProvider { + public: + VideoPeakTimeProvider() : + MediaStatsProvider(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO) {} + }; + + + class MusicSettingProvider: public MediaStatsProvider { + public: + MusicSettingProvider() : + MediaStatsProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC) {} + }; + + + class VideoSettingProvider: public MediaStatsProvider { + public: + VideoSettingProvider() : + MediaStatsProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO) {} + }; + + + class MusicFreqProvider: public MediaStatsProvider { + public: + MusicFreqProvider() : + MediaStatsProvider(MEDIA_SUBJ_MUSIC_FREQUENCY) {} + + void submitTriggerItem(); + }; + + + class VideoFreqProvider: public MediaStatsProvider { + public: + VideoFreqProvider() : + MediaStatsProvider(MEDIA_SUBJ_VIDEO_FREQUENCY) {} + + void submitTriggerItem(); + }; + +} /* namespace ctx */ + +#endif /* _CONTEXT_MEDIA_STATS_PROVIDER_H_ */ diff --git a/src/statistics/shared/DbHandleBase.cpp b/src/statistics/shared/DbHandleBase.cpp index 77982aa..979f75b 100644 --- a/src/statistics/shared/DbHandleBase.cpp +++ b/src/statistics/shared/DbHandleBase.cpp @@ -16,23 +16,25 @@ #include #include -#include #include "CommonTypes.h" #include "DbHandleBase.h" #define DAY_OF_WEEK(SECOND) "CAST(strftime('%w', " SECOND ", 'unixepoch') AS INTEGER)" #define HOUR_OF_DAY(SECOND) "CAST(strftime('%H', " SECOND ", 'unixepoch') AS INTEGER)" -ctx::StatsDbHandleBase::StatsDbHandleBase() : - __isTriggerItem(false) +using namespace ctx; + +StatsDbHandleBase::StatsDbHandleBase(ContextProvider *provider) : + isTriggerItem(false), + reqProvider(provider) { } -ctx::StatsDbHandleBase::~StatsDbHandleBase() +StatsDbHandleBase::~StatsDbHandleBase() { } -int ctx::StatsDbHandleBase::generateQid() +int StatsDbHandleBase::generateQid() { static int qid = 0; @@ -40,18 +42,17 @@ int ctx::StatsDbHandleBase::generateQid() return qid; } -bool ctx::StatsDbHandleBase::executeQuery(const char* subject, ctx::Json filter, const char* query) +bool StatsDbHandleBase::executeQuery(Json filter, const char* query) { bool ret = __dbManager.execute(generateQid(), query, this); IF_FAIL_RETURN(ret, false); - __reqSubject = subject; - __reqFilter = filter; + reqFilter = filter; return true; } -std::string ctx::StatsDbHandleBase::createWhereClause(ctx::Json filter) +std::string StatsDbHandleBase::createWhereClause(Json filter) { std::stringstream whereClause; int week = 0; @@ -141,7 +142,7 @@ std::string ctx::StatsDbHandleBase::createWhereClause(ctx::Json filter) return whereClause.str(); } -std::string ctx::StatsDbHandleBase::createSqlPeakTime(ctx::Json filter, const char* tableName, std::string whereClause) +std::string StatsDbHandleBase::createSqlPeakTime(Json filter, const char* tableName, std::string whereClause) { std::stringstream query; int limit = DEFAULT_LIMIT; @@ -160,7 +161,7 @@ std::string ctx::StatsDbHandleBase::createSqlPeakTime(ctx::Json filter, const ch return query.str(); } -std::string ctx::StatsDbHandleBase::createSqlCommonSetting(ctx::Json filter, const char* tableName, std::string whereClause) +std::string StatsDbHandleBase::createSqlCommonSetting(Json filter, const char* tableName, std::string whereClause) { std::stringstream query; @@ -187,16 +188,16 @@ std::string ctx::StatsDbHandleBase::createSqlCommonSetting(ctx::Json filter, con return query.str(); } -void ctx::StatsDbHandleBase::onTableCreated(unsigned int queryId, int error) +void StatsDbHandleBase::onTableCreated(unsigned int queryId, int error) { } -void ctx::StatsDbHandleBase::onInserted(unsigned int queryId, int error, int64_t rowId) +void StatsDbHandleBase::onInserted(unsigned int queryId, int error, int64_t rowId) { delete this; } -void ctx::StatsDbHandleBase::jsonVectorToArray(std::vector &vecJson, ctx::Json &jsonResult) +void StatsDbHandleBase::__jsonVectorToArray(std::vector &vecJson, Json &jsonResult) { std::vector::iterator vecJsonEnd = vecJson.end(); @@ -206,20 +207,20 @@ void ctx::StatsDbHandleBase::jsonVectorToArray(std::vector &vecJson, ctx:: } } -void ctx::StatsDbHandleBase::onExecuted(unsigned int queryId, int error, std::vector& records) +void StatsDbHandleBase::onExecuted(unsigned int queryId, int error, std::vector& records) { - if (__isTriggerItem) { + if (isTriggerItem) { if (records.size() == 1) { replyTriggerItem(error, records[0]); } else { _E("Invalid query result"); Json dummy; - context_manager::replyToRead(__reqSubject.c_str(), __reqFilter, ERR_OPERATION_FAILED, dummy); + reqProvider->replyToRead(reqFilter, ERR_OPERATION_FAILED, dummy); } } else { Json results = "{\"" STATS_QUERY_RESULT "\":[]}"; - jsonVectorToArray(records, results); - context_manager::replyToRead(__reqSubject.c_str(), __reqFilter, error, results); + __jsonVectorToArray(records, results); + reqProvider->replyToRead(reqFilter, error, results); } delete this; diff --git a/src/statistics/shared/DbHandleBase.h b/src/statistics/shared/DbHandleBase.h index 0a06cb9..8949550 100644 --- a/src/statistics/shared/DbHandleBase.h +++ b/src/statistics/shared/DbHandleBase.h @@ -18,34 +18,35 @@ #define _CONTEXT_STATS_DB_HANDLE_BASE_H_ #include -#include +#include #include namespace ctx { class StatsDbHandleBase : public IDatabaseListener { protected: - bool __isTriggerItem; - std::string __reqSubject; - ctx::Json __reqFilter; - DatabaseManager __dbManager; + bool isTriggerItem; + ContextProvider *reqProvider; + Json reqFilter; - StatsDbHandleBase(); + StatsDbHandleBase(ContextProvider *provider); ~StatsDbHandleBase(); - std::string createWhereClause(ctx::Json filter); - std::string createSqlPeakTime(ctx::Json filter, const char* tableName, std::string whereClause); - std::string createSqlCommonSetting(ctx::Json filter, const char* tableName, std::string whereClause); + std::string createWhereClause(Json filter); + std::string createSqlPeakTime(Json filter, const char* tableName, std::string whereClause); + std::string createSqlCommonSetting(Json filter, const char* tableName, std::string whereClause); - bool executeQuery(const char* subject, ctx::Json filter, const char* query); - virtual void replyTriggerItem(int error, ctx::Json &jsonResult) = 0; + bool executeQuery(Json filter, const char* query); + virtual void replyTriggerItem(int error, Json &jsonResult) = 0; static int generateQid(); private: - void jsonVectorToArray(std::vector &vecJson, ctx::Json &jsonResult); + void __jsonVectorToArray(std::vector &vecJson, Json &jsonResult); void onTableCreated(unsigned int queryId, int error); void onInserted(unsigned int queryId, int error, int64_t rowId); void onExecuted(unsigned int queryId, int error, std::vector& records); + + DatabaseManager __dbManager; }; } diff --git a/src/statistics/shared/SystemInfo.cpp b/src/statistics/shared/SystemInfo.cpp index 369d5c3..63731f7 100644 --- a/src/statistics/shared/SystemInfo.cpp +++ b/src/statistics/shared/SystemInfo.cpp @@ -24,7 +24,9 @@ #define CONNECTED 1 #define NOT_CONNECTED 0 -bool ctx::system_info::getAudioJackState(int* state) +using namespace ctx; + +bool system_info::getAudioJackState(int* state) { int value = NOT_CONNECTED; int err = runtime_info_get_value_int(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, &value); @@ -35,7 +37,7 @@ bool ctx::system_info::getAudioJackState(int* state) return true; } -bool ctx::system_info::getVolume(int* systemVolume, int* mediaVolume) +bool system_info::getVolume(int* systemVolume, int* mediaVolume) { int err; @@ -48,7 +50,7 @@ bool ctx::system_info::getVolume(int* systemVolume, int* mediaVolume) return true; } -bool ctx::system_info::getWifiBssid(std::string& bssid) +bool system_info::getWifiBssid(std::string& bssid) { #if 0 /* NOTE: This routine does not work, because the wifi API does not support multi-sessions in one process */ @@ -75,6 +77,6 @@ bool ctx::system_info::getWifiBssid(std::string& bssid) return !bssid.empty(); #endif - bssid = ctx::SharedVars().get(ctx::SharedVars::WIFI_BSSID); + bssid = SharedVars().get(SharedVars::WIFI_BSSID); return true; } diff --git a/src/statistics/social/DbHandle.cpp b/src/statistics/social/DbHandle.cpp index 03c7dab..5c1c0a6 100644 --- a/src/statistics/social/DbHandle.cpp +++ b/src/statistics/social/DbHandle.cpp @@ -17,39 +17,42 @@ #include #include #include -#include #include "SocialStatisticsTypes.h" #include "DbHandle.h" -ctx::SocialDbHandle::SocialDbHandle() +using namespace ctx; + +SocialDbHandle::SocialDbHandle(ContextProvider *provider) : + StatsDbHandleBase(provider) { } -ctx::SocialDbHandle::~SocialDbHandle() +SocialDbHandle::~SocialDbHandle() { } -int ctx::SocialDbHandle::read(const char* subject, ctx::Json filter) +int SocialDbHandle::read(Json filter) { std::string query; + const char *subject = reqProvider->getSubject(); if (STR_EQ(subject, SOCIAL_SUBJ_FREQ_ADDRESS)) { query = createSqlFreqAddress(filter); } else if (STR_EQ(subject, SOCIAL_SUBJ_FREQUENCY)) { - __isTriggerItem = true; + isTriggerItem = true; query = createSqlFrequency(filter); } IF_FAIL_RETURN(!query.empty(), ERR_OPERATION_FAILED); - bool ret = executeQuery(subject, filter, query.c_str()); + bool ret = executeQuery(filter, query.c_str()); IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED); return ERR_NONE; } -std::string ctx::SocialDbHandle::createWhereClause(ctx::Json filter) +std::string SocialDbHandle::createWhereClause(Json filter) { std::stringstream whereClause; int commType = -1; @@ -76,7 +79,7 @@ std::string ctx::SocialDbHandle::createWhereClause(ctx::Json filter) return whereClause.str(); } -std::string ctx::SocialDbHandle::createSqlFreqAddress(ctx::Json filter) +std::string SocialDbHandle::createSqlFreqAddress(Json filter) { std::stringstream query; int limit = DEFAULT_LIMIT; @@ -97,9 +100,9 @@ std::string ctx::SocialDbHandle::createSqlFreqAddress(ctx::Json filter) return query.str(); } -std::string ctx::SocialDbHandle::createSqlFrequency(ctx::Json filter) +std::string SocialDbHandle::createSqlFrequency(Json filter) { - ctx::Json filterCleaned; + Json filterCleaned; std::string weekStr; std::string timeOfDay; std::string address; @@ -142,11 +145,11 @@ std::string ctx::SocialDbHandle::createSqlFrequency(ctx::Json filter) return query.str(); } -void ctx::SocialDbHandle::replyTriggerItem(int error, ctx::Json &jsonResult) +void SocialDbHandle::replyTriggerItem(int error, Json &jsonResult) { - IF_FAIL_VOID_TAG(STR_EQ(__reqSubject.c_str(), SOCIAL_SUBJ_FREQUENCY), _E, "Invalid subject"); + IF_FAIL_VOID_TAG(STR_EQ(reqProvider->getSubject(), SOCIAL_SUBJ_FREQUENCY), _E, "Invalid subject"); - ctx::Json results; + Json results; std::string valStr; int val; @@ -157,5 +160,5 @@ void ctx::SocialDbHandle::replyTriggerItem(int error, ctx::Json &jsonResult) jsonResult.get(NULL, STATS_RANK, &val); results.set(NULL, STATS_RANK, val); - context_manager::replyToRead(__reqSubject.c_str(), __reqFilter, error, results); + reqProvider->replyToRead(reqFilter, error, results); } diff --git a/src/statistics/social/DbHandle.h b/src/statistics/social/DbHandle.h index 3ff4ecf..576c6a1 100644 --- a/src/statistics/social/DbHandle.h +++ b/src/statistics/social/DbHandle.h @@ -24,16 +24,16 @@ namespace ctx { class SocialDbHandle : public StatsDbHandleBase { public: - SocialDbHandle(); + SocialDbHandle(ContextProvider *provider); ~SocialDbHandle(); - int read(const char* subject, ctx::Json filter); + int read(Json filter); protected: - std::string createWhereClause(ctx::Json filter); - std::string createSqlFreqAddress(ctx::Json filter); - std::string createSqlFrequency(ctx::Json filter); - void replyTriggerItem(int error, ctx::Json &jsonResult); + std::string createWhereClause(Json filter); + std::string createSqlFreqAddress(Json filter); + std::string createSqlFrequency(Json filter); + void replyTriggerItem(int error, Json &jsonResult); }; } diff --git a/src/statistics/social/SocialStatisticsProvider.cpp b/src/statistics/social/SocialStatisticsProvider.cpp deleted file mode 100644 index f240296..0000000 --- a/src/statistics/social/SocialStatisticsProvider.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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 -#include -#include -#include "SocialStatisticsProvider.h" -#include "DbHandle.h" -#include "LogAggregator.h" - -static ctx::ContactLogAggregator *__aggregator = NULL; - -ctx::SocialStatisticsProvider *ctx::SocialStatisticsProvider::__instance = NULL; - -ctx::SocialStatisticsProvider::SocialStatisticsProvider() -{ -} - -ctx::SocialStatisticsProvider::~SocialStatisticsProvider() -{ - delete __aggregator; -} - -ctx::ContextProviderBase *ctx::SocialStatisticsProvider::create(void *data) -{ - IF_FAIL_RETURN(!__instance, __instance); - - __instance = new(std::nothrow) SocialStatisticsProvider(); - IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); - - _I(BLUE("Created")); - - if (!__instance->__init()) { - destroy(data); - return NULL; - } - - return __instance; -} - -void ctx::SocialStatisticsProvider::destroy(void *data) -{ - IF_FAIL_VOID(__instance); - delete __instance; - __instance = NULL; - _I(BLUE("Destroyed")); -} - -bool ctx::SocialStatisticsProvider::isSupported(const char* subject) -{ - return true; -} - -void ctx::SocialStatisticsProvider::submitTriggerItem() -{ - context_manager::registerTriggerItem(SOCIAL_SUBJ_FREQUENCY, OPS_READ, - "{" TRIG_DEF_RANK "," TRIG_DEF_TOTAL_COUNT "}", - "{" - "\"Address\":{\"type\":\"string\"}," - TRIG_DEF_TIME_OF_DAY "," TRIG_DEF_DAY_OF_WEEK - "}"); -} - -bool ctx::SocialStatisticsProvider::__init() -{ - __aggregator = new(std::nothrow) ContactLogAggregator(); - IF_FAIL_RETURN_TAG(__aggregator, false, _E, "Memory allocation failed"); - return true; -} - -int ctx::SocialStatisticsProvider::subscribe(const char* subject, ctx::Json option, ctx::Json* requestResult) -{ - return ERR_NOT_SUPPORTED; -} - -int ctx::SocialStatisticsProvider::unsubscribe(const char* subject, ctx::Json option) -{ - return ERR_NOT_SUPPORTED; -} - -int ctx::SocialStatisticsProvider::read(const char* subject, ctx::Json option, ctx::Json* requestResult) -{ - ctx::SocialDbHandle *handle = new(std::nothrow) ctx::SocialDbHandle(); - IF_FAIL_RETURN_TAG(handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); - - int err = handle->read(subject, option); - if (err != ERR_NONE) { - delete handle; - return err; - } - - return ERR_NONE; -} - -int ctx::SocialStatisticsProvider::write(const char* subject, ctx::Json data, ctx::Json* requestResult) -{ - return ERR_NOT_SUPPORTED; -} diff --git a/src/statistics/social/SocialStatisticsProvider.h b/src/statistics/social/SocialStatisticsProvider.h deleted file mode 100644 index 3075915..0000000 --- a/src/statistics/social/SocialStatisticsProvider.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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_STATS_SOCIAL_STATS_PROVIDER_H_ -#define _CONTEXT_STATS_SOCIAL_STATS_PROVIDER_H_ - -#include -#include "SocialStatisticsTypes.h" - -namespace ctx { - - class SocialStatisticsProvider : public ContextProviderBase { - public: - static ContextProviderBase *create(void *data); - static void destroy(void *data); - static bool isSupported(const char *subject); - static void submitTriggerItem(); - - 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); - - private: - static SocialStatisticsProvider *__instance; - - SocialStatisticsProvider(); - ~SocialStatisticsProvider(); - bool __init(); - - }; /* class SocialStatisticsProvider */ - -} /* namespace ctx */ - -#endif /* End of _CONTEXT_SOCIAL_STATS_PROVIDER_H_ */ diff --git a/src/statistics/social/SocialStatisticsTypes.h b/src/statistics/social/SocialStatisticsTypes.h index 2675302..7c68b93 100644 --- a/src/statistics/social/SocialStatisticsTypes.h +++ b/src/statistics/social/SocialStatisticsTypes.h @@ -20,6 +20,7 @@ #include "../shared/CommonTypes.h" #define SOCIAL_HISTORY_PRIV "callhistory.read" +#define SOCIAL_SUBJ_LOGGER "stats/contact/logger" #define SOCIAL_SUBJ_FREQ_ADDRESS "stats/contact/often" #define SOCIAL_SUBJ_FREQUENCY "stats/contact/frequency" diff --git a/src/statistics/social/SocialStatsLogger.cpp b/src/statistics/social/SocialStatsLogger.cpp new file mode 100644 index 0000000..a32fa80 --- /dev/null +++ b/src/statistics/social/SocialStatsLogger.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SocialStatisticsTypes.h" +#include "SocialStatsLogger.h" + +using namespace ctx; + +SocialStatsLogger::SocialStatsLogger() : + ContextProvider(SOCIAL_SUBJ_LOGGER) +{ +} + +SocialStatsLogger::~SocialStatsLogger() +{ +} + +int SocialStatsLogger::subscribe(Json option, Json* requestResult) +{ + return ERR_NONE; +} + +int SocialStatsLogger::unsubscribe(Json option) +{ + return ERR_NONE; +} diff --git a/src/statistics/social/SocialStatsLogger.h b/src/statistics/social/SocialStatsLogger.h new file mode 100644 index 0000000..17850e9 --- /dev/null +++ b/src/statistics/social/SocialStatsLogger.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CONTEXT_SOCIAL_STATS_LOGGER_H_ +#define _CONTEXT_SOCIAL_STATS_LOGGER_H_ + +#include +#include "LogAggregator.h" + +namespace ctx { + + class SocialStatsLogger : public ContextProvider { + public: + SocialStatsLogger(); + ~SocialStatsLogger(); + + int subscribe(Json option, Json* requestResult); + int unsubscribe(Json option); + + void submitTriggerItem() {} + + private: + ContactLogAggregator __aggregator; + }; + +} /* namespace ctx */ + +#endif /* _CONTEXT_SOCIAL_STATS_LOGGER_H_ */ + diff --git a/src/statistics/social/SocialStatsProvider.cpp b/src/statistics/social/SocialStatsProvider.cpp new file mode 100644 index 0000000..0c0dd6d --- /dev/null +++ b/src/statistics/social/SocialStatsProvider.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SocialStatsProvider.h" +#include "DbHandle.h" + +using namespace ctx; + +SocialStatsProvider::SocialStatsProvider(const char *subject) : + ContextProvider(subject) +{ +} + +SocialStatsProvider::~SocialStatsProvider() +{ +} + +bool SocialStatsProvider::isSupported() +{ + /* TODO */ + return true; +} + +void SocialStatsProvider::submitTriggerItem() +{ +} + +int SocialStatsProvider::read(Json option, Json* requestResult) +{ + SocialDbHandle *handle = new(std::nothrow) SocialDbHandle(this); + IF_FAIL_RETURN_TAG(handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); + + int err = handle->read(option); + if (err != ERR_NONE) { + delete handle; + return err; + } + + return ERR_NONE; +} + +void ContactFreqProvider::submitTriggerItem() +{ + registerTriggerItem(OPS_READ, + "{" TRIG_DEF_RANK "," TRIG_DEF_TOTAL_COUNT "}", + "{" + "\"Address\":{\"type\":\"string\"}," + TRIG_DEF_TIME_OF_DAY "," TRIG_DEF_DAY_OF_WEEK + "}"); +} diff --git a/src/statistics/social/SocialStatsProvider.h b/src/statistics/social/SocialStatsProvider.h new file mode 100644 index 0000000..0ee94fd --- /dev/null +++ b/src/statistics/social/SocialStatsProvider.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CONTEXT_SOCIAL_STATS_PROVIDER_H_ +#define _CONTEXT_SOCIAL_STATS_PROVIDER_H_ + +#include +#include "SocialStatisticsTypes.h" + +namespace ctx { + + class SocialStatsProvider : public ContextProvider { + public: + int read(Json option, Json* requestResult); + + bool isSupported(); + virtual void submitTriggerItem(); + + protected: + SocialStatsProvider(const char *subject); + virtual ~SocialStatsProvider(); + }; + + + class ContactFreqProvider: public SocialStatsProvider { + public: + ContactFreqProvider() : + SocialStatsProvider(SOCIAL_SUBJ_FREQUENCY) {} + + void submitTriggerItem(); + }; + + + class TopContactsProvider: public SocialStatsProvider { + public: + TopContactsProvider() : + SocialStatsProvider(SOCIAL_SUBJ_FREQ_ADDRESS) {} + }; + +} /* namespace ctx */ + +#endif /* _CONTEXT_SOCIAL_STATS_PROVIDER_H_ */ -- 2.34.1