Merge changes from Tizen 2.4 70/44770/1
authorMu-Woong <muwoong.lee@samsung.com>
Mon, 27 Jul 2015 12:43:11 +0000 (21:43 +0900)
committerMu-Woong <muwoong.lee@samsung.com>
Mon, 27 Jul 2015 12:43:11 +0000 (21:43 +0900)
- Apply on-demand object creation routine to reduce idle state runtime memory consumption

Change-Id: I963b369b25ff17be14f2f3e9eb13bd1e4ffeee90
Signed-off-by: Mu-Woong <muwoong.lee@samsung.com>
36 files changed:
CMakeLists.txt
include/device_context_provider.h
src/activity/activity.h [new file with mode: 0644]
src/activity/activity_base.cpp [new file with mode: 0644]
src/activity/activity_base.h [new file with mode: 0644]
src/activity/activity_types.h [new file with mode: 0644]
src/device_context_provider.cpp
src/device_status/activity.cpp [deleted file]
src/device_status/activity.h [deleted file]
src/device_status/battery.cpp
src/device_status/battery.h
src/device_status/device_status_types.h
src/device_status/headphone.cpp
src/device_status/headphone.h
src/device_status/psmode.cpp
src/device_status/psmode.h
src/device_status/runtime-info/base_rtinfo.cpp
src/device_status/runtime-info/base_rtinfo.h
src/device_status/runtime-info/charger.cpp
src/device_status/runtime-info/charger.h
src/device_status/runtime-info/gps.cpp
src/device_status/runtime-info/gps.h
src/device_status/runtime-info/usb.cpp
src/device_status/runtime-info/usb.h
src/device_status/wifi.cpp
src/device_status/wifi.h
src/provider_base.cpp [new file with mode: 0644]
src/provider_base.h [new file with mode: 0644]
src/social_status/call.cpp
src/social_status/call.h
src/social_status/email.cpp
src/social_status/email.h
src/social_status/message.cpp
src/social_status/message.h
src/sub_provider_base.cpp [deleted file]
src/sub_provider_base.h [deleted file]

index e83c935..bf440a4 100644 (file)
@@ -18,6 +18,7 @@ SET(provider_deps "${provider_deps} capi-network-bluetooth capi-network-wifi")
 IF("${PROFILE}" STREQUAL "mobile")
        ADD_DEFINITIONS("-D_MOBILE_")
        SET(provider_deps "${provider_deps} capi-telephony tapi msg-service capi-messaging-email motion")
+       FILE(GLOB_RECURSE SRCS ${SRCS} src/activity/*.cpp)
        FILE(GLOB_RECURSE SRCS ${SRCS} src/device_status/*.cpp)
        FILE(GLOB_RECURSE SRCS ${SRCS} src/social_status/*.cpp)
 ENDIF("${PROFILE}" STREQUAL "mobile")
@@ -26,6 +27,7 @@ ENDIF("${PROFILE}" STREQUAL "mobile")
 IF("${PROFILE}" STREQUAL "wearable")
        ADD_DEFINITIONS("-D_WEARABLE_")
        SET(provider_deps "${provider_deps} capi-telephony tapi msg-service motion")
+       FILE(GLOB_RECURSE SRCS ${SRCS} src/activity/*.cpp)
        FILE(GLOB_RECURSE SRCS ${SRCS} src/device_status/*.cpp)
        SET(SRCS ${SRCS} src/social_status/call.cpp)
        SET(SRCS ${SRCS} src/social_status/message.cpp)
index 14b8fc8..09ef1e7 100644 (file)
 #ifndef __CONTEXT_DEVICE_CONTEXT_PROVIDER_H__
 #define __CONTEXT_DEVICE_CONTEXT_PROVIDER_H__
 
-#include <provider_iface.h>
-
 namespace ctx {
-
-       class device_context_provider : public ctx::context_provider_iface {
-               public:
-                       device_context_provider();
-                       ~device_context_provider();
-
-                       bool init();
-                       bool is_supported(const char* subject);
-                       int subscribe(const char* subject, ctx::json option, ctx::json* request_result);
-                       int unsubscribe(const char* subject, ctx::json option);
-                       int read(const char* subject, ctx::json option, ctx::json* request_result);
-                       int write(const char* subject, ctx::json data, ctx::json* request_result);
-       };
-
+       bool init_device_context_provider();
 }
 
 #endif //__CONTEXT_DEVICE_CONTEXT_PROVIDER_H__
diff --git a/src/activity/activity.h b/src/activity/activity.h
new file mode 100644 (file)
index 0000000..d23b208
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DEVICE_STATUS_ACTIVITY_H_
+#define _DEVICE_STATUS_ACTIVITY_H_
+
+#include <system_info.h>
+#include "activity_base.h"
+
+#define GENERATE_ACTIVITY_PROVIDER(act_prvd, act_subj, act_type) \
+       class act_prvd : public user_activity_base { \
+       public: \
+               static context_provider_iface *create(void *data) \
+               { \
+                       CREATE_INSTANCE(ctx::act_prvd); \
+               } \
+               static void destroy(void *data) \
+               { \
+                       DESTROY_INSTANCE(); \
+               } \
+               static bool is_supported() \
+               { \
+                       return get_system_info_bool("tizen.org/feature/sensor.activity_recognition"); \
+               } \
+       protected: \
+               void destroy_self() \
+               { \
+                       destroy(NULL); \
+               } \
+       private: \
+               static act_prvd *__instance; \
+               act_prvd() : user_activity_base((act_subj), (act_type)) {} \
+       }; \
+       ctx::act_prvd *ctx::act_prvd::__instance = NULL; \
+
+namespace ctx {
+       GENERATE_ACTIVITY_PROVIDER(user_activity_stationary, USER_ACT_SUBJ_STATIONARY, ACTIVITY_STATIONARY);
+       GENERATE_ACTIVITY_PROVIDER(user_activity_walking, USER_ACT_SUBJ_WALKING, ACTIVITY_WALK);
+       GENERATE_ACTIVITY_PROVIDER(user_activity_running, USER_ACT_SUBJ_RUNNING, ACTIVITY_RUN);
+       GENERATE_ACTIVITY_PROVIDER(user_activity_in_vehicle, USER_ACT_SUBJ_IN_VEHICLE, ACTIVITY_IN_VEHICLE);
+}
+
+#endif // _DEVICE_STATUS_ACTIVITY_H_
diff --git a/src/activity/activity_base.cpp b/src/activity/activity_base.cpp
new file mode 100644 (file)
index 0000000..1b834fd
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <types_internal.h>
+#include <context_mgr.h>
+#include "activity_types.h"
+#include "activity_base.h"
+
+ctx::user_activity_base::user_activity_base(const char *subj, activity_type_e type)
+       : activity_type(type)
+       , activity_handle(NULL)
+       , subject(subj)
+{
+}
+
+ctx::user_activity_base::~user_activity_base()
+{
+       if (activity_handle)
+               activity_release(activity_handle);
+}
+
+void ctx::user_activity_base::event_cb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* user_data)
+{
+       IF_FAIL_VOID_TAG(error == ACTIVITY_ERROR_NONE, _E, "Error: %d", error);
+
+       user_activity_base *instance = static_cast<user_activity_base*>(user_data);
+       instance->handle_event(activity, data, timestamp);
+}
+
+void ctx::user_activity_base::handle_event(activity_type_e activity, const activity_data_h data, double timestamp)
+{
+       IF_FAIL_VOID_TAG(activity == activity_type, _E, "Invalid activity: %d", activity);
+
+       ctx::json data_read;
+       data_read.set(NULL, USER_ACT_EVENT, USER_ACT_DETECTED);
+
+       activity_accuracy_e accuracy = ACTIVITY_ACCURACY_LOW;
+       activity_get_accuracy(data, &accuracy);
+
+       switch (accuracy) {
+       case ACTIVITY_ACCURACY_HIGH:
+               data_read.set(NULL, USER_ACT_ACCURACY, USER_ACT_HIGH);
+               break;
+       case ACTIVITY_ACCURACY_MID:
+               data_read.set(NULL, USER_ACT_ACCURACY, USER_ACT_NORMAL);
+               break;
+       default:
+               data_read.set(NULL, USER_ACT_ACCURACY, USER_ACT_LOW);
+               break;
+       }
+
+       context_manager::publish(subject.c_str(), NULL, ERR_NONE, data_read);
+}
+
+int ctx::user_activity_base::subscribe()
+{
+       IF_FAIL_RETURN(activity_handle == NULL, ERR_NONE);
+
+       _D("Starting to monitor %s", subject.c_str());
+
+       activity_create(&activity_handle);
+       IF_FAIL_RETURN_TAG(activity_handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
+
+       int ret = activity_start_recognition(activity_handle, activity_type, event_cb, this);
+       if (ret != ACTIVITY_ERROR_NONE) {
+               _E("Recognition starting failed");
+               activity_release(activity_handle);
+               activity_handle = NULL;
+               return ERR_OPERATION_FAILED;
+       }
+
+       return ERR_NONE;
+}
+
+int ctx::user_activity_base::unsubscribe()
+{
+       IF_FAIL_RETURN(activity_handle, ERR_NONE);
+
+       _D("Stop monitoring %s", subject.c_str());
+
+       activity_stop_recognition(activity_handle);
+       activity_release(activity_handle);
+       activity_handle = NULL;
+
+       return ERR_NONE;
+}
diff --git a/src/activity/activity_base.h b/src/activity/activity_base.h
new file mode 100644 (file)
index 0000000..45fcc8d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DEVICE_STATUS_ACTIVITY_BASE_H_
+#define _DEVICE_STATUS_ACTIVITY_BASE_H_
+
+#include <string>
+#include <activity_recognition.h>
+#include "../provider_base.h"
+
+namespace ctx {
+
+       class user_activity_base : public device_provider_base {
+       public:
+               int subscribe();
+               int unsubscribe();
+
+       protected:
+               activity_type_e activity_type;
+               activity_h activity_handle;
+               std::string subject;
+
+               user_activity_base(const char *subj, activity_type_e type);
+               virtual ~user_activity_base();
+
+       private:
+               void handle_event(activity_type_e activity, const activity_data_h data, double timestamp);
+               static void event_cb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* user_data);
+       };
+
+}
+
+#endif // _DEVICE_STATUS_ACTIVITY_BASE_H_
diff --git a/src/activity/activity_types.h b/src/activity/activity_types.h
new file mode 100644 (file)
index 0000000..da38941
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef        __CONTEXT_USER_ACTIVITY_TYPES_H__
+#define        __CONTEXT_USER_ACTIVITY_TYPES_H__
+
+// Subject
+#define USER_ACT_SUBJ_CYCLING          "activity/event/cycling"
+#define USER_ACT_SUBJ_IN_VEHICLE       "activity/event/in_vehicle"
+#define USER_ACT_SUBJ_RUNNING          "activity/event/running"
+#define USER_ACT_SUBJ_STATIONARY       "activity/event/stationary"
+#define USER_ACT_SUBJ_WALKING          "activity/event/walking"
+
+// Data Key
+#define USER_ACT_EVENT         "Event"
+#define USER_ACT_ACCURACY      "Accuracy"
+
+// Data Value
+#define USER_ACT_DETECTED      "Detected"
+#define USER_ACT_LOW           "Low"
+#define USER_ACT_NORMAL                "Normal"
+#define USER_ACT_HIGH          "High"
+
+#endif //__CONTEXT_USER_ACTIVITY_TYPES_H__
index 3f188c8..940cd75 100644 (file)
  * limitations under the License.
  */
 
-#include <glib.h>
-#include <string>
-#include <map>
-#include <utility>
-
 #include <types_internal.h>
-#include <json.h>
 #include <context_mgr.h>
+#include <provider_iface.h>
 #include <device_context_provider.h>
+
 #include "device_status/device_status_types.h"
 #include "social_status/social_status_types.h"
+#include "activity/activity_types.h"
 
 #include "device_status/wifi.h"
 #include "device_status/headphone.h"
 #include "device_status/runtime-info/usb.h"
 #include "device_status/battery.h"
 #include "device_status/psmode.h"
-#include "device_status/activity.h"
 #include "social_status/call.h"
 #include "social_status/email.h"
 #include "social_status/message.h"
+#include "activity/activity.h"
 #endif
 
 #ifdef _WEARABLE_
 #include "device_status/runtime-info/usb.h"
 #include "device_status/battery.h"
 #include "device_status/psmode.h"
-#include "device_status/activity.h"
 #include "social_status/call.h"
 #include "social_status/message.h"
+#include "activity/activity.h"
 #endif
 
-#define CREATE_SUB_PROVIDER(subject, subprovider) do { \
-       ctx::sub_provider_base *sub = new ctx::subprovider(); \
-       if (sub->is_supported(subject)) { \
-               subject_map[(subject)] = sub; \
-       } else { \
-               _E("%s is not supported", subject); \
-               delete sub; \
-       }} while (0)
+#define PRIV_NETWORK   "network.get"
+#define PRIV_TELEPHONY "telephony"
+#define PRIV_MESSAGE   "message.read"
 
