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 */
add_provider(device)
add_provider(statistics)
add_provider(place)
-add_provider(custom)
+#add_provider(custom)
LIST(REMOVE_DUPLICATES deps_collected)
#define _CONTEXT_CUSTOM_BASE_H_
#include <Json.h>
-#include <ContextProviderBase.h>
+#include <ContextProvider.h>
#include <Types.h>
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();
#include <vector>
#include <Types.h>
#include <ContextManager.h>
-#include <ContextProviderBase.h>
+#include <ContextProvider.h>
#include <DatabaseManager.h>
#include <CustomContextProvider.h>
#include "CustomBase.h"
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<const char*>(data)];
# 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)
*/
#include <Types.h>
-#include <ContextManager.h>
-#include <ContextProviderBase.h>
+#include <ContextProvider.h>
#include <DeviceContextProvider.h>
#include "system/SystemTypes.h"
#include "activity/Activity.h"
#endif
-#ifdef _TV_
-#include "system/Wifi.h"
-#include "system/Headphone.h"
-#endif
-
#define PRIV_NETWORK "network.get"
#define PRIV_TELEPHONY "telephony"
#define PRIV_MESSAGE "message.read"
template<typename Provider>
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()
registerProvider<UserActivityInVehicle>(USER_ACT_SUBJ_IN_VEHICLE, NULL);
/* Create context providers, which need to be initiated before being subscribed */
+ /*
if (DeviceStatusWifi::isSupported())
DeviceStatusWifi::create(NULL);
+ */
#endif
#ifdef _WEARABLE_
registerProvider<UserActivityWalking>(USER_ACT_SUBJ_WALKING, NULL);
registerProvider<UserActivityRunning>(USER_ACT_SUBJ_RUNNING, NULL);
registerProvider<UserActivityInVehicle>(USER_ACT_SUBJ_IN_VEHICLE, NULL);
-
- /* Create context providers, which need to be initiated before being subscribed */
- if (DeviceStatusWifi::isSupported())
- DeviceStatusWifi::create(NULL);
-#endif
-
-#ifdef _TV_
- registerProvider<DeviceStatusWifi>(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK);
- registerProvider<DeviceStatusHeadphone>(DEVICE_ST_SUBJ_HEADPHONE, NULL);
-
- /* Create context providers, which need to be initiated before being subscribed */
- if (DeviceStatusWifi::isSupported())
- DeviceStatusWifi::create(NULL);
#endif
return true;
#include <system_info.h>
#include "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);
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);
#ifndef _CONTEXT_DEVICE_PROVIDER_BASE_H_
#define _CONTEXT_DEVICE_PROVIDER_BASE_H_
-#include <Types.h>
-#include <Json.h>
-#include <ContextProviderBase.h>
-
-#define CREATE_INSTANCE(prvd) \
- do { \
- IF_FAIL_RETURN(!__instance, __instance); \
- __instance = new(std::nothrow) prvd(); \
- IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); \
- _I(BLUE("Created")); \
- return __instance; \
- } while (0) \
-
-#define DESTROY_INSTANCE() \
- do { \
- IF_FAIL_VOID(__instance); \
- delete __instance; \
- __instance = NULL; \
- _I(BLUE("Destroyed")); \
- } while (0) \
-
-#define GENERATE_PROVIDER_COMMON_DECL(prvd) \
- public: \
- static ContextProviderBase *create(void *data); \
- static void destroy(void *data); \
- protected: \
- void destroySelf(); \
- private: \
- static prvd *__instance; \
-
-#define GENERATE_PROVIDER_COMMON_IMPL(prvd) \
- ctx::prvd *ctx::prvd::__instance = NULL; \
- ctx::ContextProviderBase *ctx::prvd::create(void *data) \
- { \
- CREATE_INSTANCE(prvd); \
- } \
- void ctx::prvd::destroy(void *data) \
- { \
- DESTROY_INSTANCE(); \
- } \
- void ctx::prvd::destroySelf() \
- { \
- destroy(NULL); \
- } \
+#include <ContextProvider.h>
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);
};
#ifndef _DEVICE_ACTIVITY_STATUS_H_
#define _DEVICE_ACTIVITY_STATUS_H_
-#include <system_info.h>
#include "ActivityBase.h"
#define GENERATE_ACTIVITY_PROVIDER(actPrvd, actSubj, actType) \
class actPrvd : public UserActivityBase { \
public: \
- static ContextProviderBase *create(void *data) \
- { \
- CREATE_INSTANCE(ctx::actPrvd); \
- } \
- static void destroy(void *data) \
- { \
- DESTROY_INSTANCE(); \
- } \
- static bool isSupported() \
- { \
- return getSystemInfoBool("tizen.org/feature/sensor.activity_recognition"); \
- } \
- static void submitTriggerItem() \
- { \
- context_manager::registerTriggerItem((actSubj), OPS_SUBSCRIBE, \
- "{\"Event\":{\"type\":\"string\", \"values\":[\"Detected\"]}}", \
- "{\"Accuracy\":{\"type\":\"string\", \"values\":[\"Low\", \"Normal\", \"High\"]}}" \
- ); \
- } \
- protected: \
- void destroySelf() \
- { \
- destroy(NULL); \
- } \
- private: \
- static actPrvd *__instance; \
- actPrvd() : UserActivityBase((actSubj), (actType)) {} \
+ actPrvd() : UserActivityBase(actSubj, actType) {} \
}; \
- ctx::actPrvd *ctx::actPrvd::__instance = NULL; \
namespace ctx {
GENERATE_ACTIVITY_PROVIDER(UserActivityStationary, USER_ACT_SUBJ_STATIONARY, ACTIVITY_STATIONARY);
* limitations under the License.
*/
-#include <Types.h>
-#include <ContextManager.h>
+#include <system_info.h>
#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);
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;
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");
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;
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);
* limitations under the License.
*/
-#include <stdlib.h>
-#include <Json.h>
-#include <ContextManager.h>
#include "SocialTypes.h"
#include "Call.h"
#define TELEPHONY_NOTI_ID_CNT 8
-GENERATE_PROVIDER_COMMON_IMPL(SocialStatusCall);
+
+using namespace ctx;
static bool __telephonyInitialized = false;
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<SocialStatusCall*>(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;
}
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);
return true;
}
-void ctx::SocialStatusCall::__releaseTelephony()
+void SocialStatusCall::__releaseTelephony()
{
IF_FAIL_VOID(__telephonyInitialized);
__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;
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++) {
__releaseTelephony();
}
-bool ctx::SocialStatusCall::__getCallState(telephony_call_h& handle, std::string& state)
+bool SocialStatusCall::__getCallState(telephony_call_h& handle, std::string& state)
{
state.clear();
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();
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();
if (number) {
address = number;
- free(number);
+ g_free(number);
number = NULL;
}
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");
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;
return true;
}
-int ctx::SocialStatusCall::read()
+int SocialStatusCall::read()
{
bool temporaryHandle = false;
if (!__telephonyInitialized) {
__releaseTelephony();
if (ret) {
- ctx::context_manager::replyToRead(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data);
+ replyToRead(NULL, ERR_NONE, data);
return ERR_NONE;
}
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);
* limitations under the License.
*/
-#include <Json.h>
-#include <ContextManager.h>
#include "SocialTypes.h"
#include "Contacts.h"
#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\"]}"
NULL);
}
-void ctx::SocialStatusContacts::__updateCb(const char* viewUri, void* userData)
+void SocialStatusContacts::__updateCb(const char* viewUri, void* userData)
{
SocialStatusContacts *instance = static_cast<SocialStatusContacts*>(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");
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;
return false;
}
-bool ctx::SocialStatusContacts::__setCallback()
+bool SocialStatusContacts::__setCallback()
{
int err;
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);
__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;
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);
* limitations under the License.
*/
-#include <gio/gio.h>
#include <email-api-etc.h>
-
-#include <ContextManager.h>
#include "SocialTypes.h"
#include "Email.h"
-GENERATE_PROVIDER_COMMON_IMPL(SocialStatusEmail);
+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;
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");
}
-int ctx::SocialStatusEmail::unsubscribe()
+int SocialStatusEmail::unsubscribe()
{
__dbusWatcher.unwatch(__dbusSignalId);
return ERR_NONE;
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();
};
}
* limitations under the License.
*/
-#include <Json.h>
-#include <ContextManager.h>
#include "SocialTypes.h"
#include "Message.h"
#define MAX_ADDR_SIZE 20
-GENERATE_PROVIDER_COMMON_IMPL(SocialStatusMessage);
+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\"]},"
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<SocialStatusMessage*>(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");
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;
return true;
}
-void ctx::SocialStatusMessage::__unsetCallback()
+void SocialStatusMessage::__unsetCallback()
{
if (__messageHandle)
msg_close_msg_handle(&__messageHandle);
__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;
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);
* limitations under the License.
*/
-#include <ContextManager.h>
#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();
__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\"]}"
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);
__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 {
return ERR_NONE;
}
-int ctx::DeviceStatusAlarm::unsubscribe(ctx::Json option)
+int DeviceStatusAlarm::unsubscribe(Json option)
{
int dow = __getArrangedDayOfWeek(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;
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<int>(DayOfWeek::EVERYDAY),
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<int>(DayOfWeek::EVERYDAY),
return __resetTimer(minute);
}
-bool ctx::DeviceStatusAlarm::__resetTimer(int minute)
+bool DeviceStatusAlarm::__resetTimer(int minute)
{
int dayOfWeek = __mergeDayOfWeek(__refCountMap[minute].count);
TimerState &timer = __timerStateMap[minute];
return true;
}
-void ctx::DeviceStatusAlarm::__clear()
+void DeviceStatusAlarm::__clear()
{
for (auto it = __timerStateMap.begin(); it != __timerStateMap.end(); ++it) {
if (it->second.timerId > 0) {
__refCountMap.clear();
}
-bool ctx::DeviceStatusAlarm::onTimerExpired(int timerId)
+bool DeviceStatusAlarm::onTimerExpired(int timerId)
{
time_t rawTime;
struct tm timeInfo;
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;
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))
}
return __optionSet.end();
}
-
-void ctx::DeviceStatusAlarm::__destroyIfUnused()
-{
- IF_FAIL_VOID(__optionSet.empty());
- destroy(NULL);
-}
#include <map>
#include <set>
-#include <ContextProviderBase.h>
#include <TimerManager.h>
-#include "../DeviceProviderBase.h"
+#include <ContextProvider.h>
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();
typedef std::map<int, RefCountArray> RefCountMap;
typedef std::map<int, TimerState> TimerStateMap;
- typedef std::set<ctx::Json*> OptionSet;
+ typedef std::set<Json*> OptionSet;
RefCountMap __refCountMap;
TimerStateMap __timerStateMap;
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);
};
}
* limitations under the License.
*/
-#include <ContextManager.h>
#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")
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);
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;
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:
}
}
-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);
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;
}
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);
* limitations under the License.
*/
-#include <ContextManager.h>
#include "SystemTypes.h"
#include "Headphone.h"
#define HANDLING_DELAY 2000
#define MAX_HANDLING_COUNT 3
-GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusHeadphone);
+using namespace ctx;
-ctx::DeviceStatusHeadphone::DeviceStatusHeadphone() :
+DeviceStatusHeadphone::DeviceStatusHeadphone() :
+ DeviceProviderBase(DEVICE_ST_SUBJ_HEADPHONE),
__connected(false),
__audioJackState(RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED),
__btAudioState(false),
{
}
-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\"]}"
NULL);
}
-int ctx::DeviceStatusHeadphone::subscribe()
+int DeviceStatusHeadphone::subscribe()
{
__connected = __getCurrentStatus();
return ERR_NONE;
}
-int ctx::DeviceStatusHeadphone::unsubscribe()
+int DeviceStatusHeadphone::unsubscribe()
{
runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS);
__unsetBtAudioCallback();
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;
__btAudioCallbackOn = true;
}
-void ctx::DeviceStatusHeadphone::__unsetBtAudioCallback()
+void DeviceStatusHeadphone::__unsetBtAudioCallback()
{
IF_FAIL_VOID(__btAudioCallbackOn);
__btAudioCallbackOn = false;
}
-void ctx::DeviceStatusHeadphone::__setBtAudioState(bool state)
+void DeviceStatusHeadphone::__setBtAudioState(bool state)
{
__btAudioState = state;
}
-bool ctx::DeviceStatusHeadphone::__getCurrentStatus()
+bool DeviceStatusHeadphone::__getCurrentStatus()
{
int ret;
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);
}
}
-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<ctx::DeviceStatusHeadphone*>(userData);
+ DeviceStatusHeadphone *instance = static_cast<DeviceStatusHeadphone*>(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<ctx::DeviceStatusHeadphone*>(userData);
+ DeviceStatusHeadphone *instance = static_cast<DeviceStatusHeadphone*>(userData);
IF_FAIL_VOID(connected != instance->__btAudioState);
IF_FAIL_VOID(!instance->__btEventHandlerAdded);
}
}
-gboolean ctx::DeviceStatusHeadphone::__handleBtEvent(gpointer data)
+gboolean DeviceStatusHeadphone::__handleBtEvent(gpointer data)
{
_D("BT state checking started");
- ctx::DeviceStatusHeadphone *instance = static_cast<ctx::DeviceStatusHeadphone*>(data);
+ DeviceStatusHeadphone *instance = static_cast<DeviceStatusHeadphone*>(data);
instance->__btEventHandlerAdded = false;
instance->__setBtAudioState(false);
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;
IF_FAIL_RETURN_TAG(err == BT_ERROR_NONE, false, _E, "bt_device_is_profile_connected() failed");
if (st) {
- ctx::DeviceStatusHeadphone *instance = static_cast<ctx::DeviceStatusHeadphone*>(userData);
+ DeviceStatusHeadphone *instance = static_cast<DeviceStatusHeadphone*>(userData);
instance->__setBtAudioState(true);
return false;
}
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;
bool __btEventHandlerAdded;
int __btEventHandlingCount;
- DeviceStatusHeadphone();
- ~DeviceStatusHeadphone();
-
bool __getCurrentStatus();
void __setBtAudioCallback();
void __unsetBtAudioCallback();
* limitations under the License.
*/
-#include <ContextManager.h>
#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<DeviceStatusPsmode*>(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;
}
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);
};
* limitations under the License.
*/
-#include <ContextManager.h>
#include <TimerManager.h>
#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\"]},"
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;
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;
}
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();
};
}
*/
#include <SharedVars.h>
-#include <ContextManager.h>
#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),
}
}
-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\"}"
NULL);
}
-bool ctx::DeviceStatusWifi::__getCurrentState()
+bool DeviceStatusWifi::__getCurrentState()
{
int err;
return true;
}
-bool ctx::DeviceStatusWifi::__getBssid()
+bool DeviceStatusWifi::__getBssid()
{
int err;
char *strBuf = NULL;
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:
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);
return false;
}
-void ctx::DeviceStatusWifi::__stopMonitor()
+void DeviceStatusWifi::__stopMonitor()
{
IF_FAIL_VOID(__isInitialized);
__isInitialized = false;
}
-int ctx::DeviceStatusWifi::subscribe()
+int DeviceStatusWifi::subscribe()
{
#if 0
IF_FAIL_RETURN(__startMonitor(), ERR_OPERATION_FAILED);
return ERR_NONE;
}
-int ctx::DeviceStatusWifi::unsubscribe()
+int DeviceStatusWifi::unsubscribe()
{
#if 0
__stopMonitor();
return ERR_NONE;
}
-void ctx::DeviceStatusWifi::__handleUpdate()
+void DeviceStatusWifi::__handleUpdate()
{
int prevState = __lastState;
__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<DeviceStatusWifi*>(userData);
instance->__isActivated = (state == WIFI_DEVICE_STATE_ACTIVATED);
instance->__handleUpdate();
}
-void ctx::DeviceStatusWifi::__connectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *userData)
+void DeviceStatusWifi::__connectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *userData)
{
DeviceStatusWifi *instance = static_cast<DeviceStatusWifi*>(userData);
instance->__connState = state;
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 {
wifi_connection_state_e __connState;
std::string __bssid;
- DeviceStatusWifi();
- ~DeviceStatusWifi();
-
bool __getCurrentState();
bool __getBssid();
void __clearBssid();
* limitations under the License.
*/
-#include <ContextManager.h>
#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;
}
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();
};
}
* limitations under the License.
*/
-#include <ContextManager.h>
#include "../SystemTypes.h"
#include "Gps.h"
-GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusGps);
+using namespace ctx;
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");
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;
}
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();
};
}
#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<DeviceStatusRuntimeInfo*>(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);
class DeviceStatusRuntimeInfo : public DeviceProviderBase {
public:
- DeviceStatusRuntimeInfo(runtime_info_key_e key);
+ DeviceStatusRuntimeInfo(const char *subject, runtime_info_key_e key);
int subscribe();
int unsubscribe();
* limitations under the License.
*/
-#include <ContextManager.h>
#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;
}
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();
};
}
*/
#include <Types.h>
-#include <ContextManager.h>
-#include <ContextProviderBase.h>
#include <PlaceContextProvider.h>
#ifdef _MOBILE_
template<typename Provider>
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<PlaceGeofenceProvider>(PLACE_SUBJ_GEOFENCE, PLACE_PRIV_GEOFENCE);
- PlaceGeofenceProvider::submitTriggerItem();
#ifndef _DISABLE_RECOG_ENGINE_
- PlaceRecognitionProvider::create(NULL);
registerProvider<PlaceRecognitionProvider>(PLACE_SUBJ_RECOGNITION, PLACE_PRIV_RECOGNITION);
#endif /* _DISABLE_RECOG_ENGINE_ */
#include <Types.h>
#include <Json.h>
-#include <ContextManager.h>
-#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);
return false;
}
-int ctx::GeofenceMonitorHandle::getPlaceId()
+int GeofenceMonitorHandle::getPlaceId()
{
return __placeId;
}
-void ctx::GeofenceMonitorHandle::__stopMonitor()
+void GeofenceMonitorHandle::__stopMonitor()
{
_D("Stops monitoring Place-%d", __placeId);
__prevState = GEOFENCE_STATE_UNCERTAIN;
}
-bool ctx::GeofenceMonitorHandle::__startFence(int fenceId)
+bool GeofenceMonitorHandle::__startFence(int fenceId)
{
int ret;
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;
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:
}
}
-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);
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);
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<GeofenceMonitorHandle*>(userData);
handle->__updateState(geofenceId, state);
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;
*/
#include <geofence_manager.h>
-
-#include <Types.h>
-#include <Json.h>
-#include <ContextManager.h>
+#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);
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\"]}"
"}",
"}");
}
-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);
return ERR_NONE;
}
- GeofenceMonitorHandle *handle = new(std::nothrow) GeofenceMonitorHandle();
+ GeofenceMonitorHandle *handle = new(std::nothrow) GeofenceMonitorHandle(this);
ASSERT_ALLOC(handle);
bool ret = handle->startMonitor(placeId);
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);
#define _CONTEXT_PLACE_GEOFENCE_PROVIDER_H_
#include <map>
-#include <ContextProviderBase.h>
-#include "GeofenceMonitorHandle.h"
+#include <ContextProvider.h>
#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<int, ctx::GeofenceMonitorHandle*> __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<int, GeofenceMonitorHandle*> __handleMap;
};
} /* namespace ctx */
* limitations under the License.
*/
-#include <Types.h>
-#include <ContextManager.h>
#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);
* 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;
}
#ifndef _CONTEXT_PLACE_RECOGNITION_H_
#define _CONTEXT_PLACE_RECOGNITION_H_
-#include <ContextProviderBase.h>
+#include <ContextProvider.h>
#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 */
# 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")
*/
#include <Types.h>
-#include <ContextManager.h>
-#include <ContextProviderBase.h>
+#include <ContextProvider.h>
#include <StatisticsContextProvider.h>
-#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<typename Provider>
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<AppStatisticsProvider>(APP_SUBJ_RECENTLY_USED, APP_HISTORY_PRIV);
- registerProvider<AppStatisticsProvider>(APP_SUBJ_FREQUENTLY_USED, APP_HISTORY_PRIV);
- registerProvider<AppStatisticsProvider>(APP_SUBJ_RARELY_USED, APP_HISTORY_PRIV);
- registerProvider<AppStatisticsProvider>(APP_SUBJ_PEAK_TIME, APP_HISTORY_PRIV);
- registerProvider<AppStatisticsProvider>(APP_SUBJ_COMMON_SETTING, APP_HISTORY_PRIV);
- registerProvider<AppStatisticsProvider>(APP_SUBJ_FREQUENCY, APP_HISTORY_PRIV);
- AppStatisticsProvider::submitTriggerItem();
+ registerProvider<AppStatsLogger>(APP_SUBJ_LOGGER, APP_HISTORY_PRIV);
+ registerProvider<RecentAppProvider>(APP_SUBJ_RECENTLY_USED, APP_HISTORY_PRIV);
+ registerProvider<FrequentAppProvider>(APP_SUBJ_FREQUENTLY_USED, APP_HISTORY_PRIV);
+ registerProvider<RareAppProvider>(APP_SUBJ_RARELY_USED, APP_HISTORY_PRIV);
+ registerProvider<AppPeakTimeProvider>(APP_SUBJ_PEAK_TIME, APP_HISTORY_PRIV);
+ registerProvider<AppSettingProvider>(APP_SUBJ_COMMON_SETTING, APP_HISTORY_PRIV);
+ registerProvider<AppFreqProvider>(APP_SUBJ_FREQUENCY, APP_HISTORY_PRIV);
#ifndef _DISABLE_PREDICTION_ENGINE_
// initialize the prediction engine here
#endif
#ifdef _MOBILE_
- MediaStatisticsProvider::create(NULL);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC, MEDIA_HISTORY_PRIV);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO, MEDIA_HISTORY_PRIV);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC, MEDIA_HISTORY_PRIV);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO, MEDIA_HISTORY_PRIV);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_MUSIC_FREQUENCY, MEDIA_HISTORY_PRIV);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_VIDEO_FREQUENCY, MEDIA_HISTORY_PRIV);
- MediaStatisticsProvider::submitTriggerItem();
-
- SocialStatisticsProvider::create(NULL);
- registerProvider<SocialStatisticsProvider>(SOCIAL_SUBJ_FREQ_ADDRESS, SOCIAL_HISTORY_PRIV);
- registerProvider<SocialStatisticsProvider>(SOCIAL_SUBJ_FREQUENCY, SOCIAL_HISTORY_PRIV);
- SocialStatisticsProvider::submitTriggerItem();
-#endif
+ registerProvider<MediaStatsLogger>(MEDIA_SUBJ_LOGGER, MEDIA_HISTORY_PRIV);
+ registerProvider<MusicPeakTimeProvider>(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC, MEDIA_HISTORY_PRIV);
+ registerProvider<VideoPeakTimeProvider>(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO, MEDIA_HISTORY_PRIV);
+ registerProvider<MusicSettingProvider>(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC, MEDIA_HISTORY_PRIV);
+ registerProvider<VideoSettingProvider>(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO, MEDIA_HISTORY_PRIV);
+ registerProvider<MusicFreqProvider>(MEDIA_SUBJ_MUSIC_FREQUENCY, MEDIA_HISTORY_PRIV);
+ registerProvider<VideoFreqProvider>(MEDIA_SUBJ_VIDEO_FREQUENCY, MEDIA_HISTORY_PRIV);
-#ifdef _TV_
- MediaStatisticsProvider::create(NULL);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC, MEDIA_HISTORY_PRIV);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO, MEDIA_HISTORY_PRIV);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC, MEDIA_HISTORY_PRIV);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO, MEDIA_HISTORY_PRIV);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_MUSIC_FREQUENCY, MEDIA_HISTORY_PRIV);
- registerProvider<MediaStatisticsProvider>(MEDIA_SUBJ_VIDEO_FREQUENCY, MEDIA_HISTORY_PRIV);
- MediaStatisticsProvider::submitTriggerItem();
+ registerProvider<SocialStatsLogger>(SOCIAL_SUBJ_LOGGER, SOCIAL_HISTORY_PRIV);
+ registerProvider<ContactFreqProvider>(SOCIAL_SUBJ_FREQUENCY, SOCIAL_HISTORY_PRIV);
+ registerProvider<TopContactsProvider>(SOCIAL_SUBJ_FREQ_ADDRESS, SOCIAL_HISTORY_PRIV);
#endif
return true;
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <Types.h>
-#include <Json.h>
-#include <ContextManager.h>
-#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;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _CONTEXT_STATS_APP_STATS_PROVIDER_H_
-#define _CONTEXT_STATS_APP_STATS_PROVIDER_H_
-
-#include <ContextProviderBase.h>
-#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_ */
#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"
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "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;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_APP_STATS_LOGGER_H_
+#define _CONTEXT_APP_STATS_LOGGER_H_
+
+#include <ContextProvider.h>
+#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_ */
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "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
+ "}");
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_APP_STATS_PROVIDER_H_
+#define _CONTEXT_APP_STATS_PROVIDER_H_
+
+#include <ContextProvider.h>
+#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_ */
#include <sstream>
#include <Types.h>
-#include <ContextManager.h>
#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);
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;
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;
return query.str();
}
-std::string ctx::AppDbHandle::createSqlRecentlyUsed(ctx::Json filter)
+std::string AppDbHandle::createSqlRecentlyUsed(Json filter)
{
std::stringstream query;
int limit = DEFAULT_LIMIT;
return query.str();
}
-std::string ctx::AppDbHandle::createSqlFrequentlyUsed(ctx::Json filter)
+std::string AppDbHandle::createSqlFrequentlyUsed(Json filter)
{
std::stringstream query;
int limit = DEFAULT_LIMIT;
return query.str();
}
-std::string ctx::AppDbHandle::createSqlRarelyUsed(ctx::Json filter)
+std::string AppDbHandle::createSqlRarelyUsed(Json filter)
{
std::stringstream query;
int limit = DEFAULT_LIMIT;
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;
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);
}
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);
};
}
{
}
-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();
#ifndef __CONTEXT_APP_INACTIVE_DETECTOR_H__
#define __CONTEXT_APP_INACTIVE_DETECTOR_H__
-#include <ContextProviderBase.h>
+#include <ContextProvider.h>
#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();
#include <sstream>
#include <Types.h>
-#include <ContextManager.h>
#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);
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;
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;
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);
}
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);
};
}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <glib.h>
-#include <string>
-#include <ContextManager.h>
-#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;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _CONTEXT_STATS_MEDIA_STATS_PROVIDER_H_
-#define _CONTEXT_STATS_MEDIA_STATS_PROVIDER_H_
-
-#include <ContextProviderBase.h>
-#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_ */
#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"
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "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;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_MEDIA_STATS_LOGGER_H_
+#define _CONTEXT_MEDIA_STATS_LOGGER_H_
+
+#include <ContextProvider.h>
+#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_ */
+
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "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 "}");
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_MEDIA_STATS_PROVIDER_H_
+#define _CONTEXT_MEDIA_STATS_PROVIDER_H_
+
+#include <ContextProvider.h>
+#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_ */
#include <sstream>
#include <Types.h>
-#include <ContextManager.h>
#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;
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;
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;
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;
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<Json> &vecJson, ctx::Json &jsonResult)
+void StatsDbHandleBase::__jsonVectorToArray(std::vector<Json> &vecJson, Json &jsonResult)
{
std::vector<Json>::iterator vecJsonEnd = vecJson.end();
}
}
-void ctx::StatsDbHandleBase::onExecuted(unsigned int queryId, int error, std::vector<Json>& records)
+void StatsDbHandleBase::onExecuted(unsigned int queryId, int error, std::vector<Json>& 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;
#define _CONTEXT_STATS_DB_HANDLE_BASE_H_
#include <string>
-#include <Json.h>
+#include <ContextProvider.h>
#include <DatabaseManager.h>
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<Json> &vecJson, ctx::Json &jsonResult);
+ void __jsonVectorToArray(std::vector<Json> &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<Json>& records);
+
+ DatabaseManager __dbManager;
};
}
#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);
return true;
}
-bool ctx::system_info::getVolume(int* systemVolume, int* mediaVolume)
+bool system_info::getVolume(int* systemVolume, int* mediaVolume)
{
int err;
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 */
return !bssid.empty();
#endif
- bssid = ctx::SharedVars().get(ctx::SharedVars::WIFI_BSSID);
+ bssid = SharedVars().get(SharedVars::WIFI_BSSID);
return true;
}
#include <sstream>
#include <contacts.h>
#include <Types.h>
-#include <ContextManager.h>
#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;
return whereClause.str();
}
-std::string ctx::SocialDbHandle::createSqlFreqAddress(ctx::Json filter)
+std::string SocialDbHandle::createSqlFreqAddress(Json filter)
{
std::stringstream query;
int limit = DEFAULT_LIMIT;
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;
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;
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);
}
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);
};
}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <Types.h>
-#include <Json.h>
-#include <ContextManager.h>
-#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;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _CONTEXT_STATS_SOCIAL_STATS_PROVIDER_H_
-#define _CONTEXT_STATS_SOCIAL_STATS_PROVIDER_H_
-
-#include <ContextProviderBase.h>
-#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_ */
#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"
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "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;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_SOCIAL_STATS_LOGGER_H_
+#define _CONTEXT_SOCIAL_STATS_LOGGER_H_
+
+#include <ContextProvider.h>
+#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_ */
+
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "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
+ "}");
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_SOCIAL_STATS_PROVIDER_H_
+#define _CONTEXT_SOCIAL_STATS_PROVIDER_H_
+
+#include <ContextProvider.h>
+#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_ */