From 2cfeeeed9120711c0b1dab359e22602b904b1866 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Wed, 24 Feb 2016 15:24:36 +0900 Subject: [PATCH 01/16] Replace timer_manager & timer_util with TimerManager Change-Id: I5dc43ccbfb90ef3025c495f0c350327d0e27aafe Signed-off-by: Mu-Woong Lee --- src/device/system/alarm.cpp | 28 ++++++++++------------ src/device/system/alarm.h | 7 +++--- src/device/system/time.cpp | 4 ++-- .../recognition/user_places/location_logger.cpp | 6 ++--- .../recognition/user_places/location_logger.h | 8 +++---- .../recognition/user_places/places_detector.cpp | 2 +- .../recognition/user_places/places_detector.h | 6 ++--- src/place/recognition/user_places/user_places.cpp | 7 +++--- src/place/recognition/user_places/user_places.h | 6 +++-- src/place/recognition/user_places/wifi_logger.cpp | 8 +++---- src/place/recognition/user_places/wifi_logger.h | 8 +++---- src/statistics/social/log_aggregator.cpp | 7 +++--- src/statistics/social/log_aggregator.h | 7 +++--- 13 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/device/system/alarm.cpp b/src/device/system/alarm.cpp index bd800ee..d1c6f26 100644 --- a/src/device/system/alarm.cpp +++ b/src/device/system/alarm.cpp @@ -15,8 +15,6 @@ */ #include -#include -#include #include "system_types.h" #include "alarm.h" @@ -122,7 +120,7 @@ int ctx::device_status_alarm::get_arranged_day_of_week(ctx::Json& option) std::string tmp_d; for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &tmp_d); i++) { - dow |= ctx::timer_util::convert_day_of_week_string_to_int(tmp_d); + dow |= ctx::TimerManager::dowToInt(tmp_d); } _D("Requested day of week (%#x)", dow); @@ -131,14 +129,14 @@ int ctx::device_status_alarm::get_arranged_day_of_week(ctx::Json& option) ctx::device_status_alarm::ref_count_array_s::ref_count_array_s() { - memset(count, 0, sizeof(int) * MAX_DAY); + memset(count, 0, sizeof(int) * DAYS_PER_WEEK); } int ctx::device_status_alarm::merge_day_of_week(int* ref_cnt) { int day_of_week = 0; - for (int d = 0; d < MAX_DAY; ++d) { + for (int d = 0; d < DAYS_PER_WEEK; ++d) { if (ref_cnt[d] > 0) { day_of_week |= (0x01 << d); } @@ -150,12 +148,12 @@ int ctx::device_status_alarm::merge_day_of_week(int* ref_cnt) bool ctx::device_status_alarm::add(int minute, int day_of_week) { IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 && - day_of_week > 0 && day_of_week <= timer_types::EVERYDAY, + day_of_week > 0 && day_of_week <= static_cast(DayOfWeek::EVERYDAY), false, _E, "Invalid parameter"); ref_count_array_s &ref = ref_count_map[minute]; - for (int d = 0; d < MAX_DAY; ++d) { + for (int d = 0; d < DAYS_PER_WEEK; ++d) { if ((day_of_week & (0x01 << d)) != 0) { ref.count[d] += 1; } @@ -167,12 +165,12 @@ bool ctx::device_status_alarm::add(int minute, int day_of_week) bool ctx::device_status_alarm::remove(int minute, int day_of_week) { IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 && - day_of_week > 0 && day_of_week <= timer_types::EVERYDAY, + day_of_week > 0 && day_of_week <= static_cast(DayOfWeek::EVERYDAY), false, _E, "Invalid parameter"); ref_count_array_s &ref = ref_count_map[minute]; - for (int d = 0; d < MAX_DAY; ++d) { + for (int d = 0; d < DAYS_PER_WEEK; ++d) { if ((day_of_week & (0x01 << d)) != 0 && ref.count[d] > 0) { ref.count[d] -= 1; } @@ -193,7 +191,7 @@ bool ctx::device_status_alarm::reset_timer(int minute) if (day_of_week == 0 && timer.timer_id > 0) { /* Turn off the timer at hour, if it is not necessray anymore. */ - timer_manager::remove(timer.timer_id); + __timerManager.remove(timer.timer_id); timer_state_map.erase(minute); ref_count_map.erase(minute); return true; @@ -201,7 +199,7 @@ bool ctx::device_status_alarm::reset_timer(int minute) if (timer.timer_id > 0) { /* Turn off the current timer, to set a new one. */ - timer_manager::remove(timer.timer_id); + __timerManager.remove(timer.timer_id); timer.timer_id = -1; timer.day_of_week = 0; } @@ -209,7 +207,7 @@ bool ctx::device_status_alarm::reset_timer(int minute) /* Create a new timer, w.r.t. the new day_of_week value. */ int h = minute / 60; int m = minute - h * 60; - int tid = timer_manager::set_at(h, m, day_of_week, this); + int tid = __timerManager.setAt(h, m, static_cast(day_of_week), this); IF_FAIL_RETURN_TAG(tid > 0, false, _E, "Timer setting failed"); timer.timer_id = tid; @@ -222,7 +220,7 @@ void ctx::device_status_alarm::clear() { for (timer_state_map_t::iterator it = timer_state_map.begin(); it != timer_state_map.end(); ++it) { if (it->second.timer_id > 0) { - timer_manager::remove(it->second.timer_id); + __timerManager.remove(it->second.timer_id); } } @@ -230,7 +228,7 @@ void ctx::device_status_alarm::clear() ref_count_map.clear(); } -bool ctx::device_status_alarm::on_timer_expired(int timer_id, void* user_data) +bool ctx::device_status_alarm::onTimerExpired(int timer_id) { time_t rawtime; struct tm timeinfo; @@ -254,7 +252,7 @@ void ctx::device_status_alarm::on_timer_expired(int hour, int min, int day_of_we ctx::Json data_read; int result_time = hour * 60 + min; - std::string result_day = ctx::timer_util::convert_day_of_week_int_to_string(day_of_week); + std::string result_day = ctx::TimerManager::dowToStr(day_of_week); data_read.set(NULL, DEVICE_ST_TIME_OF_DAY, result_time); data_read.set(NULL, DEVICE_ST_DAY_OF_WEEK, result_day); diff --git a/src/device/system/alarm.h b/src/device/system/alarm.h index 8f51836..8d640e3 100644 --- a/src/device/system/alarm.h +++ b/src/device/system/alarm.h @@ -20,12 +20,12 @@ #include #include #include -#include +#include #include "../provider_base.h" namespace ctx { - class device_status_alarm : public context_provider_iface, timer_listener_iface { + class device_status_alarm : public context_provider_iface, ITimerListener { GENERATE_PROVIDER_COMMON_DECL(device_status_alarm); @@ -65,6 +65,7 @@ namespace ctx { ref_count_map_t ref_count_map; timer_state_map_t timer_state_map; option_t option_set; + TimerManager __timerManager; bool add(int minute, int day_of_week); bool remove(int minute, int day_of_week); @@ -74,7 +75,7 @@ namespace ctx { int merge_day_of_week(int *ref_cnt); bool reset_timer(int hour); void on_timer_expired(int hour, int min, int day_of_week); - bool on_timer_expired(int timer_id, void *user_data); + bool onTimerExpired(int timer_id); bool is_matched(ctx::Json& option, int time, std::string day); option_t::iterator find_option(ctx::Json& option); diff --git a/src/device/system/time.cpp b/src/device/system/time.cpp index 65ba55a..7f5515a 100644 --- a/src/device/system/time.cpp +++ b/src/device/system/time.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include "system_types.h" #include "time.h" @@ -66,7 +66,7 @@ int ctx::device_status_time::read() int day_of_month = timeinfo.tm_mday; int minute_of_day = timeinfo.tm_hour * 60 + timeinfo.tm_min; - std::string day_of_week = ctx::timer_util::convert_day_of_week_int_to_string(0x01 << timeinfo.tm_wday); + std::string day_of_week = ctx::TimerManager::dowToStr(0x01 << timeinfo.tm_wday); ctx::Json data_read; data_read.set(NULL, DEVICE_ST_DAY_OF_MONTH, day_of_month); diff --git a/src/place/recognition/user_places/location_logger.cpp b/src/place/recognition/user_places/location_logger.cpp index 1a5ef29..6bee94b 100644 --- a/src/place/recognition/user_places/location_logger.cpp +++ b/src/place/recognition/user_places/location_logger.cpp @@ -486,7 +486,7 @@ void ctx::LocationLogger::broadcast(ctx::location_event_s location_event) } } -bool ctx::LocationLogger::on_timer_expired(int id, void* user_data) +bool ctx::LocationLogger::onTimerExpired(int id) { time_t now = time(nullptr); double seconds = difftime(now, timer_timestamp); @@ -564,14 +564,14 @@ void ctx::LocationLogger::passive_interval_timer_start() void ctx::LocationLogger::timer_start(time_t minutes) { timer_timestamp = time(nullptr); - timer_id = timer_manager::set_for(minutes, this, NULL); + timer_id = __timerManager.setFor(minutes, this); _D("%s (minutes=%d) timer_id = %d", timer_id >= 0 ? "SUCCESS" : "ERROR", minutes, timer_id); } void ctx::LocationLogger::timer_stop() { _D(""); - timer_manager::remove(timer_id); + __timerManager.remove(timer_id); } void ctx::LocationLogger::start_logging() diff --git a/src/place/recognition/user_places/location_logger.h b/src/place/recognition/user_places/location_logger.h index 21bcec6..f27bd31 100644 --- a/src/place/recognition/user_places/location_logger.h +++ b/src/place/recognition/user_places/location_logger.h @@ -17,9 +17,8 @@ #ifndef __CONTEXT_PLACE_STATUS_LOCATION_LOGGER_H__ #define __CONTEXT_PLACE_STATUS_LOCATION_LOGGER_H__ -#include #include -#include "timer_mgr.h" +#include #include "visit_listener_iface.h" #include "location_listener_iface.h" @@ -63,7 +62,7 @@ namespace ctx { LOCATION_LOGGER_WAITING_FOR_PASSIVE_INTERVAL = 4 } timer_purpose_e; - class LocationLogger : public timer_listener_iface, public IVisitListener { + class LocationLogger : public ITimerListener, public IVisitListener { public: LocationLogger(ILocationListener *listener_ = nullptr, @@ -103,6 +102,7 @@ namespace ctx { /* TIMER */ int timer_id; time_t timer_timestamp; + TimerManager __timerManager; timer_purpose_e timer_purpose; void set_next_timer(); void active_request_timer_start(); @@ -111,7 +111,7 @@ namespace ctx { void passive_interval_timer_start(); void timer_start(time_t minutes); void timer_stop(); - bool on_timer_expired(int timer_id, void* user_data); + bool onTimerExpired(int timerId); /* DATABASE */ static int create_table(); diff --git a/src/place/recognition/user_places/places_detector.cpp b/src/place/recognition/user_places/places_detector.cpp index a5163e4..4890db1 100644 --- a/src/place/recognition/user_places/places_detector.cpp +++ b/src/place/recognition/user_places/places_detector.cpp @@ -70,7 +70,7 @@ PLACE_COLUMN_WIFI_APS " STRING, "\ PLACE_COLUMN_CREATE_DATE " timestamp" -bool ctx::PlacesDetector::on_timer_expired(int timer_id, void* user_data) +bool ctx::PlacesDetector::onTimerExpired(int timerId) { _D(""); db_delete_places(); diff --git a/src/place/recognition/user_places/places_detector.h b/src/place/recognition/user_places/places_detector.h index 9adeb92..703f830 100644 --- a/src/place/recognition/user_places/places_detector.h +++ b/src/place/recognition/user_places/places_detector.h @@ -18,7 +18,7 @@ #define __CONTEXT_PLACE_STATUS_PLACES_DETECTOR__ #include "visit_detector.h" -#include "timer_listener_iface.h" +#include #include #include "db_listener_iface.h" #include "user_places_types.h" @@ -36,7 +36,7 @@ namespace ctx { PLACES_DETECTOR_QUERY_ID_GET_PLACES = 6 }; - class PlacesDetector : public timer_listener_iface, public db_listener_iface { + class PlacesDetector : public ITimerListener, public db_listener_iface { private: bool test_mode; @@ -65,7 +65,7 @@ namespace ctx { void process_visits(visits_t &visits); static void merge_location(const visits_t &merged_visits, Place &place); PlacesDetector(bool test_mode_ = false); - bool on_timer_expired(int timer_id, void* user_data); + bool onTimerExpired(int timerId); void on_creation_result_received(unsigned int query_id, int error) {} void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id) {} void on_query_result_received(unsigned int query_id, int error, std::vector& records); diff --git a/src/place/recognition/user_places/user_places.cpp b/src/place/recognition/user_places/user_places.cpp index bba0f1d..c0bb736 100644 --- a/src/place/recognition/user_places/user_places.cpp +++ b/src/place/recognition/user_places/user_places.cpp @@ -19,7 +19,6 @@ #include #include "user_places.h" #include "places_detector.h" -#include "timer_mgr.h" #include "../place_recognition_types.h" #include "db_mgr.h" @@ -41,10 +40,10 @@ ctx::UserPlaces::UserPlaces(place_recog_mode_e energy_mode) return; } - places_detector_timer_id = timer_manager::set_at( // execute once every night + places_detector_timer_id = __timerManager.setAt( // execute once every night PLACES_DETECTOR_TASK_START_HOUR, PLACES_DETECTOR_TASK_START_MINUTE, - timer_types::EVERYDAY, + DayOfWeek::EVERYDAY, places_detector); if (places_detector_timer_id < 0) { _E("PlacesDetector timer set FAIL"); @@ -57,7 +56,7 @@ ctx::UserPlaces::UserPlaces(place_recog_mode_e energy_mode) ctx::UserPlaces::~UserPlaces() { if (places_detector_timer_id >= 0) { - timer_manager::remove(places_detector_timer_id); + __timerManager.remove(places_detector_timer_id); _D("PlacesDetector timer removed"); } diff --git a/src/place/recognition/user_places/user_places.h b/src/place/recognition/user_places/user_places.h index d2c66da..b7084d8 100644 --- a/src/place/recognition/user_places/user_places.h +++ b/src/place/recognition/user_places/user_places.h @@ -17,11 +17,12 @@ #ifndef __CONTEXT_PLACE_STATUS_USER_PLACES_ENGINE_H__ #define __CONTEXT_PLACE_STATUS_USER_PLACES_ENGINE_H__ +#include +#include +#include #include "visit_detector.h" #include "places_detector.h" -#include #include "user_places_types.h" -#include namespace ctx { @@ -31,6 +32,7 @@ namespace ctx { VisitDetector *visit_detector; PlacesDetector *places_detector; int places_detector_timer_id; + TimerManager __timerManager; public: UserPlaces(place_recog_mode_e energy_mode = PLACE_RECOG_HIGH_ACCURACY_MODE); diff --git a/src/place/recognition/user_places/wifi_logger.cpp b/src/place/recognition/user_places/wifi_logger.cpp index 92bcdd4..5a6dfba 100644 --- a/src/place/recognition/user_places/wifi_logger.cpp +++ b/src/place/recognition/user_places/wifi_logger.cpp @@ -337,7 +337,7 @@ bool ctx::WifiLogger::check_timer_time(time_t now) return true; } -bool ctx::WifiLogger::on_timer_expired(int id, void* user_data) +bool ctx::WifiLogger::onTimerExpired(int id) { time_t now = time(nullptr); _D(""); @@ -414,7 +414,7 @@ void ctx::WifiLogger::_stop_logging() // Unset timer timer_on = false; // Remove timer - timer_manager::remove(timer_id); + __timerManager.remove(timer_id); } if (WIFI_LOGGER_PASSIVE_SCANNING) { wifi_unset_background_scan_cb(); @@ -425,7 +425,7 @@ void ctx::WifiLogger::_stop_logging() void ctx::WifiLogger::timer_start(time_t minutes) { timer_on = true; - timer_id = timer_manager::set_for(minutes, this, NULL); + timer_id = __timerManager.setFor(minutes, this); _D("%s (minutes=%d)", timer_id >= 0 ? "SUCCESS" : "ERROR", minutes); } @@ -458,7 +458,7 @@ void ctx::WifiLogger::set_interval(place_recog_mode_e energy_mode) void ctx::WifiLogger::timer_restart() { - timer_manager::remove(timer_id); + __timerManager.remove(timer_id); timer_start(interval_minutes); } diff --git a/src/place/recognition/user_places/wifi_logger.h b/src/place/recognition/user_places/wifi_logger.h index 4db601c..6b9ecb6 100644 --- a/src/place/recognition/user_places/wifi_logger.h +++ b/src/place/recognition/user_places/wifi_logger.h @@ -17,12 +17,11 @@ #ifndef __CONTEXT_PLACE_STATUS_WIFI_LOGGER_H__ #define __CONTEXT_PLACE_STATUS_WIFI_LOGGER_H__ -#include #include #include -#include "timer_mgr.h" #include #include +#include #include "wifi_listener_iface.h" #include "visit_listener_iface.h" #include "user_places_params.h" @@ -48,7 +47,7 @@ namespace ctx { - class WifiLogger : public timer_listener_iface, public IVisitListener { + class WifiLogger : public ITimerListener, public IVisitListener { public: WifiLogger(IWifiListener * listener_ = nullptr, @@ -78,6 +77,7 @@ namespace ctx { bool connected_to_wifi_ap; bool started; bool running; + TimerManager __timerManager; void _start_logging(); void _stop_logging(); @@ -85,7 +85,7 @@ namespace ctx { bool check_timer_id(int id); bool check_timer_time(time_t now); - bool on_timer_expired(int timer_id, void* user_data); + bool onTimerExpired(int timerId); static int create_table(); int db_insert_logs(); static void wifi_device_state_changed_cb(wifi_device_state_e state, void *user_data); diff --git a/src/statistics/social/log_aggregator.cpp b/src/statistics/social/log_aggregator.cpp index 309316f..fadd8cf 100644 --- a/src/statistics/social/log_aggregator.cpp +++ b/src/statistics/social/log_aggregator.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include "social_stats_types.h" #include "log_aggregator.h" @@ -27,12 +26,12 @@ ctx::contact_log_aggregator::contact_log_aggregator() , time_diff(0) { create_table(); - timer_id = timer_manager::set_at(3, 0, timer_types::EVERYDAY, this, NULL); + timer_id = __timerManager.setAt(3, 0, DayOfWeek::EVERYDAY, this); } ctx::contact_log_aggregator::~contact_log_aggregator() { - timer_manager::remove(timer_id); + __timerManager.remove(timer_id); } void ctx::contact_log_aggregator::create_table() @@ -46,7 +45,7 @@ void ctx::contact_log_aggregator::create_table() done = true; } -bool ctx::contact_log_aggregator::on_timer_expired(int timer, void* user_data) +bool ctx::contact_log_aggregator::onTimerExpired(int timer) { aggregate_contact_log(); return true; diff --git a/src/statistics/social/log_aggregator.h b/src/statistics/social/log_aggregator.h index e7aefb7..6f7583f 100644 --- a/src/statistics/social/log_aggregator.h +++ b/src/statistics/social/log_aggregator.h @@ -19,14 +19,15 @@ #include #include -#include +#include namespace ctx { - class contact_log_aggregator : public db_listener_iface, public timer_listener_iface { + class contact_log_aggregator : public db_listener_iface, public ITimerListener { private: int timer_id; int time_diff; + TimerManager __timerManager; void create_table(); void get_updated_contact_log_list(int last_time, contacts_list_h *list); void insert_contact_log_list(contacts_list_h list); @@ -42,7 +43,7 @@ namespace ctx { void on_creation_result_received(unsigned int query_id, int error) {} void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id) {} void on_query_result_received(unsigned int query_id, int error, std::vector& records); - bool on_timer_expired(int timer_id, void* user_data); + bool onTimerExpired(int timer_id); }; /* class phone_contact_log_aggregator */ -- 2.7.4 From 1bb76f75ee204c199e82ebfa0fa61e729ae6f8c7 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Mon, 14 Mar 2016 10:46:10 +0900 Subject: [PATCH 02/16] Version 0.7.3 Change-Id: I85b5aa8f68cfb86d7f2ae0dfa61f8736f1b5edc5 Signed-off-by: Somin Kim --- packaging/context-provider.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/context-provider.spec b/packaging/context-provider.spec index 2f9c5af..2e968d3 100644 --- a/packaging/context-provider.spec +++ b/packaging/context-provider.spec @@ -1,6 +1,6 @@ Name: context-provider Summary: Context Provider -Version: 0.7.2 +Version: 0.7.3 Release: 1 Group: Service/Context License: Apache-2.0 -- 2.7.4 From 5a2f730531ee82858b4e35099e94098f41038587 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Mon, 14 Mar 2016 14:27:40 +0900 Subject: [PATCH 03/16] Contacts db changed provider added Change-Id: Ie09bf1ed628486dd763e6b69aa80c46d1512cf49 Signed-off-by: Somin Kim --- src/device/device_context_provider.cpp | 3 + src/device/social/contacts.cpp | 134 +++++++++++++++++++++++++++++++++ src/device/social/contacts.h | 50 ++++++++++++ src/device/social/social_types.h | 4 + 4 files changed, 191 insertions(+) create mode 100644 src/device/social/contacts.cpp create mode 100644 src/device/social/contacts.h diff --git a/src/device/device_context_provider.cpp b/src/device/device_context_provider.cpp index 98e734c..be6d911 100644 --- a/src/device/device_context_provider.cpp +++ b/src/device/device_context_provider.cpp @@ -37,6 +37,7 @@ #include "social/call.h" #include "social/email.h" #include "social/message.h" +#include "social/contacts.h" #include "activity/activity.h" #endif @@ -61,6 +62,7 @@ #define PRIV_NETWORK "network.get" #define PRIV_TELEPHONY "telephony" #define PRIV_MESSAGE "message.read" +#define PRIV_CONTACT "contact.read" template void register_provider(const char *subject, const char *privilege) @@ -91,6 +93,7 @@ EXTAPI bool ctx::init_device_context_provider() register_provider(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY); register_provider(SOCIAL_ST_SUBJ_EMAIL, NULL); register_provider(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE); + register_provider(SOCIAL_ST_SUBJ_CONTACTS, PRIV_CONTACT); register_provider(USER_ACT_SUBJ_STATIONARY, NULL); register_provider(USER_ACT_SUBJ_WALKING, NULL); diff --git a/src/device/social/contacts.cpp b/src/device/social/contacts.cpp new file mode 100644 index 0000000..4e11e5a --- /dev/null +++ b/src/device/social/contacts.cpp @@ -0,0 +1,134 @@ +/* + * 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 +#include +#include "social_types.h" +#include "contacts.h" + +#define MY_PROFILE_VIEW _contacts_my_profile._uri +#define PERSON_VIEW _contacts_person._uri +#define TIME_INTERVAL 1 + +GENERATE_PROVIDER_COMMON_IMPL(social_status_contacts); + +ctx::social_status_contacts::social_status_contacts() + : latest_my_profile(0) + , latest_person(0) +{ +} + +ctx::social_status_contacts::~social_status_contacts() +{ +} + +bool ctx::social_status_contacts::is_supported() +{ + return true; +} + +void ctx::social_status_contacts::submit_trigger_item() +{ + context_manager::register_trigger_item(SOCIAL_ST_SUBJ_CONTACTS, OPS_SUBSCRIBE, + "{" + "\"View\":{\"type\":\"string\",\"values\":[\"MyProfile\",\"Person\"]}" + "}", + NULL); +} + +void ctx::social_status_contacts::db_change_cb(const char* view_uri, void* user_data) +{ + social_status_contacts *instance = static_cast(user_data); + instance->handle_db_change(view_uri); +} + +void ctx::social_status_contacts::handle_db_change(const char* view_uri) +{ + if (!STR_EQ(view_uri, _contacts_my_profile._uri) && !STR_EQ(view_uri, _contacts_person._uri)) { + _W("Unknown view uri"); + return; + } + + std::string view = (STR_EQ(view_uri, _contacts_my_profile._uri)? SOCIAL_ST_MY_PROFILE : SOCIAL_ST_PERSON); + IF_FAIL_VOID_TAG(!is_consecutive_change(view_uri), _D, "Ignore consecutive db change: %s", view.c_str()); + + ctx::Json data; + data.set(NULL, SOCIAL_ST_VIEW, view); + context_manager::publish(SOCIAL_ST_SUBJ_CONTACTS, NULL, ERR_NONE, data); +} + +bool ctx::social_status_contacts::is_consecutive_change(const char* view_uri) +{ + time_t now = time(NULL); + double diff = 0; + + if (STR_EQ(view_uri, MY_PROFILE_VIEW)) { + diff = difftime(now, latest_my_profile); + latest_my_profile = now; + } else if (STR_EQ(view_uri, PERSON_VIEW)) { + diff = difftime(now, latest_person); + latest_person = now; + } + + if (diff < TIME_INTERVAL) + return true; + + return false; +} + +bool ctx::social_status_contacts::set_callback() +{ + int err; + + err = contacts_connect(); + IF_FAIL_RETURN_TAG(err == CONTACTS_ERROR_NONE, false, _E, "Connecting contacts failed"); + + err = contacts_db_add_changed_cb(MY_PROFILE_VIEW, db_change_cb, this); + IF_FAIL_CATCH_TAG(err == CONTACTS_ERROR_NONE, _E, "Setting my profile view changed callback failed"); + + err = contacts_db_add_changed_cb(PERSON_VIEW, db_change_cb, this); + IF_FAIL_CATCH_TAG(err == CONTACTS_ERROR_NONE, _E, "Setting person view changed callback failed"); + + return true; + +CATCH: + contacts_disconnect(); + return false; +} + +void ctx::social_status_contacts::unset_callback() +{ + contacts_db_remove_changed_cb(MY_PROFILE_VIEW, db_change_cb, this); + contacts_db_remove_changed_cb(PERSON_VIEW, db_change_cb, this); + + contacts_disconnect(); + + latest_my_profile = 0; + latest_person = 0; +} + +int ctx::social_status_contacts::subscribe() +{ + bool ret = set_callback(); + IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED); + return ERR_NONE; +} + +int ctx::social_status_contacts::unsubscribe() +{ + unset_callback(); + return ERR_NONE; +} diff --git a/src/device/social/contacts.h b/src/device/social/contacts.h new file mode 100644 index 0000000..52adb14 --- /dev/null +++ b/src/device/social/contacts.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CONTEXT_SOCIAL_STATUS_CONTACTS_H_ +#define _CONTEXT_SOCIAL_STATUS_CONTACTS_H_ + +#include +#include "../provider_base.h" + +namespace ctx { + + class social_status_contacts : public device_provider_base { + + GENERATE_PROVIDER_COMMON_DECL(social_status_contacts); + + public: + int subscribe(); + int unsubscribe(); + static bool is_supported(); + static void submit_trigger_item(); + + private: + time_t latest_my_profile; + time_t latest_person; + + social_status_contacts(); + ~social_status_contacts(); + + bool set_callback(); + void unset_callback(); + void handle_db_change(const char* view_uri); + static void db_change_cb(const char* view_uri, void* user_data); + bool is_consecutive_change(const char* view_uri); + }; +} + +#endif // _CONTEXT_SOCIAL_STATUS_CONTACTS_H_ diff --git a/src/device/social/social_types.h b/src/device/social/social_types.h index 55c015f..47c5121 100644 --- a/src/device/social/social_types.h +++ b/src/device/social/social_types.h @@ -21,6 +21,7 @@ #define SOCIAL_ST_SUBJ_CALL "social/call" #define SOCIAL_ST_SUBJ_EMAIL "social/email" #define SOCIAL_ST_SUBJ_MESSAGE "social/message" +#define SOCIAL_ST_SUBJ_CONTACTS "social/contacts" // Data Key #define SOCIAL_ST_STATE "State" @@ -28,6 +29,7 @@ #define SOCIAL_ST_TYPE "Type" #define SOCIAL_ST_MEDIUM "Medium" #define SOCIAL_ST_ADDRESS "Address" +#define SOCIAL_ST_VIEW "View" // Data Values #define SOCIAL_ST_IDLE "Idle" @@ -44,5 +46,7 @@ #define SOCIAL_ST_RECEIVED "Received" #define SOCIAL_ST_SMS "SMS" #define SOCIAL_ST_MMS "MMS" +#define SOCIAL_ST_MY_PROFILE "MyProfile" +#define SOCIAL_ST_PERSON "Person" #endif -- 2.7.4 From 384b5eeda1af9ffe6294c880f3f095a0d05a5027 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 15 Mar 2016 12:14:48 +0900 Subject: [PATCH 04/16] Version 0.7.4 Change-Id: I0fc1b01f9d55e209b952a7e7823017d675a21b2f Signed-off-by: Mu-Woong Lee --- packaging/context-provider.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/context-provider.spec b/packaging/context-provider.spec index 2e968d3..cb86c92 100644 --- a/packaging/context-provider.spec +++ b/packaging/context-provider.spec @@ -1,6 +1,6 @@ Name: context-provider Summary: Context Provider -Version: 0.7.3 +Version: 0.7.4 Release: 1 Group: Service/Context License: Apache-2.0 -- 2.7.4 From 655a33bc4bcbe2c54e4b06b2f5563cc625de7ed7 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Tue, 15 Mar 2016 15:23:19 +0900 Subject: [PATCH 05/16] Changed attribute key & value for EVENT_CONTACTS Change-Id: I6de90e5bb5664ccc7948ccad22dbeb799515edb4 Signed-off-by: Somin Kim --- src/device/social/contacts.cpp | 6 ++++-- src/device/social/social_types.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/device/social/contacts.cpp b/src/device/social/contacts.cpp index 4e11e5a..c7ee6e3 100644 --- a/src/device/social/contacts.cpp +++ b/src/device/social/contacts.cpp @@ -44,7 +44,8 @@ void ctx::social_status_contacts::submit_trigger_item() { context_manager::register_trigger_item(SOCIAL_ST_SUBJ_CONTACTS, OPS_SUBSCRIBE, "{" - "\"View\":{\"type\":\"string\",\"values\":[\"MyProfile\",\"Person\"]}" + "\"Event\":{\"type\":\"string\",\"values\":[\"Changed\"]}," + "\"Type\":{\"type\":\"string\",\"values\":[\"MyProfile\",\"Person\"]}" "}", NULL); } @@ -66,7 +67,8 @@ void ctx::social_status_contacts::handle_db_change(const char* view_uri) IF_FAIL_VOID_TAG(!is_consecutive_change(view_uri), _D, "Ignore consecutive db change: %s", view.c_str()); ctx::Json data; - data.set(NULL, SOCIAL_ST_VIEW, view); + 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); } diff --git a/src/device/social/social_types.h b/src/device/social/social_types.h index 47c5121..1af5fb7 100644 --- a/src/device/social/social_types.h +++ b/src/device/social/social_types.h @@ -29,7 +29,6 @@ #define SOCIAL_ST_TYPE "Type" #define SOCIAL_ST_MEDIUM "Medium" #define SOCIAL_ST_ADDRESS "Address" -#define SOCIAL_ST_VIEW "View" // Data Values #define SOCIAL_ST_IDLE "Idle" @@ -48,5 +47,6 @@ #define SOCIAL_ST_MMS "MMS" #define SOCIAL_ST_MY_PROFILE "MyProfile" #define SOCIAL_ST_PERSON "Person" +#define SOCIAL_ST_CHANGED "Changed" #endif -- 2.7.4 From 93ad2b1a71b67bebab8f7870642929248d2ed314 Mon Sep 17 00:00:00 2001 From: Marcin Masternak Date: Thu, 31 Mar 2016 12:57:42 +0200 Subject: [PATCH 06/16] [place-recognition] Redundant mutex protection remove. Change-Id: I437ead59b6c9dbf6577650d25dc1493c82c2abae Signed-off-by: Marcin Masternak --- src/place/recognition/user_places/places_detector.cpp | 13 ++++--------- src/place/recognition/user_places/places_detector.h | 2 -- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/place/recognition/user_places/places_detector.cpp b/src/place/recognition/user_places/places_detector.cpp index 4890db1..a3ea9a5 100644 --- a/src/place/recognition/user_places/places_detector.cpp +++ b/src/place/recognition/user_places/places_detector.cpp @@ -301,15 +301,13 @@ void ctx::PlacesDetector::process_visits(ctx::visits_t &visits) } /* - * Pseudo-atomic operation of old places replacement by new ones. + * Replace old places by new ones. */ void ctx::PlacesDetector::detected_places_update(std::vector> &new_places) { _D(""); - detected_places_access_mutex.lock(); + // XXX: In case of thread safety issues use std::mutex to protect places list. detected_places = new_places; - new_places.clear(); - detected_places_access_mutex.unlock(); } void ctx::PlacesDetector::merge_location(const visits_t &visits, Place &place) @@ -450,9 +448,6 @@ void ctx::PlacesDetector::db_insert_place(const Place &place) std::vector> ctx::PlacesDetector::get_places() { - detected_places_access_mutex.lock(); - // indirect ret vector usage due to limit the scope of a mutex to only this single file / class - std::vector> ret = detected_places; - detected_places_access_mutex.unlock(); - return ret; + // XXX: In case of thread safety issues use std::mutex to protect places list. + return detected_places; } diff --git a/src/place/recognition/user_places/places_detector.h b/src/place/recognition/user_places/places_detector.h index 703f830..fb08ee4 100644 --- a/src/place/recognition/user_places/places_detector.h +++ b/src/place/recognition/user_places/places_detector.h @@ -23,7 +23,6 @@ #include "db_listener_iface.h" #include "user_places_types.h" #include -#include namespace ctx { @@ -56,7 +55,6 @@ namespace ctx { void db_insert_place(const Place &place); std::shared_ptr place_from_merged(visits_t &merged_visits); std::vector> detected_places; - std::mutex detected_places_access_mutex; void detected_places_update(std::vector> &new_places); public: -- 2.7.4 From f12d988670c3f8498e54eba260f6b41a950aa56e Mon Sep 17 00:00:00 2001 From: Marcin Masternak Date: Thu, 31 Mar 2016 14:18:44 +0200 Subject: [PATCH 07/16] [place-recognition] Small SVACE defects fix. Change-Id: I64f9551a55bf97c0dd16792b999e659871e5b02b Signed-off-by: Marcin Masternak --- src/place/recognition/place_recognition.cpp | 2 +- src/place/recognition/user_places/location_logger.cpp | 2 ++ src/place/recognition/user_places/piecewise_lin.cpp | 1 + src/place/recognition/user_places/wifi_logger.cpp | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/place/recognition/place_recognition.cpp b/src/place/recognition/place_recognition.cpp index 7fb092f..9cdd6f6 100644 --- a/src/place/recognition/place_recognition.cpp +++ b/src/place/recognition/place_recognition.cpp @@ -54,7 +54,7 @@ int ctx::place_recognition_provider::read(const char *subject, ctx::Json option, _J("Option", option); std::vector> places = engine.get_places(); - Json data_read = engine.compose_json(places); + Json data_read = UserPlaces::compose_json(places); // The below function needs to be called once. // It does not need to be called within this read() function. diff --git a/src/place/recognition/user_places/location_logger.cpp b/src/place/recognition/user_places/location_logger.cpp index 6bee94b..3a4fb93 100644 --- a/src/place/recognition/user_places/location_logger.cpp +++ b/src/place/recognition/user_places/location_logger.cpp @@ -207,6 +207,8 @@ ctx::LocationLogger::LocationLogger(ILocationListener *listener_, bool test_mode , location_count(0) , active_request_succeeded(false) , active_location_succeeded(false) + , timer_id(-1) + , timer_timestamp(0) , timer_purpose(LOCATION_LOGGER_WAITING_FOR_PASSIVE_INTERVAL) , location_service_state(LOCATIONS_SERVICE_DISABLED) , location_method(LOCATION_LOGGER_METHOD) diff --git a/src/place/recognition/user_places/piecewise_lin.cpp b/src/place/recognition/user_places/piecewise_lin.cpp index f22d37c..e1cbd46 100644 --- a/src/place/recognition/user_places/piecewise_lin.cpp +++ b/src/place/recognition/user_places/piecewise_lin.cpp @@ -18,6 +18,7 @@ #include ctx::PiecewiseLin::PiecewiseLin(std::vector _xs, std::vector _vs) + : n(0) { if (_xs.size() != _vs.size()) { _E("Input arguments have different sizes"); diff --git a/src/place/recognition/user_places/wifi_logger.cpp b/src/place/recognition/user_places/wifi_logger.cpp index 5a6dfba..7d0c89d 100644 --- a/src/place/recognition/user_places/wifi_logger.cpp +++ b/src/place/recognition/user_places/wifi_logger.cpp @@ -72,6 +72,7 @@ ctx::WifiLogger::WifiLogger(IWifiListener * listener_, place_recog_mode_e energy , timer_on(false) , interval_minutes(WIFI_LOGGER_INTERVAL_MINUTES_HIGH_ACCURACY) , during_visit(false) + , connected_to_wifi_ap(false) , started(false) , running(false) { -- 2.7.4 From 1d2138758fbe5daac5f2a7462fccdc2e902d7382 Mon Sep 17 00:00:00 2001 From: Marcin Masternak Date: Fri, 1 Apr 2016 13:59:34 +0200 Subject: [PATCH 08/16] [place-recognition] SVACE buffer overflow warning fix. Change-Id: I7fca0ab40c652c78968880883c05209b4a48b81a Signed-off-by: Marcin Masternak --- .../recognition/user_places/user_places_types.cpp | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/place/recognition/user_places/user_places_types.cpp b/src/place/recognition/user_places/user_places_types.cpp index 3d72852..81e253c 100644 --- a/src/place/recognition/user_places/user_places_types.cpp +++ b/src/place/recognition/user_places/user_places_types.cpp @@ -24,36 +24,43 @@ #include "user_places_params.h" #include "debug_utils.h" +#define MAC_STRING_COMPONENTS_SEPARATOR ':' #define MAC_SET_STRING_DELIMITER ',' ctx::Mac::Mac(const std::string& str) { std::stringstream ss(str); - ss >> *this; + try { + ss >> *this; + } catch (std::runtime_error &e) { + _E("%s", e.what()); + } } ctx::Mac::Mac(const char *str) { std::stringstream ss(str); - ss >> *this; + try { + ss >> *this; + } catch (std::runtime_error &e) { + _E("%s", e.what()); + } } std::istream& ctx::operator>>(std::istream &input, ctx::Mac &mac) { int h; char colon; - size_t i = 0; - while (true) { + for (size_t i = 0; i < ctx::Mac::MAC_SIZE; i++) { input >> std::hex; input >> h; mac.c[i] = h; - i++; - if (i >= ctx::Mac::MAC_SIZE) { + if (i + 1 >= ctx::Mac::MAC_SIZE) { break; } input >> colon; - if (colon != ':') { - throw std::runtime_error("Invalid mac format"); + if (colon != MAC_STRING_COMPONENTS_SEPARATOR) { + throw std::runtime_error("Invalid MAC format"); } } input >> std::dec; @@ -70,7 +77,7 @@ std::ostream& ctx::operator<<(std::ostream &output, const ctx::Mac &mac) if (i >= Mac::MAC_SIZE) { break; } - output << ":"; + output << MAC_STRING_COMPONENTS_SEPARATOR; } output << std::dec; return output; @@ -119,7 +126,12 @@ std::istream& ctx::operator>>(std::istream &input, ctx::mac_set_t &mac_set) Mac mac; char delimeter; while (!input.eof()) { - input >> mac; + try { + input >> mac; + } catch (std::runtime_error &e) { + _E("Cannot read mac_set. Exception: %s", e.what()); + break; + } mac_set.insert(mac); if (input.eof()) { break; -- 2.7.4 From 89330c31f4651690955890e3a0e902a1bb4949cf Mon Sep 17 00:00:00 2001 From: Marcin Masternak Date: Fri, 1 Apr 2016 18:46:29 +0200 Subject: [PATCH 09/16] [place-recognition] Change database asynchronous queries to synchronous. Change-Id: Ibde511e03c713008ca731acd65da27ec6dfb5b28 Signed-off-by: Marcin Masternak --- .../recognition/user_places/location_logger.cpp | 3 +- .../recognition/user_places/places_detector.cpp | 65 ++++++++-------------- .../recognition/user_places/places_detector.h | 18 +----- .../recognition/user_places/visit_detector.cpp | 3 +- 4 files changed, 29 insertions(+), 60 deletions(-) diff --git a/src/place/recognition/user_places/location_logger.cpp b/src/place/recognition/user_places/location_logger.cpp index 3a4fb93..3bcd109 100644 --- a/src/place/recognition/user_places/location_logger.cpp +++ b/src/place/recognition/user_places/location_logger.cpp @@ -193,7 +193,8 @@ int ctx::LocationLogger::db_insert_log(location_event_s location_event) data.set(NULL, LOCATION_COLUMN_METHOD, static_cast(location_event.method)); #endif /* TIZEN_ENGINEER_MODE */ - bool ret = ctx::db_manager::insert(0, LOCATION_TABLE_NAME, data); + int64_t row_id; + bool ret = db_manager::insert_sync(LOCATION_TABLE_NAME, data, &row_id); _D("%s -> DB: location table insert result", ret ? "SUCCESS" : "FAIL"); return ret; } diff --git a/src/place/recognition/user_places/places_detector.cpp b/src/place/recognition/user_places/places_detector.cpp index a3ea9a5..98cb399 100644 --- a/src/place/recognition/user_places/places_detector.cpp +++ b/src/place/recognition/user_places/places_detector.cpp @@ -74,53 +74,27 @@ bool ctx::PlacesDetector::onTimerExpired(int timerId) { _D(""); db_delete_places(); + db_delete_old_visits(); + std::vector records = db_get_visits(); + visits_t visits = visits_from_jsons(records); + process_visits(visits); return true; } -void ctx::PlacesDetector::on_query_result_received(unsigned int query_id, int error, std::vector& records) +std::vector ctx::PlacesDetector::db_get_visits() { - // TODO: - // The below "state machine" approach was choosen because it is not possible to use synchronized database queries in the main thread. - // Probably the more elegant approach would be to use event_driven_thread class where synchronized queries are allowed. - // Consider refactoring. - if (error != ERR_NONE) { - _E("on_query_result_received query_id:%d, error:%d", query_id, error); - } - else if (query_id == PLACES_DETECTOR_QUERY_ID_DELETE_PLACES) { - db_delete_old_visits(); - } - else if (query_id == PLACES_DETECTOR_QUERY_ID_DELETE_OLD_VISITS) { - db_get_visits(); - } - else if (query_id == PLACES_DETECTOR_QUERY_ID_GET_VISITS) { - visits_t visits = visits_from_jsons(records); - process_visits(visits); - } - else if (query_id == PLACES_DETECTOR_QUERY_ID_INSERT_VISIT) { - // Don't do anything. It is fine. - } - else if (query_id == PLACES_DETECTOR_QUERY_ID_INSERT_PLACE) { - // Don't do anything. It is fine. - } - else if (query_id == PLACES_DETECTOR_QUERY_ID_GET_PLACES) { - std::vector> db_places = places_from_jsons(records); - detected_places_update(db_places); - } - else { - _E("on_query_result_received unknown query_id:%d", query_id); - } -} - -void ctx::PlacesDetector::db_get_visits() -{ - bool ret = db_manager::execute(PLACES_DETECTOR_QUERY_ID_GET_VISITS, GET_VISITS_QUERY, this); + std::vector records; + bool ret = db_manager::execute_sync(GET_VISITS_QUERY, &records); _D("load visits execute query result: %s", ret ? "SUCCESS" : "FAIL"); + return records; } -void ctx::PlacesDetector::db_get_places() +std::vector ctx::PlacesDetector::db_get_places() { - bool ret = db_manager::execute(PLACES_DETECTOR_QUERY_ID_GET_PLACES, GET_PLACES_QUERY, this); + std::vector records; + bool ret = db_manager::execute_sync(GET_PLACES_QUERY, &records); _D("load places execute query result: %s", ret ? "SUCCESS" : "FAIL"); + return records; } double ctx::PlacesDetector::double_value_from_json(Json &row, const char* key) @@ -389,7 +363,8 @@ std::shared_ptr ctx::PlacesDetector::graph_from_visits(const std:: void ctx::PlacesDetector::db_delete_places() { - bool ret = db_manager::execute(PLACES_DETECTOR_QUERY_ID_DELETE_PLACES, DELETE_PLACES_QUERY, this); + std::vector records; + bool ret = db_manager::execute_sync(DELETE_PLACES_QUERY, &records); _D("delete places execute query result: %s", ret ? "SUCCESS" : "FAIL"); } @@ -407,8 +382,9 @@ void ctx::PlacesDetector::db_delete_older_visits(time_t threshold) std::stringstream query; query << "DELETE FROM " << VISIT_TABLE; query << " WHERE " << VISIT_COLUMN_END_TIME << " < " << threshold; - // query << " AND 0"; // Always false condition. Uncomment it for not deleting any visit during development. - bool ret = db_manager::execute(PLACES_DETECTOR_QUERY_ID_DELETE_OLD_VISITS, query.str().c_str(), this); + // query << " AND 0"; // XXX: Always false condition. Uncomment it for not deleting any visit during development. + std::vector records; + bool ret = db_manager::execute_sync(query.str().c_str(), &records); _D("delete old visits execute query result: %s", ret ? "SUCCESS" : "FAIL"); } @@ -419,7 +395,9 @@ ctx::PlacesDetector::PlacesDetector(bool test_mode_) return; } db_create_table(); - db_get_places(); + std::vector records = db_get_places(); + std::vector> db_places = places_from_jsons(records); + detected_places_update(db_places); } void ctx::PlacesDetector::db_create_table() @@ -442,7 +420,8 @@ void ctx::PlacesDetector::db_insert_place(const Place &place) data.set(NULL, PLACE_COLUMN_WIFI_APS, place.wifi_aps); data.set(NULL, PLACE_COLUMN_CREATE_DATE, static_cast(place.create_date)); - bool ret = db_manager::insert(PLACES_DETECTOR_QUERY_ID_INSERT_PLACE, PLACE_TABLE, data); + int64_t row_id; + bool ret = db_manager::insert_sync(PLACE_TABLE, data, &row_id); _D("insert place execute query result: %s", ret ? "SUCCESS" : "FAIL"); } diff --git a/src/place/recognition/user_places/places_detector.h b/src/place/recognition/user_places/places_detector.h index fb08ee4..e0461d9 100644 --- a/src/place/recognition/user_places/places_detector.h +++ b/src/place/recognition/user_places/places_detector.h @@ -26,16 +26,7 @@ namespace ctx { - enum { - PLACES_DETECTOR_QUERY_ID_DELETE_PLACES = 1, - PLACES_DETECTOR_QUERY_ID_DELETE_OLD_VISITS = 2, - PLACES_DETECTOR_QUERY_ID_GET_VISITS = 3, - PLACES_DETECTOR_QUERY_ID_INSERT_VISIT = 4, - PLACES_DETECTOR_QUERY_ID_INSERT_PLACE = 5, - PLACES_DETECTOR_QUERY_ID_GET_PLACES = 6 - }; - - class PlacesDetector : public ITimerListener, public db_listener_iface { + class PlacesDetector : public ITimerListener { private: bool test_mode; @@ -50,8 +41,8 @@ namespace ctx { void db_delete_places(); void db_delete_old_visits(); void db_delete_older_visits(time_t threshold); - void db_get_visits(); - void db_get_places(); + std::vector db_get_visits(); + std::vector db_get_places(); void db_insert_place(const Place &place); std::shared_ptr place_from_merged(visits_t &merged_visits); std::vector> detected_places; @@ -64,9 +55,6 @@ namespace ctx { static void merge_location(const visits_t &merged_visits, Place &place); PlacesDetector(bool test_mode_ = false); bool onTimerExpired(int timerId); - void on_creation_result_received(unsigned int query_id, int error) {} - void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id) {} - void on_query_result_received(unsigned int query_id, int error, std::vector& records); std::shared_ptr merge_visits(const std::vector &visits); std::vector> get_places(); diff --git a/src/place/recognition/user_places/visit_detector.cpp b/src/place/recognition/user_places/visit_detector.cpp index 84abb5e..26c3bb5 100644 --- a/src/place/recognition/user_places/visit_detector.cpp +++ b/src/place/recognition/user_places/visit_detector.cpp @@ -420,7 +420,8 @@ int ctx::VisitDetector::db_insert_visit(visit_s visit) _D("db: visit table insert interval: (%d, %d)", visit.interval.start, visit.interval.end); #endif /* TIZEN_ENGINEER_MODE */ - bool ret = db_manager::insert(0, VISIT_TABLE, data); + int64_t row_id; + bool ret = db_manager::insert_sync(VISIT_TABLE, data, &row_id); _D("db: visit table insert result: %s", ret ? "SUCCESS" : "FAIL"); return ret; } -- 2.7.4 From bb52ea000bf973bd227090af3f7f216d0bd4883a Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Mon, 4 Apr 2016 13:21:59 +0900 Subject: [PATCH 10/16] Apply Tizen C++ coding style based on context-common changes - ContextManager, IContextManager, ContextProviderBase(context_provider_iface) Change-Id: Icfbdfaaf570a98aba2115cb3c169722a3f01b7ab Signed-off-by: Somin Kim --- include/custom_context_provider.h | 8 +-- src/custom/custom_base.cpp | 14 ++-- src/custom/custom_base.h | 10 +-- src/custom/custom_context_provider.cpp | 30 ++++----- src/device/activity/activity.h | 4 +- src/device/activity/activity_base.cpp | 14 ++-- src/device/activity/activity_base.h | 2 +- src/device/device_context_provider.cpp | 74 +++++++++++----------- ...{provider_base.cpp => device_provider_base.cpp} | 8 +-- .../{provider_base.h => device_provider_base.h} | 14 ++-- src/device/social/call.cpp | 6 +- src/device/social/call.h | 2 +- src/device/social/contacts.cpp | 4 +- src/device/social/contacts.h | 2 +- src/device/social/email.cpp | 16 ++--- src/device/social/email.h | 2 +- src/device/social/message.cpp | 4 +- src/device/social/message.h | 2 +- src/device/system/alarm.cpp | 18 +++--- src/device/system/alarm.h | 12 ++-- src/device/system/battery.cpp | 20 +++--- src/device/system/battery.h | 2 +- src/device/system/headphone.cpp | 6 +- src/device/system/headphone.h | 2 +- src/device/system/psmode.cpp | 16 ++--- src/device/system/psmode.h | 2 +- src/device/system/runtime-info/base_rtinfo.h | 2 +- src/device/system/runtime-info/charger.cpp | 16 ++--- src/device/system/runtime-info/gps.cpp | 16 ++--- src/device/system/runtime-info/usb.cpp | 16 ++--- src/device/system/time.cpp | 14 ++-- src/device/system/time.h | 2 +- src/device/system/wifi.cpp | 12 ++-- src/device/system/wifi.h | 2 +- src/place/geofence/myplace_handle.cpp | 2 +- src/place/geofence/place_geofence.cpp | 12 ++-- src/place/geofence/place_geofence.h | 12 ++-- src/place/place_context_provider.cpp | 14 ++-- src/place/recognition/place_recognition.cpp | 14 ++-- src/place/recognition/place_recognition.h | 12 ++-- src/statistics/app/app_stats_provider.cpp | 12 ++-- src/statistics/app/app_stats_provider.h | 12 ++-- src/statistics/app/db_handle.cpp | 4 +- src/statistics/media/db_handle.cpp | 4 +- src/statistics/media/media_stats_provider.cpp | 14 ++-- src/statistics/media/media_stats_provider.h | 12 ++-- src/statistics/shared/db_handle_base.cpp | 6 +- src/statistics/social/db_handle.cpp | 4 +- src/statistics/social/social_stats_provider.cpp | 12 ++-- src/statistics/social/social_stats_provider.h | 12 ++-- src/statistics/statistics_context_provider.cpp | 50 +++++++-------- 51 files changed, 291 insertions(+), 291 deletions(-) rename src/device/{provider_base.cpp => device_provider_base.cpp} (93%) rename src/device/{provider_base.h => device_provider_base.h} (89%) diff --git a/include/custom_context_provider.h b/include/custom_context_provider.h index 17c8cc4..918dfa6 100644 --- a/include/custom_context_provider.h +++ b/include/custom_context_provider.h @@ -21,11 +21,11 @@ namespace ctx { bool init_custom_context_provider(); namespace custom_context_provider { - int add_item(std::string subject, std::string name, ctx::Json tmpl, const char* owner, bool is_init = false); - int remove_item(std::string subject); - int publish_data(std::string subject, ctx::Json fact); + int addItem(std::string subject, std::string name, ctx::Json tmpl, const char* owner, bool is_init = false); + int removeItem(std::string subject); + int publishData(std::string subject, ctx::Json fact); - context_provider_iface* create(void* data); + ContextProviderBase* create(void* data); void destroy(void* data); } } diff --git a/src/custom/custom_base.cpp b/src/custom/custom_base.cpp index c5ac58d..4371202 100644 --- a/src/custom/custom_base.cpp +++ b/src/custom/custom_base.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "custom_base.h" ctx::custom_base::custom_base(std::string subject, std::string name, ctx::Json tmpl, std::string owner) : @@ -36,16 +36,16 @@ bool ctx::custom_base::is_supported() void ctx::custom_base::submit_trigger_item() { - context_manager::register_trigger_item(_subject.c_str(), OPS_SUBSCRIBE | OPS_READ, + context_manager::registerTriggerItem(_subject.c_str(), OPS_SUBSCRIBE | OPS_READ, _tmpl.str(), NULL, _owner.c_str()); } void ctx::custom_base::unsubmit_trigger_item() { - context_manager::unregister_trigger_item(_subject.c_str()); + context_manager::unregisterTriggerItem(_subject.c_str()); } -int ctx::custom_base::subscribe(const char *subject, ctx::Json option, ctx::Json *request_result) +int ctx::custom_base::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) { return ERR_NONE; @@ -56,14 +56,14 @@ int ctx::custom_base::unsubscribe(const char *subject, ctx::Json option) return ERR_NONE; } -int ctx::custom_base::read(const char *subject, ctx::Json option, ctx::Json *request_result) +int ctx::custom_base::read(const char *subject, ctx::Json option, ctx::Json *requestResult) { ctx::Json data = latest.str(); - ctx::context_manager::reply_to_read(_subject.c_str(), NULL, ERR_NONE, data); + ctx::context_manager::replyToRead(_subject.c_str(), NULL, ERR_NONE, data); return ERR_NONE; } -int ctx::custom_base::write(const char *subject, ctx::Json data, ctx::Json *request_result) +int ctx::custom_base::write(const char *subject, ctx::Json data, ctx::Json *requestResult) { return ERR_NONE; } diff --git a/src/custom/custom_base.h b/src/custom/custom_base.h index 0278e0f..68e45cc 100644 --- a/src/custom/custom_base.h +++ b/src/custom/custom_base.h @@ -18,20 +18,20 @@ #define _CUSTOM_BASE_H_ #include -#include +#include #include namespace ctx { - class custom_base : public context_provider_iface { + class custom_base : public ContextProviderBase { public: custom_base(std::string subject, std::string name, ctx::Json tmpl, std::string owner); ~custom_base(); - int subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + 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 *request_result); - int write(const char *subject, ctx::Json data, ctx::Json *request_result); + int read(const char *subject, ctx::Json option, ctx::Json *requestResult); + int write(const char *subject, ctx::Json data, ctx::Json *requestResult); static bool is_supported(); void submit_trigger_item(); diff --git a/src/custom/custom_context_provider.cpp b/src/custom/custom_context_provider.cpp index 29c9100..88aca00 100644 --- a/src/custom/custom_context_provider.cpp +++ b/src/custom/custom_context_provider.cpp @@ -17,8 +17,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include "custom_base.h" @@ -29,24 +29,24 @@ static bool is_valid_fact(std::string subject, ctx::Json& fact); static bool check_value_int(ctx::Json& tmpl, std::string key, int value); static bool check_value_string(ctx::Json& tmpl, std::string key, std::string value); -void register_provider(const char *subject, const char *privilege) +void registerProvider(const char *subject, const char *privilege) { - ctx::context_provider_info provider_info(ctx::custom_context_provider::create, + ctx::ContextProviderInfo providerInfo(ctx::custom_context_provider::create, ctx::custom_context_provider::destroy, const_cast(subject), privilege); - ctx::context_manager::register_provider(subject, provider_info); + ctx::context_manager::registerProvider(subject, providerInfo); custom_map[subject]->submit_trigger_item(); } -void unregister_provider(const char* subject) +void unregisterProvider(const char* subject) { custom_map[subject]->unsubmit_trigger_item(); - ctx::context_manager::unregister_provider(subject); + ctx::context_manager::unregisterProvider(subject); } -EXTAPI ctx::context_provider_iface* ctx::custom_context_provider::create(void *data) +EXTAPI ctx::ContextProviderBase* ctx::custom_context_provider::create(void *data) { - // Already created in add_item() function. Return corresponding custom provider + // Already created in addItem() function. Return corresponding custom provider return custom_map[static_cast(data)]; } @@ -89,7 +89,7 @@ EXTAPI bool ctx::init_custom_context_provider() elem.get(NULL, "attributes", &attributes); elem.get(NULL, "owner", &owner); - error = ctx::custom_context_provider::add_item(subject, name, ctx::Json(attributes), owner.c_str(), true); + error = ctx::custom_context_provider::addItem(subject, name, ctx::Json(attributes), owner.c_str(), true); if (error != ERR_NONE) { _E("Failed to add custom item(%s): %#x", subject.c_str(), error); } @@ -98,7 +98,7 @@ EXTAPI bool ctx::init_custom_context_provider() return true; } -EXTAPI int ctx::custom_context_provider::add_item(std::string subject, std::string name, ctx::Json tmpl, const char* owner, bool is_init) +EXTAPI int ctx::custom_context_provider::addItem(std::string subject, std::string name, ctx::Json tmpl, const char* owner, bool is_init) { std::map::iterator it; it = custom_map.find(subject); @@ -116,7 +116,7 @@ EXTAPI int ctx::custom_context_provider::add_item(std::string subject, std::stri IF_FAIL_RETURN_TAG(custom, ERR_OUT_OF_MEMORY, _E, "Memory allocation failed"); custom_map[subject] = custom; - register_provider(custom->get_subject(), NULL); + registerProvider(custom->get_subject(), NULL); // Add item to custom template db if (!is_init) { @@ -130,13 +130,13 @@ EXTAPI int ctx::custom_context_provider::add_item(std::string subject, std::stri return ERR_NONE; } -EXTAPI int ctx::custom_context_provider::remove_item(std::string subject) +EXTAPI int ctx::custom_context_provider::removeItem(std::string subject) { std::map::iterator it; it = custom_map.find(subject); IF_FAIL_RETURN_TAG(it != custom_map.end(), ERR_NOT_SUPPORTED, _E, "%s not supported", subject.c_str()); - unregister_provider(subject.c_str()); + unregisterProvider(subject.c_str()); // Remove item from custom template db std::string q = "DELETE FROM context_trigger_custom_template WHERE subject = '" + subject + "'"; @@ -147,7 +147,7 @@ EXTAPI int ctx::custom_context_provider::remove_item(std::string subject) return ERR_NONE; } -EXTAPI int ctx::custom_context_provider::publish_data(std::string subject, ctx::Json fact) +EXTAPI int ctx::custom_context_provider::publishData(std::string subject, ctx::Json fact) { std::map::iterator it; it = custom_map.find(subject); diff --git a/src/device/activity/activity.h b/src/device/activity/activity.h index d0e0951..2f44267 100644 --- a/src/device/activity/activity.h +++ b/src/device/activity/activity.h @@ -23,7 +23,7 @@ #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) \ + static ContextProviderBase *create(void *data) \ { \ CREATE_INSTANCE(ctx::act_prvd); \ } \ @@ -37,7 +37,7 @@ } \ static void submit_trigger_item() \ { \ - context_manager::register_trigger_item((act_subj), OPS_SUBSCRIBE, \ + context_manager::registerTriggerItem((act_subj), OPS_SUBSCRIBE, \ "{\"Event\":{\"type\":\"string\", \"values\":[\"Detected\"]}}", \ "{\"Accuracy\":{\"type\":\"string\", \"values\":[\"Low\", \"Normal\", \"High\"]}}" \ ); \ diff --git a/src/device/activity/activity_base.cpp b/src/device/activity/activity_base.cpp index e0a9027..30201ca 100644 --- a/src/device/activity/activity_base.cpp +++ b/src/device/activity/activity_base.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include "activity_types.h" #include "activity_base.h" @@ -44,25 +44,25 @@ void ctx::user_activity_base::handle_event(activity_type_e activity, const activ { 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); + ctx::Json dataRead; + dataRead.set(NULL, USER_ACT_EVENT, USER_ACT_DETECTED); activity_accuracy_e accuracy = ACTIVITY_ACCURACY_LOW; activity_get_accuracy(data, &accuracy); switch (accuracy) { case ACTIVITY_ACCURACY_HIGH: - data_read.set(NULL, USER_ACT_ACCURACY, USER_ACT_HIGH); + dataRead.set(NULL, USER_ACT_ACCURACY, USER_ACT_HIGH); break; case ACTIVITY_ACCURACY_MID: - data_read.set(NULL, USER_ACT_ACCURACY, USER_ACT_NORMAL); + dataRead.set(NULL, USER_ACT_ACCURACY, USER_ACT_NORMAL); break; default: - data_read.set(NULL, USER_ACT_ACCURACY, USER_ACT_LOW); + dataRead.set(NULL, USER_ACT_ACCURACY, USER_ACT_LOW); break; } - context_manager::publish(subject.c_str(), NULL, ERR_NONE, data_read); + context_manager::publish(subject.c_str(), NULL, ERR_NONE, dataRead); } int ctx::user_activity_base::subscribe() diff --git a/src/device/activity/activity_base.h b/src/device/activity/activity_base.h index 45fcc8d..05fa503 100644 --- a/src/device/activity/activity_base.h +++ b/src/device/activity/activity_base.h @@ -19,7 +19,7 @@ #include #include -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { diff --git a/src/device/device_context_provider.cpp b/src/device/device_context_provider.cpp index be6d911..39fcf7d 100644 --- a/src/device/device_context_provider.cpp +++ b/src/device/device_context_provider.cpp @@ -15,8 +15,8 @@ */ #include -#include -#include +#include +#include #include #include "system/system_types.h" @@ -65,40 +65,40 @@ #define PRIV_CONTACT "contact.read" template -void register_provider(const char *subject, const char *privilege) +void registerProvider(const char *subject, const char *privilege) { if (!provider::is_supported()) return; - ctx::context_provider_info provider_info(provider::create, provider::destroy, NULL, privilege); - ctx::context_manager::register_provider(subject, provider_info); + ctx::ContextProviderInfo providerInfo(provider::create, provider::destroy, NULL, privilege); + ctx::context_manager::registerProvider(subject, providerInfo); provider::submit_trigger_item(); } EXTAPI bool ctx::init_device_context_provider() { - register_provider(DEVICE_ST_SUBJ_ALARM, NULL); - register_provider(DEVICE_ST_SUBJ_TIME, NULL); + registerProvider(DEVICE_ST_SUBJ_ALARM, NULL); + registerProvider(DEVICE_ST_SUBJ_TIME, NULL); #ifdef _MOBILE_ - register_provider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); - register_provider(DEVICE_ST_SUBJ_HEADPHONE, NULL); + registerProvider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); + registerProvider(DEVICE_ST_SUBJ_HEADPHONE, NULL); - register_provider(DEVICE_ST_SUBJ_CHARGER, NULL); - register_provider(DEVICE_ST_SUBJ_GPS, NULL); - register_provider(DEVICE_ST_SUBJ_USB, NULL); - register_provider(DEVICE_ST_SUBJ_BATTERY, NULL); - register_provider(DEVICE_ST_SUBJ_PSMODE, NULL); + registerProvider(DEVICE_ST_SUBJ_CHARGER, NULL); + registerProvider(DEVICE_ST_SUBJ_GPS, NULL); + registerProvider(DEVICE_ST_SUBJ_USB, NULL); + registerProvider(DEVICE_ST_SUBJ_BATTERY, NULL); + registerProvider(DEVICE_ST_SUBJ_PSMODE, NULL); - register_provider(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY); - register_provider(SOCIAL_ST_SUBJ_EMAIL, NULL); - register_provider(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE); - register_provider(SOCIAL_ST_SUBJ_CONTACTS, PRIV_CONTACT); + registerProvider(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY); + registerProvider(SOCIAL_ST_SUBJ_EMAIL, NULL); + registerProvider(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE); + registerProvider(SOCIAL_ST_SUBJ_CONTACTS, PRIV_CONTACT); - register_provider(USER_ACT_SUBJ_STATIONARY, NULL); - register_provider(USER_ACT_SUBJ_WALKING, NULL); - register_provider(USER_ACT_SUBJ_RUNNING, NULL); - register_provider(USER_ACT_SUBJ_IN_VEHICLE, NULL); + registerProvider(USER_ACT_SUBJ_STATIONARY, NULL); + registerProvider(USER_ACT_SUBJ_WALKING, NULL); + registerProvider(USER_ACT_SUBJ_RUNNING, NULL); + registerProvider(USER_ACT_SUBJ_IN_VEHICLE, NULL); /* Create context providers, which need to be initiated before being subscribed */ if (device_status_wifi::is_supported()) @@ -106,22 +106,22 @@ EXTAPI bool ctx::init_device_context_provider() #endif #ifdef _WEARABLE_ - register_provider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); - register_provider(DEVICE_ST_SUBJ_HEADPHONE, NULL); + registerProvider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); + registerProvider(DEVICE_ST_SUBJ_HEADPHONE, NULL); - register_provider(DEVICE_ST_SUBJ_CHARGER, NULL); - register_provider(DEVICE_ST_SUBJ_GPS, NULL); - register_provider(DEVICE_ST_SUBJ_USB, NULL); - register_provider(DEVICE_ST_SUBJ_BATTERY, NULL); - register_provider(DEVICE_ST_SUBJ_PSMODE, NULL); + registerProvider(DEVICE_ST_SUBJ_CHARGER, NULL); + registerProvider(DEVICE_ST_SUBJ_GPS, NULL); + registerProvider(DEVICE_ST_SUBJ_USB, NULL); + registerProvider(DEVICE_ST_SUBJ_BATTERY, NULL); + registerProvider(DEVICE_ST_SUBJ_PSMODE, NULL); - register_provider(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY); - register_provider(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE); + registerProvider(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY); + registerProvider(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE); - register_provider(USER_ACT_SUBJ_STATIONARY, NULL); - register_provider(USER_ACT_SUBJ_WALKING, NULL); - register_provider(USER_ACT_SUBJ_RUNNING, NULL); - register_provider(USER_ACT_SUBJ_IN_VEHICLE, NULL); + registerProvider(USER_ACT_SUBJ_STATIONARY, NULL); + registerProvider(USER_ACT_SUBJ_WALKING, NULL); + registerProvider(USER_ACT_SUBJ_RUNNING, NULL); + registerProvider(USER_ACT_SUBJ_IN_VEHICLE, NULL); /* Create context providers, which need to be initiated before being subscribed */ if (device_status_wifi::is_supported()) @@ -129,8 +129,8 @@ EXTAPI bool ctx::init_device_context_provider() #endif #ifdef _TV_ - register_provider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); - register_provider(DEVICE_ST_SUBJ_HEADPHONE, NULL); + registerProvider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); + registerProvider(DEVICE_ST_SUBJ_HEADPHONE, NULL); /* Create context providers, which need to be initiated before being subscribed */ if (device_status_wifi::is_supported()) diff --git a/src/device/provider_base.cpp b/src/device/device_provider_base.cpp similarity index 93% rename from src/device/provider_base.cpp rename to src/device/device_provider_base.cpp index fefe212..95f3988 100644 --- a/src/device/provider_base.cpp +++ b/src/device/device_provider_base.cpp @@ -15,14 +15,14 @@ */ #include -#include "provider_base.h" +#include "device_provider_base.h" ctx::device_provider_base::device_provider_base() : being_subscribed(false) { } -int ctx::device_provider_base::subscribe(const char *subject, ctx::Json option, ctx::Json *request_result) +int ctx::device_provider_base::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) { IF_FAIL_RETURN(!being_subscribed, ERR_NONE); @@ -47,7 +47,7 @@ int ctx::device_provider_base::unsubscribe(const char *subject, ctx::Json option return ret; } -int ctx::device_provider_base::read(const char *subject, ctx::Json option, ctx::Json *request_result) +int ctx::device_provider_base::read(const char *subject, ctx::Json option, ctx::Json *requestResult) { int ret = read(); @@ -57,7 +57,7 @@ int ctx::device_provider_base::read(const char *subject, ctx::Json option, ctx:: return ret; } -int ctx::device_provider_base::write(const char *subject, ctx::Json data, ctx::Json *request_result) +int ctx::device_provider_base::write(const char *subject, ctx::Json data, ctx::Json *requestResult) { int ret = write(); diff --git a/src/device/provider_base.h b/src/device/device_provider_base.h similarity index 89% rename from src/device/provider_base.h rename to src/device/device_provider_base.h index 39983b1..6b2c1a9 100644 --- a/src/device/provider_base.h +++ b/src/device/device_provider_base.h @@ -19,7 +19,7 @@ #include #include -#include +#include #define CREATE_INSTANCE(prvd) \ do { \ @@ -40,7 +40,7 @@ #define GENERATE_PROVIDER_COMMON_DECL(prvd) \ public: \ - static context_provider_iface *create(void *data); \ + static ContextProviderBase *create(void *data); \ static void destroy(void *data); \ protected: \ void destroy_self(); \ @@ -49,7 +49,7 @@ #define GENERATE_PROVIDER_COMMON_IMPL(prvd) \ ctx::prvd *ctx::prvd::__instance = NULL; \ - ctx::context_provider_iface *ctx::prvd::create(void *data) \ + ctx::ContextProviderBase *ctx::prvd::create(void *data) \ { \ CREATE_INSTANCE(prvd); \ } \ @@ -64,12 +64,12 @@ namespace ctx { - class device_provider_base : public context_provider_iface { + class device_provider_base : public ContextProviderBase { public: - int subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + 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 *request_result); - int write(const char *subject, ctx::Json data, ctx::Json *request_result); + int read(const char *subject, ctx::Json option, ctx::Json *requestResult); + int write(const char *subject, ctx::Json data, ctx::Json *requestResult); protected: bool being_subscribed; diff --git a/src/device/social/call.cpp b/src/device/social/call.cpp index 745442c..71e3ea8 100644 --- a/src/device/social/call.cpp +++ b/src/device/social/call.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "social_types.h" #include "call.h" @@ -57,7 +57,7 @@ bool ctx::social_status_call::is_supported() void ctx::social_status_call::submit_trigger_item() { - context_manager::register_trigger_item(SOCIAL_ST_SUBJ_CALL, OPS_SUBSCRIBE | OPS_READ, + context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CALL, OPS_SUBSCRIBE | OPS_READ, "{" "\"Medium\":{\"type\":\"string\",\"values\":[\"Voice\",\"Video\"]}," "\"State\":{\"type\":\"string\",\"values\":[\"Idle\",\"Connecting\",\"Connected\"]}," @@ -381,7 +381,7 @@ int ctx::social_status_call::read() release_telephony(); if (ret) { - ctx::context_manager::reply_to_read(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data); + ctx::context_manager::replyToRead(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data); return ERR_NONE; } diff --git a/src/device/social/call.h b/src/device/social/call.h index cdd906c..f320f5c 100644 --- a/src/device/social/call.h +++ b/src/device/social/call.h @@ -18,7 +18,7 @@ #define _CONTEXT_SOCIAL_STATUS_CALL_H_ #include -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { diff --git a/src/device/social/contacts.cpp b/src/device/social/contacts.cpp index c7ee6e3..f071e78 100644 --- a/src/device/social/contacts.cpp +++ b/src/device/social/contacts.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include "social_types.h" #include "contacts.h" @@ -42,7 +42,7 @@ bool ctx::social_status_contacts::is_supported() void ctx::social_status_contacts::submit_trigger_item() { - context_manager::register_trigger_item(SOCIAL_ST_SUBJ_CONTACTS, OPS_SUBSCRIBE, + context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CONTACTS, OPS_SUBSCRIBE, "{" "\"Event\":{\"type\":\"string\",\"values\":[\"Changed\"]}," "\"Type\":{\"type\":\"string\",\"values\":[\"MyProfile\",\"Person\"]}" diff --git a/src/device/social/contacts.h b/src/device/social/contacts.h index 52adb14..1169412 100644 --- a/src/device/social/contacts.h +++ b/src/device/social/contacts.h @@ -18,7 +18,7 @@ #define _CONTEXT_SOCIAL_STATUS_CONTACTS_H_ #include -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { diff --git a/src/device/social/email.cpp b/src/device/social/email.cpp index 831a963..898cf03 100644 --- a/src/device/social/email.cpp +++ b/src/device/social/email.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include "social_types.h" #include "email.h" @@ -40,7 +40,7 @@ bool ctx::social_status_email::is_supported() void ctx::social_status_email::submit_trigger_item() { - context_manager::register_trigger_item(SOCIAL_ST_SUBJ_EMAIL, OPS_SUBSCRIBE, + context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_EMAIL, OPS_SUBSCRIBE, "{" "\"Event\":{\"type\":\"string\",\"values\":[\"Received\",\"Sent\"]}" "}", @@ -60,15 +60,15 @@ void ctx::social_status_email::onSignal(const char* sender, const char* path, co if (sub_type == NOTI_DOWNLOAD_FINISH) { //TODO: Check if this signal actually means that there are new mails _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", sub_type, gi1, gc, gi2, gi3); - ctx::Json data_updated; - data_updated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED); - context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, data_updated); + ctx::Json dataUpdated; + dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED); + context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, dataUpdated); } else if (sub_type == NOTI_SEND_FINISH) { _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", sub_type, gi1, gc, gi2, gi3); - ctx::Json data_updated; - data_updated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_SENT); - context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, data_updated); + ctx::Json dataUpdated; + dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_SENT); + context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, dataUpdated); } } diff --git a/src/device/social/email.h b/src/device/social/email.h index 930da24..9cc7508 100644 --- a/src/device/social/email.h +++ b/src/device/social/email.h @@ -18,7 +18,7 @@ #define _CONTEXT_SOCIAL_STATUS_EMAIL_H_ #include -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { diff --git a/src/device/social/message.cpp b/src/device/social/message.cpp index 4d46fe9..cf75e4f 100644 --- a/src/device/social/message.cpp +++ b/src/device/social/message.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include "social_types.h" #include "message.h" @@ -39,7 +39,7 @@ bool ctx::social_status_message::is_supported() void ctx::social_status_message::submit_trigger_item() { - context_manager::register_trigger_item(SOCIAL_ST_SUBJ_MESSAGE, OPS_SUBSCRIBE, + context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_MESSAGE, OPS_SUBSCRIBE, "{" "\"Event\":{\"type\":\"string\",\"values\":[\"Received\"]}," "\"Type\":{\"type\":\"string\",\"values\":[\"SMS\",\"MMS\"]}," diff --git a/src/device/social/message.h b/src/device/social/message.h index 1c1d15b..5239f21 100644 --- a/src/device/social/message.h +++ b/src/device/social/message.h @@ -19,7 +19,7 @@ #include #include -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { diff --git a/src/device/system/alarm.cpp b/src/device/system/alarm.cpp index d1c6f26..d4434a9 100644 --- a/src/device/system/alarm.cpp +++ b/src/device/system/alarm.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "system_types.h" #include "alarm.h" @@ -41,7 +41,7 @@ bool ctx::device_status_alarm::is_supported() void ctx::device_status_alarm::submit_trigger_item() { - context_manager::register_trigger_item(DEVICE_ST_SUBJ_ALARM, OPS_SUBSCRIBE, + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_ALARM, OPS_SUBSCRIBE, "{" "\"TimeOfDay\":{\"type\":\"integer\",\"min\":0,\"max\":1439}," "\"DayOfWeek\":{\"type\":\"string\",\"values\":[\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\",\"Weekday\",\"Weekend\"]}" @@ -49,7 +49,7 @@ void ctx::device_status_alarm::submit_trigger_item() NULL); } -int ctx::device_status_alarm::subscribe(const char *subject, ctx::Json option, ctx::Json *request_result) +int ctx::device_status_alarm::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) { int ret = subscribe(option); destroy_if_unused(); @@ -63,13 +63,13 @@ int ctx::device_status_alarm::unsubscribe(const char *subject, ctx::Json option) return ret; } -int ctx::device_status_alarm::read(const char *subject, ctx::Json option, ctx::Json *request_result) +int ctx::device_status_alarm::read(const char *subject, ctx::Json option, ctx::Json *requestResult) { destroy_if_unused(); return ERR_NOT_SUPPORTED; } -int ctx::device_status_alarm::write(const char *subject, ctx::Json data, ctx::Json *request_result) +int ctx::device_status_alarm::write(const char *subject, ctx::Json data, ctx::Json *requestResult) { destroy_if_unused(); return ERR_NOT_SUPPORTED; @@ -250,16 +250,16 @@ void ctx::device_status_alarm::on_timer_expired(int hour, int min, int day_of_we { _I("Time: %02d:%02d, Day of Week: %#x", hour, min, day_of_week); - ctx::Json data_read; + ctx::Json dataRead; int result_time = hour * 60 + min; std::string result_day = ctx::TimerManager::dowToStr(day_of_week); - data_read.set(NULL, DEVICE_ST_TIME_OF_DAY, result_time); - data_read.set(NULL, DEVICE_ST_DAY_OF_WEEK, result_day); + dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, result_time); + dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, result_day); for (option_t::iterator it = option_set.begin(); it != option_set.end(); ++it) { ctx::Json option = (**it); if (is_matched(option, result_time, result_day)) { - context_manager::publish(DEVICE_ST_SUBJ_ALARM, option, ERR_NONE, data_read); + context_manager::publish(DEVICE_ST_SUBJ_ALARM, option, ERR_NONE, dataRead); } } } diff --git a/src/device/system/alarm.h b/src/device/system/alarm.h index 8d640e3..ff5271b 100644 --- a/src/device/system/alarm.h +++ b/src/device/system/alarm.h @@ -19,21 +19,21 @@ #include #include -#include +#include #include -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { - class device_status_alarm : public context_provider_iface, ITimerListener { + class device_status_alarm : public ContextProviderBase, ITimerListener { GENERATE_PROVIDER_COMMON_DECL(device_status_alarm); public: - int subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + 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 *request_result); - int write(const char *subject, ctx::Json data, ctx::Json *request_result); + int read(const char *subject, ctx::Json option, ctx::Json *requestResult); + int write(const char *subject, ctx::Json data, ctx::Json *requestResult); int subscribe(ctx::Json option); int unsubscribe(ctx::Json option); diff --git a/src/device/system/battery.cpp b/src/device/system/battery.cpp index 5be24b6..6207db9 100644 --- a/src/device/system/battery.cpp +++ b/src/device/system/battery.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "system_types.h" #include "battery.h" @@ -35,7 +35,7 @@ bool ctx::device_status_battery::is_supported() void ctx::device_status_battery::submit_trigger_item() { - context_manager::register_trigger_item(DEVICE_ST_SUBJ_BATTERY, OPS_SUBSCRIBE | OPS_READ, + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_BATTERY, OPS_SUBSCRIBE | OPS_READ, "{" "\"Level\":{\"type\":\"string\",\"values\":[\"Empty\",\"Critical\",\"Low\",\"Normal\",\"High\",\"Full\"]}," TRIG_BOOL_ITEM_DEF("IsCharging") @@ -58,15 +58,15 @@ void ctx::device_status_battery::handle_update(device_callback_e device_type, vo const char* level_string = trans_to_string(level); IF_FAIL_VOID(level_string); - ctx::Json data_read; - data_read.set(NULL, DEVICE_ST_LEVEL, level_string); + ctx::Json dataRead; + dataRead.set(NULL, DEVICE_ST_LEVEL, level_string); bool charging_state = false; int ret = device_battery_is_charging(&charging_state); IF_FAIL_VOID_TAG(ret == DEVICE_ERROR_NONE, _E, "Getting state failed"); - data_read.set(NULL, DEVICE_ST_IS_CHARGING, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - ctx::context_manager::publish(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, data_read); + dataRead.set(NULL, DEVICE_ST_IS_CHARGING, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + ctx::context_manager::publish(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, dataRead); } const char* ctx::device_status_battery::trans_to_string(intptr_t level) @@ -120,7 +120,7 @@ int ctx::device_status_battery::unsubscribe() int ctx::device_status_battery::read() { device_battery_level_e level; - ctx::Json data_read; + ctx::Json dataRead; int ret = device_battery_get_level_status(&level); IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED); @@ -128,14 +128,14 @@ int ctx::device_status_battery::read() const char* level_string = trans_to_string(level); IF_FAIL_RETURN(level_string, ERR_OPERATION_FAILED); - data_read.set(NULL, DEVICE_ST_LEVEL, level_string); + dataRead.set(NULL, DEVICE_ST_LEVEL, level_string); bool charging_state = false; ret = device_battery_is_charging(&charging_state); IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED); - data_read.set(NULL, DEVICE_ST_IS_CHARGING, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + dataRead.set(NULL, DEVICE_ST_IS_CHARGING, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, data_read); + ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/battery.h b/src/device/system/battery.h index 6fc3fdf..8f8a723 100644 --- a/src/device/system/battery.h +++ b/src/device/system/battery.h @@ -19,7 +19,7 @@ #include #include -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { diff --git a/src/device/system/headphone.cpp b/src/device/system/headphone.cpp index ac3d5db..91e1708 100644 --- a/src/device/system/headphone.cpp +++ b/src/device/system/headphone.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "system_types.h" #include "headphone.h" @@ -44,7 +44,7 @@ bool ctx::device_status_headphone::is_supported() void ctx::device_status_headphone::submit_trigger_item() { - context_manager::register_trigger_item(DEVICE_ST_SUBJ_HEADPHONE, OPS_SUBSCRIBE | OPS_READ, + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_HEADPHONE, OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsConnected") "," "\"Type\":{\"type\":\"string\",\"values\":[\"Normal\",\"Headset\",\"Bluetooth\"]}" @@ -81,7 +81,7 @@ int ctx::device_status_headphone::read() Json data; generate_data_packet(data); - ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data); + ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data); return ERR_NONE; } diff --git a/src/device/system/headphone.h b/src/device/system/headphone.h index f451d52..8922a61 100644 --- a/src/device/system/headphone.h +++ b/src/device/system/headphone.h @@ -20,7 +20,7 @@ #include #include #include -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { diff --git a/src/device/system/psmode.cpp b/src/device/system/psmode.cpp index dcfc359..dc39f98 100644 --- a/src/device/system/psmode.cpp +++ b/src/device/system/psmode.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "system_types.h" #include "psmode.h" @@ -35,7 +35,7 @@ bool ctx::device_status_psmode::is_supported() void ctx::device_status_psmode::submit_trigger_item() { - context_manager::register_trigger_item(DEVICE_ST_SUBJ_PSMODE, OPS_SUBSCRIBE | OPS_READ, + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_PSMODE, OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsEnabled") "}", NULL); } @@ -48,14 +48,14 @@ void ctx::device_status_psmode::update_cb(keynode_t *node, void* user_data) void ctx::device_status_psmode::handle_update(keynode_t *node) { int status; - ctx::Json data_read; + ctx::Json dataRead; status = vconf_keynode_get_int(node); IF_FAIL_VOID_TAG(status >= 0, _E, "Getting state failed"); - data_read.set(NULL, DEVICE_ST_IS_ENABLED, status == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE); + 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, data_read); + context_manager::publish(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, dataRead); } int ctx::device_status_psmode::subscribe() @@ -78,9 +78,9 @@ int ctx::device_status_psmode::read() int ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &mode); IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED); - ctx::Json data_read; - data_read.set(NULL, DEVICE_ST_IS_ENABLED, mode == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE); + ctx::Json dataRead; + dataRead.set(NULL, DEVICE_ST_IS_ENABLED, mode == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE); - ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, data_read); + ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/psmode.h b/src/device/system/psmode.h index 2cc1660..1d4e4f3 100644 --- a/src/device/system/psmode.h +++ b/src/device/system/psmode.h @@ -18,7 +18,7 @@ #define _DEVICE_STATUS_POWER_SAVING_MODE_H_ #include -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { diff --git a/src/device/system/runtime-info/base_rtinfo.h b/src/device/system/runtime-info/base_rtinfo.h index 29480c5..faaaa6a 100644 --- a/src/device/system/runtime-info/base_rtinfo.h +++ b/src/device/system/runtime-info/base_rtinfo.h @@ -18,7 +18,7 @@ #define __CONTEXT_DEVICE_STATUS_RUNTIME_INFO_H__ #include -#include "../../provider_base.h" +#include "../../device_provider_base.h" namespace ctx { diff --git a/src/device/system/runtime-info/charger.cpp b/src/device/system/runtime-info/charger.cpp index ae16d8c..d4cec25 100644 --- a/src/device/system/runtime-info/charger.cpp +++ b/src/device/system/runtime-info/charger.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "../system_types.h" #include "charger.h" @@ -36,7 +36,7 @@ bool ctx::device_status_charger::is_supported() void ctx::device_status_charger::submit_trigger_item() { - context_manager::register_trigger_item(DEVICE_ST_SUBJ_CHARGER, OPS_SUBSCRIBE | OPS_READ, + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_CHARGER, OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL); } @@ -47,22 +47,22 @@ void ctx::device_status_charger::handle_update() int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &charger_status); IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed"); - ctx::Json data_read; - data_read.set(NULL, DEVICE_ST_IS_CONNECTED, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + ctx::Json dataRead; + dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - context_manager::publish(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, data_read); + context_manager::publish(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, dataRead); } int ctx::device_status_charger::read() { bool charger_status = false; - ctx::Json data_read; + ctx::Json dataRead; int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &charger_status); IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed"); - data_read.set(NULL, DEVICE_ST_IS_CONNECTED, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, data_read); + ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/runtime-info/gps.cpp b/src/device/system/runtime-info/gps.cpp index 80aa16c..9624d38 100644 --- a/src/device/system/runtime-info/gps.cpp +++ b/src/device/system/runtime-info/gps.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "../system_types.h" #include "gps.h" @@ -54,7 +54,7 @@ bool ctx::device_status_gps::is_supported() void ctx::device_status_gps::submit_trigger_item() { - context_manager::register_trigger_item(DEVICE_ST_SUBJ_GPS, OPS_SUBSCRIBE | OPS_READ, + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_GPS, OPS_SUBSCRIBE | OPS_READ, "{" "\"State\":{\"type\":\"string\",\"values\":[\"Disabled\",\"Searching\",\"Connected\"]}" "}", @@ -67,20 +67,20 @@ void ctx::device_status_gps::handle_update() int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gps_status); IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed"); - ctx::Json data_read; + ctx::Json dataRead; const char* state_str = get_state_string(gps_status); IF_FAIL_VOID(state_str); - data_read.set(NULL, DEVICE_ST_STATE, state_str); + dataRead.set(NULL, DEVICE_ST_STATE, state_str); - context_manager::publish(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, data_read); + context_manager::publish(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead); } int ctx::device_status_gps::read() { int gps_status; - ctx::Json data_read; + ctx::Json dataRead; int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gps_status); IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed"); @@ -88,8 +88,8 @@ int ctx::device_status_gps::read() const char* state_str = get_state_string(gps_status); IF_FAIL_RETURN(state_str, ERR_OPERATION_FAILED); - data_read.set(NULL, DEVICE_ST_STATE, state_str); + dataRead.set(NULL, DEVICE_ST_STATE, state_str); - ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, data_read); + ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/runtime-info/usb.cpp b/src/device/system/runtime-info/usb.cpp index 0ab4d0d..2b7ddbc 100644 --- a/src/device/system/runtime-info/usb.cpp +++ b/src/device/system/runtime-info/usb.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include "../system_types.h" #include "usb.h" @@ -36,7 +36,7 @@ bool ctx::device_status_usb::is_supported() void ctx::device_status_usb::submit_trigger_item() { - context_manager::register_trigger_item(DEVICE_ST_SUBJ_USB, OPS_SUBSCRIBE | OPS_READ, + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_USB, OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL); } @@ -47,22 +47,22 @@ void ctx::device_status_usb::handle_update() 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 data_read; - data_read.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + ctx::Json dataRead; + dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - context_manager::publish(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, data_read); + context_manager::publish(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, dataRead); } int ctx::device_status_usb::read() { bool status = false; - ctx::Json data_read; + ctx::Json dataRead; int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_USB_CONNECTED, &status); IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed"); - data_read.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, data_read); + ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/time.cpp b/src/device/system/time.cpp index 7f5515a..6cd5ea0 100644 --- a/src/device/system/time.cpp +++ b/src/device/system/time.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include "system_types.h" #include "time.h" @@ -36,7 +36,7 @@ bool ctx::device_status_time::is_supported() void ctx::device_status_time::submit_trigger_item() { - context_manager::register_trigger_item(DEVICE_ST_SUBJ_TIME, OPS_READ, + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_TIME, OPS_READ, "{" "\"TimeOfDay\":{\"type\":\"integer\",\"min\":0,\"max\":1439}," "\"DayOfWeek\":{\"type\":\"string\",\"values\":[\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\",\"Weekday\",\"Weekend\"]}," @@ -68,14 +68,14 @@ int ctx::device_status_time::read() int minute_of_day = timeinfo.tm_hour * 60 + timeinfo.tm_min; std::string day_of_week = ctx::TimerManager::dowToStr(0x01 << timeinfo.tm_wday); - ctx::Json data_read; - data_read.set(NULL, DEVICE_ST_DAY_OF_MONTH, day_of_month); - data_read.set(NULL, DEVICE_ST_DAY_OF_WEEK, day_of_week); - data_read.set(NULL, DEVICE_ST_TIME_OF_DAY, minute_of_day); + ctx::Json dataRead; + dataRead.set(NULL, DEVICE_ST_DAY_OF_MONTH, day_of_month); + dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, day_of_week); + dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, minute_of_day); _I("Time: %02d:%02d, Day of Week: %s, Day of Month: %d", timeinfo.tm_hour, timeinfo.tm_min, day_of_week.c_str(), day_of_month); - ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_TIME, NULL, ERR_NONE, data_read); + ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_TIME, NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/time.h b/src/device/system/time.h index 6775d7a..7d44bec 100644 --- a/src/device/system/time.h +++ b/src/device/system/time.h @@ -17,7 +17,7 @@ #ifndef _DEVICE_STATUS_TIME_H_ #define _DEVICE_STATUS_TIME_H_ -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { diff --git a/src/device/system/wifi.cpp b/src/device/system/wifi.cpp index a40c179..4d237df 100644 --- a/src/device/system/wifi.cpp +++ b/src/device/system/wifi.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include "system_types.h" #include "wifi.h" @@ -39,7 +39,7 @@ ctx::device_status_wifi::~device_status_wifi() { } -ctx::context_provider_iface *ctx::device_status_wifi::create(void *data) +ctx::ContextProviderBase *ctx::device_status_wifi::create(void *data) { CREATE_INSTANCE(device_status_wifi); } @@ -62,7 +62,7 @@ bool ctx::device_status_wifi::is_supported() void ctx::device_status_wifi::submit_trigger_item() { - context_manager::register_trigger_item(DEVICE_ST_SUBJ_WIFI, OPS_SUBSCRIBE | OPS_READ, + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_WIFI, OPS_SUBSCRIBE | OPS_READ, "{" "\"State\":{\"type\":\"string\",\"values\":[\"Disabled\",\"Unconnected\",\"Connected\"]}," "\"BSSID\":{\"type\":\"string\"}" @@ -162,10 +162,10 @@ int ctx::device_status_wifi::read() { IF_FAIL_RETURN(get_current_state(), ERR_OPERATION_FAILED); - ctx::Json data_read; + ctx::Json dataRead; - if (get_response_packet(data_read)) { - ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, data_read); + if (get_response_packet(dataRead)) { + ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, dataRead); return ERR_NONE; } diff --git a/src/device/system/wifi.h b/src/device/system/wifi.h index 6bd81c1..3ed52d5 100644 --- a/src/device/system/wifi.h +++ b/src/device/system/wifi.h @@ -19,7 +19,7 @@ #include #include -#include "../provider_base.h" +#include "../device_provider_base.h" namespace ctx { diff --git a/src/place/geofence/myplace_handle.cpp b/src/place/geofence/myplace_handle.cpp index 8ea7684..d7b8fcc 100644 --- a/src/place/geofence/myplace_handle.cpp +++ b/src/place/geofence/myplace_handle.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "place_geofence_types.h" #include "myplace_handle.h" diff --git a/src/place/geofence/place_geofence.cpp b/src/place/geofence/place_geofence.cpp index c1525a1..5bcfb7f 100644 --- a/src/place/geofence/place_geofence.cpp +++ b/src/place/geofence/place_geofence.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include "place_geofence.h" ctx::place_geofence_provider *ctx::place_geofence_provider::__instance = NULL; @@ -36,7 +36,7 @@ ctx::place_geofence_provider::~place_geofence_provider() __handle_map.clear(); } -ctx::context_provider_iface *ctx::place_geofence_provider::create(void *data) +ctx::ContextProviderBase *ctx::place_geofence_provider::create(void *data) { IF_FAIL_RETURN(!__instance, __instance); __instance = new(std::nothrow) place_geofence_provider(); @@ -63,7 +63,7 @@ bool ctx::place_geofence_provider::is_supported() void ctx::place_geofence_provider::submit_trigger_item() { - context_manager::register_trigger_item(PLACE_SUBJ_GEOFENCE, OPS_SUBSCRIBE, + context_manager::registerTriggerItem(PLACE_SUBJ_GEOFENCE, OPS_SUBSCRIBE, "{" "\"Event\":{\"type\":\"string\",\"values\":[\"In\",\"Out\"]}" "}", @@ -79,7 +79,7 @@ void ctx::place_geofence_provider::__destroy_if_unused() } -int ctx::place_geofence_provider::subscribe(const char *subject, ctx::Json option, ctx::Json *request_result) +int ctx::place_geofence_provider::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) { int ret = __subscribe(option); __destroy_if_unused(); @@ -93,13 +93,13 @@ int ctx::place_geofence_provider::unsubscribe(const char *subject, ctx::Json opt return ret; } -int ctx::place_geofence_provider::read(const char *subject, ctx::Json option, ctx::Json *request_result) +int ctx::place_geofence_provider::read(const char *subject, ctx::Json option, ctx::Json *requestResult) { __destroy_if_unused(); return ERR_NOT_SUPPORTED; } -int ctx::place_geofence_provider::write(const char *subject, ctx::Json data, ctx::Json *request_result) +int ctx::place_geofence_provider::write(const char *subject, ctx::Json data, ctx::Json *requestResult) { __destroy_if_unused(); return ERR_NOT_SUPPORTED; diff --git a/src/place/geofence/place_geofence.h b/src/place/geofence/place_geofence.h index 05de007..739610f 100644 --- a/src/place/geofence/place_geofence.h +++ b/src/place/geofence/place_geofence.h @@ -18,25 +18,25 @@ #define __CONTEXT_PLACE_GEOFENCE_H__ #include -#include +#include #include "myplace_handle.h" #include "place_geofence_types.h" namespace ctx { - class place_geofence_provider : public context_provider_iface { + class place_geofence_provider : public ContextProviderBase { typedef std::map handle_map_t; public: - static context_provider_iface *create(void *data); + static ContextProviderBase *create(void *data); static void destroy(void *data); static bool is_supported(); static void submit_trigger_item(); - int subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + 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 *request_result); - int write(const char *subject, ctx::Json data, ctx::Json *request_result); + int read(const char *subject, ctx::Json option, ctx::Json *requestResult); + int write(const char *subject, ctx::Json data, ctx::Json *requestResult); private: static place_geofence_provider *__instance; diff --git a/src/place/place_context_provider.cpp b/src/place/place_context_provider.cpp index 934f780..6bcf1c3 100644 --- a/src/place/place_context_provider.cpp +++ b/src/place/place_context_provider.cpp @@ -15,8 +15,8 @@ */ #include -#include -#include +#include +#include #include #ifdef _MOBILE_ @@ -27,24 +27,24 @@ #endif /* _MOBILE_ */ template -void register_provider(const char *subject, const char *privilege) +void registerProvider(const char *subject, const char *privilege) { if (!provider::is_supported()) return; - ctx::context_provider_info provider_info(provider::create, provider::destroy, NULL, privilege); - ctx::context_manager::register_provider(subject, provider_info); + ctx::ContextProviderInfo providerInfo(provider::create, provider::destroy, NULL, privilege); + ctx::context_manager::registerProvider(subject, providerInfo); } EXTAPI bool ctx::init_place_context_provider() { #ifdef _MOBILE_ - register_provider(PLACE_SUBJ_GEOFENCE, PLACE_PRIV_GEOFENCE); + registerProvider(PLACE_SUBJ_GEOFENCE, PLACE_PRIV_GEOFENCE); place_geofence_provider::submit_trigger_item(); #ifndef _DISABLE_RECOG_ENGINE_ place_recognition_provider::create(NULL); - register_provider(PLACE_SUBJ_RECOGNITION, PLACE_PRIV_RECOGNITION); + registerProvider(PLACE_SUBJ_RECOGNITION, PLACE_PRIV_RECOGNITION); #endif /* _DISABLE_RECOG_ENGINE_ */ #endif /* _MOBILE_ */ diff --git a/src/place/recognition/place_recognition.cpp b/src/place/recognition/place_recognition.cpp index 9cdd6f6..0b1b790 100644 --- a/src/place/recognition/place_recognition.cpp +++ b/src/place/recognition/place_recognition.cpp @@ -15,13 +15,13 @@ */ #include -#include +#include #include "place_recognition.h" #include "user_places/user_places.h" ctx::place_recognition_provider *ctx::place_recognition_provider::__instance = NULL; -ctx::context_provider_iface *ctx::place_recognition_provider::create(void *data) +ctx::ContextProviderBase *ctx::place_recognition_provider::create(void *data) { IF_FAIL_RETURN(!__instance, __instance); __instance = new(std::nothrow) place_recognition_provider(); @@ -38,7 +38,7 @@ void ctx::place_recognition_provider::destroy(void *data) _I(BLUE("Destroyed")); } -int ctx::place_recognition_provider::subscribe(const char *subject, ctx::Json option, ctx::Json* request_result) +int ctx::place_recognition_provider::subscribe(const char *subject, ctx::Json option, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } @@ -48,25 +48,25 @@ int ctx::place_recognition_provider::unsubscribe(const char *subject, ctx::Json return ERR_NOT_SUPPORTED; } -int ctx::place_recognition_provider::read(const char *subject, ctx::Json option, ctx::Json* request_result) +int ctx::place_recognition_provider::read(const char *subject, ctx::Json option, ctx::Json* requestResult) { _I(BLUE("Read")); _J("Option", option); std::vector> places = engine.get_places(); - Json data_read = UserPlaces::compose_json(places); + Json dataRead = UserPlaces::compose_json(places); // The below function needs to be called once. // It does not need to be called within this read() function. // In can be called later, in another scope. // Please just be sure that, the 2nd input parameter "option" should be the same to the // "option" parameter received via ctx::place_recognition_provider::read(). - ctx::context_manager::reply_to_read(PLACE_SUBJ_RECOGNITION, option, ERR_NONE, data_read); + ctx::context_manager::replyToRead(PLACE_SUBJ_RECOGNITION, option, ERR_NONE, dataRead); return ERR_NONE; } -int ctx::place_recognition_provider::write(const char *subject, ctx::Json data, ctx::Json* request_result) +int ctx::place_recognition_provider::write(const char *subject, ctx::Json data, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } diff --git a/src/place/recognition/place_recognition.h b/src/place/recognition/place_recognition.h index 8f25424..40a93ec 100644 --- a/src/place/recognition/place_recognition.h +++ b/src/place/recognition/place_recognition.h @@ -17,23 +17,23 @@ #ifndef __CONTEXT_PLACE_RECOGNITION_H__ #define __CONTEXT_PLACE_RECOGNITION_H__ -#include +#include #include "place_recognition_types.h" #include "user_places/user_places.h" namespace ctx { - class place_recognition_provider : public context_provider_iface { + class place_recognition_provider : public ContextProviderBase { public: - static context_provider_iface *create(void *data); + static ContextProviderBase *create(void *data); static void destroy(void *data); static bool is_supported(); - int subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + 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 *request_result); - int write(const char *subject, ctx::Json data, ctx::Json *request_result); + int read(const char *subject, ctx::Json option, ctx::Json *requestResult); + int write(const char *subject, ctx::Json data, ctx::Json *requestResult); private: static place_recognition_provider *__instance; diff --git a/src/statistics/app/app_stats_provider.cpp b/src/statistics/app/app_stats_provider.cpp index cdb53f4..d924034 100644 --- a/src/statistics/app/app_stats_provider.cpp +++ b/src/statistics/app/app_stats_provider.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "app_stats_provider.h" #include "db_handle.h" @@ -41,7 +41,7 @@ ctx::app_statistics_provider::~app_statistics_provider() launch_mon = NULL; } -ctx::context_provider_iface *ctx::app_statistics_provider::create(void *data) +ctx::ContextProviderBase *ctx::app_statistics_provider::create(void *data) { IF_FAIL_RETURN(!__instance, __instance); @@ -72,7 +72,7 @@ bool ctx::app_statistics_provider::is_supported(const char* subject) void ctx::app_statistics_provider::submit_trigger_item() { - context_manager::register_trigger_item(APP_SUBJ_FREQUENCY, OPS_READ, + context_manager::registerTriggerItem(APP_SUBJ_FREQUENCY, OPS_READ, "{" TRIG_DEF_RANK "," TRIG_DEF_TOTAL_COUNT "}", "{" "\"AppId\":{\"type\":\"string\"}," @@ -98,7 +98,7 @@ CATCH: return false; } -int ctx::app_statistics_provider::subscribe(const char* subject, ctx::Json option, ctx::Json* request_result) +int ctx::app_statistics_provider::subscribe(const char* subject, ctx::Json option, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } @@ -108,7 +108,7 @@ int ctx::app_statistics_provider::unsubscribe(const char* subject, ctx::Json opt return ERR_NOT_SUPPORTED; } -int ctx::app_statistics_provider::read(const char* subject, ctx::Json option, ctx::Json* request_result) +int ctx::app_statistics_provider::read(const char* subject, ctx::Json option, ctx::Json* requestResult) { ctx::app_db_handle *handle = new(std::nothrow) ctx::app_db_handle(); IF_FAIL_RETURN_TAG(handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); @@ -122,7 +122,7 @@ int ctx::app_statistics_provider::read(const char* subject, ctx::Json option, ct return ERR_NONE; } -int ctx::app_statistics_provider::write(const char* subject, ctx::Json data, ctx::Json* request_result) +int ctx::app_statistics_provider::write(const char* subject, ctx::Json data, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } diff --git a/src/statistics/app/app_stats_provider.h b/src/statistics/app/app_stats_provider.h index 7735fd2..b224d77 100644 --- a/src/statistics/app/app_stats_provider.h +++ b/src/statistics/app/app_stats_provider.h @@ -17,22 +17,22 @@ #ifndef __CONTEXT_APP_STATS_PROVIDER_H__ #define __CONTEXT_APP_STATS_PROVIDER_H__ -#include +#include #include "app_stats_types.h" namespace ctx { - class app_statistics_provider : public context_provider_iface { + class app_statistics_provider : public ContextProviderBase { public: - static context_provider_iface *create(void *data); + static ContextProviderBase *create(void *data); static void destroy(void *data); static bool is_supported(const char *subject); static void submit_trigger_item(); - int subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + 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 *request_result); - int write(const char *subject, ctx::Json data, ctx::Json *request_result); + int read(const char *subject, ctx::Json option, ctx::Json *requestResult); + int write(const char *subject, ctx::Json data, ctx::Json *requestResult); private: static app_statistics_provider *__instance; diff --git a/src/statistics/app/db_handle.cpp b/src/statistics/app/db_handle.cpp index d293ed4..fdabb05 100644 --- a/src/statistics/app/db_handle.cpp +++ b/src/statistics/app/db_handle.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include "app_stats_types.h" #include "db_handle.h" @@ -214,5 +214,5 @@ void ctx::app_db_handle::reply_trigger_item(int error, ctx::Json &json_result) json_result.get(NULL, STATS_RANK, &val); results.set(NULL, STATS_RANK, val); - context_manager::reply_to_read(req_subject.c_str(), req_filter, error, results); + context_manager::replyToRead(req_subject.c_str(), req_filter, error, results); } diff --git a/src/statistics/media/db_handle.cpp b/src/statistics/media/db_handle.cpp index bc74429..81a1d80 100644 --- a/src/statistics/media/db_handle.cpp +++ b/src/statistics/media/db_handle.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include "../shared/system_info.h" #include "media_stats_types.h" @@ -120,5 +120,5 @@ void ctx::media_db_handle::reply_trigger_item(int error, ctx::Json &json_result) json_result.get(NULL, STATS_TOTAL_COUNT, &val); results.set(NULL, STATS_TOTAL_COUNT, val); - context_manager::reply_to_read(req_subject.c_str(), req_filter, error, results); + context_manager::replyToRead(req_subject.c_str(), req_filter, error, results); } diff --git a/src/statistics/media/media_stats_provider.cpp b/src/statistics/media/media_stats_provider.cpp index e68fe6b..feac914 100644 --- a/src/statistics/media/media_stats_provider.cpp +++ b/src/statistics/media/media_stats_provider.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "media_stats_provider.h" #include "db_handle.h" #include "media_content_monitor.h" @@ -35,7 +35,7 @@ ctx::media_statistics_provider::~media_statistics_provider() content_mon = NULL; } -ctx::context_provider_iface *ctx::media_statistics_provider::create(void *data) +ctx::ContextProviderBase *ctx::media_statistics_provider::create(void *data) { IF_FAIL_RETURN(!__instance, __instance); @@ -67,11 +67,11 @@ bool ctx::media_statistics_provider::is_supported(const char* subject) void ctx::media_statistics_provider::submit_trigger_item() { - context_manager::register_trigger_item(MEDIA_SUBJ_MUSIC_FREQUENCY, OPS_READ, + 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::register_trigger_item(MEDIA_SUBJ_VIDEO_FREQUENCY, OPS_READ, + context_manager::registerTriggerItem(MEDIA_SUBJ_VIDEO_FREQUENCY, OPS_READ, "{" TRIG_DEF_TOTAL_COUNT "}", "{" TRIG_DEF_TIME_OF_DAY "," TRIG_DEF_DAY_OF_WEEK "}"); } @@ -83,7 +83,7 @@ bool ctx::media_statistics_provider::init() return true; } -int ctx::media_statistics_provider::subscribe(const char* subject, ctx::Json option, ctx::Json* request_result) +int ctx::media_statistics_provider::subscribe(const char* subject, ctx::Json option, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } @@ -93,7 +93,7 @@ int ctx::media_statistics_provider::unsubscribe(const char* subject, ctx::Json o return ERR_NOT_SUPPORTED; } -int ctx::media_statistics_provider::read(const char* subject, ctx::Json option, ctx::Json* request_result) +int ctx::media_statistics_provider::read(const char* subject, ctx::Json option, ctx::Json* requestResult) { media_db_handle *handle = new(std::nothrow) media_db_handle(); IF_FAIL_RETURN_TAG(handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); @@ -107,7 +107,7 @@ int ctx::media_statistics_provider::read(const char* subject, ctx::Json option, return ERR_NONE; } -int ctx::media_statistics_provider::write(const char* subject, ctx::Json data, ctx::Json* request_result) +int ctx::media_statistics_provider::write(const char* subject, ctx::Json data, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } diff --git a/src/statistics/media/media_stats_provider.h b/src/statistics/media/media_stats_provider.h index 72bb198..ff695c6 100644 --- a/src/statistics/media/media_stats_provider.h +++ b/src/statistics/media/media_stats_provider.h @@ -17,22 +17,22 @@ #ifndef __CONTEXT_MEDIA_STATS_PROVIDER_H__ #define __CONTEXT_MEDIA_STATS_PROVIDER_H__ -#include +#include #include "media_stats_types.h" namespace ctx { - class media_statistics_provider : public context_provider_iface { + class media_statistics_provider : public ContextProviderBase { public: - static context_provider_iface *create(void *data); + static ContextProviderBase *create(void *data); static void destroy(void *data); static bool is_supported(const char *subject); static void submit_trigger_item(); - int subscribe(const char* subject, ctx::Json option, ctx::Json* request_result); + 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* request_result); - int write(const char* subject, ctx::Json data, ctx::Json* request_result); + int read(const char* subject, ctx::Json option, ctx::Json* requestResult); + int write(const char* subject, ctx::Json data, ctx::Json* requestResult); private: static media_statistics_provider *__instance; diff --git a/src/statistics/shared/db_handle_base.cpp b/src/statistics/shared/db_handle_base.cpp index f525b3d..159c5ca 100644 --- a/src/statistics/shared/db_handle_base.cpp +++ b/src/statistics/shared/db_handle_base.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include "common_types.h" #include "db_handle_base.h" @@ -215,12 +215,12 @@ void ctx::stats_db_handle_base::on_query_result_received(unsigned int query_id, } else { _E("Invalid query result"); Json dummy; - context_manager::reply_to_read(req_subject.c_str(), req_filter, ERR_OPERATION_FAILED, dummy); + context_manager::replyToRead(req_subject.c_str(), req_filter, ERR_OPERATION_FAILED, dummy); } } else { Json results = "{\"" STATS_QUERY_RESULT "\":[]}"; json_vector_to_array(records, results); - context_manager::reply_to_read(req_subject.c_str(), req_filter, error, results); + context_manager::replyToRead(req_subject.c_str(), req_filter, error, results); } delete this; diff --git a/src/statistics/social/db_handle.cpp b/src/statistics/social/db_handle.cpp index a42e625..1199a32 100644 --- a/src/statistics/social/db_handle.cpp +++ b/src/statistics/social/db_handle.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include "social_stats_types.h" #include "db_handle.h" @@ -158,5 +158,5 @@ void ctx::social_db_handle::reply_trigger_item(int error, ctx::Json &json_result json_result.get(NULL, STATS_RANK, &val); results.set(NULL, STATS_RANK, val); - context_manager::reply_to_read(req_subject.c_str(), req_filter, error, results); + context_manager::replyToRead(req_subject.c_str(), req_filter, error, results); } diff --git a/src/statistics/social/social_stats_provider.cpp b/src/statistics/social/social_stats_provider.cpp index 90aa35b..196b11e 100644 --- a/src/statistics/social/social_stats_provider.cpp +++ b/src/statistics/social/social_stats_provider.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "social_stats_provider.h" #include "db_handle.h" #include "log_aggregator.h" @@ -34,7 +34,7 @@ ctx::social_statistics_provider::~social_statistics_provider() delete aggregator; } -ctx::context_provider_iface *ctx::social_statistics_provider::create(void *data) +ctx::ContextProviderBase *ctx::social_statistics_provider::create(void *data) { IF_FAIL_RETURN(!__instance, __instance); @@ -66,7 +66,7 @@ bool ctx::social_statistics_provider::is_supported(const char* subject) void ctx::social_statistics_provider::submit_trigger_item() { - context_manager::register_trigger_item(SOCIAL_SUBJ_FREQUENCY, OPS_READ, + context_manager::registerTriggerItem(SOCIAL_SUBJ_FREQUENCY, OPS_READ, "{" TRIG_DEF_RANK "," TRIG_DEF_TOTAL_COUNT "}", "{" "\"Address\":{\"type\":\"string\"}," @@ -81,7 +81,7 @@ bool ctx::social_statistics_provider::init() return true; } -int ctx::social_statistics_provider::subscribe(const char* subject, ctx::Json option, ctx::Json* request_result) +int ctx::social_statistics_provider::subscribe(const char* subject, ctx::Json option, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } @@ -91,7 +91,7 @@ int ctx::social_statistics_provider::unsubscribe(const char* subject, ctx::Json return ERR_NOT_SUPPORTED; } -int ctx::social_statistics_provider::read(const char* subject, ctx::Json option, ctx::Json* request_result) +int ctx::social_statistics_provider::read(const char* subject, ctx::Json option, ctx::Json* requestResult) { ctx::social_db_handle *handle = new(std::nothrow) ctx::social_db_handle(); IF_FAIL_RETURN_TAG(handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); @@ -105,7 +105,7 @@ int ctx::social_statistics_provider::read(const char* subject, ctx::Json option, return ERR_NONE; } -int ctx::social_statistics_provider::write(const char* subject, ctx::Json data, ctx::Json* request_result) +int ctx::social_statistics_provider::write(const char* subject, ctx::Json data, ctx::Json* requestResult) { return ERR_NOT_SUPPORTED; } diff --git a/src/statistics/social/social_stats_provider.h b/src/statistics/social/social_stats_provider.h index 7ba803d..1666b78 100644 --- a/src/statistics/social/social_stats_provider.h +++ b/src/statistics/social/social_stats_provider.h @@ -17,22 +17,22 @@ #ifndef __CONTEXT_SOCIAL_STATS_PROVIDER_H__ #define __CONTEXT_SOCIAL_STATS_PROVIDER_H__ -#include +#include #include "social_stats_types.h" namespace ctx { - class social_statistics_provider : public context_provider_iface { + class social_statistics_provider : public ContextProviderBase { public: - static context_provider_iface *create(void *data); + static ContextProviderBase *create(void *data); static void destroy(void *data); static bool is_supported(const char *subject); static void submit_trigger_item(); - int subscribe(const char* subject, ctx::Json option, ctx::Json* request_result); + 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* request_result); - int write(const char* subject, ctx::Json data, ctx::Json* request_result); + int read(const char* subject, ctx::Json option, ctx::Json* requestResult); + int write(const char* subject, ctx::Json data, ctx::Json* requestResult); private: static social_statistics_provider *__instance; diff --git a/src/statistics/statistics_context_provider.cpp b/src/statistics/statistics_context_provider.cpp index 13e9c40..2d305eb 100644 --- a/src/statistics/statistics_context_provider.cpp +++ b/src/statistics/statistics_context_provider.cpp @@ -14,8 +14,8 @@ */ #include -#include -#include +#include +#include #include #include "app/app_stats_provider.h" @@ -34,24 +34,24 @@ #endif template -void register_provider(const char *subject, const char *privilege) +void registerProvider(const char *subject, const char *privilege) { if (!provider::is_supported(subject)) return; - ctx::context_provider_info provider_info(provider::create, provider::destroy, NULL, privilege); - ctx::context_manager::register_provider(subject, provider_info); + ctx::ContextProviderInfo providerInfo(provider::create, provider::destroy, NULL, privilege); + ctx::context_manager::registerProvider(subject, providerInfo); } EXTAPI bool ctx::init_statistics_context_provider() { app_statistics_provider::create(NULL); - register_provider(APP_SUBJ_RECENTLY_USED, APP_HISTORY_PRIV); - register_provider(APP_SUBJ_FREQUENTLY_USED, APP_HISTORY_PRIV); - register_provider(APP_SUBJ_RARELY_USED, APP_HISTORY_PRIV); - register_provider(APP_SUBJ_PEAK_TIME, APP_HISTORY_PRIV); - register_provider(APP_SUBJ_COMMON_SETTING, APP_HISTORY_PRIV); - register_provider(APP_SUBJ_FREQUENCY, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_RECENTLY_USED, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_FREQUENTLY_USED, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_RARELY_USED, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_PEAK_TIME, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_COMMON_SETTING, APP_HISTORY_PRIV); + registerProvider(APP_SUBJ_FREQUENCY, APP_HISTORY_PRIV); app_statistics_provider::submit_trigger_item(); #ifndef _DISABLE_PREDICTION_ENGINE_ @@ -60,28 +60,28 @@ EXTAPI bool ctx::init_statistics_context_provider() #ifdef _MOBILE_ media_statistics_provider::create(NULL); - register_provider(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC, MEDIA_HISTORY_PRIV); - register_provider(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO, MEDIA_HISTORY_PRIV); - register_provider(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC, MEDIA_HISTORY_PRIV); - register_provider(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO, MEDIA_HISTORY_PRIV); - register_provider(MEDIA_SUBJ_MUSIC_FREQUENCY, MEDIA_HISTORY_PRIV); - register_provider(MEDIA_SUBJ_VIDEO_FREQUENCY, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_MUSIC_FREQUENCY, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_VIDEO_FREQUENCY, MEDIA_HISTORY_PRIV); media_statistics_provider::submit_trigger_item(); social_statistics_provider::create(NULL); - register_provider(SOCIAL_SUBJ_FREQ_ADDRESS, SOCIAL_HISTORY_PRIV); - register_provider(SOCIAL_SUBJ_FREQUENCY, SOCIAL_HISTORY_PRIV); + registerProvider(SOCIAL_SUBJ_FREQ_ADDRESS, SOCIAL_HISTORY_PRIV); + registerProvider(SOCIAL_SUBJ_FREQUENCY, SOCIAL_HISTORY_PRIV); social_statistics_provider::submit_trigger_item(); #endif #ifdef _TV_ media_statistics_provider::create(NULL); - register_provider(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC, MEDIA_HISTORY_PRIV); - register_provider(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO, MEDIA_HISTORY_PRIV); - register_provider(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC, MEDIA_HISTORY_PRIV); - register_provider(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO, MEDIA_HISTORY_PRIV); - register_provider(MEDIA_SUBJ_MUSIC_FREQUENCY, MEDIA_HISTORY_PRIV); - register_provider(MEDIA_SUBJ_VIDEO_FREQUENCY, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_PEAK_TIME_FOR_VIDEO, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_MUSIC, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_COMMON_SETTING_FOR_VIDEO, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_MUSIC_FREQUENCY, MEDIA_HISTORY_PRIV); + registerProvider(MEDIA_SUBJ_VIDEO_FREQUENCY, MEDIA_HISTORY_PRIV); media_statistics_provider::submit_trigger_item(); #endif -- 2.7.4 From 644deafe405a7b068c9c9709e22ce50e579b8acc Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 4 Apr 2016 17:25:29 +0900 Subject: [PATCH 11/16] Build a static library, instead of a shared object The library is only being used by contextd, thus it does not need to be a shared object. Change-Id: I0dd3acd582070b946053f87b54f924288c75b8a9 Signed-off-by: Mu-Woong Lee --- CMakeLists.txt | 5 +++-- packaging/context-provider.spec | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff1cbd9..42e2659 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,8 @@ SET(compile_defs "LOG_TAG=\"CONTEXT\"") INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include ) -ADD_DEFINITIONS(-O2 -Wall -fPIC -fvisibility=hidden -Wl,--as-needed) +ADD_DEFINITIONS(-O2 -Wall -fPIC -fdata-sections -ffunction-sections -fvisibility=hidden) +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIC -Wl,--as-needed -Wl,--gc-section -Wl,--print-gc-section") # Base Dependency SET(dependencies libcontext-shared libcontext-server) @@ -38,7 +39,7 @@ FOREACH(flag ${DEPS_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -ADD_LIBRARY(${target} SHARED ${sources}) +ADD_LIBRARY(${target} STATIC ${sources}) TARGET_LINK_LIBRARIES(${target} ${DEPS_LDFLAGS}) SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS}) SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_DEFINITIONS "${compile_defs}") diff --git a/packaging/context-provider.spec b/packaging/context-provider.spec index cb86c92..3ddb5eb 100644 --- a/packaging/context-provider.spec +++ b/packaging/context-provider.spec @@ -7,6 +7,7 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz %define BUILD_PROFILE %{?profile}%{!?profile:%{?tizen_profile_name}} +%define keepstatic 1 BuildRequires: cmake @@ -64,8 +65,8 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` export CFLAGS+=" -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-parameter" export CXXFLAGS+=" -Wextra -Wcast-align -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-parameter" -export CFLAGS+=" -Wno-empty-body -fno-omit-frame-pointer -fno-optimize-sibling-calls" -export CXXFLAGS+=" -Wno-empty-body -fno-omit-frame-pointer -fno-optimize-sibling-calls" +export CFLAGS+=" -Wno-empty-body -fomit-frame-pointer -fno-optimize-sibling-calls" +export CXXFLAGS+=" -Wno-empty-body -fomit-frame-pointer -fno-optimize-sibling-calls" export CFLAGS+=" -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow" export CXXFLAGS+=" -fno-strict-aliasing -fno-unroll-loops -fsigned-char -fstrict-overflow" @@ -100,7 +101,6 @@ cp LICENSE %{buildroot}/usr/share/license/%{name} %files %manifest packaging/%{name}.manifest %defattr(-,root,root,-) -%{_libdir}/*.so* /usr/share/license/%{name} %package devel @@ -115,3 +115,4 @@ Context Provider (Development) %defattr(-,root,root,-) %{_includedir}/context-service/internal/*.h %{_libdir}/pkgconfig/%{name}.pc +%{_libdir}/*.a -- 2.7.4 From 25989911010af46f8f943ed765cffca412ab4afd Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Wed, 6 Apr 2016 11:17:31 +0900 Subject: [PATCH 12/16] Applying Tizen C++ coding style to provider initialization Change-Id: Icb44282ca2adf5309471e11ef93198ed6220a082 Signed-off-by: Somin Kim --- ..._context_provider.h => CustomContextProvider.h} | 26 +++++++++++++--------- ..._context_provider.h => DeviceContextProvider.h} | 12 +++++----- ...e_context_provider.h => PlaceContextProvider.h} | 12 +++++----- ...text_provider.h => StatisticsContextProvider.h} | 12 +++++----- src/custom/custom_context_provider.cpp | 4 ++-- src/device/device_context_provider.cpp | 4 ++-- src/place/place_context_provider.cpp | 4 ++-- src/statistics/statistics_context_provider.cpp | 4 ++-- 8 files changed, 44 insertions(+), 34 deletions(-) rename include/{custom_context_provider.h => CustomContextProvider.h} (56%) rename include/{place_context_provider.h => DeviceContextProvider.h} (75%) rename include/{device_context_provider.h => PlaceContextProvider.h} (76%) rename include/{statistics_context_provider.h => StatisticsContextProvider.h} (74%) diff --git a/include/custom_context_provider.h b/include/CustomContextProvider.h similarity index 56% rename from include/custom_context_provider.h rename to include/CustomContextProvider.h index 918dfa6..c75d63e 100644 --- a/include/custom_context_provider.h +++ b/include/CustomContextProvider.h @@ -14,20 +14,24 @@ * limitations under the License. */ -#ifndef __CONTEXT_CUSTOM_CONTEXT_PROVIDER_H__ -#define __CONTEXT_CUSTOM_CONTEXT_PROVIDER_H__ +#ifndef _CONTEXT_CUSTOM_CONTEXT_PROVIDER_H_ +#define _CONTEXT_CUSTOM_CONTEXT_PROVIDER_H_ namespace ctx { - bool init_custom_context_provider(); + + bool initCustomContextProvider(); namespace custom_context_provider { - int addItem(std::string subject, std::string name, ctx::Json tmpl, const char* owner, bool is_init = false); - int removeItem(std::string subject); - int publishData(std::string subject, ctx::Json fact); - ContextProviderBase* create(void* data); - void destroy(void* data); - } -} + int addItem(std::string subject, std::string name, ctx::Json tmpl, const char* owner, bool isInit = false); + int removeItem(std::string subject); + int publishData(std::string subject, ctx::Json fact); + + ContextProviderBase* create(void* data); + void destroy(void* data); + + } /* namespace custom_context_provider */ + +} /* namespace ctx */ -#endif //__CONTEXT_CUSTOM_CONTEXT_PROVIDER_H__ +#endif /* End of _CONTEXT_CUSTOM_CONTEXT_PROVIDER_H_ */ diff --git a/include/place_context_provider.h b/include/DeviceContextProvider.h similarity index 75% rename from include/place_context_provider.h rename to include/DeviceContextProvider.h index 407838b..1e47323 100644 --- a/include/place_context_provider.h +++ b/include/DeviceContextProvider.h @@ -14,11 +14,13 @@ * limitations under the License. */ -#ifndef __CONTEXT_PLACE_CONTEXT_PROVIDER_H__ -#define __CONTEXT_PLACE_CONTEXT_PROVIDER_H__ +#ifndef _CONTEXT_DEVICE_CONTEXT_PROVIDER_H_ +#define _CONTEXT_DEVICE_CONTEXT_PROVIDER_H_ namespace ctx { - bool init_place_context_provider(); -} -#endif /* __CONTEXT_PLACE_CONTEXT_PROVIDER_H__ */ + bool initDeviceContextProvider(); + +} /* namespace ctx */ + +#endif /* End of _CONTEXT_DEVICE_CONTEXT_PROVIDER_H_ */ diff --git a/include/device_context_provider.h b/include/PlaceContextProvider.h similarity index 76% rename from include/device_context_provider.h rename to include/PlaceContextProvider.h index 09ef1e7..e7585b0 100644 --- a/include/device_context_provider.h +++ b/include/PlaceContextProvider.h @@ -14,11 +14,13 @@ * limitations under the License. */ -#ifndef __CONTEXT_DEVICE_CONTEXT_PROVIDER_H__ -#define __CONTEXT_DEVICE_CONTEXT_PROVIDER_H__ +#ifndef _CONTEXT_PLACE_CONTEXT_PROVIDER_H_ +#define _CONTEXT_PLACE_CONTEXT_PROVIDER_H_ namespace ctx { - bool init_device_context_provider(); -} -#endif //__CONTEXT_DEVICE_CONTEXT_PROVIDER_H__ + bool initPlaceContextProvider(); + +} /* namespace ctx */ + +#endif /* End of _CONTEXT_PLACE_CONTEXT_PROVIDER_H_ */ diff --git a/include/statistics_context_provider.h b/include/StatisticsContextProvider.h similarity index 74% rename from include/statistics_context_provider.h rename to include/StatisticsContextProvider.h index b45c3fd..f356719 100644 --- a/include/statistics_context_provider.h +++ b/include/StatisticsContextProvider.h @@ -14,11 +14,13 @@ * limitations under the License. */ -#ifndef __CONTEXT_STATISTICS_CONTEXT_PROVIDER_H__ -#define __CONTEXT_STATISTICS_CONTEXT_PROVIDER_H__ +#ifndef _CONTEXT_STATISTICS_CONTEXT_PROVIDER_H_ +#define _CONTEXT_STATISTICS_CONTEXT_PROVIDER_H_ namespace ctx { - bool init_statistics_context_provider(); -} -#endif /* __CONTEXT_STATISTICS_CONTEXT_PROVIDER_H__ */ + bool initStatisticsContextProvider(); + +} /* namespace ctx */ + +#endif /* End of _CONTEXT_STATISTICS_CONTEXT_PROVIDER_H_ */ diff --git a/src/custom/custom_context_provider.cpp b/src/custom/custom_context_provider.cpp index 88aca00..5bec97e 100644 --- a/src/custom/custom_context_provider.cpp +++ b/src/custom/custom_context_provider.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include "custom_base.h" std::map custom_map; @@ -59,7 +59,7 @@ EXTAPI void ctx::custom_context_provider::destroy(void *data) } } -EXTAPI bool ctx::init_custom_context_provider() +EXTAPI bool ctx::initCustomContextProvider() { // Create custom template db std::string q = std::string("CREATE TABLE IF NOT EXISTS context_trigger_custom_template ") diff --git a/src/device/device_context_provider.cpp b/src/device/device_context_provider.cpp index 39fcf7d..1e42e20 100644 --- a/src/device/device_context_provider.cpp +++ b/src/device/device_context_provider.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include "system/system_types.h" #include "social/social_types.h" @@ -75,7 +75,7 @@ void registerProvider(const char *subject, const char *privilege) provider::submit_trigger_item(); } -EXTAPI bool ctx::init_device_context_provider() +EXTAPI bool ctx::initDeviceContextProvider() { registerProvider(DEVICE_ST_SUBJ_ALARM, NULL); registerProvider(DEVICE_ST_SUBJ_TIME, NULL); diff --git a/src/place/place_context_provider.cpp b/src/place/place_context_provider.cpp index 6bcf1c3..c3efaef 100644 --- a/src/place/place_context_provider.cpp +++ b/src/place/place_context_provider.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #ifdef _MOBILE_ #include "geofence/place_geofence.h" @@ -36,7 +36,7 @@ void registerProvider(const char *subject, const char *privilege) ctx::context_manager::registerProvider(subject, providerInfo); } -EXTAPI bool ctx::init_place_context_provider() +EXTAPI bool ctx::initPlaceContextProvider() { #ifdef _MOBILE_ registerProvider(PLACE_SUBJ_GEOFENCE, PLACE_PRIV_GEOFENCE); diff --git a/src/statistics/statistics_context_provider.cpp b/src/statistics/statistics_context_provider.cpp index 2d305eb..1fa29ee 100644 --- a/src/statistics/statistics_context_provider.cpp +++ b/src/statistics/statistics_context_provider.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "app/app_stats_provider.h" @@ -43,7 +43,7 @@ void registerProvider(const char *subject, const char *privilege) ctx::context_manager::registerProvider(subject, providerInfo); } -EXTAPI bool ctx::init_statistics_context_provider() +EXTAPI bool ctx::initStatisticsContextProvider() { app_statistics_provider::create(NULL); registerProvider(APP_SUBJ_RECENTLY_USED, APP_HISTORY_PRIV); -- 2.7.4 From ea563a7c8f713d6d8739c2437fe7ba873af3cfd7 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Tue, 5 Apr 2016 17:55:55 +0900 Subject: [PATCH 13/16] Applying Tizen C++ coding style to device context provider Change-Id: I1d3b75c1192f58facb200dee7f92062b9dbe7ba8 Signed-off-by: Somin Kim --- src/device/CMakeLists.txt | 6 +- src/device/DeviceContextProvider.cpp | 141 ++++++++++ ...ce_provider_base.cpp => DeviceProviderBase.cpp} | 42 +-- ...device_provider_base.h => DeviceProviderBase.h} | 22 +- src/device/activity/{activity.h => Activity.h} | 38 +-- .../{activity_base.cpp => ActivityBase.cpp} | 58 ++-- .../activity/{activity_base.h => ActivityBase.h} | 24 +- .../activity/{activity_types.h => ActivityTypes.h} | 6 +- src/device/device_context_provider.cpp | 141 ---------- src/device/social/{call.cpp => Call.cpp} | 155 ++++++----- src/device/social/Call.h | 58 ++++ src/device/social/{contacts.cpp => Contacts.cpp} | 70 ++--- src/device/social/{contacts.h => Contacts.h} | 28 +- src/device/social/{email.cpp => Email.cpp} | 44 +-- src/device/social/{email.h => Email.h} | 16 +- src/device/social/{message.cpp => Message.cpp} | 52 ++-- src/device/social/{message.h => Message.h} | 26 +- .../social/{social_types.h => SocialTypes.h} | 6 +- src/device/social/call.h | 58 ---- src/device/system/Alarm.cpp | 302 +++++++++++++++++++++ src/device/system/Alarm.h | 87 ++++++ src/device/system/{battery.cpp => Battery.cpp} | 78 +++--- src/device/system/{battery.h => Battery.h} | 26 +- src/device/system/Headphone.cpp | 238 ++++++++++++++++ src/device/system/Headphone.h | 65 +++++ src/device/system/{psmode.cpp => Psmode.cpp} | 32 +-- src/device/system/{psmode.h => Psmode.h} | 24 +- .../system/{system_types.h => SystemTypes.h} | 6 +- src/device/system/{time.cpp => Time.cpp} | 38 +-- src/device/system/{time.h => Time.h} | 20 +- src/device/system/Wifi.cpp | 266 ++++++++++++++++++ src/device/system/Wifi.h | 66 +++++ src/device/system/alarm.cpp | 302 --------------------- src/device/system/alarm.h | 88 ------ src/device/system/headphone.cpp | 238 ---------------- src/device/system/headphone.h | 65 ----- .../charger.cpp => runtime_info/Charger.cpp} | 32 +-- .../charger.h => runtime_info/Charger.h} | 24 +- .../{runtime-info/gps.cpp => runtime_info/Gps.cpp} | 48 ++-- .../{runtime-info/usb.h => runtime_info/Gps.h} | 24 +- .../RuntimeInfoBase.cpp} | 26 +- .../RuntimeInfoBase.h} | 22 +- .../{runtime-info/usb.cpp => runtime_info/Usb.cpp} | 22 +- .../{runtime-info/gps.h => runtime_info/Usb.h} | 24 +- src/device/system/wifi.cpp | 267 ------------------ src/device/system/wifi.h | 66 ----- 46 files changed, 1745 insertions(+), 1742 deletions(-) create mode 100644 src/device/DeviceContextProvider.cpp rename src/device/{device_provider_base.cpp => DeviceProviderBase.cpp} (55%) rename src/device/{device_provider_base.h => DeviceProviderBase.h} (83%) rename src/device/activity/{activity.h => Activity.h} (50%) rename src/device/activity/{activity_base.cpp => ActivityBase.cpp} (51%) rename src/device/activity/{activity_base.h => ActivityBase.h} (54%) rename src/device/activity/{activity_types.h => ActivityTypes.h} (89%) delete mode 100644 src/device/device_context_provider.cpp rename src/device/social/{call.cpp => Call.cpp} (64%) create mode 100644 src/device/social/Call.h rename src/device/social/{contacts.cpp => Contacts.cpp} (51%) rename src/device/social/{contacts.h => Contacts.h} (61%) rename src/device/social/{email.cpp => Email.cpp} (56%) rename src/device/social/{email.h => Email.h} (75%) rename src/device/social/{message.cpp => Message.cpp} (64%) rename src/device/social/{message.h => Message.h} (62%) rename src/device/social/{social_types.h => SocialTypes.h} (93%) delete mode 100644 src/device/social/call.h create mode 100644 src/device/system/Alarm.cpp create mode 100644 src/device/system/Alarm.h rename src/device/system/{battery.cpp => Battery.cpp} (54%) rename src/device/system/{battery.h => Battery.h} (56%) create mode 100644 src/device/system/Headphone.cpp create mode 100644 src/device/system/Headphone.h rename src/device/system/{psmode.cpp => Psmode.cpp} (66%) rename src/device/system/{psmode.h => Psmode.h} (58%) rename src/device/system/{system_types.h => SystemTypes.h} (94%) rename src/device/system/{time.cpp => Time.cpp} (57%) rename src/device/system/{time.h => Time.h} (66%) create mode 100644 src/device/system/Wifi.cpp create mode 100644 src/device/system/Wifi.h delete mode 100644 src/device/system/alarm.cpp delete mode 100644 src/device/system/alarm.h delete mode 100644 src/device/system/headphone.cpp delete mode 100644 src/device/system/headphone.h rename src/device/system/{runtime-info/charger.cpp => runtime_info/Charger.cpp} (64%) rename src/device/system/{runtime-info/charger.h => runtime_info/Charger.h} (61%) rename src/device/system/{runtime-info/gps.cpp => runtime_info/Gps.cpp} (63%) rename src/device/system/{runtime-info/usb.h => runtime_info/Gps.h} (63%) rename src/device/system/{runtime-info/base_rtinfo.cpp => runtime_info/RuntimeInfoBase.cpp} (53%) rename src/device/system/{runtime-info/base_rtinfo.h => runtime_info/RuntimeInfoBase.h} (59%) rename src/device/system/{runtime-info/usb.cpp => runtime_info/Usb.cpp} (76%) rename src/device/system/{runtime-info/gps.h => runtime_info/Usb.h} (63%) delete mode 100644 src/device/system/wifi.cpp delete mode 100644 src/device/system/wifi.h diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt index 22f35bc..20276e3 100644 --- a/src/device/CMakeLists.txt +++ b/src/device/CMakeLists.txt @@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) # prvd_cdef, prvd_deps, and prvd_srcs need to be set properly # Common Profile -FILE(GLOB prvd_srcs ./*.cpp system/alarm.cpp system/time.cpp) +FILE(GLOB prvd_srcs ./*.cpp system/Alarm.cpp system/Time.cpp) SET(prvd_deps vconf capi-system-info capi-system-device capi-system-runtime-info) # Mobile Profile @@ -20,11 +20,11 @@ IF("${PROFILE}" STREQUAL "wearable") SET(prvd_deps ${prvd_deps} capi-telephony tapi msg-service motion) FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} activity/*.cpp) FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} system/*.cpp) - FILE(GLOB prvd_srcs ${prvd_srcs} social/call.cpp social/message.cpp) + FILE(GLOB prvd_srcs ${prvd_srcs} social/Call.cpp social/Message.cpp) ENDIF("${PROFILE}" STREQUAL "wearable") # TV Profile IF("${PROFILE}" STREQUAL "tv") SET(prvd_deps ${prvd_deps} capi-network-bluetooth capi-network-wifi) - FILE(GLOB prvd_srcs ${prvd_srcs} system/headphone.cpp system/wifi.cpp) + FILE(GLOB prvd_srcs ${prvd_srcs} system/Headphone.cpp system/Wifi.cpp) ENDIF("${PROFILE}" STREQUAL "tv") diff --git a/src/device/DeviceContextProvider.cpp b/src/device/DeviceContextProvider.cpp new file mode 100644 index 0000000..b4c657e --- /dev/null +++ b/src/device/DeviceContextProvider.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "system/SystemTypes.h" +#include "social/SocialTypes.h" +#include "activity/ActivityTypes.h" + +#include "system/Alarm.h" +#include "system/Time.h" + +#ifdef _MOBILE_ +#include "system/runtime_info/Charger.h" +#include "system/runtime_info/Gps.h" +#include "system/runtime_info/Usb.h" +#include "system/Wifi.h" +#include "system/Headphone.h" +#include "system/Battery.h" +#include "system/Psmode.h" +#include "social/Call.h" +#include "social/Email.h" +#include "social/Message.h" +#include "social/Contacts.h" +#include "activity/Activity.h" +#endif + +#ifdef _WEARABLE_ +#include "system/runtime_info/Charger.h" +#include "system/runtime_info/Gps.h" +#include "system/runtime_info/Usb.h" +#include "system/Wifi.h" +#include "system/Headphone.h" +#include "system/Battery.h" +#include "system/Psmode.h" +#include "social/Call.h" +#include "social/Message.h" +#include "activity/Activity.h" +#endif + +#ifdef _TV_ +#include "system/Wifi.h" +#include "system/Headphone.h" +#endif + +#define PRIV_NETWORK "network.get" +#define PRIV_TELEPHONY "telephony" +#define PRIV_MESSAGE "message.read" +#define PRIV_CONTACT "contact.read" + +template +void registerProvider(const char *subject, const char *privilege) +{ + if (!Provider::isSupported()) + return; + + ctx::ContextProviderInfo providerInfo(Provider::create, Provider::destroy, NULL, privilege); + ctx::context_manager::registerProvider(subject, providerInfo); + Provider::submitTriggerItem(); +} + +EXTAPI bool ctx::initDeviceContextProvider() +{ + registerProvider(DEVICE_ST_SUBJ_ALARM, NULL); + registerProvider(DEVICE_ST_SUBJ_TIME, NULL); + +#ifdef _MOBILE_ + registerProvider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); + registerProvider(DEVICE_ST_SUBJ_HEADPHONE, NULL); + + registerProvider(DEVICE_ST_SUBJ_CHARGER, NULL); + registerProvider(DEVICE_ST_SUBJ_GPS, NULL); + registerProvider(DEVICE_ST_SUBJ_USB, NULL); + registerProvider(DEVICE_ST_SUBJ_BATTERY, NULL); + registerProvider(DEVICE_ST_SUBJ_PSMODE, NULL); + + registerProvider(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY); + registerProvider(SOCIAL_ST_SUBJ_EMAIL, NULL); + registerProvider(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE); + registerProvider(SOCIAL_ST_SUBJ_CONTACTS, PRIV_CONTACT); + + registerProvider(USER_ACT_SUBJ_STATIONARY, NULL); + registerProvider(USER_ACT_SUBJ_WALKING, NULL); + registerProvider(USER_ACT_SUBJ_RUNNING, NULL); + registerProvider(USER_ACT_SUBJ_IN_VEHICLE, NULL); + + /* Create context providers, which need to be initiated before being subscribed */ + if (DeviceStatusWifi::isSupported()) + DeviceStatusWifi::create(NULL); +#endif + +#ifdef _WEARABLE_ + registerProvider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); + registerProvider(DEVICE_ST_SUBJ_HEADPHONE, NULL); + + registerProvider(DEVICE_ST_SUBJ_CHARGER, NULL); + registerProvider(DEVICE_ST_SUBJ_GPS, NULL); + registerProvider(DEVICE_ST_SUBJ_USB, NULL); + registerProvider(DEVICE_ST_SUBJ_BATTERY, NULL); + registerProvider(DEVICE_ST_SUBJ_PSMODE, NULL); + + registerProvider(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY); + registerProvider(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE); + + registerProvider(USER_ACT_SUBJ_STATIONARY, NULL); + registerProvider(USER_ACT_SUBJ_WALKING, NULL); + registerProvider(USER_ACT_SUBJ_RUNNING, NULL); + registerProvider(USER_ACT_SUBJ_IN_VEHICLE, NULL); + + /* Create context providers, which need to be initiated before being subscribed */ + if (DeviceStatusWifi::isSupported()) + DeviceStatusWifi::create(NULL); +#endif + +#ifdef _TV_ + registerProvider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); + registerProvider(DEVICE_ST_SUBJ_HEADPHONE, NULL); + + /* Create context providers, which need to be initiated before being subscribed */ + if (DeviceStatusWifi::isSupported()) + DeviceStatusWifi::create(NULL); +#endif + + return true; +} diff --git a/src/device/device_provider_base.cpp b/src/device/DeviceProviderBase.cpp similarity index 55% rename from src/device/device_provider_base.cpp rename to src/device/DeviceProviderBase.cpp index 95f3988..b3aab6e 100644 --- a/src/device/device_provider_base.cpp +++ b/src/device/DeviceProviderBase.cpp @@ -15,79 +15,79 @@ */ #include -#include "device_provider_base.h" +#include "DeviceProviderBase.h" -ctx::device_provider_base::device_provider_base() - : being_subscribed(false) +ctx::DeviceProviderBase::DeviceProviderBase() + : __beingSubscribed(false) { } -int ctx::device_provider_base::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) +int ctx::DeviceProviderBase::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) { - IF_FAIL_RETURN(!being_subscribed, ERR_NONE); + IF_FAIL_RETURN(!__beingSubscribed, ERR_NONE); int ret = subscribe(); if (ret == ERR_NONE) - being_subscribed = true; + __beingSubscribed = true; else - destroy_self(); + destroySelf(); return ret; } -int ctx::device_provider_base::unsubscribe(const char *subject, ctx::Json option) +int ctx::DeviceProviderBase::unsubscribe(const char *subject, ctx::Json option) { int ret = ERR_NONE; - if (being_subscribed) + if (__beingSubscribed) ret = unsubscribe(); - destroy_self(); + destroySelf(); return ret; } -int ctx::device_provider_base::read(const char *subject, ctx::Json option, ctx::Json *requestResult) +int ctx::DeviceProviderBase::read(const char *subject, ctx::Json option, ctx::Json *requestResult) { int ret = read(); - if (!being_subscribed) - destroy_self(); + if (!__beingSubscribed) + destroySelf(); return ret; } -int ctx::device_provider_base::write(const char *subject, ctx::Json data, ctx::Json *requestResult) +int ctx::DeviceProviderBase::write(const char *subject, ctx::Json data, ctx::Json *requestResult) { int ret = write(); - if (!being_subscribed) - destroy_self(); + if (!__beingSubscribed) + destroySelf(); return ret; } -int ctx::device_provider_base::subscribe() +int ctx::DeviceProviderBase::subscribe() { return ERR_NOT_SUPPORTED; } -int ctx::device_provider_base::unsubscribe() +int ctx::DeviceProviderBase::unsubscribe() { return ERR_NOT_SUPPORTED; } -int ctx::device_provider_base::read() +int ctx::DeviceProviderBase::read() { return ERR_NOT_SUPPORTED; } -int ctx::device_provider_base::write() +int ctx::DeviceProviderBase::write() { return ERR_NOT_SUPPORTED; } -bool ctx::device_provider_base::get_system_info_bool(const char *key) +bool ctx::DeviceProviderBase::getSystemInfoBool(const char *key) { bool supported = false; int ret = system_info_get_platform_bool(key, &supported); diff --git a/src/device/device_provider_base.h b/src/device/DeviceProviderBase.h similarity index 83% rename from src/device/device_provider_base.h rename to src/device/DeviceProviderBase.h index 6b2c1a9..3d81233 100644 --- a/src/device/device_provider_base.h +++ b/src/device/DeviceProviderBase.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __CONTEXT_DEVICE_PROVIDER_BASE_H__ -#define __CONTEXT_DEVICE_PROVIDER_BASE_H__ +#ifndef _CONTEXT_DEVICE_PROVIDER_BASE_H_ +#define _CONTEXT_DEVICE_PROVIDER_BASE_H_ #include #include @@ -43,7 +43,7 @@ static ContextProviderBase *create(void *data); \ static void destroy(void *data); \ protected: \ - void destroy_self(); \ + void destroySelf(); \ private: \ static prvd *__instance; \ @@ -57,14 +57,14 @@ { \ DESTROY_INSTANCE(); \ } \ - void ctx::prvd::destroy_self() \ + void ctx::prvd::destroySelf() \ { \ destroy(NULL); \ } \ namespace ctx { - class device_provider_base : public ContextProviderBase { + class DeviceProviderBase : public ContextProviderBase { public: int subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult); int unsubscribe(const char *subject, ctx::Json option); @@ -72,19 +72,19 @@ namespace ctx { int write(const char *subject, ctx::Json data, ctx::Json *requestResult); protected: - bool being_subscribed; + bool __beingSubscribed; - device_provider_base(); - virtual ~device_provider_base() {} + DeviceProviderBase(); + virtual ~DeviceProviderBase() {} virtual int subscribe(); virtual int unsubscribe(); virtual int read(); virtual int write(); - virtual void destroy_self() = 0; + virtual void destroySelf() = 0; - static bool get_system_info_bool(const char *key); + static bool getSystemInfoBool(const char *key); }; } -#endif +#endif // _CONTEXT_DEVICE_PROVIDER_BASE_H_ diff --git a/src/device/activity/activity.h b/src/device/activity/Activity.h similarity index 50% rename from src/device/activity/activity.h rename to src/device/activity/Activity.h index 2f44267..b7bf49e 100644 --- a/src/device/activity/activity.h +++ b/src/device/activity/Activity.h @@ -14,50 +14,50 @@ * limitations under the License. */ -#ifndef _DEVICE_STATUS_ACTIVITY_H_ -#define _DEVICE_STATUS_ACTIVITY_H_ +#ifndef _DEVICE_ACTIVITY_STATUS_H_ +#define _DEVICE_ACTIVITY_STATUS_H_ #include -#include "activity_base.h" +#include "ActivityBase.h" -#define GENERATE_ACTIVITY_PROVIDER(act_prvd, act_subj, act_type) \ - class act_prvd : public user_activity_base { \ +#define GENERATE_ACTIVITY_PROVIDER(actPrvd, actSubj, actType) \ + class actPrvd : public UserActivityBase { \ public: \ static ContextProviderBase *create(void *data) \ { \ - CREATE_INSTANCE(ctx::act_prvd); \ + CREATE_INSTANCE(ctx::actPrvd); \ } \ static void destroy(void *data) \ { \ DESTROY_INSTANCE(); \ } \ - static bool is_supported() \ + static bool isSupported() \ { \ - return get_system_info_bool("tizen.org/feature/sensor.activity_recognition"); \ + return getSystemInfoBool("tizen.org/feature/sensor.activity_recognition"); \ } \ - static void submit_trigger_item() \ + static void submitTriggerItem() \ { \ - context_manager::registerTriggerItem((act_subj), OPS_SUBSCRIBE, \ + context_manager::registerTriggerItem((actSubj), OPS_SUBSCRIBE, \ "{\"Event\":{\"type\":\"string\", \"values\":[\"Detected\"]}}", \ "{\"Accuracy\":{\"type\":\"string\", \"values\":[\"Low\", \"Normal\", \"High\"]}}" \ ); \ } \ protected: \ - void destroy_self() \ + void destroySelf() \ { \ destroy(NULL); \ } \ private: \ - static act_prvd *__instance; \ - act_prvd() : user_activity_base((act_subj), (act_type)) {} \ + static actPrvd *__instance; \ + actPrvd() : UserActivityBase((actSubj), (actType)) {} \ }; \ - ctx::act_prvd *ctx::act_prvd::__instance = NULL; \ + ctx::actPrvd *ctx::actPrvd::__instance = NULL; \ namespace ctx { - GENERATE_ACTIVITY_PROVIDER(user_activity_stationary, USER_ACT_SUBJ_STATIONARY, ACTIVITY_STATIONARY); - GENERATE_ACTIVITY_PROVIDER(user_activity_walking, USER_ACT_SUBJ_WALKING, ACTIVITY_WALK); - GENERATE_ACTIVITY_PROVIDER(user_activity_running, USER_ACT_SUBJ_RUNNING, ACTIVITY_RUN); - GENERATE_ACTIVITY_PROVIDER(user_activity_in_vehicle, USER_ACT_SUBJ_IN_VEHICLE, ACTIVITY_IN_VEHICLE); + GENERATE_ACTIVITY_PROVIDER(UserActivityStationary, USER_ACT_SUBJ_STATIONARY, ACTIVITY_STATIONARY); + GENERATE_ACTIVITY_PROVIDER(UserActivityWalking, USER_ACT_SUBJ_WALKING, ACTIVITY_WALK); + GENERATE_ACTIVITY_PROVIDER(UserActivityRunning, USER_ACT_SUBJ_RUNNING, ACTIVITY_RUN); + GENERATE_ACTIVITY_PROVIDER(UserActivityInVehicle, USER_ACT_SUBJ_IN_VEHICLE, ACTIVITY_IN_VEHICLE); } -#endif // _DEVICE_STATUS_ACTIVITY_H_ +#endif // _DEVICE_ACTIVITY_STATUS_H_ diff --git a/src/device/activity/activity_base.cpp b/src/device/activity/ActivityBase.cpp similarity index 51% rename from src/device/activity/activity_base.cpp rename to src/device/activity/ActivityBase.cpp index 30201ca..67cd4e3 100644 --- a/src/device/activity/activity_base.cpp +++ b/src/device/activity/ActivityBase.cpp @@ -16,33 +16,33 @@ #include #include -#include "activity_types.h" -#include "activity_base.h" +#include "ActivityTypes.h" +#include "ActivityBase.h" -ctx::user_activity_base::user_activity_base(const char *subj, activity_type_e type) - : activity_type(type) - , activity_handle(NULL) - , subject(subj) +ctx::UserActivityBase::UserActivityBase(const char *subj, activity_type_e type) : + __activityType(type), + __activityHandle(NULL), + __subject(subj) { } -ctx::user_activity_base::~user_activity_base() +ctx::UserActivityBase::~UserActivityBase() { - if (activity_handle) - activity_release(activity_handle); + if (__activityHandle) + activity_release(__activityHandle); } -void ctx::user_activity_base::event_cb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* user_data) +void ctx::UserActivityBase::__updateCb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* userData) { IF_FAIL_VOID_TAG(error == ACTIVITY_ERROR_NONE, _E, "Error: %d", error); - user_activity_base *instance = static_cast(user_data); - instance->handle_event(activity, data, timestamp); + UserActivityBase *instance = static_cast(userData); + instance->__handleUpdate(activity, data, timestamp); } -void ctx::user_activity_base::handle_event(activity_type_e activity, const activity_data_h data, double timestamp) +void ctx::UserActivityBase::__handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp) { - IF_FAIL_VOID_TAG(activity == activity_type, _E, "Invalid activity: %d", activity); + IF_FAIL_VOID_TAG(activity == __activityType, _E, "Invalid activity: %d", activity); ctx::Json dataRead; dataRead.set(NULL, USER_ACT_EVENT, USER_ACT_DETECTED); @@ -62,38 +62,38 @@ void ctx::user_activity_base::handle_event(activity_type_e activity, const activ break; } - context_manager::publish(subject.c_str(), NULL, ERR_NONE, dataRead); + context_manager::publish(__subject.c_str(), NULL, ERR_NONE, dataRead); } -int ctx::user_activity_base::subscribe() +int ctx::UserActivityBase::subscribe() { - IF_FAIL_RETURN(activity_handle == NULL, ERR_NONE); + IF_FAIL_RETURN(__activityHandle == NULL, ERR_NONE); - _D("Starting to monitor %s", subject.c_str()); + _D("Starting to monitor %s", __subject.c_str()); - activity_create(&activity_handle); - IF_FAIL_RETURN_TAG(activity_handle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); + activity_create(&__activityHandle); + IF_FAIL_RETURN_TAG(__activityHandle, ERR_OPERATION_FAILED, _E, "Memory allocation failed"); - int ret = activity_start_recognition(activity_handle, activity_type, event_cb, this); + int ret = activity_start_recognition(__activityHandle, __activityType, __updateCb, this); if (ret != ACTIVITY_ERROR_NONE) { _E("Recognition starting failed"); - activity_release(activity_handle); - activity_handle = NULL; + activity_release(__activityHandle); + __activityHandle = NULL; return ERR_OPERATION_FAILED; } return ERR_NONE; } -int ctx::user_activity_base::unsubscribe() +int ctx::UserActivityBase::unsubscribe() { - IF_FAIL_RETURN(activity_handle, ERR_NONE); + IF_FAIL_RETURN(__activityHandle, ERR_NONE); - _D("Stop monitoring %s", subject.c_str()); + _D("Stop monitoring %s", __subject.c_str()); - activity_stop_recognition(activity_handle); - activity_release(activity_handle); - activity_handle = NULL; + activity_stop_recognition(__activityHandle); + activity_release(__activityHandle); + __activityHandle = NULL; return ERR_NONE; } diff --git a/src/device/activity/activity_base.h b/src/device/activity/ActivityBase.h similarity index 54% rename from src/device/activity/activity_base.h rename to src/device/activity/ActivityBase.h index 05fa503..c7ce566 100644 --- a/src/device/activity/activity_base.h +++ b/src/device/activity/ActivityBase.h @@ -14,33 +14,33 @@ * limitations under the License. */ -#ifndef _DEVICE_STATUS_ACTIVITY_BASE_H_ -#define _DEVICE_STATUS_ACTIVITY_BASE_H_ +#ifndef _DEVICE_ACTIVITY_STATUS_BASE_H_ +#define _DEVICE_ACTIVITY_STATUS_BASE_H_ #include #include -#include "../device_provider_base.h" +#include "../DeviceProviderBase.h" namespace ctx { - class user_activity_base : public device_provider_base { + class UserActivityBase : public DeviceProviderBase { public: int subscribe(); int unsubscribe(); protected: - activity_type_e activity_type; - activity_h activity_handle; - std::string subject; + activity_type_e __activityType; + activity_h __activityHandle; + std::string __subject; - user_activity_base(const char *subj, activity_type_e type); - virtual ~user_activity_base(); + UserActivityBase(const char *subj, activity_type_e type); + virtual ~UserActivityBase(); private: - void handle_event(activity_type_e activity, const activity_data_h data, double timestamp); - static void event_cb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* user_data); + void __handleUpdate(activity_type_e activity, const activity_data_h data, double timestamp); + static void __updateCb(activity_type_e activity, const activity_data_h data, double timestamp, activity_error_e error, void* userData); }; } -#endif // _DEVICE_STATUS_ACTIVITY_BASE_H_ +#endif // _DEVICE_ACTIVITY_STATUS_BASE_H_ diff --git a/src/device/activity/activity_types.h b/src/device/activity/ActivityTypes.h similarity index 89% rename from src/device/activity/activity_types.h rename to src/device/activity/ActivityTypes.h index c15bbb4..4562b7b 100644 --- a/src/device/activity/activity_types.h +++ b/src/device/activity/ActivityTypes.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __CONTEXT_USER_ACTIVITY_TYPES_H__ -#define __CONTEXT_USER_ACTIVITY_TYPES_H__ +#ifndef _DEVICE_ACTIVITY_STATUS_TYPES_H_ +#define _DEVICE_ACTIVITY_STATUS_TYPES_H_ // Subject #define USER_ACT_SUBJ_IN_VEHICLE "activity/in_vehicle" @@ -33,4 +33,4 @@ #define USER_ACT_NORMAL "Normal" #define USER_ACT_HIGH "High" -#endif //__CONTEXT_USER_ACTIVITY_TYPES_H__ +#endif // _DEVICE_ACTIVITY_STATUS_TYPES_H_ diff --git a/src/device/device_context_provider.cpp b/src/device/device_context_provider.cpp deleted file mode 100644 index 1e42e20..0000000 --- a/src/device/device_context_provider.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "system/system_types.h" -#include "social/social_types.h" -#include "activity/activity_types.h" - -#include "system/alarm.h" -#include "system/time.h" - -#ifdef _MOBILE_ -#include "system/runtime-info/charger.h" -#include "system/runtime-info/gps.h" -#include "system/runtime-info/usb.h" -#include "system/wifi.h" -#include "system/headphone.h" -#include "system/battery.h" -#include "system/psmode.h" -#include "social/call.h" -#include "social/email.h" -#include "social/message.h" -#include "social/contacts.h" -#include "activity/activity.h" -#endif - -#ifdef _WEARABLE_ -#include "system/runtime-info/charger.h" -#include "system/runtime-info/gps.h" -#include "system/runtime-info/usb.h" -#include "system/wifi.h" -#include "system/headphone.h" -#include "system/battery.h" -#include "system/psmode.h" -#include "social/call.h" -#include "social/message.h" -#include "activity/activity.h" -#endif - -#ifdef _TV_ -#include "system/wifi.h" -#include "system/headphone.h" -#endif - -#define PRIV_NETWORK "network.get" -#define PRIV_TELEPHONY "telephony" -#define PRIV_MESSAGE "message.read" -#define PRIV_CONTACT "contact.read" - -template -void registerProvider(const char *subject, const char *privilege) -{ - if (!provider::is_supported()) - return; - - ctx::ContextProviderInfo providerInfo(provider::create, provider::destroy, NULL, privilege); - ctx::context_manager::registerProvider(subject, providerInfo); - provider::submit_trigger_item(); -} - -EXTAPI bool ctx::initDeviceContextProvider() -{ - registerProvider(DEVICE_ST_SUBJ_ALARM, NULL); - registerProvider(DEVICE_ST_SUBJ_TIME, NULL); - -#ifdef _MOBILE_ - registerProvider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); - registerProvider(DEVICE_ST_SUBJ_HEADPHONE, NULL); - - registerProvider(DEVICE_ST_SUBJ_CHARGER, NULL); - registerProvider(DEVICE_ST_SUBJ_GPS, NULL); - registerProvider(DEVICE_ST_SUBJ_USB, NULL); - registerProvider(DEVICE_ST_SUBJ_BATTERY, NULL); - registerProvider(DEVICE_ST_SUBJ_PSMODE, NULL); - - registerProvider(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY); - registerProvider(SOCIAL_ST_SUBJ_EMAIL, NULL); - registerProvider(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE); - registerProvider(SOCIAL_ST_SUBJ_CONTACTS, PRIV_CONTACT); - - registerProvider(USER_ACT_SUBJ_STATIONARY, NULL); - registerProvider(USER_ACT_SUBJ_WALKING, NULL); - registerProvider(USER_ACT_SUBJ_RUNNING, NULL); - registerProvider(USER_ACT_SUBJ_IN_VEHICLE, NULL); - - /* Create context providers, which need to be initiated before being subscribed */ - if (device_status_wifi::is_supported()) - device_status_wifi::create(NULL); -#endif - -#ifdef _WEARABLE_ - registerProvider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); - registerProvider(DEVICE_ST_SUBJ_HEADPHONE, NULL); - - registerProvider(DEVICE_ST_SUBJ_CHARGER, NULL); - registerProvider(DEVICE_ST_SUBJ_GPS, NULL); - registerProvider(DEVICE_ST_SUBJ_USB, NULL); - registerProvider(DEVICE_ST_SUBJ_BATTERY, NULL); - registerProvider(DEVICE_ST_SUBJ_PSMODE, NULL); - - registerProvider(SOCIAL_ST_SUBJ_CALL, PRIV_TELEPHONY); - registerProvider(SOCIAL_ST_SUBJ_MESSAGE, PRIV_MESSAGE); - - registerProvider(USER_ACT_SUBJ_STATIONARY, NULL); - registerProvider(USER_ACT_SUBJ_WALKING, NULL); - registerProvider(USER_ACT_SUBJ_RUNNING, NULL); - registerProvider(USER_ACT_SUBJ_IN_VEHICLE, NULL); - - /* Create context providers, which need to be initiated before being subscribed */ - if (device_status_wifi::is_supported()) - device_status_wifi::create(NULL); -#endif - -#ifdef _TV_ - registerProvider(DEVICE_ST_SUBJ_WIFI, PRIV_NETWORK); - registerProvider(DEVICE_ST_SUBJ_HEADPHONE, NULL); - - /* Create context providers, which need to be initiated before being subscribed */ - if (device_status_wifi::is_supported()) - device_status_wifi::create(NULL); -#endif - - return true; -} diff --git a/src/device/social/call.cpp b/src/device/social/Call.cpp similarity index 64% rename from src/device/social/call.cpp rename to src/device/social/Call.cpp index 71e3ea8..d8bbebe 100644 --- a/src/device/social/call.cpp +++ b/src/device/social/Call.cpp @@ -17,14 +17,14 @@ #include #include #include -#include "social_types.h" -#include "call.h" +#include "SocialTypes.h" +#include "Call.h" #define TELEPHONY_NOTI_ID_CNT 8 -GENERATE_PROVIDER_COMMON_IMPL(social_status_call); +GENERATE_PROVIDER_COMMON_IMPL(SocialStatusCall); -static bool telephony_initialized = false; -static telephony_noti_e call_noti_ids[] = +static bool __telephonyInitialized = false; +static telephony_noti_e __callNotiIds[] = { TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE, TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE, @@ -38,24 +38,24 @@ static telephony_noti_e call_noti_ids[] = TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING, TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING, }; -static ctx::Json latest; +static ctx::Json __latest; -ctx::social_status_call::social_status_call() +ctx::SocialStatusCall::SocialStatusCall() { - handle_list.count = 0; - handle_list.handle = NULL; + __handleList.count = 0; + __handleList.handle = NULL; } -ctx::social_status_call::~social_status_call() +ctx::SocialStatusCall::~SocialStatusCall() { } -bool ctx::social_status_call::is_supported() +bool ctx::SocialStatusCall::isSupported() { - return get_system_info_bool("tizen.org/feature/network.telephony"); + return getSystemInfoBool("tizen.org/feature/network.telephony"); } -void ctx::social_status_call::submit_trigger_item() +void ctx::SocialStatusCall::submitTriggerItem() { context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CALL, OPS_SUBSCRIBE | OPS_READ, "{" @@ -67,21 +67,20 @@ void ctx::social_status_call::submit_trigger_item() //TODO remove Connecting, Connected } -void ctx::social_status_call::call_event_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data) +void ctx::SocialStatusCall::__updateCb(telephony_h handle, telephony_noti_e notiId, void *data, void *userData) { - social_status_call *instance = static_cast(user_data); - instance->handle_call_event(handle, noti_id, data); + SocialStatusCall *instance = static_cast(userData); + instance->__handleUpdate(handle, notiId, data); } -void ctx::social_status_call::handle_call_event(telephony_h handle, telephony_noti_e noti_id, void* id) +void ctx::SocialStatusCall::__handleUpdate(telephony_h handle, telephony_noti_e notiId, void* id) { - Json data; unsigned int count; - telephony_call_h *call_list; + telephony_call_h *callList; // Call state - switch (noti_id) { + switch (notiId) { case TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE: case TELEPHONY_NOTI_VIDEO_CALL_STATUS_IDLE: data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE); @@ -103,12 +102,12 @@ void ctx::social_status_call::handle_call_event(telephony_h handle, telephony_no case TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING: case TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING:*/ default: - _E("Unkown noti id: %d", noti_id); + _E("Unkown noti id: %d", notiId); return; } // Call type - switch (noti_id) { + switch (notiId) { case TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE: case TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE: case TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING: @@ -126,70 +125,70 @@ void ctx::social_status_call::handle_call_event(telephony_h handle, telephony_no case TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING: case TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING:*/ default: - _E("Unkown noti id: %d", noti_id); + _E("Unkown noti id: %d", notiId); return; } - int err = telephony_call_get_call_list(handle, &count, &call_list); + int err = telephony_call_get_call_list(handle, &count, &callList); IF_FAIL_VOID_TAG(err == TELEPHONY_ERROR_NONE, _E, "Getting call list failed"); - unsigned int call_id = *static_cast(id); + unsigned int callId = *static_cast(id); for (unsigned int i = 0; i < count; i++) { - unsigned int tmp_id; + unsigned int tempId; // Handle id - if (!get_call_handle_id(call_list[i], tmp_id)) { + if (!__getCallHandleId(callList[i], tempId)) { continue; } - if (call_id != tmp_id) { + if (callId != tempId) { continue; } // Address std::string address; - if (get_call_address(call_list[i], address)) { + if (__getCallAddress(callList[i], address)) { data.set(NULL, SOCIAL_ST_ADDRESS, address); break; } } - if (latest != data) { + if (__latest != data) { context_manager::publish(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data); - latest = data.str(); + __latest = data.str(); } - telephony_call_release_call_list(count, &call_list); + telephony_call_release_call_list(count, &callList); } -bool ctx::social_status_call::init_telephony() +bool ctx::SocialStatusCall::__initTelephony() { - IF_FAIL_RETURN(!telephony_initialized, true); + IF_FAIL_RETURN(!__telephonyInitialized, true); - int err = telephony_init(&handle_list); + int err = telephony_init(&__handleList); IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Initialization failed"); - telephony_initialized = true; + __telephonyInitialized = true; return true; } -void ctx::social_status_call::release_telephony() +void ctx::SocialStatusCall::__releaseTelephony() { - IF_FAIL_VOID(telephony_initialized); + IF_FAIL_VOID(__telephonyInitialized); - telephony_deinit(&handle_list); + telephony_deinit(&__handleList); - telephony_initialized = false; + __telephonyInitialized = false; } -bool ctx::social_status_call::set_callback() +bool ctx::SocialStatusCall::__setCallback() { //TODO: Consider dual-sim devices - IF_FAIL_RETURN_TAG(init_telephony(), false, _E, "Initialization failed"); + IF_FAIL_RETURN_TAG(__initTelephony(), false, _E, "Initialization failed"); int err; - for (unsigned int i = 0; i < handle_list.count; i++) { + for (unsigned int i = 0; i < __handleList.count; i++) { for (unsigned int j = 0; j < TELEPHONY_NOTI_ID_CNT; j++) { - err = telephony_set_noti_cb(handle_list.handle[i], call_noti_ids[j], call_event_cb, this); + err = telephony_set_noti_cb(__handleList.handle[i], __callNotiIds[j], __updateCb, this); IF_FAIL_CATCH(err == TELEPHONY_ERROR_NONE); } } @@ -198,22 +197,22 @@ bool ctx::social_status_call::set_callback() CATCH: _E("Initialization failed"); - release_telephony(); + __releaseTelephony(); return false; } -void ctx::social_status_call::unset_callback() +void ctx::SocialStatusCall::__unsetCallback() { - for (unsigned int i = 0; i < handle_list.count; i++) { + for (unsigned int i = 0; i < __handleList.count; i++) { for (unsigned int j = 0; j < TELEPHONY_NOTI_ID_CNT; j++) { - telephony_unset_noti_cb(handle_list.handle[i], call_noti_ids[j]); + telephony_unset_noti_cb(__handleList.handle[i], __callNotiIds[j]); } } - release_telephony(); + __releaseTelephony(); } -bool ctx::social_status_call::get_call_state(telephony_call_h& handle, std::string& state) +bool ctx::SocialStatusCall::__getCallState(telephony_call_h& handle, std::string& state) { state.clear(); @@ -246,7 +245,7 @@ bool ctx::social_status_call::get_call_state(telephony_call_h& handle, std::stri return true; } -bool ctx::social_status_call::get_call_type(telephony_call_h& handle, std::string& type) +bool ctx::SocialStatusCall::__getCallType(telephony_call_h& handle, std::string& type) { type.clear(); @@ -271,7 +270,7 @@ bool ctx::social_status_call::get_call_type(telephony_call_h& handle, std::strin return true; } -bool ctx::social_status_call::get_call_address(telephony_call_h& handle, std::string& address) +bool ctx::SocialStatusCall::__getCallAddress(telephony_call_h& handle, std::string& address) { address.clear(); @@ -290,7 +289,7 @@ bool ctx::social_status_call::get_call_address(telephony_call_h& handle, std::st return true; } -bool ctx::social_status_call::get_call_handle_id(telephony_call_h& handle, unsigned int& id) +bool ctx::SocialStatusCall::__getCallHandleId(telephony_call_h& handle, unsigned int& id) { int err = telephony_call_get_handle_id(handle, &id); IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, false, _E, "Getting handle id failed"); @@ -298,50 +297,50 @@ bool ctx::social_status_call::get_call_handle_id(telephony_call_h& handle, unsig return true; } -int ctx::social_status_call::subscribe() +int ctx::SocialStatusCall::subscribe() { - bool ret = set_callback(); + bool ret = __setCallback(); IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::social_status_call::unsubscribe() +int ctx::SocialStatusCall::unsubscribe() { - unset_callback(); + __unsetCallback(); return ERR_NONE; } -bool ctx::social_status_call::read_current_status(telephony_h& handle, ctx::Json& data) +bool ctx::SocialStatusCall::__readCurrentStatus(telephony_h& handle, ctx::Json* data) { unsigned int count = 0; - telephony_call_h *call_list = NULL; - telephony_call_get_call_list(handle, &count, &call_list); + telephony_call_h *callList = NULL; + telephony_call_get_call_list(handle, &count, &callList); // Default data - data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE); + data->set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE); // Held & Dialing are ignored for (unsigned int i = 0; i < count; i++) { // Call state std::string state; - if (get_call_state(call_list[i], state)) { + if (__getCallState(callList[i], state)) { // Skip Held & Dialing if (state.compare(SOCIAL_ST_HELD) == 0 || state.compare(SOCIAL_ST_DIALING) == 0) continue; - data.set(NULL, SOCIAL_ST_STATE, state); + data->set(NULL, SOCIAL_ST_STATE, state); } // Call type std::string type; - if (get_call_type(call_list[i], type)) { - data.set(NULL, SOCIAL_ST_MEDIUM, type); + if (__getCallType(callList[i], type)) { + data->set(NULL, SOCIAL_ST_MEDIUM, type); } // Address std::string address; - if (get_call_address(call_list[i], address)) { - data.set(NULL, SOCIAL_ST_ADDRESS, address); + if (__getCallAddress(callList[i], address)) { + data->set(NULL, SOCIAL_ST_ADDRESS, address); } if (state == SOCIAL_ST_ACTIVE) { @@ -349,36 +348,36 @@ bool ctx::social_status_call::read_current_status(telephony_h& handle, ctx::Json } } - telephony_call_release_call_list(count, &call_list); + telephony_call_release_call_list(count, &callList); return true; } -int ctx::social_status_call::read() +int ctx::SocialStatusCall::read() { - bool temporary_handle = false; - if (!telephony_initialized) { - IF_FAIL_RETURN(init_telephony(), ERR_OPERATION_FAILED); - temporary_handle = true; + bool temporaryHandle = false; + if (!__telephonyInitialized) { + IF_FAIL_RETURN(__initTelephony(), ERR_OPERATION_FAILED); + temporaryHandle = true; } bool ret = true; Json data; data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE); - for (unsigned int i = 0; i < handle_list.count; i++) { + for (unsigned int i = 0; i < __handleList.count; i++) { telephony_sim_state_e state; - int err = telephony_sim_get_state(handle_list.handle[i], &state); + int err = telephony_sim_get_state(__handleList.handle[i], &state); IF_FAIL_RETURN_TAG(err == TELEPHONY_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting SIM status failed"); if (state != TELEPHONY_SIM_STATE_AVAILABLE) continue; - ret = read_current_status(handle_list.handle[i], data); + ret = __readCurrentStatus(__handleList.handle[i], &data); break; } - if (temporary_handle) - release_telephony(); + if (temporaryHandle) + __releaseTelephony(); if (ret) { ctx::context_manager::replyToRead(SOCIAL_ST_SUBJ_CALL, NULL, ERR_NONE, data); diff --git a/src/device/social/Call.h b/src/device/social/Call.h new file mode 100644 index 0000000..38fdab9 --- /dev/null +++ b/src/device/social/Call.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _CONTEXT_SOCIAL_STATUS_CALL_H_ +#define _CONTEXT_SOCIAL_STATUS_CALL_H_ + +#include +#include "../DeviceProviderBase.h" + +namespace ctx { + + class SocialStatusCall : public DeviceProviderBase { + + GENERATE_PROVIDER_COMMON_DECL(SocialStatusCall); + + public: + int subscribe(); + int unsubscribe(); + int read(); + static bool isSupported(); + static void submitTriggerItem(); + + private: + telephony_handle_list_s __handleList; + + SocialStatusCall(); + ~SocialStatusCall(); + + bool __initTelephony(); + void __releaseTelephony(); + bool __setCallback(); + void __unsetCallback(); + bool __readCurrentStatus(telephony_h& handle, ctx::Json* data); + + bool __getCallState(telephony_call_h& handle, std::string& state); + bool __getCallType(telephony_call_h& handle, std::string& type); + bool __getCallAddress(telephony_call_h& handle, std::string& address); + bool __getCallHandleId(telephony_call_h& handle, unsigned int& id); + + void __handleUpdate(telephony_h handle, telephony_noti_e notiId, void* id); + static void __updateCb(telephony_h handle, telephony_noti_e notiId, void *data, void *userData); + }; +} + +#endif // _CONTEXT_SOCIAL_STATUS_CALL_H_ diff --git a/src/device/social/contacts.cpp b/src/device/social/Contacts.cpp similarity index 51% rename from src/device/social/contacts.cpp rename to src/device/social/Contacts.cpp index f071e78..4604c37 100644 --- a/src/device/social/contacts.cpp +++ b/src/device/social/Contacts.cpp @@ -16,31 +16,31 @@ #include #include -#include "social_types.h" -#include "contacts.h" +#include "SocialTypes.h" +#include "Contacts.h" #define MY_PROFILE_VIEW _contacts_my_profile._uri #define PERSON_VIEW _contacts_person._uri #define TIME_INTERVAL 1 -GENERATE_PROVIDER_COMMON_IMPL(social_status_contacts); +GENERATE_PROVIDER_COMMON_IMPL(SocialStatusContacts); -ctx::social_status_contacts::social_status_contacts() - : latest_my_profile(0) - , latest_person(0) +ctx::SocialStatusContacts::SocialStatusContacts() : + __latestMyProfile(0), + __latestPerson(0) { } -ctx::social_status_contacts::~social_status_contacts() +ctx::SocialStatusContacts::~SocialStatusContacts() { } -bool ctx::social_status_contacts::is_supported() +bool ctx::SocialStatusContacts::isSupported() { return true; } -void ctx::social_status_contacts::submit_trigger_item() +void ctx::SocialStatusContacts::submitTriggerItem() { context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_CONTACTS, OPS_SUBSCRIBE, "{" @@ -50,21 +50,21 @@ void ctx::social_status_contacts::submit_trigger_item() NULL); } -void ctx::social_status_contacts::db_change_cb(const char* view_uri, void* user_data) +void ctx::SocialStatusContacts::__updateCb(const char* viewUri, void* userData) { - social_status_contacts *instance = static_cast(user_data); - instance->handle_db_change(view_uri); + SocialStatusContacts *instance = static_cast(userData); + instance->__handleUpdate(viewUri); } -void ctx::social_status_contacts::handle_db_change(const char* view_uri) +void ctx::SocialStatusContacts::__handleUpdate(const char* viewUri) { - if (!STR_EQ(view_uri, _contacts_my_profile._uri) && !STR_EQ(view_uri, _contacts_person._uri)) { + if (!STR_EQ(viewUri, _contacts_my_profile._uri) && !STR_EQ(viewUri, _contacts_person._uri)) { _W("Unknown view uri"); return; } - std::string view = (STR_EQ(view_uri, _contacts_my_profile._uri)? SOCIAL_ST_MY_PROFILE : SOCIAL_ST_PERSON); - IF_FAIL_VOID_TAG(!is_consecutive_change(view_uri), _D, "Ignore consecutive db change: %s", view.c_str()); + std::string view = (STR_EQ(viewUri, _contacts_my_profile._uri)? SOCIAL_ST_MY_PROFILE : SOCIAL_ST_PERSON); + IF_FAIL_VOID_TAG(!__isConsecutiveChange(viewUri), _D, "Ignore consecutive db change: %s", view.c_str()); ctx::Json data; data.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_CHANGED); @@ -72,17 +72,17 @@ void ctx::social_status_contacts::handle_db_change(const char* view_uri) context_manager::publish(SOCIAL_ST_SUBJ_CONTACTS, NULL, ERR_NONE, data); } -bool ctx::social_status_contacts::is_consecutive_change(const char* view_uri) +bool ctx::SocialStatusContacts::__isConsecutiveChange(const char* viewUri) { time_t now = time(NULL); double diff = 0; - if (STR_EQ(view_uri, MY_PROFILE_VIEW)) { - diff = difftime(now, latest_my_profile); - latest_my_profile = now; - } else if (STR_EQ(view_uri, PERSON_VIEW)) { - diff = difftime(now, latest_person); - latest_person = now; + if (STR_EQ(viewUri, MY_PROFILE_VIEW)) { + diff = difftime(now, __latestMyProfile); + __latestMyProfile = now; + } else if (STR_EQ(viewUri, PERSON_VIEW)) { + diff = difftime(now, __latestPerson); + __latestPerson = now; } if (diff < TIME_INTERVAL) @@ -91,17 +91,17 @@ bool ctx::social_status_contacts::is_consecutive_change(const char* view_uri) return false; } -bool ctx::social_status_contacts::set_callback() +bool ctx::SocialStatusContacts::__setCallback() { int err; err = contacts_connect(); IF_FAIL_RETURN_TAG(err == CONTACTS_ERROR_NONE, false, _E, "Connecting contacts failed"); - err = contacts_db_add_changed_cb(MY_PROFILE_VIEW, db_change_cb, this); + err = contacts_db_add_changed_cb(MY_PROFILE_VIEW, __updateCb, this); IF_FAIL_CATCH_TAG(err == CONTACTS_ERROR_NONE, _E, "Setting my profile view changed callback failed"); - err = contacts_db_add_changed_cb(PERSON_VIEW, db_change_cb, this); + err = contacts_db_add_changed_cb(PERSON_VIEW, __updateCb, this); IF_FAIL_CATCH_TAG(err == CONTACTS_ERROR_NONE, _E, "Setting person view changed callback failed"); return true; @@ -111,26 +111,26 @@ CATCH: return false; } -void ctx::social_status_contacts::unset_callback() +void ctx::SocialStatusContacts::__unsetCallback() { - contacts_db_remove_changed_cb(MY_PROFILE_VIEW, db_change_cb, this); - contacts_db_remove_changed_cb(PERSON_VIEW, db_change_cb, this); + contacts_db_remove_changed_cb(MY_PROFILE_VIEW, __updateCb, this); + contacts_db_remove_changed_cb(PERSON_VIEW, __updateCb, this); contacts_disconnect(); - latest_my_profile = 0; - latest_person = 0; + __latestMyProfile = 0; + __latestPerson = 0; } -int ctx::social_status_contacts::subscribe() +int ctx::SocialStatusContacts::subscribe() { - bool ret = set_callback(); + bool ret = __setCallback(); IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::social_status_contacts::unsubscribe() +int ctx::SocialStatusContacts::unsubscribe() { - unset_callback(); + __unsetCallback(); return ERR_NONE; } diff --git a/src/device/social/contacts.h b/src/device/social/Contacts.h similarity index 61% rename from src/device/social/contacts.h rename to src/device/social/Contacts.h index 1169412..b99929b 100644 --- a/src/device/social/contacts.h +++ b/src/device/social/Contacts.h @@ -18,32 +18,32 @@ #define _CONTEXT_SOCIAL_STATUS_CONTACTS_H_ #include -#include "../device_provider_base.h" +#include "../DeviceProviderBase.h" namespace ctx { - class social_status_contacts : public device_provider_base { + class SocialStatusContacts : public DeviceProviderBase { - GENERATE_PROVIDER_COMMON_DECL(social_status_contacts); + GENERATE_PROVIDER_COMMON_DECL(SocialStatusContacts); public: int subscribe(); int unsubscribe(); - static bool is_supported(); - static void submit_trigger_item(); + static bool isSupported(); + static void submitTriggerItem(); private: - time_t latest_my_profile; - time_t latest_person; + time_t __latestMyProfile; + time_t __latestPerson; - social_status_contacts(); - ~social_status_contacts(); + SocialStatusContacts(); + ~SocialStatusContacts(); - bool set_callback(); - void unset_callback(); - void handle_db_change(const char* view_uri); - static void db_change_cb(const char* view_uri, void* user_data); - bool is_consecutive_change(const char* view_uri); + bool __setCallback(); + void __unsetCallback(); + void __handleUpdate(const char* viewUri); + static void __updateCb(const char* viewUri, void* userData); + bool __isConsecutiveChange(const char* viewUri); }; } diff --git a/src/device/social/email.cpp b/src/device/social/Email.cpp similarity index 56% rename from src/device/social/email.cpp rename to src/device/social/Email.cpp index 898cf03..c49f185 100644 --- a/src/device/social/email.cpp +++ b/src/device/social/Email.cpp @@ -18,27 +18,27 @@ #include #include -#include "social_types.h" -#include "email.h" +#include "SocialTypes.h" +#include "Email.h" -GENERATE_PROVIDER_COMMON_IMPL(social_status_email); +GENERATE_PROVIDER_COMMON_IMPL(SocialStatusEmail); -ctx::social_status_email::social_status_email() - : dbus_signal_id(-1) - , __dbusWatcher(DBusType::SESSION) +ctx::SocialStatusEmail::SocialStatusEmail() : + __dbusSignalId(-1), + __dbusWatcher(DBusType::SESSION) { } -ctx::social_status_email::~social_status_email() +ctx::SocialStatusEmail::~SocialStatusEmail() { } -bool ctx::social_status_email::is_supported() +bool ctx::SocialStatusEmail::isSupported() { - return get_system_info_bool("tizen.org/feature/network.telephony"); + return getSystemInfoBool("tizen.org/feature/network.telephony"); } -void ctx::social_status_email::submit_trigger_item() +void ctx::SocialStatusEmail::submitTriggerItem() { context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_EMAIL, OPS_SUBSCRIBE, "{" @@ -47,25 +47,25 @@ void ctx::social_status_email::submit_trigger_item() NULL); } -void ctx::social_status_email::onSignal(const char* sender, const char* path, const char* iface, const char* name, GVariant* param) +void ctx::SocialStatusEmail::onSignal(const char* sender, const char* path, const char* iface, const char* name, GVariant* param) { - gint sub_type = 0; + gint subType = 0; gint gi1 = 0; const gchar *gc = NULL; gint gi2 = 0; gint gi3 = 0; - g_variant_get(param, "(ii&sii)", &sub_type, &gi1, &gc, &gi2, &gi3); + g_variant_get(param, "(ii&sii)", &subType, &gi1, &gc, &gi2, &gi3); - if (sub_type == NOTI_DOWNLOAD_FINISH) { + if (subType == NOTI_DOWNLOAD_FINISH) { //TODO: Check if this signal actually means that there are new mails - _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", sub_type, gi1, gc, gi2, gi3); + _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", subType, gi1, gc, gi2, gi3); ctx::Json dataUpdated; dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED); context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, dataUpdated); - } else if (sub_type == NOTI_SEND_FINISH) { - _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", sub_type, gi1, gc, gi2, gi3); + } else if (subType == NOTI_SEND_FINISH) { + _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", subType, gi1, gc, gi2, gi3); ctx::Json dataUpdated; dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_SENT); context_manager::publish(SOCIAL_ST_SUBJ_EMAIL, NULL, ERR_NONE, dataUpdated); @@ -73,16 +73,16 @@ void ctx::social_status_email::onSignal(const char* sender, const char* path, co } -int ctx::social_status_email::subscribe() +int ctx::SocialStatusEmail::subscribe() { - dbus_signal_id = __dbusWatcher.watch(NULL, NULL, "User.Email.NetworkStatus", "email", this); - IF_FAIL_RETURN_TAG(dbus_signal_id >= 0, ERR_OPERATION_FAILED, _E, "Email dbus signal subscription failed"); + __dbusSignalId = __dbusWatcher.watch(NULL, NULL, "User.Email.NetworkStatus", "email", this); + IF_FAIL_RETURN_TAG(__dbusSignalId >= 0, ERR_OPERATION_FAILED, _E, "Email dbus signal subscription failed"); return ERR_NONE; } -int ctx::social_status_email::unsubscribe() +int ctx::SocialStatusEmail::unsubscribe() { - __dbusWatcher.unwatch(dbus_signal_id); + __dbusWatcher.unwatch(__dbusSignalId); return ERR_NONE; } diff --git a/src/device/social/email.h b/src/device/social/Email.h similarity index 75% rename from src/device/social/email.h rename to src/device/social/Email.h index 9cc7508..4daaea0 100644 --- a/src/device/social/email.h +++ b/src/device/social/Email.h @@ -18,27 +18,27 @@ #define _CONTEXT_SOCIAL_STATUS_EMAIL_H_ #include -#include "../device_provider_base.h" +#include "../DeviceProviderBase.h" namespace ctx { - class social_status_email : public device_provider_base, public IDBusSignalListener { + class SocialStatusEmail : public DeviceProviderBase, public IDBusSignalListener { - GENERATE_PROVIDER_COMMON_DECL(social_status_email); + GENERATE_PROVIDER_COMMON_DECL(SocialStatusEmail); public: int subscribe(); int unsubscribe(); void onSignal(const char *sender, const char *path, const char *iface, const char *name, GVariant *param); - static bool is_supported(); - static void submit_trigger_item(); + static bool isSupported(); + static void submitTriggerItem(); private: - int64_t dbus_signal_id; + int64_t __dbusSignalId; DBusSignalWatcher __dbusWatcher; - social_status_email(); - ~social_status_email(); + SocialStatusEmail(); + ~SocialStatusEmail(); }; } diff --git a/src/device/social/message.cpp b/src/device/social/Message.cpp similarity index 64% rename from src/device/social/message.cpp rename to src/device/social/Message.cpp index cf75e4f..7643175 100644 --- a/src/device/social/message.cpp +++ b/src/device/social/Message.cpp @@ -16,28 +16,28 @@ #include #include -#include "social_types.h" -#include "message.h" +#include "SocialTypes.h" +#include "Message.h" #define MAX_ADDR_SIZE 20 -GENERATE_PROVIDER_COMMON_IMPL(social_status_message); +GENERATE_PROVIDER_COMMON_IMPL(SocialStatusMessage); -ctx::social_status_message::social_status_message() - : message_handle(NULL) +ctx::SocialStatusMessage::SocialStatusMessage() : + __messageHandle(NULL) { } -ctx::social_status_message::~social_status_message() +ctx::SocialStatusMessage::~SocialStatusMessage() { } -bool ctx::social_status_message::is_supported() +bool ctx::SocialStatusMessage::isSupported() { - return get_system_info_bool("tizen.org/feature/network.telephony"); + return getSystemInfoBool("tizen.org/feature/network.telephony"); } -void ctx::social_status_message::submit_trigger_item() +void ctx::SocialStatusMessage::submitTriggerItem() { context_manager::registerTriggerItem(SOCIAL_ST_SUBJ_MESSAGE, OPS_SUBSCRIBE, "{" @@ -48,13 +48,13 @@ void ctx::social_status_message::submit_trigger_item() NULL); } -void ctx::social_status_message::state_change_cb(msg_handle_t handle, msg_struct_t msg, void* user_data) +void ctx::SocialStatusMessage::__updateCb(msg_handle_t handle, msg_struct_t msg, void* userData) { - social_status_message *instance = static_cast(user_data); - instance->handle_state_change(msg); + SocialStatusMessage *instance = static_cast(userData); + instance->__handleUpdate(msg); } -void ctx::social_status_message::handle_state_change(msg_struct_t msg) +void ctx::SocialStatusMessage::__handleUpdate(msg_struct_t msg) { int err; int type; @@ -94,41 +94,41 @@ void ctx::social_status_message::handle_state_change(msg_struct_t msg) context_manager::publish(SOCIAL_ST_SUBJ_MESSAGE, NULL, ERR_NONE, data); } -bool ctx::social_status_message::set_callback() +bool ctx::SocialStatusMessage::__setCallback() { int err; - err = msg_open_msg_handle(&message_handle); + err = msg_open_msg_handle(&__messageHandle); IF_FAIL_RETURN_TAG(err == MSG_SUCCESS, false, _E, "Handle creation failed"); - err = msg_reg_sms_message_callback(message_handle, state_change_cb, 0, this); + err = msg_reg_sms_message_callback(__messageHandle, __updateCb, 0, this); if (err != MSG_SUCCESS) { - msg_close_msg_handle(&message_handle); + msg_close_msg_handle(&__messageHandle); _E("Setting SMS event callback failed"); return false; } - msg_reg_mms_conf_message_callback(message_handle, state_change_cb, NULL, this); + msg_reg_mms_conf_message_callback(__messageHandle, __updateCb, NULL, this); return true; } -void ctx::social_status_message::unset_callback() +void ctx::SocialStatusMessage::__unsetCallback() { - if (message_handle) - msg_close_msg_handle(&message_handle); + if (__messageHandle) + msg_close_msg_handle(&__messageHandle); - message_handle = NULL; + __messageHandle = NULL; } -int ctx::social_status_message::subscribe() +int ctx::SocialStatusMessage::subscribe() { - bool ret = set_callback(); + bool ret = __setCallback(); IF_FAIL_RETURN(ret, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::social_status_message::unsubscribe() +int ctx::SocialStatusMessage::unsubscribe() { - unset_callback(); + __unsetCallback(); return ERR_NONE; } diff --git a/src/device/social/message.h b/src/device/social/Message.h similarity index 62% rename from src/device/social/message.h rename to src/device/social/Message.h index 5239f21..91c33b3 100644 --- a/src/device/social/message.h +++ b/src/device/social/Message.h @@ -19,31 +19,31 @@ #include #include -#include "../device_provider_base.h" +#include "../DeviceProviderBase.h" namespace ctx { - class social_status_message : public device_provider_base { + class SocialStatusMessage : public DeviceProviderBase { - GENERATE_PROVIDER_COMMON_DECL(social_status_message); + GENERATE_PROVIDER_COMMON_DECL(SocialStatusMessage); public: int subscribe(); int unsubscribe(); - static bool is_supported(); - static void submit_trigger_item(); + static bool isSupported(); + static void submitTriggerItem(); private: - msg_handle_t message_handle; - bool being_subscribed; + msg_handle_t __messageHandle; + bool __beingSubscribed; - social_status_message(); - ~social_status_message(); + SocialStatusMessage(); + ~SocialStatusMessage(); - bool set_callback(); - void unset_callback(); - void handle_state_change(msg_struct_t msg); - static void state_change_cb(msg_handle_t handle, msg_struct_t msg, void* user_data); + bool __setCallback(); + void __unsetCallback(); + void __handleUpdate(msg_struct_t msg); + static void __updateCb(msg_handle_t handle, msg_struct_t msg, void* userData); }; } diff --git a/src/device/social/social_types.h b/src/device/social/SocialTypes.h similarity index 93% rename from src/device/social/social_types.h rename to src/device/social/SocialTypes.h index 1af5fb7..82dccff 100644 --- a/src/device/social/social_types.h +++ b/src/device/social/SocialTypes.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __CONTEXT_SOCIAL_STATUS_TYPES_INTERNAL_H__ -#define __CONTEXT_SOCIAL_STATUS_TYPES_INTERNAL_H__ +#ifndef _CONTEXT_SOCIAL_STATUS_TYPES_H_ +#define _CONTEXT_SOCIAL_STATUS_TYPES_H_ // Subject #define SOCIAL_ST_SUBJ_CALL "social/call" @@ -49,4 +49,4 @@ #define SOCIAL_ST_PERSON "Person" #define SOCIAL_ST_CHANGED "Changed" -#endif +#endif //_CONTEXT_SOCIAL_STATUS_TYPES_H diff --git a/src/device/social/call.h b/src/device/social/call.h deleted file mode 100644 index f320f5c..0000000 --- a/src/device/social/call.h +++ /dev/null @@ -1,58 +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_SOCIAL_STATUS_CALL_H_ -#define _CONTEXT_SOCIAL_STATUS_CALL_H_ - -#include -#include "../device_provider_base.h" - -namespace ctx { - - class social_status_call : public device_provider_base { - - GENERATE_PROVIDER_COMMON_DECL(social_status_call); - - public: - int subscribe(); - int unsubscribe(); - int read(); - static bool is_supported(); - static void submit_trigger_item(); - - private: - telephony_handle_list_s handle_list; - - social_status_call(); - ~social_status_call(); - - bool init_telephony(); - void release_telephony(); - bool set_callback(); - void unset_callback(); - bool read_current_status(telephony_h& handle, ctx::Json& data); - - bool get_call_state(telephony_call_h& handle, std::string& state); - bool get_call_type(telephony_call_h& handle, std::string& type); - bool get_call_address(telephony_call_h& handle, std::string& address); - bool get_call_handle_id(telephony_call_h& handle, unsigned int& id); - - void handle_call_event(telephony_h handle, telephony_noti_e noti_id, void* id); - static void call_event_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data); - }; -} - -#endif // _CONTEXT_SOCIAL_STATUS_CALL_H_ diff --git a/src/device/system/Alarm.cpp b/src/device/system/Alarm.cpp new file mode 100644 index 0000000..fc7aa10 --- /dev/null +++ b/src/device/system/Alarm.cpp @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "SystemTypes.h" +#include "Alarm.h" + +GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusAlarm); + +ctx::DeviceStatusAlarm::DeviceStatusAlarm() +{ +} + +ctx::DeviceStatusAlarm::~DeviceStatusAlarm() +{ + __clear(); + + for (auto it = __optionSet.begin(); it != __optionSet.end(); ++it) { + delete *it; + } + __optionSet.clear(); +} + +bool ctx::DeviceStatusAlarm::isSupported() +{ + return true; +} + +void ctx::DeviceStatusAlarm::submitTriggerItem() +{ + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_ALARM, OPS_SUBSCRIBE, + "{" + "\"TimeOfDay\":{\"type\":\"integer\",\"min\":0,\"max\":1439}," + "\"DayOfWeek\":{\"type\":\"string\",\"values\":[\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\",\"Weekday\",\"Weekend\"]}" + "}", + NULL); +} + +int ctx::DeviceStatusAlarm::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) +{ + int ret = subscribe(option); + __destroyIfUnused(); + return ret; +} + +int ctx::DeviceStatusAlarm::unsubscribe(const char *subject, ctx::Json option) +{ + int ret = unsubscribe(option); + __destroyIfUnused(); + return ret; +} + +int ctx::DeviceStatusAlarm::read(const char *subject, ctx::Json option, ctx::Json *requestResult) +{ + __destroyIfUnused(); + return ERR_NOT_SUPPORTED; +} + +int ctx::DeviceStatusAlarm::write(const char *subject, ctx::Json data, ctx::Json *requestResult) +{ + __destroyIfUnused(); + return ERR_NOT_SUPPORTED; +} + +int ctx::DeviceStatusAlarm::subscribe(ctx::Json option) +{ + int dow = __getArrangedDayOfWeek(option); + + int time; + for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) { + __add(time, dow); + } + + ctx::Json* elem = new(std::nothrow) ctx::Json(option); + if (elem) { + __optionSet.insert(elem); + } else { + unsubscribe(option); + _E("Memory allocation failed"); + return ERR_OUT_OF_MEMORY; + } + + return ERR_NONE; +} + +int ctx::DeviceStatusAlarm::unsubscribe(ctx::Json option) +{ + int dow = __getArrangedDayOfWeek(option); + + int time; + for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) { + __remove(time, dow); + } + + OptionSet::iterator target = __findOption(option); + if (target != __optionSet.end()) { + delete (*target); + __optionSet.erase(target); + } + + return ERR_NONE; +} + +int ctx::DeviceStatusAlarm::__getArrangedDayOfWeek(ctx::Json& option) +{ + int dow = 0; + + std::string tempDay; + for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &tempDay); i++) { + dow |= ctx::TimerManager::dowToInt(tempDay); + } + _D("Requested day of week (%#x)", dow); + + return dow; +} + +ctx::DeviceStatusAlarm::RefCountArray::RefCountArray() +{ + memset(count, 0, sizeof(int) * DAYS_PER_WEEK); +} + +int ctx::DeviceStatusAlarm::__mergeDayOfWeek(int* refCnt) +{ + int dayOfWeek = 0; + + for (int d = 0; d < DAYS_PER_WEEK; ++d) { + if (refCnt[d] > 0) { + dayOfWeek |= (0x01 << d); + } + } + + return dayOfWeek; +} + +bool ctx::DeviceStatusAlarm::__add(int minute, int dayOfWeek) +{ + IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 && + dayOfWeek > 0 && dayOfWeek <= static_cast(DayOfWeek::EVERYDAY), + false, _E, "Invalid parameter"); + + RefCountArray &ref = __refCountMap[minute]; + + for (int d = 0; d < DAYS_PER_WEEK; ++d) { + if ((dayOfWeek & (0x01 << d)) != 0) { + ref.count[d] += 1; + } + } + + return __resetTimer(minute); +} + +bool ctx::DeviceStatusAlarm::__remove(int minute, int dayOfWeek) +{ + IF_FAIL_RETURN_TAG(minute >= 0 && minute < 1440 && + dayOfWeek > 0 && dayOfWeek <= static_cast(DayOfWeek::EVERYDAY), + false, _E, "Invalid parameter"); + + RefCountArray &ref = __refCountMap[minute]; + + for (int d = 0; d < DAYS_PER_WEEK; ++d) { + if ((dayOfWeek & (0x01 << d)) != 0 && ref.count[d] > 0) { + ref.count[d] -= 1; + } + } + + return __resetTimer(minute); +} + +bool ctx::DeviceStatusAlarm::__resetTimer(int minute) +{ + int dayOfWeek = __mergeDayOfWeek(__refCountMap[minute].count); + TimerState &timer = __timerStateMap[minute]; + + if (dayOfWeek == timer.dayOfWeek) { + /* Necessary timers are already running... */ + return true; + } + + if (dayOfWeek == 0 && timer.timerId > 0) { + /* Turn off the timer at hour, if it is not necessray anymore. */ + __timerManager.remove(timer.timerId); + __timerStateMap.erase(minute); + __refCountMap.erase(minute); + return true; + } + + if (timer.timerId > 0) { + /* Turn off the current timer, to set a new one. */ + __timerManager.remove(timer.timerId); + timer.timerId = -1; + timer.dayOfWeek = 0; + } + + /* Create a new timer, w.r.t. the new dayOfWeek value. */ + int h = minute / 60; + int m = minute - h * 60; + int tid = __timerManager.setAt(h, m, static_cast(dayOfWeek), this); + IF_FAIL_RETURN_TAG(tid > 0, false, _E, "Timer setting failed"); + + timer.timerId = tid; + timer.dayOfWeek = dayOfWeek; + + return true; +} + +void ctx::DeviceStatusAlarm::__clear() +{ + for (auto it = __timerStateMap.begin(); it != __timerStateMap.end(); ++it) { + if (it->second.timerId > 0) { + __timerManager.remove(it->second.timerId); + } + } + + __timerStateMap.clear(); + __refCountMap.clear(); +} + +bool ctx::DeviceStatusAlarm::onTimerExpired(int timerId) +{ + time_t rawTime; + struct tm timeInfo; + + time(&rawTime); + tzset(); + localtime_r(&rawTime, &timeInfo); + + int hour = timeInfo.tm_hour; + int min = timeInfo.tm_min; + int dayOfWeek = (0x01 << timeInfo.tm_wday); + + __handleUpdate(hour, min, dayOfWeek); + + return true; +} + +void ctx::DeviceStatusAlarm::__handleUpdate(int hour, int min, int dayOfWeek) +{ + _I("Time: %02d:%02d, Day of Week: %#x", hour, min, dayOfWeek); + + ctx::Json dataRead; + int resultTime = hour * 60 + min; + std::string resultDay = ctx::TimerManager::dowToStr(dayOfWeek); + dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, resultTime); + dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, resultDay); + + for (auto it = __optionSet.begin(); it != __optionSet.end(); ++it) { + ctx::Json option = (**it); + if (__isMatched(option, resultTime, resultDay)) { + context_manager::publish(DEVICE_ST_SUBJ_ALARM, option, ERR_NONE, dataRead); + } + } +} + +bool ctx::DeviceStatusAlarm::__isMatched(ctx::Json& option, int time, std::string day) +{ + bool ret = false; + int optionTime; + for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &optionTime); i++){ + if (time == optionTime) { + ret = true; + break; + } + } + IF_FAIL_RETURN(ret, false); + + std::string optionDay; + for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &optionDay); i++){ + if (day == optionDay) { + return true; + } + } + + return false; +} + +ctx::DeviceStatusAlarm::OptionSet::iterator ctx::DeviceStatusAlarm::__findOption(ctx::Json& option) +{ + for (auto it = __optionSet.begin(); it != __optionSet.end(); ++it) { + if (option == (**it)) + return it; + } + return __optionSet.end(); +} + +void ctx::DeviceStatusAlarm::__destroyIfUnused() +{ + IF_FAIL_VOID(__optionSet.empty()); + destroy(NULL); +} diff --git a/src/device/system/Alarm.h b/src/device/system/Alarm.h new file mode 100644 index 0000000..0ae4fce --- /dev/null +++ b/src/device/system/Alarm.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _DEVICE_SYSTEM_STATUS_ALARM_H_ +#define _DEVICE_SYSTEM_STATUS_ALARM_H_ + +#include +#include +#include +#include +#include "../DeviceProviderBase.h" + +namespace ctx { + + class DeviceStatusAlarm : public ContextProviderBase, ITimerListener { + + GENERATE_PROVIDER_COMMON_DECL(DeviceStatusAlarm); + + public: + int subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult); + int unsubscribe(const char *subject, ctx::Json option); + int read(const char *subject, ctx::Json option, ctx::Json *requestResult); + int write(const char *subject, ctx::Json data, ctx::Json *requestResult); + + int subscribe(ctx::Json option); + int unsubscribe(ctx::Json option); + static bool isSupported(); + static void submitTriggerItem(); + + protected: + bool onTimerExpired(int timerId); + + private: + DeviceStatusAlarm(); + ~DeviceStatusAlarm(); + + struct RefCountArray { + int count[7]; /* reference counts for days of week*/ + RefCountArray(); + }; + + struct TimerState { + int timerId; + int dayOfWeek; /* day of week, merged into one integer */ + TimerState() : timerId(-1), dayOfWeek(0) {} + }; + + typedef std::map RefCountMap; + typedef std::map TimerStateMap; + typedef std::set OptionSet; + + RefCountMap __refCountMap; + TimerStateMap __timerStateMap; + OptionSet __optionSet; + TimerManager __timerManager; + + bool __add(int minute, int dayOfWeek); + bool __remove(int minute, int dayOfWeek); + bool __resetTimer(int hour); + void __clear(); + void __handleUpdate(int hour, int min, int dayOfWeek); + + int __getArrangedDayOfWeek(ctx::Json& option); + int __mergeDayOfWeek(int *refCnt); + + bool __isMatched(ctx::Json& option, int time, std::string day); + OptionSet::iterator __findOption(ctx::Json& option); + + void __destroyIfUnused(); + + }; +} + +#endif // _DEVICE_SYSTEM_STATUS_ALARM_H_ diff --git a/src/device/system/battery.cpp b/src/device/system/Battery.cpp similarity index 54% rename from src/device/system/battery.cpp rename to src/device/system/Battery.cpp index 6207db9..8313333 100644 --- a/src/device/system/battery.cpp +++ b/src/device/system/Battery.cpp @@ -15,25 +15,25 @@ */ #include -#include "system_types.h" -#include "battery.h" +#include "SystemTypes.h" +#include "Battery.h" -GENERATE_PROVIDER_COMMON_IMPL(device_status_battery); +GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusBattery); -ctx::device_status_battery::device_status_battery() +ctx::DeviceStatusBattery::DeviceStatusBattery() { } -ctx::device_status_battery::~device_status_battery() +ctx::DeviceStatusBattery::~DeviceStatusBattery() { } -bool ctx::device_status_battery::is_supported() +bool ctx::DeviceStatusBattery::isSupported() { return true; } -void ctx::device_status_battery::submit_trigger_item() +void ctx::DeviceStatusBattery::submitTriggerItem() { context_manager::registerTriggerItem(DEVICE_ST_SUBJ_BATTERY, OPS_SUBSCRIBE | OPS_READ, "{" @@ -43,33 +43,33 @@ void ctx::device_status_battery::submit_trigger_item() NULL); } -void ctx::device_status_battery::update_cb(device_callback_e device_type, void* value, void* user_data) +void ctx::DeviceStatusBattery::__updateCb(device_callback_e deviceType, void* value, void* userData) { - IF_FAIL_VOID(device_type == DEVICE_CALLBACK_BATTERY_LEVEL); + IF_FAIL_VOID(deviceType == DEVICE_CALLBACK_BATTERY_LEVEL); - device_status_battery *instance = static_cast(user_data); - instance->handle_update(device_type, value); + DeviceStatusBattery *instance = static_cast(userData); + instance->__handleUpdate(deviceType, value); } -void ctx::device_status_battery::handle_update(device_callback_e device_type, void* value) +void ctx::DeviceStatusBattery::__handleUpdate(device_callback_e deviceType, void* value) { intptr_t level = (intptr_t)value; - const char* level_string = trans_to_string(level); - IF_FAIL_VOID(level_string); + const char* levelString = __transToString(level); + IF_FAIL_VOID(levelString); ctx::Json dataRead; - dataRead.set(NULL, DEVICE_ST_LEVEL, level_string); + dataRead.set(NULL, DEVICE_ST_LEVEL, levelString); - bool charging_state = false; - int ret = device_battery_is_charging(&charging_state); + bool chargingState = false; + int ret = device_battery_is_charging(&chargingState); IF_FAIL_VOID_TAG(ret == DEVICE_ERROR_NONE, _E, "Getting state failed"); - dataRead.set(NULL, DEVICE_ST_IS_CHARGING, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + dataRead.set(NULL, DEVICE_ST_IS_CHARGING, chargingState ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); ctx::context_manager::publish(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, dataRead); } -const char* ctx::device_status_battery::trans_to_string(intptr_t level) +const char* ctx::DeviceStatusBattery::__transToString(intptr_t level) { switch (level) { case DEVICE_BATTERY_LEVEL_EMPTY: @@ -85,17 +85,17 @@ const char* ctx::device_status_battery::trans_to_string(intptr_t level) return DEVICE_ST_NORMAL; case DEVICE_BATTERY_LEVEL_FULL: - { - int percent; - device_battery_get_percent(&percent); - - if (percent == 100) { - return DEVICE_ST_FULL; - } else { - return DEVICE_ST_HIGH; - } + { + int percent; + device_battery_get_percent(&percent); + + if (percent == 100) { + return DEVICE_ST_FULL; + } else { + return DEVICE_ST_HIGH; } break; + } default: _E("Invalid battery level"); @@ -103,21 +103,21 @@ const char* ctx::device_status_battery::trans_to_string(intptr_t level) } } -int ctx::device_status_battery::subscribe() +int ctx::DeviceStatusBattery::subscribe() { - int ret = device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, update_cb, this); + int ret = device_add_callback(DEVICE_CALLBACK_BATTERY_LEVEL, __updateCb, this); IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::device_status_battery::unsubscribe() +int ctx::DeviceStatusBattery::unsubscribe() { - int ret = device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, update_cb); + int ret = device_remove_callback(DEVICE_CALLBACK_BATTERY_LEVEL, __updateCb); IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::device_status_battery::read() +int ctx::DeviceStatusBattery::read() { device_battery_level_e level; ctx::Json dataRead; @@ -125,16 +125,16 @@ int ctx::device_status_battery::read() int ret = device_battery_get_level_status(&level); IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED); - const char* level_string = trans_to_string(level); - IF_FAIL_RETURN(level_string, ERR_OPERATION_FAILED); + const char* levelString = __transToString(level); + IF_FAIL_RETURN(levelString, ERR_OPERATION_FAILED); - dataRead.set(NULL, DEVICE_ST_LEVEL, level_string); + dataRead.set(NULL, DEVICE_ST_LEVEL, levelString); - bool charging_state = false; - ret = device_battery_is_charging(&charging_state); + bool chargingState = false; + ret = device_battery_is_charging(&chargingState); IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED); - dataRead.set(NULL, DEVICE_ST_IS_CHARGING, charging_state ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + dataRead.set(NULL, DEVICE_ST_IS_CHARGING, chargingState ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_BATTERY, NULL, ERR_NONE, dataRead); return ERR_NONE; diff --git a/src/device/system/battery.h b/src/device/system/Battery.h similarity index 56% rename from src/device/system/battery.h rename to src/device/system/Battery.h index 8f8a723..cbc11ba 100644 --- a/src/device/system/battery.h +++ b/src/device/system/Battery.h @@ -14,33 +14,33 @@ * limitations under the License. */ -#ifndef _DEVICE_STATUS_BATTERY_LEVEL_H_ -#define _DEVICE_STATUS_BATTERY_LEVEL_H_ +#ifndef _DEVICE_SYSTEM_STATUS_BATTERY_H_ +#define _DEVICE_SYSTEM_STATUS_BATTERY_H_ #include #include -#include "../device_provider_base.h" +#include "../DeviceProviderBase.h" namespace ctx { - class device_status_battery : public device_provider_base { + class DeviceStatusBattery : public DeviceProviderBase { - GENERATE_PROVIDER_COMMON_DECL(device_status_battery); + GENERATE_PROVIDER_COMMON_DECL(DeviceStatusBattery); public: int subscribe(); int unsubscribe(); int read(); - static bool is_supported(); - static void submit_trigger_item(); + static bool isSupported(); + static void submitTriggerItem(); private: - device_status_battery(); - ~device_status_battery(); - const char* trans_to_string(intptr_t level); - void handle_update(device_callback_e device_type, void* value); - static void update_cb(device_callback_e device_type, void* value, void* user_data); + DeviceStatusBattery(); + ~DeviceStatusBattery(); + const char* __transToString(intptr_t level); + void __handleUpdate(device_callback_e deviceType, void* value); + static void __updateCb(device_callback_e deviceType, void* value, void* userData); }; } -#endif // _DEVICE_STATUS_BATTERY_LEVEL_H_ +#endif // _DEVICE_SYSTEM_STATUS_BATTERY_H_ diff --git a/src/device/system/Headphone.cpp b/src/device/system/Headphone.cpp new file mode 100644 index 0000000..3ec1281 --- /dev/null +++ b/src/device/system/Headphone.cpp @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "SystemTypes.h" +#include "Headphone.h" + +#define HANDLING_DELAY 2000 +#define MAX_HANDLING_COUNT 3 + +GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusHeadphone); + +ctx::DeviceStatusHeadphone::DeviceStatusHeadphone() : + __connected(false), + __audioJackState(RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED), + __btAudioState(false), + __btAudioCallbackOn(false), + __btEventHandlerAdded(false), + __btEventHandlingCount(0) +{ +} + +ctx::DeviceStatusHeadphone::~DeviceStatusHeadphone() +{ +} + +bool ctx::DeviceStatusHeadphone::isSupported() +{ + return true; +} + +void ctx::DeviceStatusHeadphone::submitTriggerItem() +{ + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_HEADPHONE, OPS_SUBSCRIBE | OPS_READ, + "{" + TRIG_BOOL_ITEM_DEF("IsConnected") "," + "\"Type\":{\"type\":\"string\",\"values\":[\"Normal\",\"Headset\",\"Bluetooth\"]}" + "}", + NULL); +} + +int ctx::DeviceStatusHeadphone::subscribe() +{ + __connected = __getCurrentStatus(); + + // Wired headphone + int ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, __onAudioJackStateChanged, this); + IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED); + + // Bluetooth headphone + __setBtAudioCallback(); + + return ERR_NONE; +} + +int ctx::DeviceStatusHeadphone::unsubscribe() +{ + runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS); + __unsetBtAudioCallback(); + + return ERR_NONE; +} + +int ctx::DeviceStatusHeadphone::read() +{ + if (!__beingSubscribed) + __connected = __getCurrentStatus(); + + Json data; + __generateDataPacket(&data); + ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data); + + return ERR_NONE; +} + +void ctx::DeviceStatusHeadphone::__setBtAudioCallback() +{ + IF_FAIL_VOID(!__btAudioCallbackOn); + int ret; + + ret = bt_initialize(); + if (ret != BT_ERROR_NONE) { + _W("Bluetooth initialization failed"); + return; + } + + ret = bt_device_set_connection_state_changed_cb(__onBtConnectionChanged, this); + if (ret != BT_ERROR_NONE) { + bt_deinitialize(); + return; + } + + __btAudioCallbackOn = true; +} + +void ctx::DeviceStatusHeadphone::__unsetBtAudioCallback() +{ + IF_FAIL_VOID(__btAudioCallbackOn); + + bt_device_unset_connection_state_changed_cb(); + bt_deinitialize(); + + __btAudioCallbackOn = false; +} + +void ctx::DeviceStatusHeadphone::__setBtAudioState(bool state) +{ + __btAudioState = state; +} + +bool ctx::DeviceStatusHeadphone::__getCurrentStatus() +{ + int ret; + + // Wired audio + ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, &__audioJackState); + IF_FAIL_RETURN(ret == ERR_NONE, __connected); + + // Bluetooth audio + __btAudioState = false; + ret = bt_initialize(); + if (ret == BT_ERROR_NONE) { + bt_adapter_foreach_bonded_device(__onBtBond, this); + bt_deinitialize(); + } + + return ((__audioJackState != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || __btAudioState); +} + +void ctx::DeviceStatusHeadphone::__generateDataPacket(ctx::Json* data) +{ + data->set(NULL, DEVICE_ST_IS_CONNECTED, __connected ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + + switch (__audioJackState) { + case RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_3WIRE: + data->set(NULL, DEVICE_ST_TYPE, DEVICE_ST_NORMAL); + break; + case RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_4WIRE: + data->set(NULL, DEVICE_ST_TYPE, DEVICE_ST_HEADSET); + break; + default: + if (__btAudioState) + data->set(NULL, DEVICE_ST_TYPE, DEVICE_ST_BLUETOOTH); + break; + } +} + +bool ctx::DeviceStatusHeadphone::__handleUpdate() +{ + bool prevState = __connected; + __connected = ((__audioJackState != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || __btAudioState); + + IF_FAIL_RETURN(prevState != __connected, false); + + ctx::Json data; + __generateDataPacket(&data); + ctx::context_manager::publish(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data); + return true; +} + +void ctx::DeviceStatusHeadphone::__handleAudioJackEvent() +{ + int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, &__audioJackState); + IF_FAIL_VOID_TAG(ret == ERR_NONE, _E, "Getting runtime info failed"); + __handleUpdate(); +} + +void ctx::DeviceStatusHeadphone::__onAudioJackStateChanged(runtime_info_key_e runtimeKey, void* userData) +{ + _D("EarJack"); + ctx::DeviceStatusHeadphone *instance = static_cast(userData); + instance->__handleAudioJackEvent(); +} + +void ctx::DeviceStatusHeadphone::__onBtConnectionChanged(bool connected, bt_device_connection_info_s *connInfo, void *userData) +{ + ctx::DeviceStatusHeadphone *instance = static_cast(userData); + IF_FAIL_VOID(connected != instance->__btAudioState); + IF_FAIL_VOID(!instance->__btEventHandlerAdded); + + if (connected) { + _D("BT state checking scheduled"); + instance->__btEventHandlerAdded = true; + instance->__btEventHandlingCount = 0; + g_timeout_add(HANDLING_DELAY, __handleBtEvent, userData); + } else { + __handleBtEvent(userData); + } +} + +gboolean ctx::DeviceStatusHeadphone::__handleBtEvent(gpointer data) +{ + _D("BT state checking started"); + ctx::DeviceStatusHeadphone *instance = static_cast(data); + instance->__btEventHandlerAdded = false; + + instance->__setBtAudioState(false); + int err = bt_adapter_foreach_bonded_device(__onBtBond, data); + IF_FAIL_RETURN_TAG(err == BT_ERROR_NONE, FALSE, _E, "bt_adapter_foreach_bonded_device() failed"); + + instance->__btEventHandlingCount++; + + if (instance->__handleUpdate() || instance->__btEventHandlingCount >= MAX_HANDLING_COUNT) + return FALSE; + + return TRUE; +} + +bool ctx::DeviceStatusHeadphone::__onBtBond(bt_device_info_s *deviceInfo, void* userData) +{ + if (deviceInfo->bt_class.major_device_class != BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO) + return true; + + bool st = false; + int err = bt_device_is_profile_connected(deviceInfo->remote_address, BT_PROFILE_A2DP, &st); + IF_FAIL_RETURN_TAG(err == BT_ERROR_NONE, false, _E, "bt_device_is_profile_connected() failed"); + + if (st) { + ctx::DeviceStatusHeadphone *instance = static_cast(userData); + instance->__setBtAudioState(true); + return false; + } + + return true; +} diff --git a/src/device/system/Headphone.h b/src/device/system/Headphone.h new file mode 100644 index 0000000..394a6d9 --- /dev/null +++ b/src/device/system/Headphone.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _DEVICE_SYSTEM_STATUS_HEADPHONE_H_ +#define _DEVICE_STATUS_HEADPNOHE_H_ + +#include +#include +#include +#include "../DeviceProviderBase.h" + +namespace ctx { + + class DeviceStatusHeadphone : public DeviceProviderBase { + + GENERATE_PROVIDER_COMMON_DECL(DeviceStatusHeadphone); + + public: + int subscribe(); + int unsubscribe(); + int read(); + static bool isSupported(); + static void submitTriggerItem(); + + private: + bool __connected; + int __audioJackState; + bool __btAudioState; + bool __btAudioCallbackOn; + bool __btEventHandlerAdded; + int __btEventHandlingCount; + + DeviceStatusHeadphone(); + ~DeviceStatusHeadphone(); + + bool __getCurrentStatus(); + void __setBtAudioCallback(); + void __unsetBtAudioCallback(); + void __setBtAudioState(bool state); + + void __generateDataPacket(Json* data); + bool __handleUpdate(); + void __handleAudioJackEvent(); + static gboolean __handleBtEvent(gpointer data); + + static void __onAudioJackStateChanged(runtime_info_key_e runtimeKey, void* userData); + static void __onBtConnectionChanged(bool connected, bt_device_connection_info_s *connInfo, void *userData); + static bool __onBtBond(bt_device_info_s *deviceInfo, void* userData); + }; +} + +#endif // _DEVICE_SYSTEM_STATUS_HEADPHONE_H_ diff --git a/src/device/system/psmode.cpp b/src/device/system/Psmode.cpp similarity index 66% rename from src/device/system/psmode.cpp rename to src/device/system/Psmode.cpp index dc39f98..894faf0 100644 --- a/src/device/system/psmode.cpp +++ b/src/device/system/Psmode.cpp @@ -15,37 +15,37 @@ */ #include -#include "system_types.h" -#include "psmode.h" +#include "SystemTypes.h" +#include "Psmode.h" -GENERATE_PROVIDER_COMMON_IMPL(device_status_psmode); +GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusPsmode); -ctx::device_status_psmode::device_status_psmode() +ctx::DeviceStatusPsmode::DeviceStatusPsmode() { } -ctx::device_status_psmode::~device_status_psmode() +ctx::DeviceStatusPsmode::~DeviceStatusPsmode() { } -bool ctx::device_status_psmode::is_supported() +bool ctx::DeviceStatusPsmode::isSupported() { return true; } -void ctx::device_status_psmode::submit_trigger_item() +void ctx::DeviceStatusPsmode::submitTriggerItem() { context_manager::registerTriggerItem(DEVICE_ST_SUBJ_PSMODE, OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsEnabled") "}", NULL); } -void ctx::device_status_psmode::update_cb(keynode_t *node, void* user_data) +void ctx::DeviceStatusPsmode::__updateCb(keynode_t *node, void* userData) { - device_status_psmode *instance = static_cast(user_data); - instance->handle_update(node); + DeviceStatusPsmode *instance = static_cast(userData); + instance->__handleUpdate(node); } -void ctx::device_status_psmode::handle_update(keynode_t *node) +void ctx::DeviceStatusPsmode::__handleUpdate(keynode_t *node) { int status; ctx::Json dataRead; @@ -58,21 +58,21 @@ void ctx::device_status_psmode::handle_update(keynode_t *node) context_manager::publish(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, dataRead); } -int ctx::device_status_psmode::subscribe() +int ctx::DeviceStatusPsmode::subscribe() { - int ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, update_cb, this); + int ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, __updateCb, this); IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::device_status_psmode::unsubscribe() +int ctx::DeviceStatusPsmode::unsubscribe() { - int ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, update_cb); + int ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, __updateCb); IF_FAIL_RETURN(ret == VCONF_OK, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::device_status_psmode::read() +int ctx::DeviceStatusPsmode::read() { int mode; int ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &mode); diff --git a/src/device/system/psmode.h b/src/device/system/Psmode.h similarity index 58% rename from src/device/system/psmode.h rename to src/device/system/Psmode.h index 1d4e4f3..d18201e 100644 --- a/src/device/system/psmode.h +++ b/src/device/system/Psmode.h @@ -14,31 +14,31 @@ * limitations under the License. */ -#ifndef _DEVICE_STATUS_POWER_SAVING_MODE_H_ -#define _DEVICE_STATUS_POWER_SAVING_MODE_H_ +#ifndef _DEVICE_SYSTEM_STATUS_POWER_SAVING_MODE_H_ +#define _DEVICE_SYSTEM_STATUS_POWER_SAVING_MODE_H_ #include -#include "../device_provider_base.h" +#include "../DeviceProviderBase.h" namespace ctx { - class device_status_psmode : public device_provider_base { + class DeviceStatusPsmode : public DeviceProviderBase { - GENERATE_PROVIDER_COMMON_DECL(device_status_psmode); + GENERATE_PROVIDER_COMMON_DECL(DeviceStatusPsmode); public: int subscribe(); int unsubscribe(); int read(); - static bool is_supported(); - static void submit_trigger_item(); + static bool isSupported(); + static void submitTriggerItem(); private: - device_status_psmode(); - ~device_status_psmode(); - void handle_update(keynode_t *node); - static void update_cb(keynode_t *node, void* user_data); + DeviceStatusPsmode(); + ~DeviceStatusPsmode(); + void __handleUpdate(keynode_t *node); + static void __updateCb(keynode_t *node, void* userData); }; } -#endif // _DEVICE_STATUS_POWER_SAVING_H_ +#endif // _DEVICE_SYSTEM_STATUS_POWER_SAVING_MODE_H_ diff --git a/src/device/system/system_types.h b/src/device/system/SystemTypes.h similarity index 94% rename from src/device/system/system_types.h rename to src/device/system/SystemTypes.h index 2faa361..3129a36 100644 --- a/src/device/system/system_types.h +++ b/src/device/system/SystemTypes.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __CONTEXT_DEVICESTATUS_TYPES_H__ -#define __CONTEXT_DEVICESTATUS_TYPES_H__ +#ifndef _DEVICE_SYSTEM_STATUS_TYPES_H_ +#define _DEVICE_SYSTEM_STATUS_TYPES_H_ // Subject #define DEVICE_ST_SUBJ_BATTERY "system/battery" @@ -62,4 +62,4 @@ #define TRIG_BOOL_ITEM_DEF(sbj) "\"" sbj "\":{\"type\":\"integer\",\"min\":0,\"max\":1}" -#endif //__CONTEXT_DEVICESTATUS_TYPES_H__ +#endif //_DEVICE_SYSTEM_STATUS_TYPES_H_ diff --git a/src/device/system/time.cpp b/src/device/system/Time.cpp similarity index 57% rename from src/device/system/time.cpp rename to src/device/system/Time.cpp index 6cd5ea0..af3ded1 100644 --- a/src/device/system/time.cpp +++ b/src/device/system/Time.cpp @@ -16,25 +16,25 @@ #include #include -#include "system_types.h" -#include "time.h" +#include "SystemTypes.h" +#include "Time.h" -GENERATE_PROVIDER_COMMON_IMPL(device_status_time); +GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusTime); -ctx::device_status_time::device_status_time() +ctx::DeviceStatusTime::DeviceStatusTime() { } -ctx::device_status_time::~device_status_time() +ctx::DeviceStatusTime::~DeviceStatusTime() { } -bool ctx::device_status_time::is_supported() +bool ctx::DeviceStatusTime::isSupported() { return true; } -void ctx::device_status_time::submit_trigger_item() +void ctx::DeviceStatusTime::submitTriggerItem() { context_manager::registerTriggerItem(DEVICE_ST_SUBJ_TIME, OPS_READ, "{" @@ -45,35 +45,35 @@ void ctx::device_status_time::submit_trigger_item() NULL); } -int ctx::device_status_time::subscribe() +int ctx::DeviceStatusTime::subscribe() { return ERR_NOT_SUPPORTED; } -int ctx::device_status_time::unsubscribe() +int ctx::DeviceStatusTime::unsubscribe() { return ERR_NOT_SUPPORTED; } -int ctx::device_status_time::read() +int ctx::DeviceStatusTime::read() { time_t rawtime; - struct tm timeinfo; + struct tm timeInfo; time(&rawtime); tzset(); - localtime_r(&rawtime, &timeinfo); + localtime_r(&rawtime, &timeInfo); - int day_of_month = timeinfo.tm_mday; - int minute_of_day = timeinfo.tm_hour * 60 + timeinfo.tm_min; - std::string day_of_week = ctx::TimerManager::dowToStr(0x01 << timeinfo.tm_wday); + int dayOfMonth = timeInfo.tm_mday; + int minuteOfDay = timeInfo.tm_hour * 60 + timeInfo.tm_min; + std::string dayOfWeek = ctx::TimerManager::dowToStr(0x01 << timeInfo.tm_wday); ctx::Json dataRead; - dataRead.set(NULL, DEVICE_ST_DAY_OF_MONTH, day_of_month); - dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, day_of_week); - dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, minute_of_day); + dataRead.set(NULL, DEVICE_ST_DAY_OF_MONTH, dayOfMonth); + dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, dayOfWeek); + dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, minuteOfDay); - _I("Time: %02d:%02d, Day of Week: %s, Day of Month: %d", timeinfo.tm_hour, timeinfo.tm_min, day_of_week.c_str(), day_of_month); + _I("Time: %02d:%02d, Day of Week: %s, Day of Month: %d", timeInfo.tm_hour, timeInfo.tm_min, dayOfWeek.c_str(), dayOfMonth); ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_TIME, NULL, ERR_NONE, dataRead); diff --git a/src/device/system/time.h b/src/device/system/Time.h similarity index 66% rename from src/device/system/time.h rename to src/device/system/Time.h index 7d44bec..2a97993 100644 --- a/src/device/system/time.h +++ b/src/device/system/Time.h @@ -14,28 +14,28 @@ * limitations under the License. */ -#ifndef _DEVICE_STATUS_TIME_H_ -#define _DEVICE_STATUS_TIME_H_ +#ifndef _DEVICE_SYSTEM_STATUS_TIME_H_ +#define _DEVICE_SYSTEM_STATUS_TIME_H_ -#include "../device_provider_base.h" +#include "../DeviceProviderBase.h" namespace ctx { - class device_status_time : public device_provider_base { + class DeviceStatusTime : public DeviceProviderBase { - GENERATE_PROVIDER_COMMON_DECL(device_status_time); + GENERATE_PROVIDER_COMMON_DECL(DeviceStatusTime); public: int subscribe(); int unsubscribe(); int read(); - static bool is_supported(); - static void submit_trigger_item(); + static bool isSupported(); + static void submitTriggerItem(); private: - device_status_time(); - ~device_status_time(); + DeviceStatusTime(); + ~DeviceStatusTime(); }; } -#endif // _DEVICE_STATUS_TIME_H_ +#endif // _DEVICE_SYSTEM_STATUS_TIME_H_ diff --git a/src/device/system/Wifi.cpp b/src/device/system/Wifi.cpp new file mode 100644 index 0000000..e3a8a3a --- /dev/null +++ b/src/device/system/Wifi.cpp @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "SystemTypes.h" +#include "Wifi.h" + +ctx::DeviceStatusWifi *ctx::DeviceStatusWifi::__instance = NULL; + +ctx::DeviceStatusWifi::DeviceStatusWifi() : + __lastState(UNKNOWN), + __isInitialized(false), + __isActivated(false), + __connState(WIFI_CONNECTION_STATE_FAILURE) +{ + IF_FAIL_VOID_TAG(__startMonitor(), _W, "WiFi monitor initialization failed"); + + if (!__getCurrentState()) { + __stopMonitor(); + _W("Getting current WiFi status failed"); + } +} + +ctx::DeviceStatusWifi::~DeviceStatusWifi() +{ +} + +ctx::ContextProviderBase *ctx::DeviceStatusWifi::create(void *data) +{ + CREATE_INSTANCE(DeviceStatusWifi); +} + +void ctx::DeviceStatusWifi::destroy(void *data) +{ + __instance->__stopMonitor(); + DESTROY_INSTANCE(); +} + +void ctx::DeviceStatusWifi::destroySelf() +{ + /* WiFi status will be monitored continuously, even if no client is subscribing it */ +} + +bool ctx::DeviceStatusWifi::isSupported() +{ + return getSystemInfoBool("tizen.org/feature/network.wifi"); +} + +void ctx::DeviceStatusWifi::submitTriggerItem() +{ + context_manager::registerTriggerItem(DEVICE_ST_SUBJ_WIFI, OPS_SUBSCRIBE | OPS_READ, + "{" + "\"State\":{\"type\":\"string\",\"values\":[\"Disabled\",\"Unconnected\",\"Connected\"]}," + "\"BSSID\":{\"type\":\"string\"}" + "}", + NULL); +} + +bool ctx::DeviceStatusWifi::__getCurrentState() +{ + int err; + + if (!__isInitialized) { + err = wifi_initialize(); + IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_initialize() failed"); + } + + err = wifi_is_activated(&__isActivated); + IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_is_activated() failed"); + + err = wifi_get_connection_state(&__connState); + IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_get_connection_state() failed"); + + if (__isActivated) { + if (__connState == WIFI_CONNECTION_STATE_CONNECTED) { + __lastState = CONNECTED; + __getBssid(); + } else { + __lastState = UNCONNECTED; + __clearBssid(); + } + } else { + __lastState = DISABLED; + __clearBssid(); + } + + if (!__isInitialized) + wifi_deinitialize(); + + return true; +} + +bool ctx::DeviceStatusWifi::__getBssid() +{ + int err; + char *strBuf = NULL; + wifi_ap_h ap = NULL; + + err = wifi_get_connected_ap(&ap); + IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_get_connected_ap() failed"); + + wifi_ap_get_bssid(ap, &strBuf); + __bssid = (strBuf != NULL ? strBuf : ""); + g_free(strBuf); + + wifi_ap_destroy(ap); + + if (__bssid.empty()) + _W("Failed to get BSSID"); + + SharedVars().set(ctx::SharedVars::WIFI_BSSID, __bssid); + _D("BSSID: %s", __bssid.c_str()); + + return !__bssid.empty(); +} + +void ctx::DeviceStatusWifi::__clearBssid() +{ + __bssid.clear(); + SharedVars().clear(ctx::SharedVars::WIFI_BSSID); + _D("No WiFi connection"); +} + +bool ctx::DeviceStatusWifi::__getResponsePacket(ctx::Json* data) +{ + switch (__lastState) { + case DISABLED: + data->set(NULL, DEVICE_ST_STATE, DEVICE_ST_DISABLED); + break; + + case UNCONNECTED: + data->set(NULL, DEVICE_ST_STATE, DEVICE_ST_UNCONNECTED); + break; + + case CONNECTED: + data->set(NULL, DEVICE_ST_STATE, DEVICE_ST_CONNECTED); + data->set(NULL, DEVICE_ST_BSSID, __bssid); + break; + + default: + return false; + } + + return true; +} + +int ctx::DeviceStatusWifi::read() +{ + IF_FAIL_RETURN(__getCurrentState(), ERR_OPERATION_FAILED); + + ctx::Json dataRead; + if (__getResponsePacket(&dataRead)) { + ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, dataRead); + return ERR_NONE; + } + + return ERR_OPERATION_FAILED; +} + +bool ctx::DeviceStatusWifi::__startMonitor() +{ + IF_FAIL_RETURN(!__isInitialized, true); + + int err; + err = wifi_initialize(); + IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_initialize() failed"); + + err = wifi_set_device_state_changed_cb(__deviceStateChangedCb, this); + IF_FAIL_CATCH_TAG(err == WIFI_ERROR_NONE, _E, "wifi_set_device_state_changed_cb() failed"); + + err = wifi_set_connection_state_changed_cb(__connectionStateChangedCb, this); + IF_FAIL_CATCH_TAG(err == WIFI_ERROR_NONE, _E, "wifi_set_connection_state_changed_cb() failed"); + + __isInitialized = true; + return true; + +CATCH: + wifi_deinitialize(); + return false; +} + +void ctx::DeviceStatusWifi::__stopMonitor() +{ + IF_FAIL_VOID(__isInitialized); + + wifi_unset_device_state_changed_cb(); + wifi_unset_connection_state_changed_cb(); + wifi_deinitialize(); + __isInitialized = false; +} + +int ctx::DeviceStatusWifi::subscribe() +{ +#if 0 + IF_FAIL_RETURN(__startMonitor(), ERR_OPERATION_FAILED); + if (!__getCurrentState()) { + __stopMonitor(); + return ERR_OPERATION_FAILED; + } +#endif + + return ERR_NONE; +} + +int ctx::DeviceStatusWifi::unsubscribe() +{ +#if 0 + __stopMonitor(); +#endif + return ERR_NONE; +} + +void ctx::DeviceStatusWifi::__handleUpdate() +{ + int prevState = __lastState; + + if (__isActivated) { + if (__connState == WIFI_CONNECTION_STATE_CONNECTED) { + __lastState = CONNECTED; + } else { + __lastState = UNCONNECTED; + } + } else { + __lastState = DISABLED; + } + + if (__lastState != prevState) { + if (__lastState == CONNECTED) { + __getBssid(); + } else { + __clearBssid(); + } + + ctx::Json data; + if (__beingSubscribed && __getResponsePacket(&data)) + context_manager::publish(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, data); + } +} + +void ctx::DeviceStatusWifi::__deviceStateChangedCb(wifi_device_state_e state, void *userData) +{ + DeviceStatusWifi *instance = static_cast(userData); + instance->__isActivated = (state == WIFI_DEVICE_STATE_ACTIVATED); + instance->__handleUpdate(); +} + +void ctx::DeviceStatusWifi::__connectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *userData) +{ + DeviceStatusWifi *instance = static_cast(userData); + instance->__connState = state; + instance->__handleUpdate(); +} diff --git a/src/device/system/Wifi.h b/src/device/system/Wifi.h new file mode 100644 index 0000000..59b721d --- /dev/null +++ b/src/device/system/Wifi.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _DEVICE_SYSTEM_STATUS_WIFI_H_ +#define _DEVICE_SYSTEM_STATUS_WIFI_H_ + +#include +#include +#include "../DeviceProviderBase.h" + +namespace ctx { + + class DeviceStatusWifi : public DeviceProviderBase { + + GENERATE_PROVIDER_COMMON_DECL(DeviceStatusWifi); + + public: + int subscribe(); + int unsubscribe(); + int read(); + static bool isSupported(); + static void submitTriggerItem(); + + private: + enum InternalState { + UNKNOWN = -1, + DISABLED = 0, + UNCONNECTED, + CONNECTED, + }; + + int __lastState; + bool __isInitialized; + bool __isActivated; + wifi_connection_state_e __connState; + std::string __bssid; + + DeviceStatusWifi(); + ~DeviceStatusWifi(); + + bool __getCurrentState(); + bool __getBssid(); + void __clearBssid(); + bool __getResponsePacket(Json* data); + void __handleUpdate(); + bool __startMonitor(); + void __stopMonitor(); + static void __deviceStateChangedCb(wifi_device_state_e state, void *userData); + static void __connectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *userData); + }; +} + +#endif // _CONTEXT_SYSTEM_STATUS_WIFI_H_ diff --git a/src/device/system/alarm.cpp b/src/device/system/alarm.cpp deleted file mode 100644 index d4434a9..0000000 --- a/src/device/system/alarm.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "system_types.h" -#include "alarm.h" - -GENERATE_PROVIDER_COMMON_IMPL(device_status_alarm); - -ctx::device_status_alarm::device_status_alarm() -{ -} - -ctx::device_status_alarm::~device_status_alarm() -{ - clear(); - - for (ctx::device_status_alarm::option_t::iterator it = option_set.begin(); it != option_set.end(); ++it) { - delete *it; - } - option_set.clear(); -} - -bool ctx::device_status_alarm::is_supported() -{ - return true; -} - -void ctx::device_status_alarm::submit_trigger_item() -{ - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_ALARM, OPS_SUBSCRIBE, - "{" - "\"TimeOfDay\":{\"type\":\"integer\",\"min\":0,\"max\":1439}," - "\"DayOfWeek\":{\"type\":\"string\",\"values\":[\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\",\"Sun\",\"Weekday\",\"Weekend\"]}" - "}", - NULL); -} - -int ctx::device_status_alarm::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) -{ - int ret = subscribe(option); - destroy_if_unused(); - return ret; -} - -int ctx::device_status_alarm::unsubscribe(const char *subject, ctx::Json option) -{ - int ret = unsubscribe(option); - destroy_if_unused(); - return ret; -} - -int ctx::device_status_alarm::read(const char *subject, ctx::Json option, ctx::Json *requestResult) -{ - destroy_if_unused(); - return ERR_NOT_SUPPORTED; -} - -int ctx::device_status_alarm::write(const char *subject, ctx::Json data, ctx::Json *requestResult) -{ - destroy_if_unused(); - return ERR_NOT_SUPPORTED; -} - -int ctx::device_status_alarm::subscribe(ctx::Json option) -{ - int dow = get_arranged_day_of_week(option); - - int time; - for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) { - add(time, dow); - } - - ctx::Json* elem = new(std::nothrow) ctx::Json(option); - if (elem) { - option_set.insert(elem); - } else { - unsubscribe(option); - _E("Memory allocation failed"); - return ERR_OUT_OF_MEMORY; - } - - return ERR_NONE; -} - -int ctx::device_status_alarm::unsubscribe(ctx::Json option) -{ - int dow = get_arranged_day_of_week(option); - - int time; - for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) { - remove(time, dow); - } - - option_t::iterator target = find_option(option); - if (target != option_set.end()) { - delete (*target); - option_set.erase(target); - } - - return ERR_NONE; -} - -int ctx::device_status_alarm::get_arranged_day_of_week(ctx::Json& option) -{ - int dow = 0; - - std::string tmp_d; - for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &tmp_d); i++) { - dow |= ctx::TimerManager::dowToInt(tmp_d); - } - _D("Requested day of week (%#x)", dow); - - return dow; -} - -ctx::device_status_alarm::ref_count_array_s::ref_count_array_s() -{ - memset(count, 0, sizeof(int) * DAYS_PER_WEEK); -} - -int ctx::device_status_alarm::merge_day_of_week(int* ref_cnt) -{ - int day_of_week = 0; - - for (int d = 0; d < DAYS_PER_WEEK; ++d) { - if (ref_cnt[d] > 0) { - day_of_week |= (0x01 << d); - } - } - - return day_of_week; -} - -bool ctx::device_status_alarm::add(int minute, int day_of_week) -{ - IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 && - day_of_week > 0 && day_of_week <= static_cast(DayOfWeek::EVERYDAY), - false, _E, "Invalid parameter"); - - ref_count_array_s &ref = ref_count_map[minute]; - - for (int d = 0; d < DAYS_PER_WEEK; ++d) { - if ((day_of_week & (0x01 << d)) != 0) { - ref.count[d] += 1; - } - } - - return reset_timer(minute); -} - -bool ctx::device_status_alarm::remove(int minute, int day_of_week) -{ - IF_FAIL_RETURN_TAG(minute >=0 && minute < 1440 && - day_of_week > 0 && day_of_week <= static_cast(DayOfWeek::EVERYDAY), - false, _E, "Invalid parameter"); - - ref_count_array_s &ref = ref_count_map[minute]; - - for (int d = 0; d < DAYS_PER_WEEK; ++d) { - if ((day_of_week & (0x01 << d)) != 0 && ref.count[d] > 0) { - ref.count[d] -= 1; - } - } - - return reset_timer(minute); -} - -bool ctx::device_status_alarm::reset_timer(int minute) -{ - int day_of_week = merge_day_of_week(ref_count_map[minute].count); - timer_state_s &timer = timer_state_map[minute]; - - if (day_of_week == timer.day_of_week) { - /* Necessary timers are already running... */ - return true; - } - - if (day_of_week == 0 && timer.timer_id > 0) { - /* Turn off the timer at hour, if it is not necessray anymore. */ - __timerManager.remove(timer.timer_id); - timer_state_map.erase(minute); - ref_count_map.erase(minute); - return true; - } - - if (timer.timer_id > 0) { - /* Turn off the current timer, to set a new one. */ - __timerManager.remove(timer.timer_id); - timer.timer_id = -1; - timer.day_of_week = 0; - } - - /* Create a new timer, w.r.t. the new day_of_week value. */ - int h = minute / 60; - int m = minute - h * 60; - int tid = __timerManager.setAt(h, m, static_cast(day_of_week), this); - IF_FAIL_RETURN_TAG(tid > 0, false, _E, "Timer setting failed"); - - timer.timer_id = tid; - timer.day_of_week = day_of_week; - - return true; -} - -void ctx::device_status_alarm::clear() -{ - for (timer_state_map_t::iterator it = timer_state_map.begin(); it != timer_state_map.end(); ++it) { - if (it->second.timer_id > 0) { - __timerManager.remove(it->second.timer_id); - } - } - - timer_state_map.clear(); - ref_count_map.clear(); -} - -bool ctx::device_status_alarm::onTimerExpired(int timer_id) -{ - time_t rawtime; - struct tm timeinfo; - - time(&rawtime); - tzset(); - localtime_r(&rawtime, &timeinfo); - - int hour = timeinfo.tm_hour; - int min = timeinfo.tm_min; - int day_of_week = (0x01 << timeinfo.tm_wday); - - on_timer_expired(hour, min, day_of_week); - - return true; -} - -void ctx::device_status_alarm::on_timer_expired(int hour, int min, int day_of_week) -{ - _I("Time: %02d:%02d, Day of Week: %#x", hour, min, day_of_week); - - ctx::Json dataRead; - int result_time = hour * 60 + min; - std::string result_day = ctx::TimerManager::dowToStr(day_of_week); - dataRead.set(NULL, DEVICE_ST_TIME_OF_DAY, result_time); - dataRead.set(NULL, DEVICE_ST_DAY_OF_WEEK, result_day); - - for (option_t::iterator it = option_set.begin(); it != option_set.end(); ++it) { - ctx::Json option = (**it); - if (is_matched(option, result_time, result_day)) { - context_manager::publish(DEVICE_ST_SUBJ_ALARM, option, ERR_NONE, dataRead); - } - } -} - -bool ctx::device_status_alarm::is_matched(ctx::Json& option, int time, std::string day) -{ - bool ret = false; - int opt_time; - for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &opt_time); i++){ - if (time == opt_time) { - ret = true; - break; - } - } - IF_FAIL_RETURN(ret, false); - - std::string opt_day; - for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &opt_day); i++){ - if (day == opt_day) { - return true; - } - } - - return false; -} - -ctx::device_status_alarm::option_t::iterator ctx::device_status_alarm::find_option(ctx::Json& option) -{ - for (ctx::device_status_alarm::option_t::iterator it = option_set.begin(); it != option_set.end(); ++it) { - if (option == (**it)) - return it; - } - return option_set.end(); -} - -void ctx::device_status_alarm::destroy_if_unused() -{ - IF_FAIL_VOID(option_set.empty()); - destroy(NULL); -} diff --git a/src/device/system/alarm.h b/src/device/system/alarm.h deleted file mode 100644 index ff5271b..0000000 --- a/src/device/system/alarm.h +++ /dev/null @@ -1,88 +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_ALARM_H_ -#define _DEVICE_STATUS_ALARM_H_ - -#include -#include -#include -#include -#include "../device_provider_base.h" - -namespace ctx { - - class device_status_alarm : public ContextProviderBase, ITimerListener { - - GENERATE_PROVIDER_COMMON_DECL(device_status_alarm); - - public: - int subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult); - int unsubscribe(const char *subject, ctx::Json option); - int read(const char *subject, ctx::Json option, ctx::Json *requestResult); - int write(const char *subject, ctx::Json data, ctx::Json *requestResult); - - int subscribe(ctx::Json option); - int unsubscribe(ctx::Json option); - static bool is_supported(); - static void submit_trigger_item(); - - private: - device_status_alarm(); - ~device_status_alarm(); - void handle_update(); - static void update_cb(void* user_data); - int get_arranged_day_of_week(ctx::Json& option); - - struct ref_count_array_s { - int count[7]; /* reference counts for days of week*/ - ref_count_array_s(); - }; - - struct timer_state_s { - int timer_id; - int day_of_week; /* day of week, merged into one integer */ - timer_state_s() : timer_id(-1), day_of_week(0) {} - }; - - typedef std::map ref_count_map_t; - typedef std::map timer_state_map_t; - typedef std::set option_t; - - ref_count_map_t ref_count_map; - timer_state_map_t timer_state_map; - option_t option_set; - TimerManager __timerManager; - - bool add(int minute, int day_of_week); - bool remove(int minute, int day_of_week); - void clear(); - bool empty(); - - int merge_day_of_week(int *ref_cnt); - bool reset_timer(int hour); - void on_timer_expired(int hour, int min, int day_of_week); - bool onTimerExpired(int timer_id); - - bool is_matched(ctx::Json& option, int time, std::string day); - option_t::iterator find_option(ctx::Json& option); - - void destroy_if_unused(); - - }; -} - -#endif // _DEVICE_STATUS_ALARM_H_ diff --git a/src/device/system/headphone.cpp b/src/device/system/headphone.cpp deleted file mode 100644 index 91e1708..0000000 --- a/src/device/system/headphone.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "system_types.h" -#include "headphone.h" - -#define HANDLING_DELAY 2000 -#define MAX_HANDLING_COUNT 3 - -GENERATE_PROVIDER_COMMON_IMPL(device_status_headphone); - -ctx::device_status_headphone::device_status_headphone() - : connected(false) - , audio_jack_state(RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) - , bt_audio_state(false) - , bt_audio_callback_on(false) - , bt_event_handler_added(false) - , bt_event_handling_count(0) -{ -} - -ctx::device_status_headphone::~device_status_headphone() -{ -} - -bool ctx::device_status_headphone::is_supported() -{ - return true; -} - -void ctx::device_status_headphone::submit_trigger_item() -{ - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_HEADPHONE, OPS_SUBSCRIBE | OPS_READ, - "{" - TRIG_BOOL_ITEM_DEF("IsConnected") "," - "\"Type\":{\"type\":\"string\",\"values\":[\"Normal\",\"Headset\",\"Bluetooth\"]}" - "}", - NULL); -} - -int ctx::device_status_headphone::subscribe() -{ - connected = get_current_status(); - - // Wired headphone - int ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, on_audio_jack_state_changed, this); - IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED); - - // Bluetooth headphone - set_bt_audio_callback(); - - return ERR_NONE; -} - -int ctx::device_status_headphone::unsubscribe() -{ - runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS); - unset_bt_audio_callback(); - - return ERR_NONE; -} - -int ctx::device_status_headphone::read() -{ - if (!being_subscribed) - connected = get_current_status(); - - Json data; - generate_data_packet(data); - ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data); - - return ERR_NONE; -} - -void ctx::device_status_headphone::set_bt_audio_callback() -{ - IF_FAIL_VOID(!bt_audio_callback_on); - int ret; - - ret = bt_initialize(); - if (ret != BT_ERROR_NONE) { - _W("Bluetooth initialization failed"); - return; - } - - ret = bt_device_set_connection_state_changed_cb(on_bt_connection_changed, this); - if (ret != BT_ERROR_NONE) { - bt_deinitialize(); - return; - } - - bt_audio_callback_on = true; -} - -void ctx::device_status_headphone::unset_bt_audio_callback() -{ - IF_FAIL_VOID(bt_audio_callback_on); - - bt_device_unset_connection_state_changed_cb(); - bt_deinitialize(); - - bt_audio_callback_on = false; -} - -void ctx::device_status_headphone::set_bt_audio_state(bool state) -{ - bt_audio_state = state; -} - -bool ctx::device_status_headphone::get_current_status() -{ - int ret; - - // Wired audio - ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, &audio_jack_state); - IF_FAIL_RETURN(ret == ERR_NONE, connected); - - // Bluetooth audio - bt_audio_state = false; - ret = bt_initialize(); - if (ret == BT_ERROR_NONE) { - bt_adapter_foreach_bonded_device(on_bt_bond, this); - bt_deinitialize(); - } - - return ((audio_jack_state != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || bt_audio_state); -} - -void ctx::device_status_headphone::generate_data_packet(ctx::Json &data) -{ - data.set(NULL, DEVICE_ST_IS_CONNECTED, connected ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); - - switch (audio_jack_state) { - case RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_3WIRE: - data.set(NULL, DEVICE_ST_TYPE, DEVICE_ST_NORMAL); - break; - case RUNTIME_INFO_AUDIO_JACK_STATUS_CONNECTED_4WIRE: - data.set(NULL, DEVICE_ST_TYPE, DEVICE_ST_HEADSET); - break; - default: - if (bt_audio_state) - data.set(NULL, DEVICE_ST_TYPE, DEVICE_ST_BLUETOOTH); - break; - } -} - -bool ctx::device_status_headphone::handle_event() -{ - bool prev_state = connected; - connected = ((audio_jack_state != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || bt_audio_state); - - IF_FAIL_RETURN(prev_state != connected, false); - - ctx::Json data; - generate_data_packet(data); - ctx::context_manager::publish(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data); - return true; -} - -void ctx::device_status_headphone::handle_audio_jack_event() -{ - int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_AUDIO_JACK_STATUS, &audio_jack_state); - IF_FAIL_VOID_TAG(ret == ERR_NONE, _E, "Getting runtime info failed"); - handle_event(); -} - -void ctx::device_status_headphone::on_audio_jack_state_changed(runtime_info_key_e runtime_key, void* user_data) -{ - _D("EarJack"); - ctx::device_status_headphone *instance = static_cast(user_data); - instance->handle_audio_jack_event(); -} - -void ctx::device_status_headphone::on_bt_connection_changed(bool connected, bt_device_connection_info_s *conn_info, void *user_data) -{ - ctx::device_status_headphone *instance = static_cast(user_data); - IF_FAIL_VOID(connected != instance->bt_audio_state); - IF_FAIL_VOID(!instance->bt_event_handler_added); - - if (connected) { - _D("BT state checking scheduled"); - instance->bt_event_handler_added = true; - instance->bt_event_handling_count = 0; - g_timeout_add(HANDLING_DELAY, handle_bt_event, user_data); - } else { - handle_bt_event(user_data); - } -} - -gboolean ctx::device_status_headphone::handle_bt_event(gpointer data) -{ - _D("BT state checking started"); - ctx::device_status_headphone *instance = static_cast(data); - instance->bt_event_handler_added = false; - - instance->set_bt_audio_state(false); - int err = bt_adapter_foreach_bonded_device(on_bt_bond, data); - IF_FAIL_RETURN_TAG(err == BT_ERROR_NONE, FALSE, _E, "bt_adapter_foreach_bonded_device() failed"); - - instance->bt_event_handling_count++; - - if (instance->handle_event() || instance->bt_event_handling_count >= MAX_HANDLING_COUNT) - return FALSE; - - return TRUE; -} - -bool ctx::device_status_headphone::on_bt_bond(bt_device_info_s *device_info, void* user_data) -{ - if (device_info->bt_class.major_device_class != BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO) - return true; - - bool st = false; - int err = bt_device_is_profile_connected(device_info->remote_address, BT_PROFILE_A2DP, &st); - IF_FAIL_RETURN_TAG(err == BT_ERROR_NONE, false, _E, "bt_device_is_profile_connected() failed"); - - if (st) { - ctx::device_status_headphone *instance = static_cast(user_data); - instance->set_bt_audio_state(true); - return false; - } - - return true; -} diff --git a/src/device/system/headphone.h b/src/device/system/headphone.h deleted file mode 100644 index 8922a61..0000000 --- a/src/device/system/headphone.h +++ /dev/null @@ -1,65 +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_HEADPHONE_H_ -#define _DEVICE_STATUS_HEADPNOHE_H_ - -#include -#include -#include -#include "../device_provider_base.h" - -namespace ctx { - - class device_status_headphone : public device_provider_base { - - GENERATE_PROVIDER_COMMON_DECL(device_status_headphone); - - public: - int subscribe(); - int unsubscribe(); - int read(); - static bool is_supported(); - static void submit_trigger_item(); - - private: - bool connected; - int audio_jack_state; - bool bt_audio_state; - bool bt_audio_callback_on; - bool bt_event_handler_added; - int bt_event_handling_count; - - device_status_headphone(); - ~device_status_headphone(); - - bool get_current_status(); - void set_bt_audio_callback(); - void unset_bt_audio_callback(); - void set_bt_audio_state(bool state); - - void generate_data_packet(Json &data); - bool handle_event(); - void handle_audio_jack_event(); - - static gboolean handle_bt_event(gpointer data); - static void on_audio_jack_state_changed(runtime_info_key_e runtime_key, void* user_data); - static void on_bt_connection_changed(bool connected, bt_device_connection_info_s *conn_info, void *user_data); - static bool on_bt_bond(bt_device_info_s *device_info, void* user_data); - }; -} - -#endif // _DEVICE_STATUS_HEADPHONE_H_ diff --git a/src/device/system/runtime-info/charger.cpp b/src/device/system/runtime_info/Charger.cpp similarity index 64% rename from src/device/system/runtime-info/charger.cpp rename to src/device/system/runtime_info/Charger.cpp index d4cec25..30802d9 100644 --- a/src/device/system/runtime-info/charger.cpp +++ b/src/device/system/runtime_info/Charger.cpp @@ -15,53 +15,53 @@ */ #include -#include "../system_types.h" -#include "charger.h" +#include "../SystemTypes.h" +#include "Charger.h" -GENERATE_PROVIDER_COMMON_IMPL(device_status_charger); +GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusCharger); -ctx::device_status_charger::device_status_charger() - : device_status_runtime_info(RUNTIME_INFO_KEY_CHARGER_CONNECTED) +ctx::DeviceStatusCharger::DeviceStatusCharger() : + DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_CHARGER_CONNECTED) { } -ctx::device_status_charger::~device_status_charger() +ctx::DeviceStatusCharger::~DeviceStatusCharger() { } -bool ctx::device_status_charger::is_supported() +bool ctx::DeviceStatusCharger::isSupported() { return true; } -void ctx::device_status_charger::submit_trigger_item() +void ctx::DeviceStatusCharger::submitTriggerItem() { context_manager::registerTriggerItem(DEVICE_ST_SUBJ_CHARGER, OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL); } -void ctx::device_status_charger::handle_update() +void ctx::DeviceStatusCharger::handleUpdate() { - bool charger_status = false; + bool chargerStatus = false; - int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &charger_status); + int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &chargerStatus); IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed"); ctx::Json dataRead; - dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, chargerStatus ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); context_manager::publish(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, dataRead); } -int ctx::device_status_charger::read() +int ctx::DeviceStatusCharger::read() { - bool charger_status = false; + bool chargerStatus = false; ctx::Json dataRead; - int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &charger_status); + int ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_CHARGER_CONNECTED, &chargerStatus); IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed"); - dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, charger_status ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); + dataRead.set(NULL, DEVICE_ST_IS_CONNECTED, chargerStatus ? DEVICE_ST_TRUE : DEVICE_ST_FALSE); ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_CHARGER, NULL, ERR_NONE, dataRead); return ERR_NONE; diff --git a/src/device/system/runtime-info/charger.h b/src/device/system/runtime_info/Charger.h similarity index 61% rename from src/device/system/runtime-info/charger.h rename to src/device/system/runtime_info/Charger.h index 52aeb4c..38cbca8 100644 --- a/src/device/system/runtime-info/charger.h +++ b/src/device/system/runtime_info/Charger.h @@ -14,27 +14,29 @@ * limitations under the License. */ -#ifndef _DEVICE_STATUS_CHARGER_H_ -#define _DEVICE_STATUS_CHARGER_H_ +#ifndef _DEVICE_SYSTEM_STATUS_CHARGER_ +#define _DEVICE_SYSTEM_STATUS_CHARGER_ -#include "base_rtinfo.h" +#include "RuntimeInfoBase.h" namespace ctx { - class device_status_charger : public device_status_runtime_info { + class DeviceStatusCharger : public DeviceStatusRuntimeInfo { - GENERATE_PROVIDER_COMMON_DECL(device_status_charger); + GENERATE_PROVIDER_COMMON_DECL(DeviceStatusCharger); public: int read(); - static bool is_supported(); - static void submit_trigger_item(); + static bool isSupported(); + static void submitTriggerItem(); + + protected: + void handleUpdate(); private: - device_status_charger(); - ~device_status_charger(); - void handle_update(); + DeviceStatusCharger(); + ~DeviceStatusCharger(); }; } -#endif // _DEVICE_STATUS_CHARGER_H_ +#endif // _DEVICE_SYSTEM_STATUS_CHARGER_H_ diff --git a/src/device/system/runtime-info/gps.cpp b/src/device/system/runtime_info/Gps.cpp similarity index 63% rename from src/device/system/runtime-info/gps.cpp rename to src/device/system/runtime_info/Gps.cpp index 9624d38..9ec1c02 100644 --- a/src/device/system/runtime-info/gps.cpp +++ b/src/device/system/runtime_info/Gps.cpp @@ -15,14 +15,14 @@ */ #include -#include "../system_types.h" -#include "gps.h" +#include "../SystemTypes.h" +#include "Gps.h" -GENERATE_PROVIDER_COMMON_IMPL(device_status_gps); +GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusGps); -static const char* get_state_string(int gps_state) +static const char* __getStatusString(int gpsStatus) { - switch (gps_state) { + switch (gpsStatus) { case RUNTIME_INFO_GPS_STATUS_DISABLED: return DEVICE_ST_DISABLED; @@ -33,26 +33,26 @@ static const char* get_state_string(int gps_state) return DEVICE_ST_CONNECTED; default: - _E("Unknown GPS status: %d", gps_state); + _E("Unknown GPS status: %d", gpsStatus); return NULL; } } -ctx::device_status_gps::device_status_gps() - : device_status_runtime_info(RUNTIME_INFO_KEY_GPS_STATUS) +ctx::DeviceStatusGps::DeviceStatusGps() : + DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_GPS_STATUS) { } -ctx::device_status_gps::~device_status_gps() +ctx::DeviceStatusGps::~DeviceStatusGps() { } -bool ctx::device_status_gps::is_supported() +bool ctx::DeviceStatusGps::isSupported() { - return get_system_info_bool("tizen.org/feature/location.gps"); + return getSystemInfoBool("tizen.org/feature/location.gps"); } -void ctx::device_status_gps::submit_trigger_item() +void ctx::DeviceStatusGps::submitTriggerItem() { context_manager::registerTriggerItem(DEVICE_ST_SUBJ_GPS, OPS_SUBSCRIBE | OPS_READ, "{" @@ -61,34 +61,34 @@ void ctx::device_status_gps::submit_trigger_item() NULL); } -void ctx::device_status_gps::handle_update() +void ctx::DeviceStatusGps::handleUpdate() { - int gps_status; - int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gps_status); + int gpsStatus; + int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gpsStatus); IF_FAIL_VOID_TAG(ret == RUNTIME_INFO_ERROR_NONE, _E, "Getting runtime info failed"); ctx::Json dataRead; - const char* state_str = get_state_string(gps_status); - IF_FAIL_VOID(state_str); + const char* stateStr = __getStatusString(gpsStatus); + IF_FAIL_VOID(stateStr); - dataRead.set(NULL, DEVICE_ST_STATE, state_str); + dataRead.set(NULL, DEVICE_ST_STATE, stateStr); context_manager::publish(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead); } -int ctx::device_status_gps::read() +int ctx::DeviceStatusGps::read() { - int gps_status; + int gpsStatus; ctx::Json dataRead; - int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gps_status); + int ret = runtime_info_get_value_int(RUNTIME_INFO_KEY_GPS_STATUS, &gpsStatus); IF_FAIL_RETURN_TAG(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED, _E, "Getting runtime info failed"); - const char* state_str = get_state_string(gps_status); - IF_FAIL_RETURN(state_str, ERR_OPERATION_FAILED); + const char* stateStr = __getStatusString(gpsStatus); + IF_FAIL_RETURN(stateStr, ERR_OPERATION_FAILED); - dataRead.set(NULL, DEVICE_ST_STATE, state_str); + dataRead.set(NULL, DEVICE_ST_STATE, stateStr); ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_GPS, NULL, ERR_NONE, dataRead); return ERR_NONE; diff --git a/src/device/system/runtime-info/usb.h b/src/device/system/runtime_info/Gps.h similarity index 63% rename from src/device/system/runtime-info/usb.h rename to src/device/system/runtime_info/Gps.h index bc01425..38bc8e8 100644 --- a/src/device/system/runtime-info/usb.h +++ b/src/device/system/runtime_info/Gps.h @@ -14,27 +14,29 @@ * limitations under the License. */ -#ifndef _DEVICE_STATUS_USB_H_ -#define _DEVICE_STATUS_USB_H_ +#ifndef _DEVICE_SYSTEM_STATUS_GPS_H_ +#define _DEVICE_SYSTEM_STATUS_GPS_H_ -#include "base_rtinfo.h" +#include "RuntimeInfoBase.h" namespace ctx { - class device_status_usb : public device_status_runtime_info { + class DeviceStatusGps : public DeviceStatusRuntimeInfo { - GENERATE_PROVIDER_COMMON_DECL(device_status_usb); + GENERATE_PROVIDER_COMMON_DECL(DeviceStatusGps); public: int read(); - static bool is_supported(); - static void submit_trigger_item(); + static bool isSupported(); + static void submitTriggerItem(); + + protected: + void handleUpdate(); private: - device_status_usb(); - ~device_status_usb(); - void handle_update(); + DeviceStatusGps(); + ~DeviceStatusGps(); }; } -#endif // _DEVICE_STATUS_USB_H_ +#endif // _DEVICE_SYSTEM_STATUS_GPS_H_ diff --git a/src/device/system/runtime-info/base_rtinfo.cpp b/src/device/system/runtime_info/RuntimeInfoBase.cpp similarity index 53% rename from src/device/system/runtime-info/base_rtinfo.cpp rename to src/device/system/runtime_info/RuntimeInfoBase.cpp index 2d3f0e3..61b117f 100644 --- a/src/device/system/runtime-info/base_rtinfo.cpp +++ b/src/device/system/runtime_info/RuntimeInfoBase.cpp @@ -14,35 +14,35 @@ * limitations under the License. */ -#include "base_rtinfo.h" +#include "RuntimeInfoBase.h" -ctx::device_status_runtime_info::device_status_runtime_info(runtime_info_key_e key) - : info_key(key) +ctx::DeviceStatusRuntimeInfo::DeviceStatusRuntimeInfo(runtime_info_key_e key) : + __infoKey(key) { } -runtime_info_key_e ctx::device_status_runtime_info::get_info_key() +runtime_info_key_e ctx::DeviceStatusRuntimeInfo::__getInfoKey() { - return info_key; + return __infoKey; } -void ctx::device_status_runtime_info::update_cb(runtime_info_key_e key, void* user_data) +void ctx::DeviceStatusRuntimeInfo::updateCb(runtime_info_key_e runtimeKey, void* userData) { - device_status_runtime_info *instance = static_cast(user_data); - IF_FAIL_VOID_TAG(key == instance->get_info_key(), _W, "Runtime info key mismatch"); - instance->handle_update(); + DeviceStatusRuntimeInfo *instance = static_cast(userData); + IF_FAIL_VOID_TAG(runtimeKey == instance->__getInfoKey(), _W, "Runtime info key mismatch"); + instance->handleUpdate(); } -int ctx::device_status_runtime_info::subscribe() +int ctx::DeviceStatusRuntimeInfo::subscribe() { - int ret = runtime_info_set_changed_cb(info_key, update_cb, this); + int ret = runtime_info_set_changed_cb(__infoKey, updateCb, this); IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED); return ERR_NONE; } -int ctx::device_status_runtime_info::unsubscribe() +int ctx::DeviceStatusRuntimeInfo::unsubscribe() { - int ret = runtime_info_unset_changed_cb(info_key); + int ret = runtime_info_unset_changed_cb(__infoKey); IF_FAIL_RETURN(ret == RUNTIME_INFO_ERROR_NONE, ERR_OPERATION_FAILED); return ERR_NONE; } diff --git a/src/device/system/runtime-info/base_rtinfo.h b/src/device/system/runtime_info/RuntimeInfoBase.h similarity index 59% rename from src/device/system/runtime-info/base_rtinfo.h rename to src/device/system/runtime_info/RuntimeInfoBase.h index faaaa6a..a0e2c20 100644 --- a/src/device/system/runtime-info/base_rtinfo.h +++ b/src/device/system/runtime_info/RuntimeInfoBase.h @@ -14,32 +14,32 @@ * limitations under the License. */ -#ifndef __CONTEXT_DEVICE_STATUS_RUNTIME_INFO_H__ -#define __CONTEXT_DEVICE_STATUS_RUNTIME_INFO_H__ +#ifndef _DEVICE_SYSTEM_STATUS_RUNTIME_INFO_BASE_H_ +#define _DEVICE_SYSTEM_STATUS_RUNTIME_INFO_BASE_H_ #include -#include "../../device_provider_base.h" +#include "../../DeviceProviderBase.h" namespace ctx { - class device_status_runtime_info : public device_provider_base { + class DeviceStatusRuntimeInfo : public DeviceProviderBase { public: - device_status_runtime_info(runtime_info_key_e key); + DeviceStatusRuntimeInfo(runtime_info_key_e key); int subscribe(); int unsubscribe(); virtual int read() = 0; protected: - runtime_info_key_e info_key; + runtime_info_key_e __infoKey; - virtual ~device_status_runtime_info(){} - static void update_cb(runtime_info_key_e runtime_key, void* user_data); - virtual void handle_update() = 0; + virtual ~DeviceStatusRuntimeInfo(){} + static void updateCb(runtime_info_key_e runtimeKey, void* userData); + virtual void handleUpdate() = 0; private: - runtime_info_key_e get_info_key(); + runtime_info_key_e __getInfoKey(); }; } -#endif +#endif // _DEVICE_SYSTEM_STATUS_RUNTIME_INFO_BASE_H_ diff --git a/src/device/system/runtime-info/usb.cpp b/src/device/system/runtime_info/Usb.cpp similarity index 76% rename from src/device/system/runtime-info/usb.cpp rename to src/device/system/runtime_info/Usb.cpp index 2b7ddbc..929a03f 100644 --- a/src/device/system/runtime-info/usb.cpp +++ b/src/device/system/runtime_info/Usb.cpp @@ -15,32 +15,32 @@ */ #include -#include "../system_types.h" -#include "usb.h" +#include "../SystemTypes.h" +#include "Usb.h" -GENERATE_PROVIDER_COMMON_IMPL(device_status_usb); +GENERATE_PROVIDER_COMMON_IMPL(DeviceStatusUsb); -ctx::device_status_usb::device_status_usb() - : device_status_runtime_info(RUNTIME_INFO_KEY_USB_CONNECTED) +ctx::DeviceStatusUsb::DeviceStatusUsb() : + DeviceStatusRuntimeInfo(RUNTIME_INFO_KEY_USB_CONNECTED) { } -ctx::device_status_usb::~device_status_usb() +ctx::DeviceStatusUsb::~DeviceStatusUsb() { } -bool ctx::device_status_usb::is_supported() +bool ctx::DeviceStatusUsb::isSupported() { - return get_system_info_bool("tizen.org/feature/usb.host"); + return getSystemInfoBool("tizen.org/feature/usb.host"); } -void ctx::device_status_usb::submit_trigger_item() +void ctx::DeviceStatusUsb::submitTriggerItem() { context_manager::registerTriggerItem(DEVICE_ST_SUBJ_USB, OPS_SUBSCRIBE | OPS_READ, "{" TRIG_BOOL_ITEM_DEF("IsConnected") "}", NULL); } -void ctx::device_status_usb::handle_update() +void ctx::DeviceStatusUsb::handleUpdate() { bool status = false; @@ -53,7 +53,7 @@ void ctx::device_status_usb::handle_update() context_manager::publish(DEVICE_ST_SUBJ_USB, NULL, ERR_NONE, dataRead); } -int ctx::device_status_usb::read() +int ctx::DeviceStatusUsb::read() { bool status = false; ctx::Json dataRead; diff --git a/src/device/system/runtime-info/gps.h b/src/device/system/runtime_info/Usb.h similarity index 63% rename from src/device/system/runtime-info/gps.h rename to src/device/system/runtime_info/Usb.h index 4d94cc0..4602752 100644 --- a/src/device/system/runtime-info/gps.h +++ b/src/device/system/runtime_info/Usb.h @@ -14,27 +14,29 @@ * limitations under the License. */ -#ifndef _DEVICE_STATUS_GPS_H_ -#define _DEVICE_STATUS_GPS_H_ +#ifndef _DEVICE_SYSTEM_STATUS_USB_H_ +#define _DEVICE_SYSTEM_STATUS_USB_H_ -#include "base_rtinfo.h" +#include "RuntimeInfoBase.h" namespace ctx { - class device_status_gps : public device_status_runtime_info { + class DeviceStatusUsb : public DeviceStatusRuntimeInfo { - GENERATE_PROVIDER_COMMON_DECL(device_status_gps); + GENERATE_PROVIDER_COMMON_DECL(DeviceStatusUsb); public: int read(); - static bool is_supported(); - static void submit_trigger_item(); + static bool isSupported(); + static void submitTriggerItem(); + + protected: + void handleUpdate(); private: - device_status_gps(); - ~device_status_gps(); - void handle_update(); + DeviceStatusUsb(); + ~DeviceStatusUsb(); }; } -#endif // _DEVICE_STATUS_GPS_H_ +#endif // _DEVICE_SYSTEM_STATUS_USB_H_ diff --git a/src/device/system/wifi.cpp b/src/device/system/wifi.cpp deleted file mode 100644 index 4d237df..0000000 --- a/src/device/system/wifi.cpp +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "system_types.h" -#include "wifi.h" - -ctx::device_status_wifi *ctx::device_status_wifi::__instance = NULL; - -ctx::device_status_wifi::device_status_wifi() - : last_state(_UNKNOWN) - , is_initialized(false) - , is_activated(false) - , conn_state(WIFI_CONNECTION_STATE_FAILURE) -{ - IF_FAIL_VOID_TAG(start_monitor(), _W, "WiFi monitor initialization failed"); - - if (!get_current_state()) { - stop_monitor(); - _W("Getting current WiFi status failed"); - } -} - -ctx::device_status_wifi::~device_status_wifi() -{ -} - -ctx::ContextProviderBase *ctx::device_status_wifi::create(void *data) -{ - CREATE_INSTANCE(device_status_wifi); -} - -void ctx::device_status_wifi::destroy(void *data) -{ - __instance->stop_monitor(); - DESTROY_INSTANCE(); -} - -void ctx::device_status_wifi::destroy_self() -{ - /* WiFi status will be monitored continuously, even if no client is subscribing it */ -} - -bool ctx::device_status_wifi::is_supported() -{ - return get_system_info_bool("tizen.org/feature/network.wifi"); -} - -void ctx::device_status_wifi::submit_trigger_item() -{ - context_manager::registerTriggerItem(DEVICE_ST_SUBJ_WIFI, OPS_SUBSCRIBE | OPS_READ, - "{" - "\"State\":{\"type\":\"string\",\"values\":[\"Disabled\",\"Unconnected\",\"Connected\"]}," - "\"BSSID\":{\"type\":\"string\"}" - "}", - NULL); -} - -bool ctx::device_status_wifi::get_current_state() -{ - int err; - - if (!is_initialized) { - err = wifi_initialize(); - IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_initialize() failed"); - } - - err = wifi_is_activated(&is_activated); - IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_is_activated() failed"); - - err = wifi_get_connection_state(&conn_state); - IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_get_connection_state() failed"); - - if (is_activated) { - if (conn_state == WIFI_CONNECTION_STATE_CONNECTED) { - last_state = _CONNECTED; - get_bssid(); - } else { - last_state = _UNCONNECTED; - clear_bssid(); - } - } else { - last_state = _DISABLED; - clear_bssid(); - } - - if (!is_initialized) - wifi_deinitialize(); - - return true; -} - -bool ctx::device_status_wifi::get_bssid() -{ - int err; - char *str_buf = NULL; - wifi_ap_h ap = NULL; - - err = wifi_get_connected_ap(&ap); - IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_get_connected_ap() failed"); - - wifi_ap_get_bssid(ap, &str_buf); - bssid = (str_buf != NULL ? str_buf : ""); - g_free(str_buf); - - wifi_ap_destroy(ap); - - if (bssid.empty()) - _W("Failed to get BSSID"); - - SharedVars().set(ctx::SharedVars::WIFI_BSSID, bssid); - _D("BSSID: %s", bssid.c_str()); - - return !bssid.empty(); -} - -void ctx::device_status_wifi::clear_bssid() -{ - bssid.clear(); - SharedVars().clear(ctx::SharedVars::WIFI_BSSID); - _D("No WiFi connection"); -} - -bool ctx::device_status_wifi::get_response_packet(ctx::Json &data) -{ - switch (last_state) { - case _DISABLED: - data.set(NULL, DEVICE_ST_STATE, DEVICE_ST_DISABLED); - break; - - case _UNCONNECTED: - data.set(NULL, DEVICE_ST_STATE, DEVICE_ST_UNCONNECTED); - break; - - case _CONNECTED: - data.set(NULL, DEVICE_ST_STATE, DEVICE_ST_CONNECTED); - data.set(NULL, DEVICE_ST_BSSID, bssid); - break; - - default: - return false; - } - - return true; -} - -int ctx::device_status_wifi::read() -{ - IF_FAIL_RETURN(get_current_state(), ERR_OPERATION_FAILED); - - ctx::Json dataRead; - - if (get_response_packet(dataRead)) { - ctx::context_manager::replyToRead(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, dataRead); - return ERR_NONE; - } - - return ERR_OPERATION_FAILED; -} - -bool ctx::device_status_wifi::start_monitor() -{ - IF_FAIL_RETURN(!is_initialized, true); - - int err; - err = wifi_initialize(); - IF_FAIL_RETURN_TAG(err == WIFI_ERROR_NONE, false, _E, "wifi_initialize() failed"); - - err = wifi_set_device_state_changed_cb(device_state_changed_cb, this); - IF_FAIL_CATCH_TAG(err == WIFI_ERROR_NONE, _E, "wifi_set_device_state_changed_cb() failed"); - - err = wifi_set_connection_state_changed_cb(connection_state_changed_cb, this); - IF_FAIL_CATCH_TAG(err == WIFI_ERROR_NONE, _E, "wifi_set_connection_state_changed_cb() failed"); - - is_initialized = true; - return true; - -CATCH: - wifi_deinitialize(); - return false; -} - -void ctx::device_status_wifi::stop_monitor() -{ - IF_FAIL_VOID(is_initialized); - - wifi_unset_device_state_changed_cb(); - wifi_unset_connection_state_changed_cb(); - wifi_deinitialize(); - is_initialized = false; -} - -int ctx::device_status_wifi::subscribe() -{ -#if 0 - IF_FAIL_RETURN(start_monitor(), ERR_OPERATION_FAILED); - if (!get_current_state()) { - stop_monitor(); - return ERR_OPERATION_FAILED; - } -#endif - - return ERR_NONE; -} - -int ctx::device_status_wifi::unsubscribe() -{ -#if 0 - stop_monitor(); -#endif - return ERR_NONE; -} - -void ctx::device_status_wifi::aggregate_updated_data() -{ - int prev_state = last_state; - - if (is_activated) { - if (conn_state == WIFI_CONNECTION_STATE_CONNECTED) { - last_state = _CONNECTED; - } else { - last_state = _UNCONNECTED; - } - } else { - last_state = _DISABLED; - } - - if (last_state != prev_state) { - if (last_state == _CONNECTED) { - get_bssid(); - } else { - clear_bssid(); - } - - ctx::Json data; - if (being_subscribed && get_response_packet(data)) - context_manager::publish(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, data); - } -} - -void ctx::device_status_wifi::device_state_changed_cb(wifi_device_state_e state, void *user_data) -{ - device_status_wifi *instance = static_cast(user_data); - instance->is_activated = (state == WIFI_DEVICE_STATE_ACTIVATED); - instance->aggregate_updated_data(); -} - -void ctx::device_status_wifi::connection_state_changed_cb(wifi_connection_state_e state, wifi_ap_h ap, void *user_data) -{ - device_status_wifi *instance = static_cast(user_data); - instance->conn_state = state; - instance->aggregate_updated_data(); -} diff --git a/src/device/system/wifi.h b/src/device/system/wifi.h deleted file mode 100644 index 3ed52d5..0000000 --- a/src/device/system/wifi.h +++ /dev/null @@ -1,66 +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_STATUS_WIFI_H__ -#define __CONTEXT_DEVICE_STATUS_WIFI_H__ - -#include -#include -#include "../device_provider_base.h" - -namespace ctx { - - class device_status_wifi : public device_provider_base { - - GENERATE_PROVIDER_COMMON_DECL(device_status_wifi); - - public: - int subscribe(); - int unsubscribe(); - int read(); - static bool is_supported(); - static void submit_trigger_item(); - - private: - enum _state_e { - _UNKNOWN = -1, - _DISABLED = 0, - _UNCONNECTED, - _CONNECTED, - }; - - int last_state; - bool is_initialized; - bool is_activated; - wifi_connection_state_e conn_state; - std::string bssid; - - device_status_wifi(); - ~device_status_wifi(); - - bool get_current_state(); - bool get_bssid(); - void clear_bssid(); - bool get_response_packet(Json &data); - void aggregate_updated_data(); - bool start_monitor(); - void stop_monitor(); - static void device_state_changed_cb(wifi_device_state_e state, void *user_data); - static void connection_state_changed_cb(wifi_connection_state_e state, wifi_ap_h ap, void *user_data); - }; -} - -#endif -- 2.7.4 From 5ba9bc46546ff288c2694075106535f116c3f889 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Wed, 6 Apr 2016 13:21:03 +0900 Subject: [PATCH 14/16] Applying Tizen C++ coding style to custom context provider Change-Id: I7cdbed7358584669caef5eb7ffc5a59c08b70734 Signed-off-by: Somin Kim --- src/custom/CustomBase.cpp | 91 ++++++++++++++++++++++ src/custom/{custom_base.h => CustomBase.h} | 36 ++++----- ...text_provider.cpp => CustomContextProvider.cpp} | 84 ++++++++++---------- src/custom/custom_base.cpp | 91 ---------------------- 4 files changed, 151 insertions(+), 151 deletions(-) create mode 100644 src/custom/CustomBase.cpp rename src/custom/{custom_base.h => CustomBase.h} (64%) rename src/custom/{custom_context_provider.cpp => CustomContextProvider.cpp} (70%) delete mode 100644 src/custom/custom_base.cpp diff --git a/src/custom/CustomBase.cpp b/src/custom/CustomBase.cpp new file mode 100644 index 0000000..529835b --- /dev/null +++ b/src/custom/CustomBase.cpp @@ -0,0 +1,91 @@ +/* + * 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 +#include "CustomBase.h" + +ctx::CustomBase::CustomBase(std::string subject, std::string name, ctx::Json tmpl, std::string owner) : + __subject(subject), + __name(name), + __tmpl(tmpl), + __owner(owner) +{ +} + +ctx::CustomBase::~CustomBase() +{ +} + +bool ctx::CustomBase::isSupported() +{ + return true; +} + +void ctx::CustomBase::submitTriggerItem() +{ + context_manager::registerTriggerItem(__subject.c_str(), OPS_SUBSCRIBE | OPS_READ, + __tmpl.str(), NULL, __owner.c_str()); +} + +void ctx::CustomBase::unsubmitTriggerItem() +{ + context_manager::unregisterTriggerItem(__subject.c_str()); +} + +int ctx::CustomBase::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) +{ + return ERR_NONE; + +} + +int ctx::CustomBase::unsubscribe(const char *subject, ctx::Json option) +{ + return ERR_NONE; +} + +int ctx::CustomBase::read(const char *subject, ctx::Json option, ctx::Json *requestResult) +{ + ctx::Json data = __latest.str(); + ctx::context_manager::replyToRead(__subject.c_str(), NULL, ERR_NONE, data); + return ERR_NONE; +} + +int ctx::CustomBase::write(const char *subject, ctx::Json data, ctx::Json *requestResult) +{ + return ERR_NONE; +} + +void ctx::CustomBase::handleUpdate(ctx::Json data) +{ + // Store latest state + __latest = data.str(); + ctx::context_manager::publish(__subject.c_str(), NULL, ERR_NONE, data); +} + +const char* ctx::CustomBase::getSubject() +{ + return __subject.c_str(); +} + +std::string ctx::CustomBase::getOwner() +{ + return __owner; +} + +ctx::Json ctx::CustomBase::getTemplate() +{ + return __tmpl; +} diff --git a/src/custom/custom_base.h b/src/custom/CustomBase.h similarity index 64% rename from src/custom/custom_base.h rename to src/custom/CustomBase.h index 68e45cc..c95ba5c 100644 --- a/src/custom/custom_base.h +++ b/src/custom/CustomBase.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef _CUSTOM_BASE_H_ -#define _CUSTOM_BASE_H_ +#ifndef _CONTEXT_CUSTOM_BASE_H_ +#define _CONTEXT_CUSTOM_BASE_H_ #include #include @@ -23,33 +23,33 @@ namespace ctx { - class custom_base : public ContextProviderBase { + class CustomBase : public ContextProviderBase { public: - custom_base(std::string subject, std::string name, ctx::Json tmpl, std::string owner); - ~custom_base(); + CustomBase(std::string subject, std::string name, ctx::Json tmpl, std::string owner); + ~CustomBase(); 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); - static bool is_supported(); - void submit_trigger_item(); - void unsubmit_trigger_item(); + static bool isSupported(); + void submitTriggerItem(); + void unsubmitTriggerItem(); - void handle_update(ctx::Json data); + void handleUpdate(ctx::Json data); - const char* get_subject(); - std::string get_owner(); - ctx::Json get_template(); + const char* getSubject(); + std::string getOwner(); + ctx::Json getTemplate(); private: - std::string _subject; - std::string _name; - ctx::Json _tmpl; - std::string _owner; - ctx::Json latest; + std::string __subject; + std::string __name; + ctx::Json __tmpl; + std::string __owner; + ctx::Json __latest; }; } -#endif // _CUSTOM_BASE_H_ +#endif /* End of _CONTEXT_CUSTOM_BASE_H_ */ diff --git a/src/custom/custom_context_provider.cpp b/src/custom/CustomContextProvider.cpp similarity index 70% rename from src/custom/custom_context_provider.cpp rename to src/custom/CustomContextProvider.cpp index 5bec97e..286f28e 100644 --- a/src/custom/custom_context_provider.cpp +++ b/src/custom/CustomContextProvider.cpp @@ -21,13 +21,13 @@ #include #include #include -#include "custom_base.h" +#include "CustomBase.h" -std::map custom_map; +static std::map __customMap; -static bool is_valid_fact(std::string subject, ctx::Json& fact); -static bool check_value_int(ctx::Json& tmpl, std::string key, int value); -static bool check_value_string(ctx::Json& tmpl, std::string key, std::string value); +static bool __isValidFact(std::string subject, ctx::Json& fact); +static bool __checkValueInt(ctx::Json& tmpl, std::string key, int value); +static bool __checkValueString(ctx::Json& tmpl, std::string key, std::string value); void registerProvider(const char *subject, const char *privilege) { @@ -35,27 +35,27 @@ void registerProvider(const char *subject, const char *privilege) ctx::custom_context_provider::destroy, const_cast(subject), privilege); ctx::context_manager::registerProvider(subject, providerInfo); - custom_map[subject]->submit_trigger_item(); + __customMap[subject]->submitTriggerItem(); } void unregisterProvider(const char* subject) { - custom_map[subject]->unsubmit_trigger_item(); + __customMap[subject]->unsubmitTriggerItem(); ctx::context_manager::unregisterProvider(subject); } EXTAPI ctx::ContextProviderBase* ctx::custom_context_provider::create(void *data) { // Already created in addItem() function. Return corresponding custom provider - return custom_map[static_cast(data)]; + return __customMap[static_cast(data)]; } EXTAPI void ctx::custom_context_provider::destroy(void *data) { - std::map::iterator it = custom_map.find(static_cast(data)); - if (it != custom_map.end()) { + std::map::iterator it = __customMap.find(static_cast(data)); + if (it != __customMap.end()) { delete it->second; - custom_map.erase(it); + __customMap.erase(it); } } @@ -71,15 +71,15 @@ EXTAPI bool ctx::initCustomContextProvider() IF_FAIL_RETURN_TAG(ret, false, _E, "Create template table failed"); // Register custom items - std::string q_select = "SELECT * FROM context_trigger_custom_template"; - ret = db_manager::execute_sync(q_select.c_str(), &record); + std::string qSelect = "SELECT * FROM context_trigger_custom_template"; + ret = db_manager::execute_sync(qSelect.c_str(), &record); IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to query custom templates"); IF_FAIL_RETURN(record.size() > 0, true); int error; - std::vector::iterator vec_end = record.end(); - for (std::vector::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) { - ctx::Json elem = *vec_pos; + std::vector::iterator vedEnd = record.end(); + for (auto vecPos = record.begin(); vecPos != vedEnd; ++vecPos) { + ctx::Json elem = *vecPos; std::string subject; std::string name; std::string attributes; @@ -98,13 +98,13 @@ EXTAPI bool ctx::initCustomContextProvider() return true; } -EXTAPI int ctx::custom_context_provider::addItem(std::string subject, std::string name, ctx::Json tmpl, const char* owner, bool is_init) +EXTAPI int ctx::custom_context_provider::addItem(std::string subject, std::string name, ctx::Json tmpl, const char* owner, bool isInit) { - std::map::iterator it; - it = custom_map.find(subject); + std::map::iterator it; + it = __customMap.find(subject); - if (it != custom_map.end()) { - if ((it->second)->get_template() != tmpl) { // Same item name, but different template + if (it != __customMap.end()) { + if ((it->second)->getTemplate() != tmpl) { // Same item name, but different template return ERR_DATA_EXIST; } // Same item name with same template @@ -112,14 +112,14 @@ EXTAPI int ctx::custom_context_provider::addItem(std::string subject, std::strin } // Create custom base - ctx::custom_base* custom = new(std::nothrow) custom_base(subject, name, tmpl, owner); + ctx::CustomBase* custom = new(std::nothrow) CustomBase(subject, name, tmpl, owner); IF_FAIL_RETURN_TAG(custom, ERR_OUT_OF_MEMORY, _E, "Memory allocation failed"); - custom_map[subject] = custom; + __customMap[subject] = custom; - registerProvider(custom->get_subject(), NULL); + registerProvider(custom->getSubject(), NULL); // Add item to custom template db - if (!is_init) { + if (!isInit) { std::string q = "INSERT OR IGNORE INTO context_trigger_custom_template (subject, name, attributes, owner) VALUES ('" + subject + "', '" + name + "', '" + tmpl.str() + "', '" + owner + "'); "; std::vector record; @@ -132,9 +132,9 @@ EXTAPI int ctx::custom_context_provider::addItem(std::string subject, std::strin EXTAPI int ctx::custom_context_provider::removeItem(std::string subject) { - std::map::iterator it; - it = custom_map.find(subject); - IF_FAIL_RETURN_TAG(it != custom_map.end(), ERR_NOT_SUPPORTED, _E, "%s not supported", subject.c_str()); + std::map::iterator it; + it = __customMap.find(subject); + IF_FAIL_RETURN_TAG(it != __customMap.end(), ERR_NOT_SUPPORTED, _E, "%s not supported", subject.c_str()); unregisterProvider(subject.c_str()); @@ -149,20 +149,20 @@ EXTAPI int ctx::custom_context_provider::removeItem(std::string subject) EXTAPI int ctx::custom_context_provider::publishData(std::string subject, ctx::Json fact) { - std::map::iterator it; - it = custom_map.find(subject); - IF_FAIL_RETURN_TAG(it != custom_map.end(), ERR_NOT_SUPPORTED, _E, "%s not supported", subject.c_str()); + std::map::iterator it; + it = __customMap.find(subject); + IF_FAIL_RETURN_TAG(it != __customMap.end(), ERR_NOT_SUPPORTED, _E, "%s not supported", subject.c_str()); - bool ret = is_valid_fact(subject, fact); + bool ret = __isValidFact(subject, fact); IF_FAIL_RETURN_TAG(ret, ERR_INVALID_DATA, _E, "Invalid fact(%s)", subject.c_str()); - custom_map[subject]->handle_update(fact); + __customMap[subject]->handleUpdate(fact); return ERR_NONE; } -bool is_valid_fact(std::string subject, ctx::Json& fact) +bool __isValidFact(std::string subject, ctx::Json& fact) { - ctx::Json tmpl = custom_map[subject]->get_template(); + ctx::Json tmpl = __customMap[subject]->getTemplate(); IF_FAIL_RETURN_TAG(tmpl != EMPTY_JSON_OBJECT, false, _E, "Failed to get template"); bool ret; @@ -179,14 +179,14 @@ bool is_valid_fact(std::string subject, ctx::Json& fact) ret = fact.get(NULL, key.c_str(), &val); IF_FAIL_RETURN_TAG(ret, false, _E, "Custom fact: invalid data type"); - ret = check_value_int(tmpl, key, val); + ret = __checkValueInt(tmpl, key, val); IF_FAIL_RETURN_TAG(ret, false, _E, "Custom fact: invalid value"); } else if (type == "string") { std::string val_str; ret = fact.get(NULL, key.c_str(), &val_str); IF_FAIL_RETURN_TAG(ret, false, _E, "Custom fact: invalid data type"); - ret = check_value_string(tmpl, key, val_str); + ret = __checkValueString(tmpl, key, val_str); IF_FAIL_RETURN_TAG(ret, false, _E, "Custom fact: invalid value"); } else { _E("Custom fact: invalid data type"); @@ -197,7 +197,7 @@ bool is_valid_fact(std::string subject, ctx::Json& fact) return true; } -bool check_value_int(ctx::Json& tmpl, std::string key, int value) +bool __checkValueInt(ctx::Json& tmpl, std::string key, int value) { int min, max; @@ -212,16 +212,16 @@ bool check_value_int(ctx::Json& tmpl, std::string key, int value) return true; } -bool check_value_string(ctx::Json& tmpl, std::string key, std::string value) +bool __checkValueString(ctx::Json& tmpl, std::string key, std::string value) { // case1: any value is accepted if (tmpl.getSize(key.c_str(), "values") <= 0) return true; // case2: check acceptable value - std::string t_val; - for (int i = 0; tmpl.getAt(key.c_str(), "values", i, &t_val); i++) { - if (t_val == value) + std::string tmplValue; + for (int i = 0; tmpl.getAt(key.c_str(), "values", i, &tmplValue); i++) { + if (tmplValue == value) return true; } diff --git a/src/custom/custom_base.cpp b/src/custom/custom_base.cpp deleted file mode 100644 index 4371202..0000000 --- a/src/custom/custom_base.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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 -#include "custom_base.h" - -ctx::custom_base::custom_base(std::string subject, std::string name, ctx::Json tmpl, std::string owner) : - _subject(subject), - _name(name), - _tmpl(tmpl), - _owner(owner) -{ -} - -ctx::custom_base::~custom_base() -{ -} - -bool ctx::custom_base::is_supported() -{ - return true; -} - -void ctx::custom_base::submit_trigger_item() -{ - context_manager::registerTriggerItem(_subject.c_str(), OPS_SUBSCRIBE | OPS_READ, - _tmpl.str(), NULL, _owner.c_str()); -} - -void ctx::custom_base::unsubmit_trigger_item() -{ - context_manager::unregisterTriggerItem(_subject.c_str()); -} - -int ctx::custom_base::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) -{ - return ERR_NONE; - -} - -int ctx::custom_base::unsubscribe(const char *subject, ctx::Json option) -{ - return ERR_NONE; -} - -int ctx::custom_base::read(const char *subject, ctx::Json option, ctx::Json *requestResult) -{ - ctx::Json data = latest.str(); - ctx::context_manager::replyToRead(_subject.c_str(), NULL, ERR_NONE, data); - return ERR_NONE; -} - -int ctx::custom_base::write(const char *subject, ctx::Json data, ctx::Json *requestResult) -{ - return ERR_NONE; -} - -void ctx::custom_base::handle_update(ctx::Json data) -{ - // Store latest state - latest = data.str(); - ctx::context_manager::publish(_subject.c_str(), NULL, ERR_NONE, data); -} - -const char* ctx::custom_base::get_subject() -{ - return _subject.c_str(); -} - -std::string ctx::custom_base::get_owner() -{ - return _owner; -} - -ctx::Json ctx::custom_base::get_template() -{ - return _tmpl; -} -- 2.7.4 From 3bbe9bd327d239c06ce3e15d5ecc7306ff4e5b50 Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Thu, 7 Apr 2016 18:28:07 +0900 Subject: [PATCH 15/16] Applying Tizen C++ coding style to place context provider(geofence) Change-Id: Ic81ae68d2e39dcea8adf4e7fbdbad6bafa9919aa Signed-off-by: Somin Kim --- ...ntext_provider.cpp => PlaceContextProvider.cpp} | 12 +- src/place/geofence/GeofenceMonitorHandle.cpp | 218 +++++++++++++++++++++ src/place/geofence/GeofenceMonitorHandle.h | 55 ++++++ src/place/geofence/PlaceGeofenceProvider.cpp | 151 ++++++++++++++ .../{place_geofence.h => PlaceGeofenceProvider.h} | 27 ++- ...place_geofence_types.h => PlaceGeofenceTypes.h} | 26 ++- src/place/geofence/myplace_handle.cpp | 218 --------------------- src/place/geofence/myplace_handle.h | 59 ------ src/place/geofence/place_geofence.cpp | 151 -------------- src/place/recognition/place_recognition.cpp | 2 +- src/place/recognition/place_recognition.h | 2 +- 11 files changed, 457 insertions(+), 464 deletions(-) rename src/place/{place_context_provider.cpp => PlaceContextProvider.cpp} (82%) create mode 100644 src/place/geofence/GeofenceMonitorHandle.cpp create mode 100644 src/place/geofence/GeofenceMonitorHandle.h create mode 100644 src/place/geofence/PlaceGeofenceProvider.cpp rename src/place/geofence/{place_geofence.h => PlaceGeofenceProvider.h} (69%) rename src/place/geofence/{place_geofence_types.h => PlaceGeofenceTypes.h} (63%) delete mode 100644 src/place/geofence/myplace_handle.cpp delete mode 100644 src/place/geofence/myplace_handle.h delete mode 100644 src/place/geofence/place_geofence.cpp diff --git a/src/place/place_context_provider.cpp b/src/place/PlaceContextProvider.cpp similarity index 82% rename from src/place/place_context_provider.cpp rename to src/place/PlaceContextProvider.cpp index c3efaef..f168dd1 100644 --- a/src/place/place_context_provider.cpp +++ b/src/place/PlaceContextProvider.cpp @@ -20,27 +20,27 @@ #include #ifdef _MOBILE_ -#include "geofence/place_geofence.h" +#include "geofence/PlaceGeofenceProvider.h" #ifndef _DISABLE_RECOG_ENGINE_ #include "recognition/place_recognition.h" #endif /* _DISABLE_RECOG_ENGINE_ */ #endif /* _MOBILE_ */ -template +template void registerProvider(const char *subject, const char *privilege) { - if (!provider::is_supported()) + if (!Provider::isSupported()) return; - ctx::ContextProviderInfo providerInfo(provider::create, provider::destroy, NULL, privilege); + ctx::ContextProviderInfo providerInfo(Provider::create, Provider::destroy, NULL, privilege); ctx::context_manager::registerProvider(subject, providerInfo); } EXTAPI bool ctx::initPlaceContextProvider() { #ifdef _MOBILE_ - registerProvider(PLACE_SUBJ_GEOFENCE, PLACE_PRIV_GEOFENCE); - place_geofence_provider::submit_trigger_item(); + registerProvider(PLACE_SUBJ_GEOFENCE, PLACE_PRIV_GEOFENCE); + PlaceGeofenceProvider::submitTriggerItem(); #ifndef _DISABLE_RECOG_ENGINE_ place_recognition_provider::create(NULL); diff --git a/src/place/geofence/GeofenceMonitorHandle.cpp b/src/place/geofence/GeofenceMonitorHandle.cpp new file mode 100644 index 0000000..52b4b07 --- /dev/null +++ b/src/place/geofence/GeofenceMonitorHandle.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "PlaceGeofenceTypes.h" +#include "GeofenceMonitorHandle.h" + +ctx::GeofenceMonitorHandle::GeofenceMonitorHandle() : + __placeId(-1), + __prevState(GEOFENCE_STATE_UNCERTAIN), + __geoHandle(NULL) +{ +} + +ctx::GeofenceMonitorHandle::~GeofenceMonitorHandle() +{ + __stopMonitor(); +} + +bool ctx::GeofenceMonitorHandle::startMonitor(int placeId) +{ + _D("Starts to monitor Place-%d", placeId); + + IF_FAIL_RETURN(placeId >= 0, false); + IF_FAIL_RETURN_TAG(__geoHandle == NULL, false, _E, "Re-starting MyPlace monitor"); + + geofence_manager_create(&__geoHandle); + IF_FAIL_RETURN_TAG(__geoHandle, false, _E, "Geofence initialization failed"); + + int ret; + + ret = geofence_manager_set_geofence_state_changed_cb(__geoHandle, __fenceStateCb, this); + IF_FAIL_CATCH_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, _E, "Setting state callback failed"); + + ret = geofence_manager_set_geofence_event_cb(__geoHandle, __fenceEventCb, this); + IF_FAIL_CATCH_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, _E, "Setting event callback failed"); + + ret = geofence_manager_foreach_place_geofence_list(__geoHandle, placeId, __fenceListCb, this); + IF_FAIL_CATCH_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, _E, "Getting fence list failed"); + + __placeId = placeId; + return true; + +CATCH: + __stopMonitor(); + return false; +} + +int ctx::GeofenceMonitorHandle::getPlaceId() +{ + return __placeId; +} + +void ctx::GeofenceMonitorHandle::__stopMonitor() +{ + _D("Stops monitoring Place-%d", __placeId); + + //TODO: Do we need to stop all geofences explicitly? + if (__geoHandle) { + geofence_manager_destroy(__geoHandle); + __geoHandle = NULL; + } + + __geoStateMap.clear(); + __placeId = -1; + __prevState = GEOFENCE_STATE_UNCERTAIN; +} + +bool ctx::GeofenceMonitorHandle::__startFence(int fenceId) +{ + int ret; + + ret = geofence_manager_start(__geoHandle, fenceId); + IF_FAIL_RETURN_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, true, _W, "Starting failed"); + + geofence_status_h status; + ret = geofence_status_create(fenceId, &status); + IF_FAIL_RETURN_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, true, _W, "Getting status failed"); + + geofence_state_e state = GEOFENCE_STATE_UNCERTAIN; + geofence_status_get_state(status, &state); + geofence_status_destroy(status); + + __geoStateMap[fenceId] = state; + + return true; +} + +void ctx::GeofenceMonitorHandle::__removeFence(int fenceId) +{ + geofence_manager_stop(__geoHandle, fenceId); + __geoStateMap.erase(fenceId); +} + +void ctx::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; + } +} + +void ctx::GeofenceMonitorHandle::__updateState(int fenceId, geofence_state_e state) +{ + __geoStateMap[fenceId] = state; +} + +static const char* get_state_string(geofence_state_e state) +{ + switch (state) { + case GEOFENCE_STATE_IN: + return PLACE_GEOFENCE_IN; + case GEOFENCE_STATE_OUT: + return PLACE_GEOFENCE_OUT; + case GEOFENCE_STATE_UNCERTAIN: + return PLACE_GEOFENCE_UNCERTAIN; + default: + return PLACE_GEOFENCE_UNCERTAIN; + } +} + +void ctx::GeofenceMonitorHandle::__emitStateChange() +{ + geofence_state_e current_state = GEOFENCE_STATE_UNCERTAIN; + int outCount = 0; + + for (auto it = __geoStateMap.begin(); it != __geoStateMap.end(); ++it) { + if (it->second == GEOFENCE_STATE_IN) { + current_state = GEOFENCE_STATE_IN; + break; + } else if (it->second == GEOFENCE_STATE_OUT) { + ++ outCount; + } + } + + if (current_state != GEOFENCE_STATE_IN && outCount > 0) { + current_state = GEOFENCE_STATE_OUT; + } + + if (current_state == __prevState) { + return; + } + + __prevState = current_state; + + Json option; + option.set(NULL, PLACE_GEOFENCE_PLACE_ID, __placeId); + + Json data; + data.set(NULL, PLACE_GEOFENCE_PLACE_ID, __placeId); + data.set(NULL, PLACE_GEOFENCE_EVENT, get_state_string(current_state)); + + context_manager::publish(PLACE_SUBJ_GEOFENCE, option, ERR_NONE, data); +} + +bool ctx::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); + + GeofenceMonitorHandle *handle = reinterpret_cast(userData); + return handle->__startFence(geofenceId); +} + +void ctx::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); + + GeofenceMonitorHandle *handle = reinterpret_cast(userData); + + IF_FAIL_VOID_TAG(placeId == handle->getPlaceId(), _W, "Mismatched Place ID"); + + handle->__updateFence(geofenceId, manage); +} + +void ctx::GeofenceMonitorHandle::__fenceStateCb(int geofenceId, geofence_state_e state, void* userData) +{ + GeofenceMonitorHandle *handle = reinterpret_cast(userData); + handle->__updateState(geofenceId, state); + handle->__emitStateChange(); +} diff --git a/src/place/geofence/GeofenceMonitorHandle.h b/src/place/geofence/GeofenceMonitorHandle.h new file mode 100644 index 0000000..3f15432 --- /dev/null +++ b/src/place/geofence/GeofenceMonitorHandle.h @@ -0,0 +1,55 @@ +/* + * 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_PLACE_GEOFENCE_MONITOR_HANDLE_H_ +#define _CONTEXT_PLACE_GEOFENCE_MONITOR_HANDLE_H_ + +#include +#include +#include + +namespace ctx { + + class GeofenceMonitorHandle { + + public: + GeofenceMonitorHandle(); + ~GeofenceMonitorHandle(); + + bool startMonitor(int placeId); + int getPlaceId(); + + private: + int __placeId; + geofence_state_e __prevState; + geofence_manager_h __geoHandle; + std::map __geoStateMap; + + void __emitStateChange(); + void __stopMonitor(); + bool __startFence(int fenceId); + void __removeFence(int fenceId); + void __updateFence(int fenceId, geofence_manage_e manage); + void __updateState(int fenceId, geofence_state_e state); + + static bool __fenceListCb(int geofenceId, geofence_h fence, int fenceIndex, int fenceCount, void* userData); + static void __fenceEventCb(int placeId, int geofenceId, geofence_manager_error_e error, geofence_manage_e manage, void* userData); + static void __fenceStateCb(int geofenceId, geofence_state_e state, void* userData); + }; + +} /* namespace ctx */ + +#endif /* End of _CONTEXT_PLACE_GEOFENCE_MONITOR_HANDLE_H_ */ diff --git a/src/place/geofence/PlaceGeofenceProvider.cpp b/src/place/geofence/PlaceGeofenceProvider.cpp new file mode 100644 index 0000000..a1a5b5f --- /dev/null +++ b/src/place/geofence/PlaceGeofenceProvider.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include "PlaceGeofenceProvider.h" + +ctx::PlaceGeofenceProvider *ctx::PlaceGeofenceProvider::__instance = NULL; + +ctx::PlaceGeofenceProvider::PlaceGeofenceProvider() +{ +} + +ctx::PlaceGeofenceProvider::~PlaceGeofenceProvider() +{ + for (auto it = __handleMap.begin(); it != __handleMap.end(); ++it) { + 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 supported = false; + int ret = geofence_manager_is_supported(&supported); + IF_FAIL_RETURN_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, false, _E, "geofence_manager_is_supported() failed"); + return supported; +} + +void ctx::PlaceGeofenceProvider::submitTriggerItem() +{ + context_manager::registerTriggerItem(PLACE_SUBJ_GEOFENCE, OPS_SUBSCRIBE, + "{" + "\"Event\":{\"type\":\"string\",\"values\":[\"In\",\"Out\"]}" + "}", + "{" + "\"PlaceId\":{\"type\":\"integer\",\"min\":1}" + "}"); +} + +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 placeId = -1; + option.get(NULL, PLACE_GEOFENCE_PLACE_ID, &placeId); + IF_FAIL_RETURN_TAG(placeId != -1, ERR_INVALID_PARAMETER, _E, "Getting PlaceID failed"); + + auto it = __handleMap.find(placeId); + if (it != __handleMap.end()) { + _D("Place ID %d is being monitored already", placeId); + return ERR_NONE; + } + + GeofenceMonitorHandle *handle = new(std::nothrow) GeofenceMonitorHandle(); + ASSERT_ALLOC(handle); + + bool ret = handle->startMonitor(placeId); + if (!ret) { + _E("Monitoring Place ID %d failed", placeId); + delete handle; + return ERR_OPERATION_FAILED; + } + + __handleMap[placeId] = handle; + + return ERR_NONE; +} + +int ctx::PlaceGeofenceProvider::__unsubscribe(ctx::Json option) +{ + int placeId = -1; + option.get(NULL, PLACE_GEOFENCE_PLACE_ID, &placeId); + IF_FAIL_RETURN_TAG(placeId != -1, ERR_INVALID_PARAMETER, _E, "Getting PlaceID failed"); + + auto it = __handleMap.find(placeId); + if (it == __handleMap.end()) { + _D("Place ID %d is not being monitored", placeId); + return ERR_NONE; + } + + delete it->second; + __handleMap.erase(it); + + return ERR_NONE; +} diff --git a/src/place/geofence/place_geofence.h b/src/place/geofence/PlaceGeofenceProvider.h similarity index 69% rename from src/place/geofence/place_geofence.h rename to src/place/geofence/PlaceGeofenceProvider.h index 739610f..a95f4c6 100644 --- a/src/place/geofence/place_geofence.h +++ b/src/place/geofence/PlaceGeofenceProvider.h @@ -14,24 +14,23 @@ * limitations under the License. */ -#ifndef __CONTEXT_PLACE_GEOFENCE_H__ -#define __CONTEXT_PLACE_GEOFENCE_H__ +#ifndef _CONTEXT_PLACE_GEOFENCE_PROVIDER_H_ +#define _CONTEXT_PLACE_GEOFENCE_PROVIDER_H_ #include #include -#include "myplace_handle.h" -#include "place_geofence_types.h" +#include "GeofenceMonitorHandle.h" +#include "PlaceGeofenceTypes.h" namespace ctx { - class place_geofence_provider : public ContextProviderBase { - typedef std::map handle_map_t; + class PlaceGeofenceProvider : public ContextProviderBase { public: static ContextProviderBase *create(void *data); static void destroy(void *data); - static bool is_supported(); - static void submit_trigger_item(); + 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); @@ -39,17 +38,17 @@ namespace ctx { int write(const char *subject, ctx::Json data, ctx::Json *requestResult); private: - static place_geofence_provider *__instance; - handle_map_t __handle_map; + static PlaceGeofenceProvider *__instance; + std::map __handleMap; - place_geofence_provider(); - ~place_geofence_provider(); + PlaceGeofenceProvider(); + ~PlaceGeofenceProvider(); int __subscribe(ctx::Json option); int __unsubscribe(ctx::Json option); - void __destroy_if_unused(); + void __destroyIfUnused(); }; } /* namespace ctx */ -#endif /* __CONTEXT_PLACE_GEOFENCE_H__ */ +#endif /* End of _CONTEXT_PLACE_GEOFENCE_PROVIDER_H_ */ diff --git a/src/place/geofence/place_geofence_types.h b/src/place/geofence/PlaceGeofenceTypes.h similarity index 63% rename from src/place/geofence/place_geofence_types.h rename to src/place/geofence/PlaceGeofenceTypes.h index b9aa61a..fa66a41 100644 --- a/src/place/geofence/place_geofence_types.h +++ b/src/place/geofence/PlaceGeofenceTypes.h @@ -14,24 +14,22 @@ * limitations under the License. */ -#ifndef __CONTEXT_PLACE_GEOFENCE_TYPES__ -#define __CONTEXT_PLACE_GEOFENCE_TYPES__ +#ifndef _CONTEXT_PLACE_GEOFENCE_TYPES_H_ +#define _CONTEXT_PLACE_GEOFENCE_TYPES_H_ -// Context Items +// Subject #define PLACE_SUBJ_GEOFENCE "place/geofence" +// Privilege #define PLACE_PRIV_GEOFENCE "location" -// Option Keys -#define PLACE_STATUS_OPT_MYPLACE_ID "PlaceId" +// Option & Data Key +#define PLACE_GEOFENCE_PLACE_ID "PlaceId" +#define PLACE_GEOFENCE_EVENT "Event" -// Data Keys -#define PLACE_STATUS_DATA_MYPLACE_ID "PlaceId" -#define PLACE_STATUS_DATA_MYPLACE_EVENT "Event" +// Data Value +#define PLACE_GEOFENCE_UNCERTAIN "Uncertain" +#define PLACE_GEOFENCE_IN "In" +#define PLACE_GEOFENCE_OUT "Out" -// Data Values -#define MYPLACE_EVENT_UNCERTAIN "Uncertain" -#define MYPLACE_EVENT_IN "In" -#define MYPLACE_EVENT_OUT "Out" - -#endif +#endif /* End of _CONTEXT_PLACE_GEOFENCE_TYPES_H_ */ diff --git a/src/place/geofence/myplace_handle.cpp b/src/place/geofence/myplace_handle.cpp deleted file mode 100644 index d7b8fcc..0000000 --- a/src/place/geofence/myplace_handle.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include "place_geofence_types.h" -#include "myplace_handle.h" - -ctx::myplace_handle::myplace_handle() - : _place_id(-1) - , prev_state(GEOFENCE_STATE_UNCERTAIN) - , geo_handle(NULL) -{ -} - -ctx::myplace_handle::~myplace_handle() -{ - stop_monitor(); -} - -bool ctx::myplace_handle::start_monitor(int place_id) -{ - _D("Starts to monitor Place-%d", place_id); - - IF_FAIL_RETURN(place_id >= 0, false); - IF_FAIL_RETURN_TAG(geo_handle == NULL, false, _E, "Re-starting MyPlace monitor"); - - geofence_manager_create(&geo_handle); - IF_FAIL_RETURN_TAG(geo_handle, false, _E, "Geofence initialization failed"); - - int ret; - - ret = geofence_manager_set_geofence_state_changed_cb(geo_handle, fence_state_cb, this); - IF_FAIL_CATCH_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, _E, "Setting state callback failed"); - - ret = geofence_manager_set_geofence_event_cb(geo_handle, fence_event_cb, this); - IF_FAIL_CATCH_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, _E, "Setting event callback failed"); - - ret = geofence_manager_foreach_place_geofence_list(geo_handle, place_id, fence_list_cb, this); - IF_FAIL_CATCH_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, _E, "Getting fence list failed"); - - _place_id = place_id; - return true; - -CATCH: - stop_monitor(); - return false; -} - -int ctx::myplace_handle::get_place_id() -{ - return _place_id; -} - -void ctx::myplace_handle::stop_monitor() -{ - _D("Stops monitoring Place-%d", _place_id); - - //TODO: Do we need to stop all geofences explicitly? - if (geo_handle) { - geofence_manager_destroy(geo_handle); - geo_handle = NULL; - } - - geo_state_map.clear(); - _place_id = -1; - prev_state = GEOFENCE_STATE_UNCERTAIN; -} - -bool ctx::myplace_handle::start_fence(int fence_id) -{ - int ret; - - ret = geofence_manager_start(geo_handle, fence_id); - IF_FAIL_RETURN_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, true, _W, "Starting failed"); - - geofence_status_h status; - ret = geofence_status_create(fence_id, &status); - IF_FAIL_RETURN_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, true, _W, "Getting status failed"); - - geofence_state_e state = GEOFENCE_STATE_UNCERTAIN; - geofence_status_get_state(status, &state); - geofence_status_destroy(status); - - geo_state_map[fence_id] = state; - - return true; -} - -void ctx::myplace_handle::remove_fence(int fence_id) -{ - geofence_manager_stop(geo_handle, fence_id); - geo_state_map.erase(fence_id); -} - -void ctx::myplace_handle::update_fence(int fence_id, geofence_manage_e manage) -{ - switch (manage) { - case GEOFENCE_MANAGE_PLACE_REMOVED: - _W("[Place-%d] Removed", _place_id); - stop_monitor(); - break; - case GEOFENCE_MANAGE_FENCE_ADDED: - _I("[Place %d] Fence-%d added", _place_id, fence_id); - start_fence(fence_id); - emit_state_change(); - break; - case GEOFENCE_MANAGE_FENCE_REMOVED: - _I("[Place-%d] Fence-%d removed", _place_id, fence_id); - remove_fence(fence_id); - emit_state_change(); - break; - case GEOFENCE_MANAGE_FENCE_STARTED: - _D("[Place-%d] Fence-%d started", _place_id, fence_id); - break; - case GEOFENCE_MANAGE_FENCE_STOPPED: - _D("[Place-%d] Fence-%d stopped", _place_id, fence_id); - //TODO: Do we need to restart this? - break; - default: - _D("[Place-%d] Ignoring the manage event %d", _place_id, manage); - break; - } -} - -void ctx::myplace_handle::update_state(int fence_id, geofence_state_e state) -{ - geo_state_map[fence_id] = state; -} - -static const char* get_state_string(geofence_state_e state) -{ - switch (state) { - case GEOFENCE_STATE_IN: - return MYPLACE_EVENT_IN; - case GEOFENCE_STATE_OUT: - return MYPLACE_EVENT_OUT; - case GEOFENCE_STATE_UNCERTAIN: - return MYPLACE_EVENT_UNCERTAIN; - default: - return MYPLACE_EVENT_UNCERTAIN; - } -} - -void ctx::myplace_handle::emit_state_change() -{ - geofence_state_e current_state = GEOFENCE_STATE_UNCERTAIN; - int out_count = 0; - - for (geo_state_map_t::iterator it = geo_state_map.begin(); it != geo_state_map.end(); ++it) { - if (it->second == GEOFENCE_STATE_IN) { - current_state = GEOFENCE_STATE_IN; - break; - } else if (it->second == GEOFENCE_STATE_OUT) { - ++ out_count; - } - } - - if (current_state != GEOFENCE_STATE_IN && out_count > 0) { - current_state = GEOFENCE_STATE_OUT; - } - - if (current_state == prev_state) { - return; - } - - prev_state = current_state; - - Json option; - option.set(NULL, PLACE_STATUS_DATA_MYPLACE_ID, _place_id); - - Json data; - data.set(NULL, PLACE_STATUS_DATA_MYPLACE_ID, _place_id); - data.set(NULL, PLACE_STATUS_DATA_MYPLACE_EVENT, get_state_string(current_state)); - - context_manager::publish(PLACE_SUBJ_GEOFENCE, option, ERR_NONE, data); -} - -bool ctx::myplace_handle::fence_list_cb(int geofence_id, geofence_h fence, int fence_index, int fence_cnt, void* user_data) -{ - _D("FenceID: %d, Index: %d, Count: %d", geofence_id, fence_index, fence_cnt); - IF_FAIL_RETURN(fence_cnt > 0, false); - - myplace_handle *handle = reinterpret_cast(user_data); - return handle->start_fence(geofence_id); -} - -void ctx::myplace_handle::fence_event_cb(int place_id, int geofence_id, geofence_manager_error_e error, geofence_manage_e manage, void* user_data) -{ - IF_FAIL_VOID_TAG(error == GEOFENCE_MANAGER_ERROR_NONE, _W, "Geofence error: %d", error); - - myplace_handle *handle = reinterpret_cast(user_data); - - IF_FAIL_VOID_TAG(place_id == handle->get_place_id(), _W, "Mismatched Place ID"); - - handle->update_fence(geofence_id, manage); -} - -void ctx::myplace_handle::fence_state_cb(int geofence_id, geofence_state_e state, void* user_data) -{ - myplace_handle *handle = reinterpret_cast(user_data); - handle->update_state(geofence_id, state); - handle->emit_state_change(); -} diff --git a/src/place/geofence/myplace_handle.h b/src/place/geofence/myplace_handle.h deleted file mode 100644 index c8b4913..0000000 --- a/src/place/geofence/myplace_handle.h +++ /dev/null @@ -1,59 +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_PLACE_MYPLACE_HANDLE_H__ -#define __CONTEXT_PLACE_MYPLACE_HANDLE_H__ - -#include -#include -#include -#include - -namespace ctx { - - class myplace_handle { - - typedef std::map geo_state_map_t; - typedef std::set string_set_t; - - public: - myplace_handle(); - ~myplace_handle(); - - bool start_monitor(int place_id); - int get_place_id(); - - private: - int _place_id; - geofence_state_e prev_state; - geofence_manager_h geo_handle; - geo_state_map_t geo_state_map; - - void emit_state_change(); - void stop_monitor(); - bool start_fence(int fence_id); - void remove_fence(int fence_id); - void update_fence(int fence_id, geofence_manage_e manage); - void update_state(int fence_id, geofence_state_e state); - - static bool fence_list_cb(int geofence_id, geofence_h fence, int fence_index, int fence_cnt, void* user_data); - static void fence_event_cb(int place_id, int geofence_id, geofence_manager_error_e error, geofence_manage_e manage, void* user_data); - static void fence_state_cb(int geofence_id, geofence_state_e state, void* user_data); - }; - -} /* namespace ctx */ - -#endif /* __CONTEXT_PLACE_MYPLACE_HANDLE_H__ */ diff --git a/src/place/geofence/place_geofence.cpp b/src/place/geofence/place_geofence.cpp deleted file mode 100644 index 5bcfb7f..0000000 --- a/src/place/geofence/place_geofence.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include -#include -#include "place_geofence.h" - -ctx::place_geofence_provider *ctx::place_geofence_provider::__instance = NULL; - -ctx::place_geofence_provider::place_geofence_provider() -{ -} - -ctx::place_geofence_provider::~place_geofence_provider() -{ - for (handle_map_t::iterator it = __handle_map.begin(); it != __handle_map.end(); ++it) { - delete it->second; - } - - __handle_map.clear(); -} - -ctx::ContextProviderBase *ctx::place_geofence_provider::create(void *data) -{ - IF_FAIL_RETURN(!__instance, __instance); - __instance = new(std::nothrow) place_geofence_provider(); - IF_FAIL_RETURN_TAG(__instance, NULL, _E, "Memory allocation failed"); - _I(BLUE("Created")); - return __instance; -} - -void ctx::place_geofence_provider::destroy(void *data) -{ - IF_FAIL_VOID(__instance); - delete __instance; - __instance = NULL; - _I(BLUE("Destroyed")); -} - -bool ctx::place_geofence_provider::is_supported() -{ - bool supported = false; - int ret = geofence_manager_is_supported(&supported); - IF_FAIL_RETURN_TAG(ret == GEOFENCE_MANAGER_ERROR_NONE, false, _E, "geofence_manager_is_supported() failed"); - return supported; -} - -void ctx::place_geofence_provider::submit_trigger_item() -{ - context_manager::registerTriggerItem(PLACE_SUBJ_GEOFENCE, OPS_SUBSCRIBE, - "{" - "\"Event\":{\"type\":\"string\",\"values\":[\"In\",\"Out\"]}" - "}", - "{" - "\"PlaceId\":{\"type\":\"integer\",\"min\":1}" - "}"); -} - -void ctx::place_geofence_provider::__destroy_if_unused() -{ - IF_FAIL_VOID(__handle_map.empty()); - destroy(NULL); -} - - -int ctx::place_geofence_provider::subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult) -{ - int ret = __subscribe(option); - __destroy_if_unused(); - return ret; -} - -int ctx::place_geofence_provider::unsubscribe(const char *subject, ctx::Json option) -{ - int ret = __unsubscribe(option); - __destroy_if_unused(); - return ret; -} - -int ctx::place_geofence_provider::read(const char *subject, ctx::Json option, ctx::Json *requestResult) -{ - __destroy_if_unused(); - return ERR_NOT_SUPPORTED; -} - -int ctx::place_geofence_provider::write(const char *subject, ctx::Json data, ctx::Json *requestResult) -{ - __destroy_if_unused(); - return ERR_NOT_SUPPORTED; -} - -int ctx::place_geofence_provider::__subscribe(ctx::Json option) -{ - int pid = -1; - option.get(NULL, PLACE_STATUS_OPT_MYPLACE_ID, &pid); - IF_FAIL_RETURN_TAG(pid != -1, ERR_INVALID_PARAMETER, _E, "Getting PlaceID failed"); - - handle_map_t::iterator it = __handle_map.find(pid); - if (it != __handle_map.end()) { - _D("Place ID %d is being monitored already", pid); - return ERR_NONE; - } - - myplace_handle *handle = new(std::nothrow) myplace_handle(); - ASSERT_ALLOC(handle); - - bool ret = handle->start_monitor(pid); - if (!ret) { - _E("Monitoring Place ID %d failed", pid); - delete handle; - return ERR_OPERATION_FAILED; - } - - __handle_map[pid] = handle; - - return ERR_NONE; -} - -int ctx::place_geofence_provider::__unsubscribe(ctx::Json option) -{ - int pid = -1; - option.get(NULL, PLACE_STATUS_OPT_MYPLACE_ID, &pid); - IF_FAIL_RETURN_TAG(pid != -1, ERR_INVALID_PARAMETER, _E, "Getting PlaceID failed"); - - handle_map_t::iterator it = __handle_map.find(pid); - if (it == __handle_map.end()) { - _D("Place ID %d is not being monitored", pid); - return ERR_NONE; - } - - delete it->second; - __handle_map.erase(it); - - return ERR_NONE; -} diff --git a/src/place/recognition/place_recognition.cpp b/src/place/recognition/place_recognition.cpp index 0b1b790..0088b5e 100644 --- a/src/place/recognition/place_recognition.cpp +++ b/src/place/recognition/place_recognition.cpp @@ -71,7 +71,7 @@ int ctx::place_recognition_provider::write(const char *subject, ctx::Json data, return ERR_NOT_SUPPORTED; } -bool ctx::place_recognition_provider::is_supported() +bool ctx::place_recognition_provider::isSupported() { return true; } diff --git a/src/place/recognition/place_recognition.h b/src/place/recognition/place_recognition.h index 40a93ec..14d76d9 100644 --- a/src/place/recognition/place_recognition.h +++ b/src/place/recognition/place_recognition.h @@ -28,7 +28,7 @@ namespace ctx { public: static ContextProviderBase *create(void *data); static void destroy(void *data); - static bool is_supported(); + static bool isSupported(); int subscribe(const char *subject, ctx::Json option, ctx::Json *requestResult); int unsubscribe(const char *subject, ctx::Json option); -- 2.7.4 From a3ec22a4e061a26cb2a07baca635cc59f494873e Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Fri, 8 Apr 2016 10:55:36 +0900 Subject: [PATCH 16/16] Version 0.7.5 Change-Id: Ib8b9d452b443ddc929d2d1d5471061ec1d8e0fea Signed-off-by: Somin Kim --- packaging/context-provider.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/context-provider.spec b/packaging/context-provider.spec index 3ddb5eb..a259bde 100644 --- a/packaging/context-provider.spec +++ b/packaging/context-provider.spec @@ -1,6 +1,6 @@ Name: context-provider Summary: Context Provider -Version: 0.7.4 +Version: 0.7.5 Release: 1 Group: Service/Context License: Apache-2.0 -- 2.7.4