-typedef std::map<std::string, ctx::sub_provider_base*> subject_map_t;
-static subject_map_t subject_map;
+template<typename provider>
+void register_provider(const char *subject, const char *privilege)
+{
+       if (!provider::is_supported())
+               return;
 
-static void load_sub_providers()
+       ctx::context_provider_info provider_info(provider::create, provider::destroy, NULL, privilege);
+       ctx::context_manager::register_provider(subject, provider_info);
+}
+
+EXTAPI bool ctx::init_device_context_provider()
 {
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_WIFI, device_status_wifi);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_HEADPHONE, device_status_headphone);
+       register_provider<device_status_wifi>(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK);
+       register_provider<device_status_headphone>(DEVICE_ST_SUBJ_HEADPHONE, NULL);
 
 #ifdef _MOBILE_
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_CHARGER, device_status_charger);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_GPS, device_status_gps);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_USB, device_status_usb);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_BATTERY, device_status_battery_level);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_POWER_SAVING_MODE, device_status_power_saving_mode);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_ACTIVITY_WALKING, device_status_activity);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_ACTIVITY_RUNNING, device_status_activity);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_ACTIVITY_STATIONARY, device_status_activity);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_ACTIVITY_IN_VEHICLE, device_status_activity);
-       CREATE_SUB_PROVIDER(SOCIAL_ST_SUBJ_CALL, social_status_call);
-       CREATE_SUB_PROVIDER(SOCIAL_ST_SUBJ_EMAIL, social_status_email);
-       CREATE_SUB_PROVIDER(SOCIAL_ST_SUBJ_MESSAGE, social_status_message);
+       register_provider<device_status_charger>(DEVICE_ST_SUBJ_CHARGER, NULL);
+       register_provider<device_status_gps>(DEVICE_ST_SUBJ_GPS, NULL);
+       register_provider<device_status_usb>(DEVICE_ST_SUBJ_USB, NULL);
+       register_provider<device_status_battery>(DEVICE_ST_SUBJ_BATTERY, NULL);
+       register_provider<device_status_psmode>(DEVICE_ST_SUBJ_PSMODE, NULL);
+
+       register_provider<social_status_call>(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY);
+       register_provider<social_status_email>(SOCIAL_ST_SUBJ_EMAIL, NULL);
+       register_provider<social_status_message>(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE);
+
+       register_provider<user_activity_stationary>(USER_ACT_SUBJ_STATIONARY, NULL);
+       register_provider<user_activity_walking>(USER_ACT_SUBJ_WALKING, NULL);
+       register_provider<user_activity_running>(USER_ACT_SUBJ_RUNNING, NULL);
+       register_provider<user_activity_in_vehicle>(USER_ACT_SUBJ_IN_VEHICLE, NULL);
 #endif
 
 #ifdef _WEARABLE_
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_CHARGER, device_status_charger);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_GPS, device_status_gps);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_USB, device_status_usb);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_BATTERY, device_status_battery_level);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_POWER_SAVING_MODE, device_status_power_saving_mode);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_ACTIVITY_WALKING, device_status_activity);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_ACTIVITY_RUNNING, device_status_activity);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_ACTIVITY_STATIONARY, device_status_activity);
-       CREATE_SUB_PROVIDER(DEVICE_ST_SUBJ_ACTIVITY_IN_VEHICLE, device_status_activity);
-       CREATE_SUB_PROVIDER(SOCIAL_ST_SUBJ_CALL, social_status_call);
-       CREATE_SUB_PROVIDER(SOCIAL_ST_SUBJ_MESSAGE, social_status_message);
+       register_provider<device_status_charger>(DEVICE_ST_SUBJ_CHARGER, NULL);
+       register_provider<device_status_gps>(DEVICE_ST_SUBJ_GPS, NULL);
+       register_provider<device_status_usb>(DEVICE_ST_SUBJ_USB, NULL);
+       register_provider<device_status_battery>(DEVICE_ST_SUBJ_BATTERY, NULL);
+       register_provider<device_status_psmode>(DEVICE_ST_SUBJ_PSMODE, NULL);
+
+       register_provider<social_status_call>(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY);
+       register_provider<social_status_message>(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE);
+
+       register_provider<user_activity_stationary>(USER_ACT_SUBJ_STATIONARY, NULL);
+       register_provider<user_activity_walking>(USER_ACT_SUBJ_WALKING, NULL);
+       register_provider<user_activity_running>(USER_ACT_SUBJ_RUNNING, NULL);
+       register_provider<user_activity_in_vehicle>(USER_ACT_SUBJ_IN_VEHICLE, NULL);
 #endif
-}
-
-static void unload_sub_providers()
-{
-       for (subject_map_t::iterator it = subject_map.begin(); it != subject_map.end(); ++it) {
-               delete it->second;
-       }
-
-       subject_map.clear();
-}
-
-EXTAPI ctx::device_context_provider::device_context_provider()
-{
-}
 
-
-EXTAPI ctx::device_context_provider::~device_context_provider()
-{
-       unload_sub_providers();
-}
-
-
-bool ctx::device_context_provider::init()
-{
-       IF_FAIL_RETURN(subject_map.empty(), true);
-
-       try {
-               load_sub_providers();
-       } catch (std::bad_alloc& ba) {
-               _E("Memory allocation failed");
-               return false;
-       }
-
-       for (subject_map_t::iterator it = subject_map.begin(); it != subject_map.end(); ++it) {
-               context_manager::register_provider(it->first.c_str(), this);
-       }
-
-       _D("Done");
        return true;
 }
-
-bool ctx::device_context_provider::is_supported(const char* subject)
-{
-       subject_map_t::iterator it = subject_map.find(subject);
-
-       if (it != subject_map.end())
-               return it->second->is_supported(subject);
-
-       return false;
-}
-
-int ctx::device_context_provider::subscribe(const char* subject, ctx::json option, ctx::json* request_result)
-{
-       _D("Starts to publish '%s'", subject);
-
-       subject_map_t::iterator it = subject_map.find(subject);
-
-       if (it != subject_map.end())
-               return it->second->subscribe(subject);
-
-       return ERR_NOT_SUPPORTED;
-}
-
-
-int ctx::device_context_provider::unsubscribe(const char* subject, ctx::json option)
-{
-       _D("Stops publishing '%s'", subject);
-
-       subject_map_t::iterator it = subject_map.find(subject);
-
-       if (it != subject_map.end())
-               return it->second->unsubscribe(subject);
-
-       return ERR_NOT_SUPPORTED;
-}
-
-
-int ctx::device_context_provider::read(const char* subject, ctx::json option, ctx::json* request_result)
-{
-       _D("Reads '%s'", subject);
-
-       subject_map_t::iterator it = subject_map.find(subject);
-
-       if (it != subject_map.end())
-               return it->second->read(subject);
-
-       return ERR_NOT_SUPPORTED;
-}
-
-
-int ctx::device_context_provider::write(const char* subject, ctx::json data, ctx::json* request_result)
-{
-       return ERR_NOT_SUPPORTED;
-}
diff --git a/src/device_status/activity.cpp b/src/device_status/activity.cpp
deleted file mode 100644 (file)
index 26cf906..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "activity.h"
-
-#define NUM_ACTIVITY 5 // Activity type enum starts from 1. This number should be greater than the number of activity types.
-
-struct activity_recog_s {
-       const char *name;
-       activity_h handle;
-       activity_recog_s() : name(NULL), handle(NULL) {}
-};
-
-static activity_recog_s activity_recog[NUM_ACTIVITY];
-
-static int get_activity_id(const char* subject)
-{
-       for (int i = 1; i < NUM_ACTIVITY; ++i) {
-               if (STR_EQ(subject, activity_recog[i].name))
-                       return i;
-       }
-
-       return 0;
-}
-
-ctx::device_status_activity::device_status_activity()
-{
-       activity_recog[ACTIVITY_STATIONARY].name = DEVICE_ST_SUBJ_ACTIVITY_STATIONARY;
-       activity_recog[ACTIVITY_WALK].name = DEVICE_ST_SUBJ_ACTIVITY_WALKING;
-       activity_recog[ACTIVITY_RUN].name = DEVICE_ST_SUBJ_ACTIVITY_RUNNING;
-       activity_recog[ACTIVITY_IN_VEHICLE].name = DEVICE_ST_SUBJ_ACTIVITY_IN_VEHICLE;
-}
-
-ctx::device_status_activity::~device_status_activity()
-{
-       for (int i=0; i<NUM_ACTIVITY; ++i) {
-               if (activity_recog[i].handle == NULL) continue;
-               activity_release(activity_recog[i].handle);
-               activity_recog[i].handle = NULL;
-       }
-}
-
-void ctx::device_status_activity::event_cb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* user_data)
-{
-       IF_FAIL_VOID_TAG(error == ACTIVITY_ERROR_NONE, _E, "Error: %d", error);
-       IF_FAIL_VOID_TAG(activity > 0 && activity < NUM_ACTIVITY, _E, "Unknown activity: %d", activity);
-
-       device_status_activity *instance = static_cast<device_status_activity*>(user_data);
-       instance->handle_event(activity, data, timestamp);
-}
-
-void ctx::device_status_activity::handle_event(activity_type_e activity, const activity_data_h data, double timestamp)
-{
-       ctx::json data_read;
-       data_read.set(NULL, DEVICE_ST_EVENT, DEVICE_ST_DETECTED);
-
-       activity_accuracy_e accuracy = ACTIVITY_ACCURACY_LOW;
-       activity_get_accuracy(data, &accuracy);
-
-       switch (accuracy) {
-       case ACTIVITY_ACCURACY_HIGH:
-               data_read.set(NULL, DEVICE_ST_ACCURACY, DEVICE_ST_HIGH);
-               break;
-       case ACTIVITY_ACCURACY_MID:
-               data_read.set(NULL, DEVICE_ST_ACCURACY, DEVICE_ST_NORMAL);
-               break;
-       default:
-               data_read.set(NULL, DEVICE_ST_ACCURACY, DEVICE_ST_LOW);
-               break;
-       }
-
-       publish(activity_recog[activity].name, ERR_NONE, data_read);
-}
-
-int ctx::device_status_activity::subscribe(const char* subject)
-{
-       int act_num = get_activity_id(subject);
-       IF_FAIL_RETURN(act_num > 0, ERR_INVALID_PARAMETER);
-
-       int ret;
-       activity_h handle = NULL;
-       bool supported = false;
-
-       activity_is_supported(static_cast<activity_type_e>(act_num), &supported);
-       IF_FAIL_RETURN(supported, ERR_NOT_SUPPORTED);
-       IF_FAIL_CATCH(activity_recog[act_num].handle == NULL);
-
-       _D("Starting to monitor %s", subject);
-
-       activity_create(&handle);
-       IF_FAIL_RETURN_TAG(handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed");
-
-       ret = activity_start_recognition(handle, static_cast<activity_type_e>(act_num), event_cb, this);
-       if (ret != ACTIVITY_ERROR_NONE) {
-               _E("Recognition starting failed");
-               activity_release(handle);
-               return ERR_OPERATION_FAILED;
-       }
-
-       activity_recog[act_num].handle = handle;
-
-CATCH:
-       return ERR_NONE;
-}
-
-int ctx::device_status_activity::unsubscribe(const char* subject)
-{
-       int act_num = get_activity_id(subject);
-       IF_FAIL_RETURN(act_num > 0, ERR_INVALID_PARAMETER);
-
-       IF_FAIL_RETURN(activity_recog[act_num].handle, ERR_NONE);
-
-       _D("Stop monitoring %s", subject);
-
-       activity_stop_recognition(activity_recog[act_num].handle);
-       activity_release(activity_recog[act_num].handle);
-       activity_recog[act_num].handle = NULL;
-
-       return ERR_NONE;
-}
-
-bool ctx::device_status_activity::is_supported(const char* subject)
-{
-       bool supported = false;
-       activity_is_supported(static_cast<activity_type_e>(get_activity_id(subject)), &supported);
-       return supported;
-}
diff --git a/src/device_status/activity.h b/src/device_status/activity.h
deleted file mode 100644 (file)
index 7b72420..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _DEVICE_STATUS_ACTIVITY_H_
-#define _DEVICE_STATUS_ACTIVITY_H_
-
-#include <activity_recognition.h>
-#include "../sub_provider_base.h"
-
-namespace ctx {
-
-       class device_status_activity : public sub_provider_base {
-               public:
-                       device_status_activity();
-                       ~device_status_activity();
-
-                       int subscribe(const char* subject);
-                       int unsubscribe(const char* subject);
-                       bool is_supported(const char* subject);
-
-               private:
-                       void handle_event(activity_type_e activity, const activity_data_h data, double timestamp);
-                       static void event_cb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* user_data);
-       };
-}
-
-#endif // _DEVICE_STATUS_ACTIVITY_H_
index bd89cd7..d38f099 100644 (file)
  * limitations under the License.
  */
 
+#include <context_mgr.h>
+#include "device_status_types.h"
 #include "battery.h"
 
-static const char* trans_to_string(intptr_t level)
-{
-       switch (level) {
-       case DEVICE_BATTERY_LEVEL_EMPTY :
-               return DEVICE_ST_EMPTY;
+GENERATE_PROVIDER_COMMON_IMPL(device_status_battery);
 
-       case DEVICE_BATTERY_LEVEL_CRITICAL :
-               return DEVICE_ST_CRITICAL;
-
-       case DEVICE_BATTERY_LEVEL_LOW :
-               return DEVICE_ST_LOW;
-
-       case DEVICE_BATTERY_LEVEL_HIGH :
-               return DEVICE_ST_NORMAL;
-
-       case DEVICE_BATTERY_LEVEL_FULL :
-               {
-                       int percent;
-                       device_battery_get_percent(&percent);
-
-                       if (percent == 100) {
-                               return DEVICE_ST_FULL;
-                       } else {
-                               return DEVICE_ST_HIGH;
-                       }
-               }
-               break;
+ctx::device_status_battery::device_status_battery()
+{
+}
 
-       default:
-               _E("battery_level receive abnormal value from device api");
-               return NULL;
-       }
+ctx::device_status_battery::~device_status_battery()
+{
 }
 
-ctx::device_status_battery_level::device_status_battery_level()
-       : being_subscribed(false)
+bool ctx::device_status_battery::is_supported()
 {
+       return true;
 }
 
-void ctx::device_status_battery_level::update_cb(device_callback_e device_type, void* value, void* user_data)
+void ctx::device_status_battery::update_cb(device_callback_e device_type, void* value, void* user_data)
 {
        IF_FAIL_VOID(device_type == DEVICE_CALLBACK_BATTERY_LEVEL);
 
-       device_status_battery_level *instance = static_cast<device_status_battery_level*>(user_data);
+       device_status_battery *instance = static_cast<device_status_battery*>(user_data);
        instance->handle_update(device_type, value);
 }
 
-void ctx::device_status_battery_level::handle_update(device_callback_e device_type, void* value)
+void ctx::device_status_battery::handle_update(device_callback_e device_type, void* value)
 {
        intptr_t level = (intptr_t)value;
 
@@ -78,31 +56,56 @@ void ctx::device_status_battery_level::handle_update(device_callback_e device_ty
        IF_FAIL_VOID_TAG(ret == DEVICE_ERROR_NONE, _E, "Getting state failed");
 
        data_read.set(NULL, DEVICE_ST_IS_CHARGING, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
-
-       publish(DEVICE_ST_SUBJ_BATTERY, ERR_NONE, data_read);
+       ctx::context_manager::publish(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, data_read);
 }
 
-int ctx::device_status_battery_level::subscribe(const char* subject)
+const char* ctx::device_status_battery::trans_to_string(intptr_t level)
 {
-       if (!being_subscribed) {
-               int ret = device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, update_cb, this);
-               IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
+       switch (level) {
+       case DEVICE_BATTERY_LEVEL_EMPTY :
+               return DEVICE_ST_EMPTY;
+
+       case DEVICE_BATTERY_LEVEL_CRITICAL :
+               return DEVICE_ST_CRITICAL;
+
+       case DEVICE_BATTERY_LEVEL_LOW :
+               return DEVICE_ST_LOW;
+
+       case DEVICE_BATTERY_LEVEL_HIGH :
+               return DEVICE_ST_NORMAL;
+
+       case DEVICE_BATTERY_LEVEL_FULL :
+               {
+                       int percent;
+                       device_battery_get_percent(&percent);
+
+                       if (percent == 100) {
+                               return DEVICE_ST_FULL;
+                       } else {
+                               return DEVICE_ST_HIGH;
+                       } }
+               break;
+
+       default: _E("battery_level receive abnormal value from device api");
+               return NULL;
        }
+}
 
-       being_subscribed = true;
+int ctx::device_status_battery::subscribe()
+{
+       int ret = device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, update_cb, this);
+       IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
        return ERR_NONE;
 }
 
-int ctx::device_status_battery_level::unsubscribe(const char* subject)
+int ctx::device_status_battery::unsubscribe()
 {
-       being_subscribed = false;
        int ret = device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, update_cb);
        IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED);
-
        return ERR_NONE;
 }
 
-int ctx::device_status_battery_level::read(const char* subject)
+int ctx::device_status_battery::read()
 {
        device_battery_level_e level;
        ctx::json data_read;
index 2f08071..951e9d1 100644 (file)
 
 #include <device/callback.h>
 #include <device/battery.h>
-#include "../sub_provider_base.h"
+#include "../provider_base.h"
 
 namespace ctx {
 
-       class device_status_battery_level : public sub_provider_base {
-               public:
-                       device_status_battery_level();
-                       ~device_status_battery_level(){}
+       class device_status_battery : public device_provider_base {
 
-                       int subscribe(const char* subject);
-                       int unsubscribe(const char* subject);
-                       int read(const char* subject);
+               GENERATE_PROVIDER_COMMON_DECL(device_status_battery);
 
-               private:
-                       bool being_subscribed;
+       public:
+               int subscribe();
+               int unsubscribe();
+               int read();
+               static bool is_supported();
 
-                       void handle_update(device_callback_e device_type, void* value);
-                       static void update_cb(device_callback_e device_type, void* value, void* user_data);
+       private:
+               device_status_battery();
+               ~device_status_battery();
+               const char* trans_to_string(intptr_t level);
+               void handle_update(device_callback_e device_type, void* value);
+               static void update_cb(device_callback_e device_type, void* value, void* user_data);
        };
 }
 
index cd6e0ef..a978625 100644 (file)
 #define DEVICE_ST_SUBJ_USB                             "system/state/usb"
 #define DEVICE_ST_SUBJ_GPS                             "system/state/gps"
 #define DEVICE_ST_SUBJ_VIBRATION_MODE          "system/state/vibration_mode"
-#define DEVICE_ST_SUBJ_POWER_SAVING_MODE       "system/state/ps_mode"
-#define DEVICE_ST_SUBJ_FLIGHT_MODE             "system/state/flight_mode"
-#define DEVICE_ST_SUBJ_SILENT_MODE             "system/state/silent_mode"
-#define DEVICE_ST_SUBJ_ACTIVITY_CYCLING                "activity/event/cycling"
-#define DEVICE_ST_SUBJ_ACTIVITY_IN_VEHICLE     "activity/event/in_vehicle"
-#define DEVICE_ST_SUBJ_ACTIVITY_RUNNING                "activity/event/running"
-#define DEVICE_ST_SUBJ_ACTIVITY_STATIONARY     "activity/event/stationary"
-#define DEVICE_ST_SUBJ_ACTIVITY_WALKING                "activity/event/walking"
+#define DEVICE_ST_SUBJ_PSMODE                  "system/state/ps_mode"
 
 // Data Key
 #define DEVICE_ST_EVENT                        "Event"
 #define DEVICE_ST_STATE                        "State"
 #define DEVICE_ST_TYPE                 "Type"
 #define DEVICE_ST_LEVEL                        "Level"
-#define DEVICE_ST_ACCURACY             "Accuracy"
 #define DEVICE_ST_BSSID                        "BSSID"
 #define DEVICE_ST_IS_CONNECTED "IsConnected"
 #define DEVICE_ST_IS_ENABLED   "IsEnabled"
 #define DEVICE_ST_IS_CHARGING  "IsCharging"
 #define DEVICE_ST_DETECTED             "Detected"
-#define DEVICE_ST_ACCURACY             "Accuracy"
 
 // Data Value
 #define DEVICE_ST_TRUE                 1
index 3782460..c73ae0b 100644 (file)
  * limitations under the License.
  */
 
+#include <context_mgr.h>
+#include "device_status_types.h"
 #include "headphone.h"
 
 #define HANDLING_DELAY 2000
 #define MAX_HANDLING_COUNT 3
 
+GENERATE_PROVIDER_COMMON_IMPL(device_status_headphone);
+
 ctx::device_status_headphone::device_status_headphone()
-       : being_subscribed(false)
-       , connected(false)
+       : connected(false)
        , audio_jack_state(RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED)
        , bt_audio_state(false)
        , bt_audio_callback_on(false)
@@ -30,34 +33,38 @@ ctx::device_status_headphone::device_status_headphone()
 {
 }
 
-int ctx::device_status_headphone::subscribe(const char* subject)
+ctx::device_status_headphone::~device_status_headphone()
 {
-       if (!being_subscribed) {
-               connected = get_current_status();
+}
 
-               // Wired headphone
-               int ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, on_audio_jack_state_changed, this);
-               IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
+bool ctx::device_status_headphone::is_supported()
+{
+       return true;
+}
 
-               // Bluetooth headphone
-               set_bt_audio_callback();
-       }
+int ctx::device_status_headphone::subscribe()
+{
+       connected = get_current_status();
+
+       // Wired headphone
+       int ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, on_audio_jack_state_changed, this);
+       IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
+
+       // Bluetooth headphone
+       set_bt_audio_callback();
 
-       being_subscribed = true;
        return ERR_NONE;
 }
 
-int ctx::device_status_headphone::unsubscribe(const char* subject)
+int ctx::device_status_headphone::unsubscribe()
 {
-       being_subscribed = false;
-
        runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS);
        unset_bt_audio_callback();
 
        return ERR_NONE;
 }
 
-int ctx::device_status_headphone::read(const char* subject)
+int ctx::device_status_headphone::read()
 {
        if (!being_subscribed)
                connected = get_current_status();
@@ -150,7 +157,7 @@ bool ctx::device_status_headphone::handle_event()
 
        ctx::json data;
        generate_data_packet(data);
-       publish(DEVICE_ST_SUBJ_HEADPHONE, ERR_NONE, data);
+       ctx::context_manager::publish(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data);
        return true;
 }
 
index 9357d4e..50fc5c3 100644 (file)
 #include <glib.h>
 #include <runtime_info.h>
 #include <bluetooth.h>
-#include "../sub_provider_base.h"
+#include "../provider_base.h"
 
 namespace ctx {
 
-       class device_status_headphone : public sub_provider_base {
-               public:
-                       device_status_headphone();
-                       ~device_status_headphone() {}
-
-                       int subscribe(const char* subject);
-                       int unsubscribe(const char* subject);
-                       int read(const char* subject);
-
-               private:
-                       bool being_subscribed;
-                       bool connected;
-                       int audio_jack_state;
-                       bool bt_audio_state;
-                       bool bt_audio_callback_on;
-                       bool bt_event_handler_added;
-                       int bt_event_handling_count;
-
-                       bool get_current_status();
-                       void set_bt_audio_callback();
-                       void unset_bt_audio_callback();
-                       void set_bt_audio_state(bool state);
-
-                       void generate_data_packet(json &data);
-                       bool handle_event();
-                       void handle_audio_jack_event();
-
-                       static gboolean handle_bt_event(gpointer data);
-                       static void on_audio_jack_state_changed(runtime_info_key_e runtime_key, void* user_data);
-                       static void on_bt_connection_changed(bool connected, bt_device_connection_info_s *conn_info, void *user_data);
-                       static bool on_bt_bond(bt_device_info_s *device_info, void* user_data);
+       class device_status_headphone : public device_provider_base {
+
+               GENERATE_PROVIDER_COMMON_DECL(device_status_headphone);
+
+       public:
+               int subscribe();
+               int unsubscribe();
+               int read();
+               static bool is_supported();
+
+       private:
+               bool connected;
+               int audio_jack_state;
+               bool bt_audio_state;
+               bool bt_audio_callback_on;
+               bool bt_event_handler_added;
+               int bt_event_handling_count;
+
+               device_status_headphone();
+               ~device_status_headphone();
+
+               bool get_current_status();
+               void set_bt_audio_callback();
+               void unset_bt_audio_callback();
+               void set_bt_audio_state(bool state);
+
+               void generate_data_packet(json &data);
+               bool handle_event();
+               void handle_audio_jack_event();
+
+               static gboolean handle_bt_event(gpointer data);
+               static void on_audio_jack_state_changed(runtime_info_key_e runtime_key, void* user_data);
+               static void on_bt_connection_changed(bool connected, bt_device_connection_info_s *conn_info, void *user_data);
+               static bool on_bt_bond(bt_device_info_s *device_info, void* user_data);
        };
 }
 
index f14c91d..2122d08 100644 (file)
  * limitations under the License.
  */
 
+#include <context_mgr.h>
+#include "device_status_types.h"
 #include "psmode.h"
 
-ctx::device_status_power_saving_mode::device_status_power_saving_mode()
-       : being_subscribed(false)
+GENERATE_PROVIDER_COMMON_IMPL(device_status_psmode);
+
+ctx::device_status_psmode::device_status_psmode()
+{
+}
+
+ctx::device_status_psmode::~device_status_psmode()
 {
 }
 
-void ctx::device_status_power_saving_mode::update_cb(keynode_t *node, void* user_data)
+bool ctx::device_status_psmode::is_supported()
 {
-       device_status_power_saving_mode *instance = static_cast<device_status_power_saving_mode*>(user_data);
+       return true;
+}
+
+void ctx::device_status_psmode::update_cb(keynode_t *node, void* user_data)
+{
+       device_status_psmode *instance = static_cast<device_status_psmode*>(user_data);
        instance->handle_update(node);
 }
 
-void ctx::device_status_power_saving_mode::handle_update(keynode_t *node)
+void ctx::device_status_psmode::handle_update(keynode_t *node)
 {
        int status;
        ctx::json data_read;
@@ -37,31 +49,24 @@ void ctx::device_status_power_saving_mode::handle_update(keynode_t *node)
 
        data_read.set(NULL, DEVICE_ST_IS_ENABLED, status == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE);
 
-       publish(DEVICE_ST_SUBJ_POWER_SAVING_MODE, ERR_NONE, data_read);
+       context_manager::publish(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, data_read);
 }
 
-int ctx::device_status_power_saving_mode::subscribe(const char* subject)
+int ctx::device_status_psmode::subscribe()
 {
-       if (!being_subscribed) {
-               int ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, update_cb, this);
-               IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED);
-       }
-
-       being_subscribed = true;
+       int ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, update_cb, this);
+       IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED);
        return ERR_NONE;
 }
 
-int ctx::device_status_power_saving_mode::unsubscribe(const char* subject)
+int ctx::device_status_psmode::unsubscribe()
 {
-       being_subscribed = false;
-
        int ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, update_cb);
        IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED);
-
        return ERR_NONE;
 }
 
-int ctx::device_status_power_saving_mode::read(const char* subject)
+int ctx::device_status_psmode::read()
 {
        int mode;
        int ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &mode);
@@ -70,6 +75,6 @@ int ctx::device_status_power_saving_mode::read(const char* subject)
        ctx::json data_read;
        data_read.set(NULL, DEVICE_ST_IS_ENABLED, mode == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE);
 
-       ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_POWER_SAVING_MODE, NULL, ERR_NONE, data_read);
+       ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, data_read);
        return ERR_NONE;
 }
index 85bbe39..fc4275c 100644 (file)
 #define _DEVICE_STATUS_POWER_SAVING_MODE_H_
 
 #include <vconf.h>
-#include "../sub_provider_base.h"
+#include "../provider_base.h"
 
 namespace ctx {
 
-       class device_status_power_saving_mode : public sub_provider_base {
-               public:
-                       device_status_power_saving_mode();
-                       ~device_status_power_saving_mode(){}
+       class device_status_psmode : public device_provider_base {
 
-                       int subscribe(const char* subject);
-                       int unsubscribe(const char* subject);
-                       int read(const char* subject);
+               GENERATE_PROVIDER_COMMON_DECL(device_status_psmode);
 
-               private:
-                       bool being_subscribed;
+       public:
+               int subscribe();
+               int unsubscribe();
+               int read();
+               static bool is_supported();
 
-                       void handle_update(keynode_t *node);
-                       static void update_cb(keynode_t *node, void* user_data);
+       private:
+               device_status_psmode();
+               ~device_status_psmode();
+               void handle_update(keynode_t *node);
+               static void update_cb(keynode_t *node, void* user_data);
        };
 }
 
index 59ccdbc..2d3f0e3 100644 (file)
@@ -17,8 +17,7 @@
 #include "base_rtinfo.h"
 
 ctx::device_status_runtime_info::device_status_runtime_info(runtime_info_key_e key)
-       : being_subscribed(false)
-       , info_key(key)
+       : info_key(key)
 {
 }
 
@@ -34,23 +33,16 @@ void ctx::device_status_runtime_info::update_cb(runtime_info_key_e key, void* us
        instance->handle_update();
 }
 
-int ctx::device_status_runtime_info::subscribe(const char* subject)
+int ctx::device_status_runtime_info::subscribe()
 {
-       if (!being_subscribed) {
-               int ret = runtime_info_set_changed_cb(info_key, update_cb, this);
-               IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
-       }
-
-       being_subscribed = true;
+       int ret = runtime_info_set_changed_cb(info_key, update_cb, this);
+       IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
        return ERR_NONE;
 }
 
-int ctx::device_status_runtime_info::unsubscribe(const char* subject)
+int ctx::device_status_runtime_info::unsubscribe()
 {
-       being_subscribed = false;
-
        int ret = runtime_info_unset_changed_cb(info_key);
        IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED);
-
        return ERR_NONE;
 }
index 165eec3..29480c5 100644 (file)
 #define __CONTEXT_DEVICE_STATUS_RUNTIME_INFO_H__
 
 #include <runtime_info.h>
-#include "../../sub_provider_base.h"
+#include "../../provider_base.h"
 
 namespace ctx {
 
-       typedef std::set<std::string> string_set_t;
+       class device_status_runtime_info : public device_provider_base {
+       public:
+               device_status_runtime_info(runtime_info_key_e key);
 
-       class device_status_runtime_info : public sub_provider_base {
-               public:
-                       device_status_runtime_info(runtime_info_key_e key);
-                       virtual ~device_status_runtime_info(){}
+               int subscribe();
+               int unsubscribe();
+               virtual int read() = 0;
 
-                       int subscribe(const char* subject);
-                       int unsubscribe(const char* subject);
-                       virtual int read(const char* subject) = 0;
+       protected:
+               runtime_info_key_e info_key;
 
-               protected:
-                       bool being_subscribed;
-                       runtime_info_key_e info_key;
+               virtual ~device_status_runtime_info(){}
+               static void update_cb(runtime_info_key_e runtime_key, void* user_data);
+               virtual void handle_update() = 0;
 
-                       static void update_cb(runtime_info_key_e runtime_key, void* user_data);
-                       virtual void handle_update() = 0;
-
-               private:
-                       runtime_info_key_e get_info_key();
+       private:
+               runtime_info_key_e get_info_key();
        };
 }
 
index b4bbf94..df1b63c 100644 (file)
  * limitations under the License.
  */
 
+#include <context_mgr.h>
+#include "../device_status_types.h"
 #include "charger.h"
 
+GENERATE_PROVIDER_COMMON_IMPL(device_status_charger);
+
+ctx::device_status_charger::device_status_charger()
+       : device_status_runtime_info(RUNTIME_INFO_KEY_CHARGER_CONNECTED)
+{
+}
+
+ctx::device_status_charger::~device_status_charger()
+{
+}
+
+bool ctx::device_status_charger::is_supported()
+{
+       return true;
+}
+
 void ctx::device_status_charger::handle_update()
 {
        bool charger_status = false;
@@ -26,10 +44,10 @@ void ctx::device_status_charger::handle_update()
        ctx::json data_read;
        data_read.set(NULL, DEVICE_ST_IS_CONNECTED, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
 
-       publish(DEVICE_ST_SUBJ_CHARGER, ERR_NONE, data_read);
+       context_manager::publish(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, data_read);
 }
 
-int ctx::device_status_charger::read(const char* subject)
+int ctx::device_status_charger::read()
 {
        bool charger_status = false;
        ctx::json data_read;
index 0e474bd..70020a0 100644 (file)
 namespace ctx {
 
        class device_status_charger : public device_status_runtime_info {
-               public:
-                       device_status_charger() : device_status_runtime_info(RUNTIME_INFO_KEY_CHARGER_CONNECTED) {}
-                       ~device_status_charger(){}
 
-                       int read(const char* subject);
+               GENERATE_PROVIDER_COMMON_DECL(device_status_charger);
 
-               private:
-                       void handle_update();
+       public:
+               int read();
+               static bool is_supported();
+
+       private:
+               device_status_charger();
+               ~device_status_charger();
+               void handle_update();
        };
 }
 
index 8bf741c..ccd6ee6 100644 (file)
  * limitations under the License.
  */
 
-#include <system_info.h>
+#include <context_mgr.h>
+#include "../device_status_types.h"
 #include "gps.h"
 
+GENERATE_PROVIDER_COMMON_IMPL(device_status_gps);
+
 static const char* get_state_string(int gps_state)
 {
        switch (gps_state) {
@@ -35,6 +38,20 @@ static const char* get_state_string(int gps_state)
        }
 }
 
+ctx::device_status_gps::device_status_gps()
+       : device_status_runtime_info(RUNTIME_INFO_KEY_GPS_STATUS)
+{
+}
+
+ctx::device_status_gps::~device_status_gps()
+{
+}
+
+bool ctx::device_status_gps::is_supported()
+{
+       return get_system_info_bool("tizen.org/feature/location.gps");
+}
+
 void ctx::device_status_gps::handle_update()
 {
        int gps_status;
@@ -48,10 +65,10 @@ void ctx::device_status_gps::handle_update()
 
        data_read.set(NULL, DEVICE_ST_STATE, state_str);
 
-       publish(DEVICE_ST_SUBJ_GPS, ERR_NONE, data_read);
+       context_manager::publish(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, data_read);
 }
 
-int ctx::device_status_gps::read(const char* subject)
+int ctx::device_status_gps::read()
 {
        int gps_status;
        ctx::json data_read;
@@ -67,13 +84,3 @@ int ctx::device_status_gps::read(const char* subject)
        ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, data_read);
        return ERR_NONE;
 }
-
-bool ctx::device_status_gps::is_supported(const char* subject)
-{
-       bool supported = false;
-
-       int ret = system_info_get_platform_bool("tizen.org/feature/location.gps", &supported);
-       IF_FAIL_RETURN_TAG(ret == SYSTEM_INFO_ERROR_NONE, false, _E, "system_info_get_platform_bool() failed");
-
-       return supported;
-}
index 6754a7e..fdbe0cf 100644 (file)
 namespace ctx {
 
        class device_status_gps : public device_status_runtime_info {
-               public:
-                       device_status_gps() : device_status_runtime_info(RUNTIME_INFO_KEY_GPS_STATUS) {}
-                       ~device_status_gps(){}
 
-                       int read(const char* subject);
-                       bool is_supported(const char* subject);
+               GENERATE_PROVIDER_COMMON_DECL(device_status_gps);
 
-               private:
-                       void handle_update();
+       public:
+               int read();
+               static bool is_supported();
+
+       private:
+               device_status_gps();
+               ~device_status_gps();
+               void handle_update();
        };
 }
 
index 4b62f94..cefb72e 100644 (file)
  * limitations under the License.
  */
 
-#include <system_info.h>
+#include <context_mgr.h>
+#include "../device_status_types.h"
 #include "usb.h"
 
+GENERATE_PROVIDER_COMMON_IMPL(device_status_usb);
+
+ctx::device_status_usb::device_status_usb()
+       : device_status_runtime_info(RUNTIME_INFO_KEY_USB_CONNECTED)
+{
+}
+
+ctx::device_status_usb::~device_status_usb()
+{
+}
+
+bool ctx::device_status_usb::is_supported()
+{
+       return get_system_info_bool("tizen.org/feature/usb.host");
+}
+
 void ctx::device_status_usb::handle_update()
 {
        bool status = false;
@@ -27,10 +44,10 @@ void ctx::device_status_usb::handle_update()
        ctx::json data_read;
        data_read.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE);
 
-       publish(DEVICE_ST_SUBJ_USB, ERR_NONE, data_read);
+       context_manager::publish(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, data_read);
 }
 
-int ctx::device_status_usb::read(const char* subject)
+int ctx::device_status_usb::read()
 {
        bool status = false;
        ctx::json data_read;
@@ -43,13 +60,3 @@ int ctx::device_status_usb::read(const char* subject)
        ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, data_read);
        return ERR_NONE;
 }
-
-bool ctx::device_status_usb::is_supported(const char* subject)
-{
-       bool supported = false;
-
-       int ret = system_info_get_platform_bool("tizen.org/feature/usb.host", &supported);
-       IF_FAIL_RETURN_TAG(ret == SYSTEM_INFO_ERROR_NONE, false, _E, "system_info_get_platform_bool() failed");
-
-       return supported;
-}
index 19e5e92..2242bd0 100644 (file)
 namespace ctx {
 
        class device_status_usb : public device_status_runtime_info {
-               public:
-                       device_status_usb() : device_status_runtime_info(RUNTIME_INFO_KEY_USB_CONNECTED) {}
-                       ~device_status_usb(){}
 
-                       int read(const char* subject);
-                       bool is_supported(const char* subject);
+               GENERATE_PROVIDER_COMMON_DECL(device_status_usb);
 
-               private:
-                       void handle_update();
+       public:
+               int read();
+               static bool is_supported();
+
+       private:
+               device_status_usb();
+               ~device_status_usb();
+               void handle_update();
        };
 }
 
index 0dc29b3..86b4412 100644 (file)
  * limitations under the License.
  */
 
-#include <system_info.h>
+#include <context_mgr.h>
+#include "device_status_types.h"
 #include "wifi.h"
 
+GENERATE_PROVIDER_COMMON_IMPL(device_status_wifi);
+
 ctx::device_status_wifi::device_status_wifi()
-       : being_subscribed(false)
-       , last_state(_UNKNOWN)
+       : last_state(_UNKNOWN)
        , is_initialized(false)
        , is_activated(false)
 {
 }
 
-bool ctx::device_status_wifi::is_supported(const char* subject)
+ctx::device_status_wifi::~device_status_wifi()
 {
-       bool supported = false;
-
-       int ret = system_info_get_platform_bool("tizen.org/feature/network.wifi", &supported);
-       IF_FAIL_RETURN_TAG(ret == SYSTEM_INFO_ERROR_NONE, false, _E, "wifi is_supported() failed");
+}
 
-       return supported;
+bool ctx::device_status_wifi::is_supported()
+{
+       return get_system_info_bool("tizen.org/feature/network.wifi");
 }
 
 bool ctx::device_status_wifi::get_current_state()
@@ -111,7 +112,7 @@ bool ctx::device_status_wifi::get_response_packet(ctx::json &data)
        return true;
 }
 
-int ctx::device_status_wifi::read(const char* subject)
+int ctx::device_status_wifi::read()
 {
        IF_FAIL_RETURN(get_current_state(), ERR_OPERATION_FAILED);
 
@@ -157,24 +158,19 @@ void ctx::device_status_wifi::stop_monitor()
        is_initialized = false;
 }
 
-int ctx::device_status_wifi::subscribe(const char* subject)
+int ctx::device_status_wifi::subscribe()
 {
-       if (!being_subscribed) {
-               IF_FAIL_RETURN(start_monitor(), ERR_OPERATION_FAILED);
-               if (!get_current_state()) {
-                       stop_monitor();
-                       return ERR_OPERATION_FAILED;
-               }
+       IF_FAIL_RETURN(start_monitor(), ERR_OPERATION_FAILED);
+       if (!get_current_state()) {
+               stop_monitor();
+               return ERR_OPERATION_FAILED;
        }
 
-       being_subscribed = true;
        return ERR_NONE;
 }
 
-int ctx::device_status_wifi::unsubscribe(const char* subject)
+int ctx::device_status_wifi::unsubscribe()
 {
-       being_subscribed = false;
-
        stop_monitor();
        return ERR_NONE;
 }
@@ -199,7 +195,7 @@ void ctx::device_status_wifi::aggregate_updated_data()
 
                ctx::json data;
                if (get_response_packet(data))
-                       publish(DEVICE_ST_SUBJ_WIFI, ERR_NONE, data);
+                       context_manager::publish(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, data);
        }
 }
 
index 2cb7779..1f5d304 100644 (file)
 
 #include <string>
 #include <wifi.h>
-#include "../sub_provider_base.h"
+#include "../provider_base.h"
 
 namespace ctx {
 
-       class device_status_wifi : public sub_provider_base {
-       public:
-               device_status_wifi();
-               ~device_status_wifi(){}
+       class device_status_wifi : public device_provider_base {
+
+               GENERATE_PROVIDER_COMMON_DECL(device_status_wifi);
 
-               int subscribe(const char* subject);
-               int unsubscribe(const char* subject);
-               int read(const char* subject);
-               bool is_supported(const char* subject);
+       public:
+               int subscribe();
+               int unsubscribe();
+               int read();
+               static bool is_supported();
 
        private:
                enum _state_e {
@@ -41,13 +41,15 @@ namespace ctx {
                        _CONNECTED,
                };
 
-               bool being_subscribed;
                int last_state;
                bool is_initialized;
                bool is_activated;
                wifi_connection_state_e conn_state;
                std::string bssid;
 
+               device_status_wifi();
+               ~device_status_wifi();
+
                bool get_current_state();
                bool get_bssid();
                bool get_response_packet(json &data);
diff --git a/src/provider_base.cpp b/src/provider_base.cpp
new file mode 100644 (file)
index 0000000..acc61cd
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <system_info.h>
+#include "provider_base.h"
+
+ctx::device_provider_base::device_provider_base()
+       : being_subscribed(false)
+{
+}
+
+int ctx::device_provider_base::subscribe(const char *subject, ctx::json option, ctx::json *request_result)
+{
+       IF_FAIL_RETURN(!being_subscribed, ERR_NONE);
+
+       int ret = subscribe();
+
+       if (ret == ERR_NONE)
+               being_subscribed = true;
+       else
+               destroy_self();
+
+       return ret;
+}
+
+int ctx::device_provider_base::unsubscribe(const char *subject, ctx::json option)
+{
+       int ret = ERR_NONE;
+
+       if (being_subscribed)
+               ret = unsubscribe();
+
+       destroy_self();
+       return ret;
+}
+
+int ctx::device_provider_base::read(const char *subject, ctx::json option, ctx::json *request_result)
+{
+       int ret = read();
+
+       if (!being_subscribed)
+               destroy_self();
+
+       return ret;
+}
+
+int ctx::device_provider_base::write(const char *subject, ctx::json data, ctx::json *request_result)
+{
+       int ret = write();
+
+       if (!being_subscribed)
+               destroy_self();
+
+       return ret;
+}
+
+int ctx::device_provider_base::subscribe()
+{
+       return ERR_NOT_SUPPORTED;
+}
+
+int ctx::device_provider_base::unsubscribe()
+{
+       return ERR_NOT_SUPPORTED;
+}
+
+int ctx::device_provider_base::read()
+{
+       return ERR_NOT_SUPPORTED;
+}
+
+int ctx::device_provider_base::write()
+{
+       return ERR_NOT_SUPPORTED;
+}
+
+bool ctx::device_provider_base::get_system_info_bool(const char *key)
+{
+       bool supported = false;
+       int ret = system_info_get_platform_bool(key, &supported);
+       IF_FAIL_RETURN_TAG(ret == SYSTEM_INFO_ERROR_NONE, false, _E, "system_info_get_platform_bool() failed");
+       return supported;
+}
diff --git a/src/provider_base.h b/src/provider_base.h
new file mode 100644 (file)
index 0000000..c05f4c7
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CONTEXT_DEVICE_PROVIDER_BASE_H__
+#define __CONTEXT_DEVICE_PROVIDER_BASE_H__
+
+#include <types_internal.h>
+#include <json.h>
+#include <provider_iface.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 context_provider_iface *create(void *data); \
+               static void destroy(void *data); \
+       protected: \
+               void destroy_self(); \
+       private: \
+               static prvd *__instance; \
+
+#define GENERATE_PROVIDER_COMMON_IMPL(prvd) \
+       ctx::prvd *ctx::prvd::__instance = NULL; \
+       ctx::context_provider_iface *ctx::prvd::create(void *data) \
+       { \
+               CREATE_INSTANCE(prvd); \
+       } \
+       void ctx::prvd::destroy(void *data) \
+       { \
+               DESTROY_INSTANCE(); \
+       } \
+       void ctx::prvd::destroy_self() \
+       { \
+               destroy(NULL); \
+       } \
+
+namespace ctx {
+
+       class device_provider_base : public context_provider_iface {
+       public:
+               int subscribe(const char *subject, ctx::json option, ctx::json *request_result);
+               int unsubscribe(const char *subject, ctx::json option);
+               int read(const char *subject, ctx::json option, ctx::json *request_result);
+               int write(const char *subject, ctx::json data, ctx::json *request_result);
+
+       protected:
+               bool being_subscribed;
+
+               device_provider_base();
+               virtual ~device_provider_base() {}
+
+               virtual int subscribe();
+               virtual int unsubscribe();
+               virtual int read();
+               virtual int write();
+               virtual void destroy_self() = 0;
+
+               static bool get_system_info_bool(const char *key);
+       };
+}
+
+#endif
index 97d58ca..82e8550 100644 (file)
  */
 
 #include <stdlib.h>
-#include <json.h>
-#include <system_info.h>
 #include <tapi_common.h>
 #include <ITapiCall.h>
+#include <json.h>
+#include <context_mgr.h>
+#include "social_status_types.h"
 #include "call.h"
 
+GENERATE_PROVIDER_COMMON_IMPL(social_status_call);
+
 static bool telephony_initialized = false;
 static TapiHandle* tapi_handle = NULL;
 
@@ -33,7 +36,6 @@ static void call_status_cb(TelCallStatus_t *out, void *user_data)
 }
 
 ctx::social_status_call::social_status_call()
-       : being_subscribed(false)
 {
        tapi_handle = NULL;
 }
@@ -42,6 +44,11 @@ ctx::social_status_call::~social_status_call()
 {
 }
 
+bool ctx::social_status_call::is_supported()
+{
+       return get_system_info_bool("tizen.org/feature/network.telephony");
+}
+
 void ctx::social_status_call::call_event_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data)
 {
        social_status_call *instance = static_cast<social_status_call*>(user_data);
@@ -85,7 +92,7 @@ void ctx::social_status_call::handle_call_event(telephony_h handle, telephony_no
                break;
        }
 
-       publish(SOCIAL_ST_SUBJ_CALL, ERR_NONE, data);
+       context_manager::publish(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data);
 }
 
 bool ctx::social_status_call::init_telephony()
@@ -165,21 +172,16 @@ bool ctx::social_status_call::get_call_address(std::string& address)
        return true;
 }
 
-int ctx::social_status_call::subscribe(const char* subject)
+int ctx::social_status_call::subscribe()
 {
-       if (!being_subscribed) {
-               bool ret = set_callback();
-               IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
-       }
-
-       being_subscribed = true;
+       bool ret = set_callback();
+       IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
        return ERR_NONE;
 }
 
 
-int ctx::social_status_call::unsubscribe(const char* subject)
+int ctx::social_status_call::unsubscribe()
 {
-       being_subscribed = false;
        unset_callback();
        return ERR_NONE;
 }
@@ -215,7 +217,7 @@ bool ctx::social_status_call::read_current_status(ctx::json& data)
        return true;
 }
 
-int ctx::social_status_call::read(const char* subject)
+int ctx::social_status_call::read()
 {
        bool temporary_handle = false;
        if (!telephony_initialized) {
@@ -236,11 +238,3 @@ int ctx::social_status_call::read(const char* subject)
 
        return ERR_OPERATION_FAILED;
 }
-
-bool ctx::social_status_call::is_supported(const char* subject)
-{
-       bool supported = false;
-       int ret = system_info_get_platform_bool("tizen.org/feature/network.telephony", &supported);
-       IF_FAIL_RETURN_TAG(ret == SYSTEM_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "support check failed");
-       return supported;
-}
index 27035fc..c130c23 100644 (file)
 #define _CONTEXT_SOCIAL_STATUS_CALL_H_
 
 #include <telephony.h>
-#include "../sub_provider_base.h"
+#include "../provider_base.h"
 
 namespace ctx {
 
-       class social_status_call : public sub_provider_base {
-               public:
-                       social_status_call();
-                       ~social_status_call();
+       class social_status_call : public device_provider_base {
 
-                       int subscribe(const char* subject);
-                       int unsubscribe(const char* subject);
-                       int read(const char* subject);
-                       bool is_supported(const char* subject);
+               GENERATE_PROVIDER_COMMON_DECL(social_status_call);
 
-               private:
-                       telephony_handle_list_s handle_list;
-                       bool being_subscribed;
+       public:
+               int subscribe();
+               int unsubscribe();
+               int read();
+               static bool is_supported();
 
-                       bool init_telephony();
-                       void release_telephony();
-                       bool set_callback();
-                       void unset_callback();
-                       bool read_current_status(ctx::json& data);
+       private:
+               telephony_handle_list_s handle_list;
 
-                       bool get_voice_call_state(telephony_call_state_e& state);
-                       bool get_video_call_state(telephony_call_state_e& state);
-                       bool get_call_address(std::string& address);
+               social_status_call();
+               ~social_status_call();
 
-                       void handle_call_event(telephony_h handle, telephony_noti_e noti_id);
-                       static void call_event_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data);
+               bool init_telephony();
+               void release_telephony();
+               bool set_callback();
+               void unset_callback();
+               bool read_current_status(ctx::json& data);
+
+               bool get_voice_call_state(telephony_call_state_e& state);
+               bool get_video_call_state(telephony_call_state_e& state);
+               bool get_call_address(std::string& address);
+
+               void handle_call_event(telephony_h handle, telephony_noti_e noti_id);
+               static void call_event_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data);
        };
 }
 
index e4ea558..a0a98f2 100644 (file)
 
 #include <gio/gio.h>
 #include <email-api-etc.h>
-#include <system_info.h>
 
+#include <context_mgr.h>
+#include "social_status_types.h"
 #include <dbus_server.h>
 #include "email.h"
 
+GENERATE_PROVIDER_COMMON_IMPL(social_status_email);
+
 ctx::social_status_email::social_status_email()
-       : being_subscribed(false)
 {
 }
 
+ctx::social_status_email::~social_status_email()
+{
+}
+
+bool ctx::social_status_email::is_supported()
+{
+       return get_system_info_bool("tizen.org/feature/network.telephony");
+}
+
 void ctx::social_status_email::on_signal_received(const char* sender, const char* path, const char* iface, const char* name, GVariant* param)
 {
        gint sub_type = 0;
@@ -41,32 +52,27 @@ void ctx::social_status_email::on_signal_received(const char* sender, const char
                _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", sub_type, gi1, gc, gi2, gi3);
                ctx::json data_updated;
                data_updated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED);
-               publish(SOCIAL_ST_SUBJ_EMAIL, ERR_NONE, data_updated);
+               context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, data_updated);
 
        } else if (sub_type == NOTI_SEND_FINISH) {
                _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", sub_type, gi1, gc, gi2, gi3);
                ctx::json data_updated;
                data_updated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_SENT);
-               publish(SOCIAL_ST_SUBJ_EMAIL, ERR_NONE, data_updated);
+               context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, data_updated);
        }
 }
 
 
-int ctx::social_status_email::subscribe(const char* subject)
+int ctx::social_status_email::subscribe()
 {
-       if (!being_subscribed) {
-               dbus_signal_id = ctx::dbus_server::signal_subscribe(NULL, NULL, "User.Email.NetworkStatus", "email", this);
-               IF_FAIL_RETURN_TAG(dbus_signal_id >= 0, ERR_OPERATION_FAILED, _E, "Email dbus signal subscription failed");
-       }
-
-       being_subscribed = true;
+       dbus_signal_id = ctx::dbus_server::signal_subscribe(NULL, NULL, "User.Email.NetworkStatus", "email", this);
+       IF_FAIL_RETURN_TAG(dbus_signal_id >= 0, ERR_OPERATION_FAILED, _E, "Email dbus signal subscription failed");
        return ERR_NONE;
 }
 
 
-int ctx::social_status_email::unsubscribe(const char* subject)
+int ctx::social_status_email::unsubscribe()
 {
-       being_subscribed = false;
        ctx::dbus_server::signal_unsubscribe(dbus_signal_id);
        return ERR_NONE;
 }
index e7a17f1..3156067 100644 (file)
 #define _CONTEXT_SOCIAL_STATUS_EMAIL_H_
 
 #include <dbus_listener_iface.h>
-#include "../sub_provider_base.h"
+#include "../provider_base.h"
 
 namespace ctx {
 
-       class social_status_email : public sub_provider_base, public dbus_listener_iface {
-               public:
-                       social_status_email();
-                       ~social_status_email() {}
+       class social_status_email : public device_provider_base, public dbus_listener_iface {
 
-                       int subscribe(const char* subject);
-                       int unsubscribe(const char* subject);
+               GENERATE_PROVIDER_COMMON_DECL(social_status_email);
 
-                       void on_signal_received(const char* sender, const char* path, const char* iface, const char* name, GVariant* param);
+       public:
+               int subscribe();
+               int unsubscribe();
+               void on_signal_received(const char* sender, const char* path, const char* iface, const char* name, GVariant* param);
+               static bool is_supported();
 
-               private:
-                       int64_t dbus_signal_id;
-                       bool being_subscribed;
+       private:
+               int64_t dbus_signal_id;
+
+               social_status_email();
+               ~social_status_email();
        };
 }
 
index ae6a753..1d75ef3 100644 (file)
  */
 
 #include <json.h>
-#include <system_info.h>
+#include <context_mgr.h>
+#include "social_status_types.h"
 #include "message.h"
 
 #define MAX_ADDR_SIZE 20
 
+GENERATE_PROVIDER_COMMON_IMPL(social_status_message);
+
 ctx::social_status_message::social_status_message()
        : message_handle(NULL)
-       , being_subscribed(false)
 {
 }
 
+ctx::social_status_message::~social_status_message()
+{
+}
+
+bool ctx::social_status_message::is_supported()
+{
+       return get_system_info_bool("tizen.org/feature/network.telephony");
+}
+
 void ctx::social_status_message::state_change_cb(msg_handle_t handle, msg_struct_t msg, void* user_data)
 {
        social_status_message *instance = static_cast<social_status_message*>(user_data);
@@ -69,7 +80,7 @@ void ctx::social_status_message::handle_state_change(msg_struct_t msg)
        data.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED);
        data.set(NULL, SOCIAL_ST_ADDRESS, address);
 
-       publish(SOCIAL_ST_SUBJ_MESSAGE, ERR_NONE, data);
+       context_manager::publish(SOCIAL_ST_SUBJ_MESSAGE, NULL, ERR_NONE, data);
 }
 
 bool ctx::social_status_message::set_callback()
@@ -98,28 +109,15 @@ void ctx::social_status_message::unset_callback()
        message_handle = NULL;
 }
 
-int ctx::social_status_message::subscribe(const char* subject)
+int ctx::social_status_message::subscribe()
 {
-       if (!being_subscribed) {
-               bool ret = set_callback();
-               IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
-       }
-
-       being_subscribed = true;
+       bool ret = set_callback();
+       IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED);
        return ERR_NONE;
 }
 
-int ctx::social_status_message::unsubscribe(const char* subject)
+int ctx::social_status_message::unsubscribe()
 {
-       being_subscribed = false;
        unset_callback();
        return ERR_NONE;
 }
-
-bool ctx::social_status_message::is_supported(const char* subject)
-{
-       bool supported = false;
-       int ret = system_info_get_platform_bool("tizen.org/feature/network.telephony", &supported);
-       IF_FAIL_RETURN_TAG(ret == SYSTEM_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "support check failed");
-       return supported;
-}
index e9dbc86..bb7383c 100644 (file)
 
 #include <msg.h>
 #include <msg_transport.h>
-#include "../sub_provider_base.h"
+#include "../provider_base.h"
 
 namespace ctx {
 
-       class social_status_message : public sub_provider_base {
-               public:
-                       social_status_message();
-                       ~social_status_message() {}
+       class social_status_message : public device_provider_base {
 
-                       int subscribe(const char* subject);
-                       int unsubscribe(const char* subject);
-                       bool is_supported(const char* subject);
+               GENERATE_PROVIDER_COMMON_DECL(social_status_message);
 
-               private:
-                       msg_handle_t message_handle;
-                       bool being_subscribed;
+       public:
+               int subscribe();
+               int unsubscribe();
+               static bool is_supported();
 
-                       bool set_callback();
-                       void unset_callback();
-                       void handle_state_change(msg_struct_t msg);
-                       static void state_change_cb(msg_handle_t handle, msg_struct_t msg, void* user_data);
+       private:
+               msg_handle_t message_handle;
+               bool being_subscribed;
+
+               social_status_message();
+               ~social_status_message();
+
+               bool set_callback();
+               void unset_callback();
+               void handle_state_change(msg_struct_t msg);
+               static void state_change_cb(msg_handle_t handle, msg_struct_t msg, void* user_data);
        };
 }
 
diff --git a/src/sub_provider_base.cpp b/src/sub_provider_base.cpp
deleted file mode 100644 (file)
index 829f8ce..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "sub_provider_base.h"
-
-int ctx::sub_provider_base::subscribe(const char* subject)
-{
-       return ERR_NOT_SUPPORTED;
-}
-
-int ctx::sub_provider_base::unsubscribe(const char* subject)
-{
-       return ERR_NOT_SUPPORTED;
-}
-
-int ctx::sub_provider_base::read(const char* subject)
-{
-       return ERR_NOT_SUPPORTED;
-}
-
-bool ctx::sub_provider_base::is_supported(const char* subject)
-{
-       // Generally, if a sub-analyzer is implemented by inheriting this class, "subject" is supported.
-       return true;
-}
-
-void ctx::sub_provider_base::publish(const char* subject, int error, ctx::json data)
-{
-       ctx::json option;
-       _D("Publishing '%s'", subject);
-       ctx::context_manager::publish(subject, option, error, data);
-}
diff --git a/src/sub_provider_base.h b/src/sub_provider_base.h
deleted file mode 100644 (file)
index de1bc60..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __CONTEXT_DEVICE_SUB_PROVIDER_BASE_H__
-#define __CONTEXT_DEVICE_SUB_PROVIDER_BASE_H__
-
-#include <set>
-#include <string>
-#include <json.h>
-#include <context_mgr.h>
-#include <device_context_provider.h>
-#include "device_status/device_status_types.h"
-#include "social_status/social_status_types.h"
-
-namespace ctx {
-
-       class sub_provider_base {
-               public:
-                       sub_provider_base(){}
-                       virtual ~sub_provider_base(){}
-
-                       virtual int subscribe(const char* subject);
-                       virtual int unsubscribe(const char* subject);
-                       virtual int read(const char* subject);
-                       virtual bool is_supported(const char* subject);
-
-               protected:
-                       void publish(const char* subject, int error, ctx::json data);
-       };
-}
-
-#endif