From 9ce08713c4b8c36ee1a600bab22ae81431d9854c Mon Sep 17 00:00:00 2001 From: Somin Kim Date: Tue, 2 Feb 2016 13:47:51 +0900 Subject: [PATCH 01/16] Custom item recovery logic added when initialized (Uninstalled provider's item handling is still needed) Change-Id: I7e020b28174bbf2f868cd9c255fbe65dbcd1fbc2 Signed-off-by: Somin Kim --- include/custom_context_provider.h | 2 +- src/custom/custom_context_provider.cpp | 53 +++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/include/custom_context_provider.h b/include/custom_context_provider.h index 584cf3b..10e4275 100644 --- a/include/custom_context_provider.h +++ b/include/custom_context_provider.h @@ -21,7 +21,7 @@ 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); + 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); diff --git a/src/custom/custom_context_provider.cpp b/src/custom/custom_context_provider.cpp index 923fa1a..dd79fd5 100644 --- a/src/custom/custom_context_provider.cpp +++ b/src/custom/custom_context_provider.cpp @@ -15,9 +15,11 @@ */ #include +#include #include #include #include +#include #include #include "custom_base.h" @@ -59,10 +61,44 @@ EXTAPI void ctx::custom_context_provider::destroy(void *data) EXTAPI bool ctx::init_custom_context_provider() { + // Create custom template db + std::string q = std::string("CREATE TABLE IF NOT EXISTS context_trigger_custom_template ") + + "(subject TEXT DEFAULT '' NOT NULL PRIMARY KEY, name TEXT DEFAULT '' NOT NULL, operation INTEGER DEFAULT 3 NOT NULL, " + + "attributes TEXT DEFAULT '' NOT NULL, owner TEXT DEFAULT '' NOT NULL)"; + + std::vector record; + bool ret = db_manager::execute_sync(q.c_str(), &record); + 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); + 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::string subject; + std::string name; + std::string attributes; + std::string owner; + elem.get(NULL, "subject", &subject); + elem.get(NULL, "name", &name); + 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); + if (error != ERR_NONE) { + _E("Failed to add custom item(%s): %#x", subject.c_str(), error); + } + } + return true; } -EXTAPI int ctx::custom_context_provider::add_item(std::string subject, std::string name, ctx::json tmpl, const char* owner) +EXTAPI int ctx::custom_context_provider::add_item(std::string subject, std::string name, ctx::json tmpl, const char* owner, bool is_init) { std::map::iterator it; it = custom_map.find(subject); @@ -82,6 +118,15 @@ EXTAPI int ctx::custom_context_provider::add_item(std::string subject, std::stri register_provider(custom->get_subject(), NULL); + // Add item to custom template db + if (!is_init) { + std::string q = "INSERT OR IGNORE INTO context_trigger_custom_template (subject, name, attributes, owner) VALUES ('" + + subject + "', '" + name + "', '" + tmpl.str() + "', '" + owner + "'); "; + std::vector record; + bool ret = db_manager::execute_sync(q.c_str(), &record); + IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to query custom templates"); + } + return ERR_NONE; } @@ -93,6 +138,12 @@ EXTAPI int ctx::custom_context_provider::remove_item(std::string subject) unregister_provider(subject.c_str()); + // Remove item from custom template db + std::string q = "DELETE FROM context_trigger_custom_template WHERE subject = '" + subject + "'"; + std::vector record; + bool ret = db_manager::execute_sync(q.c_str(), &record); + IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to query custom templates"); + return ERR_NONE; } -- 2.7.4 From 548fce4ecf480762644b75f6c4cb861b5a2c7614 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 16 Feb 2016 21:41:41 +0900 Subject: [PATCH 02/16] Replace build dependency context-common with libcontext-shared & server Change-Id: I8bdcb6e90f29fa579cbc03f5b098a8a98037367d Signed-off-by: Mu-Woong Lee --- CMakeLists.txt | 2 +- packaging/context-provider.spec | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea5ae1a..af3b0b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ INCLUDE_DIRECTORIES( ADD_DEFINITIONS(-O2 -Wall -fPIC -fvisibility=hidden -Wl,--as-needed) # Common Dependency -SET(deps_common "context-common") +SET(deps_common "libcontext-shared libcontext-server") # Profiles IF("${PROFILE}" STREQUAL "mobile") diff --git a/packaging/context-provider.spec b/packaging/context-provider.spec index 9924dd9..2f9c5af 100644 --- a/packaging/context-provider.spec +++ b/packaging/context-provider.spec @@ -10,7 +10,8 @@ Source0: %{name}-%{version}.tar.gz BuildRequires: cmake -BuildRequires: pkgconfig(context-common) +BuildRequires: pkgconfig(libcontext-shared) +BuildRequires: pkgconfig(libcontext-server) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(capi-system-device) -- 2.7.4 From 90f6a2fd9acf5a0d233731ae4e502abd4b0d7c06 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Wed, 17 Feb 2016 22:08:05 +0900 Subject: [PATCH 03/16] Create one unified so instead of one so for each provider Change-Id: I6da5e80c83ca926b47e7d0639c725c304dfcaee9 Signed-off-by: Mu-Woong Lee --- CMakeLists.txt | 34 ++++++++++---- src/CMakeLists.txt | 26 +++++++---- src/custom/CMakeLists.txt | 24 +--------- src/device/CMakeLists.txt | 63 +++++++++----------------- src/place/CMakeLists.txt | 37 ++++----------- src/statistics/CMakeLists.txt | 54 ++++++---------------- src/statistics/app/active_window_monitor.cpp | 2 +- src/statistics/app/app_stats_types.h | 2 +- src/statistics/app/db_handle.h | 2 +- src/statistics/media/db_handle.cpp | 2 +- src/statistics/media/db_handle.h | 2 +- src/statistics/media/media_content_monitor.cpp | 2 +- src/statistics/media/media_stats_types.h | 2 +- src/statistics/social/db_handle.h | 2 +- src/statistics/social/social_stats_types.h | 2 +- 15 files changed, 96 insertions(+), 160 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af3b0b4..b5e59aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(context-provider) INCLUDE(GNUInstallDirs) +SET(target "context-provider") +SET(compile_defs "LOG_TAG=\"CONTEXT\"") # Common Options INCLUDE_DIRECTORIES( @@ -8,8 +10,8 @@ INCLUDE_DIRECTORIES( ) ADD_DEFINITIONS(-O2 -Wall -fPIC -fvisibility=hidden -Wl,--as-needed) -# Common Dependency -SET(deps_common "libcontext-shared libcontext-server") +# Base Dependency +SET(dependencies "libcontext-shared libcontext-server") # Profiles IF("${PROFILE}" STREQUAL "mobile") @@ -26,6 +28,22 @@ ENDIF("${PROFILE}" STREQUAL "tv") # Include Sub-modules ADD_SUBDIRECTORY(src) +MESSAGE("Compile definitions: ${compile_defs}") + +# Build +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(DEPS REQUIRED ${dependencies}) + +FOREACH(flag ${DEPS_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +ADD_LIBRARY(${target} SHARED ${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}") +SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) # Package Config SET(VERSION ${FULLVER}) @@ -34,11 +52,9 @@ SET(PC_NAME ${PROJECT_NAME}) SET(PC_DESCRIPTION "Tizen Context Framework Context Provider") SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/context-service") SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") -SET(PC_CFLAGS -I\${includedir}/context-service) - -GET_DIRECTORY_PROPERTY(PC_LDFLAGS DIRECTORY src DEFINITION target_all) -GET_DIRECTORY_PROPERTY(PC_REQUIRED DIRECTORY src DEFINITION deps_all) -SET(PC_REQUIRED "${deps_common} ${PC_REQUIRED}") +SET(PC_CFLAGS "-I\${includedir}/context-service") +SET(PC_LDFLAGS "-l${target}") +SET(PC_REQUIRED "${dependencies}") CONFIGURE_FILE( ${PROJECT_NAME}.pc.in @@ -48,7 +64,9 @@ CONFIGURE_FILE( # Installing INSTALL( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/context-service/internal + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/context-service/internal FILES_MATCHING PATTERN "*.h" ) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 737a746..9d45a9a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,22 +2,28 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) FUNCTION(add_provider prvd_name) ADD_SUBDIRECTORY(${prvd_name}) - GET_DIRECTORY_PROPERTY(target_sub DIRECTORY ${prvd_name} DEFINITION target) - GET_DIRECTORY_PROPERTY(deps_sub DIRECTORY ${prvd_name} DEFINITION deps) - SET(target_all "${target_all} -l${target_sub}" PARENT_SCOPE) - SET(deps_list "${deps_list} ${deps_sub}" PARENT_SCOPE) + GET_DIRECTORY_PROPERTY(srcs_subdir DIRECTORY ${prvd_name} DEFINITION prvd_srcs) + GET_DIRECTORY_PROPERTY(deps_subdir DIRECTORY ${prvd_name} DEFINITION prvd_deps) + GET_DIRECTORY_PROPERTY(cdef_subdir DIRECTORY ${prvd_name} DEFINITION prvd_cdef) + SET(srcs_collected ${srcs_collected} ${srcs_subdir} PARENT_SCOPE) + SET(deps_collected ${deps_collected} ${deps_subdir} PARENT_SCOPE) + SET(cdef_collected ${cdef_collected} ${cdef_subdir} PARENT_SCOPE) ENDFUNCTION(add_provider) + add_provider(device) add_provider(statistics) add_provider(place) add_provider(custom) -SEPARATE_ARGUMENTS(deps_list) -LIST(REMOVE_DUPLICATES deps_list) -FOREACH(item IN LISTS deps_list) - SET(deps_all "${deps_all} ${item}") + +LIST(REMOVE_DUPLICATES deps_collected) +FOREACH(item IN LISTS deps_collected) + SET(deps_filtered "${deps_filtered} ${item}") ENDFOREACH(item) -STRING(STRIP "${target_all}" target_all) -STRING(STRIP "${deps_all}" deps_all) +STRING(STRIP "${deps_filtered}" deps_filtered) + +SET(sources ${sources} ${srcs_collected} PARENT_SCOPE) +SET(dependencies "${dependencies} ${deps_filtered}" PARENT_SCOPE) +SET(compile_defs ${compile_defs} ${cdef_collected} PARENT_SCOPE) diff --git a/src/custom/CMakeLists.txt b/src/custom/CMakeLists.txt index 881c3a4..4623e2b 100644 --- a/src/custom/CMakeLists.txt +++ b/src/custom/CMakeLists.txt @@ -1,25 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(target "ctx-custom") +# prvd_cdef, prvd_deps, and prvd_srcs need to be set properly # Common Profile -FILE(GLOB srcs ./*.cpp) - -MESSAGE("Custom Provider Sources: ${srcs}") - -# Build -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(custom_pkgs REQUIRED ${deps_common}) - -FOREACH(flag ${custom_pkgs_CFLAGS}) - SET(extra_cflags "${extra_cflags} ${flag}") -ENDFOREACH(flag) - -ADD_LIBRARY(${target} SHARED ${srcs}) -TARGET_LINK_LIBRARIES(${target} ${custom_pkgs_LDFLAGS}) -SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_FLAGS ${extra_cflags}) -SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_DEFINITIONS "LOG_TAG=\"CONTEXT-CUSTOM\"") -SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) -SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) - -# Install -INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) +FILE(GLOB prvd_srcs ./*.cpp) diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt index 94a604b..d7e66ef 100644 --- a/src/device/CMakeLists.txt +++ b/src/device/CMakeLists.txt @@ -1,58 +1,37 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(target "ctx-device") -SET(definitions LOG_TAG=\"CONTEXT-DEVICE\") +# prvd_cdef, prvd_deps, and prvd_srcs need to be set properly # Common Profile -FILE(GLOB srcs ./*.cpp) -SET(deps "vconf capi-system-info capi-system-device capi-system-runtime-info") +FILE(GLOB prvd_srcs ./*.cpp) +SET(prvd_deps vconf capi-system-info capi-system-device capi-system-runtime-info) # Mobile Profile IF("${PROFILE}" STREQUAL "mobile") - SET(deps "${deps} capi-network-bluetooth capi-network-wifi") - SET(deps "${deps} capi-telephony tapi msg-service capi-messaging-email motion") - FILE(GLOB_RECURSE srcs ${srcs} activity/*.cpp) - FILE(GLOB_RECURSE srcs ${srcs} system/*.cpp) - FILE(GLOB_RECURSE srcs ${srcs} social/*.cpp) + SET(prvd_deps ${prvd_deps} capi-network-bluetooth capi-network-wifi) + SET(prvd_deps ${prvd_deps} capi-telephony tapi msg-service capi-messaging-email motion) + FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} activity/*.cpp) + FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} system/*.cpp) + FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} social/*.cpp) ENDIF("${PROFILE}" STREQUAL "mobile") # Wearable Profile IF("${PROFILE}" STREQUAL "wearable") - SET(deps "${deps} capi-network-bluetooth capi-network-wifi") - SET(deps "${deps} capi-telephony tapi msg-service motion") - FILE(GLOB_RECURSE srcs ${srcs} activity/*.cpp) - FILE(GLOB_RECURSE srcs ${srcs} system/*.cpp) - SET(srcs ${srcs} social/call.cpp) - SET(srcs ${srcs} social/message.cpp) + SET(prvd_deps ${prvd_deps} capi-network-bluetooth capi-network-wifi) + 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) + SET(prvd_srcs ${prvd_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/social/call.cpp) + SET(prvd_srcs ${prvd_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/social/message.cpp) ENDIF("${PROFILE}" STREQUAL "wearable") # TV Profile IF("${PROFILE}" STREQUAL "tv") - SET(deps "${deps} capi-network-bluetooth capi-network-wifi") - SET(srcs - ${srcs} - system/headphone.cpp - system/wifi.cpp - system/alarm.cpp - system/time.cpp + SET(prvd_deps ${prvd_deps} capi-network-bluetooth capi-network-wifi) + SET(prvd_srcs + ${prvd_srcs} + ${CMAKE_CURRENT_SOURCE_DIR}/system/headphone.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/system/wifi.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/system/alarm.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/system/time.cpp ) ENDIF("${PROFILE}" STREQUAL "tv") - -MESSAGE("Device Provider Sources: ${srcs}") - -# Build -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(device_pkgs REQUIRED ${deps_common} ${deps}) - -FOREACH(flag ${device_pkgs_CFLAGS}) - SET(extra_cflags "${extra_cflags} ${flag}") -ENDFOREACH(flag) - -ADD_LIBRARY(${target} SHARED ${srcs}) -TARGET_LINK_LIBRARIES(${target} ${device_pkgs_LDFLAGS}) -SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_FLAGS ${extra_cflags}) -SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_DEFINITIONS "${definitions}") -SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) -SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) - -# Install -INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) diff --git a/src/place/CMakeLists.txt b/src/place/CMakeLists.txt index 65d1c98..1db79f7 100644 --- a/src/place/CMakeLists.txt +++ b/src/place/CMakeLists.txt @@ -1,43 +1,22 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(target "ctx-place") -SET(definitions LOG_TAG=\"CONTEXT-PLACE\") +# prvd_cdef, prvd_deps, and prvd_srcs need to be set properly # Build flag for the place auto detection engine. # Set this to "yes" to enable the engine. SET(enable_recog_engine "no") # Common Profile -FILE(GLOB srcs *.cpp) +FILE(GLOB prvd_srcs *.cpp) # Mobile Profile IF("${PROFILE}" STREQUAL "mobile") - FILE(GLOB_RECURSE srcs ${srcs} geofence/*.cpp) - SET(deps "${deps} capi-geofence-manager") + FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} geofence/*.cpp) + SET(prvd_deps ${prvd_deps} capi-geofence-manager) IF("${enable_recog_engine}" STREQUAL "yes") - FILE(GLOB_RECURSE srcs ${srcs} recognition/*.cpp) - SET(deps "${deps} capi-location-manager") - SET(deps "${deps} capi-network-wifi") + FILE(GLOB_RECURSE prvd_srcs ${prvd_srcs} recognition/*.cpp) + SET(prvd_deps ${prvd_deps} capi-location-manager) + SET(prvd_deps ${prvd_deps} capi-network-wifi) ELSE("${enable_recog_engine}" STREQUAL "yes") - SET(definitions ${definitions} "_DISABLE_RECOG_ENGINE_") + SET(prvd_cdef ${prvd_cdef} _DISABLE_RECOG_ENGINE_) ENDIF("${enable_recog_engine}" STREQUAL "yes") ENDIF("${PROFILE}" STREQUAL "mobile") - -MESSAGE("Place Provider Sources: ${srcs}") - -# Build -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(place_pkgs REQUIRED ${deps_common} ${deps}) - -FOREACH(flag ${place_pkgs_CFLAGS}) - SET(extra_cflags "${extra_cflags} ${flag}") -ENDFOREACH(flag) - -ADD_LIBRARY(${target} SHARED ${srcs}) -TARGET_LINK_LIBRARIES(${target} ${place_pkgs_LDFLAGS}) -SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_FLAGS ${extra_cflags}) -SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_DEFINITIONS "${definitions}") -SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) -SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) - -# Install -INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) diff --git a/src/statistics/CMakeLists.txt b/src/statistics/CMakeLists.txt index 69df65a..79ac9c5 100644 --- a/src/statistics/CMakeLists.txt +++ b/src/statistics/CMakeLists.txt @@ -1,35 +1,29 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(target "ctx-statistics") -SET(definitions LOG_TAG=\"CONTEXT-STATS\") +# prvd_cdef, prvd_deps, and prvd_srcs need to be set properly # Build flag for the prediction engine. # Set this to "yes" to enable the engine. SET(enable_prediction_engine "no") -# Common Options -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_SOURCE_DIR}/shared -) - # Common Profile -FILE(GLOB srcs ./*.cpp) -FILE(GLOB srcs ${srcs} shared/*.cpp) -FILE(GLOB srcs ${srcs} app/*.cpp) +FILE(GLOB prvd_srcs ./*.cpp) +FILE(GLOB prvd_srcs ${prvd_srcs} shared/*.cpp) +FILE(GLOB prvd_srcs ${prvd_srcs} app/*.cpp) IF("${enable_prediction_engine}" STREQUAL "yes") - FILE(GLOB srcs ${srcs} prediction/*.cpp) + FILE(GLOB prvd_srcs ${prvd_srcs} prediction/*.cpp) ELSE("${enable_prediction_engine}" STREQUAL "yes") - SET(definitions ${definitions} "_DISABLE_PREDICTION_ENGINE_") + SET(prvd_cdef ${prvd_cdef} _DISABLE_PREDICTION_ENGINE_) ENDIF("${enable_prediction_engine}" STREQUAL "yes") -SET(deps "capi-system-runtime-info pkgmgr pkgmgr-info capi-appfw-package-manager") -SET(deps "${deps} capi-appfw-application capi-appfw-app-manager") -SET(deps "${deps} capi-media-sound-manager") +SET(prvd_deps capi-system-runtime-info pkgmgr pkgmgr-info capi-appfw-package-manager) +SET(prvd_deps ${prvd_deps} capi-appfw-application capi-appfw-app-manager) +SET(prvd_deps ${prvd_deps} capi-media-sound-manager) # Mobile Profile IF("${PROFILE}" STREQUAL "mobile") - FILE(GLOB srcs ${srcs} media/*.cpp) - FILE(GLOB srcs ${srcs} social/*.cpp) - SET(deps "${deps} contacts-service2 capi-content-media-content") + FILE(GLOB prvd_srcs ${prvd_srcs} media/*.cpp) + FILE(GLOB prvd_srcs ${prvd_srcs} social/*.cpp) + SET(prvd_deps ${prvd_deps} contacts-service2 capi-content-media-content) ENDIF("${PROFILE}" STREQUAL "mobile") # Wearable Profile @@ -38,26 +32,6 @@ ENDIF("${PROFILE}" STREQUAL "mobile") # TV Profile IF("${PROFILE}" STREQUAL "tv") - FILE(GLOB srcs ${srcs} media/*.cpp) - SET(deps "${deps} capi-content-media-content") + FILE(GLOB prvd_srcs ${prvd_srcs} media/*.cpp) + SET(prvd_deps ${prvd_deps} capi-content-media-content) ENDIF("${PROFILE}" STREQUAL "tv") - -MESSAGE("Statistics Provider Sources: ${srcs}") - -# Build -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(stats_pkgs REQUIRED ${deps_common} ${deps}) - -FOREACH(flag ${stats_pkgs_CFLAGS}) - SET(extra_cflags "${extra_cflags} ${flag}") -ENDFOREACH(flag) - -ADD_LIBRARY(${target} SHARED ${srcs}) -TARGET_LINK_LIBRARIES(${target} ${stats_pkgs_LDFLAGS}) -SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_FLAGS ${extra_cflags}) -SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_DEFINITIONS "${definitions}") -SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) -SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) - -# Install -INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries) diff --git a/src/statistics/app/active_window_monitor.cpp b/src/statistics/app/active_window_monitor.cpp index 58b0d9f..701209b 100644 --- a/src/statistics/app/active_window_monitor.cpp +++ b/src/statistics/app/active_window_monitor.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include "../shared/system_info.h" #include "app_stats_types.h" #include "active_window_monitor.h" diff --git a/src/statistics/app/app_stats_types.h b/src/statistics/app/app_stats_types.h index 96ed505..279a75c 100644 --- a/src/statistics/app/app_stats_types.h +++ b/src/statistics/app/app_stats_types.h @@ -17,7 +17,7 @@ #ifndef __CONTEXT_APP_STATS_TYPES_H__ #define __CONTEXT_APP_STATS_TYPES_H__ -#include +#include "../shared/common_types.h" #define APP_HISTORY_PRIV "apphistory.read" #define APP_SUBJ_RECENTLY_USED "stats/app/recently" diff --git a/src/statistics/app/db_handle.h b/src/statistics/app/db_handle.h index 8cb2659..f629f00 100644 --- a/src/statistics/app/db_handle.h +++ b/src/statistics/app/db_handle.h @@ -19,7 +19,7 @@ #include #include -#include +#include "../shared/db_handle_base.h" namespace ctx { class app_db_handle : public stats_db_handle_base { diff --git a/src/statistics/media/db_handle.cpp b/src/statistics/media/db_handle.cpp index 50d0dec..6515c9f 100644 --- a/src/statistics/media/db_handle.cpp +++ b/src/statistics/media/db_handle.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include "../shared/system_info.h" #include "media_stats_types.h" #include "db_handle.h" diff --git a/src/statistics/media/db_handle.h b/src/statistics/media/db_handle.h index a42c247..8fbe72a 100644 --- a/src/statistics/media/db_handle.h +++ b/src/statistics/media/db_handle.h @@ -19,7 +19,7 @@ #include #include -#include +#include "../shared/db_handle_base.h" namespace ctx { class media_db_handle : public stats_db_handle_base { diff --git a/src/statistics/media/media_content_monitor.cpp b/src/statistics/media/media_content_monitor.cpp index 4fbeed7..9c945d7 100644 --- a/src/statistics/media/media_content_monitor.cpp +++ b/src/statistics/media/media_content_monitor.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include "../shared/system_info.h" #include "media_stats_types.h" #include "db_handle.h" #include "media_content_monitor.h" diff --git a/src/statistics/media/media_stats_types.h b/src/statistics/media/media_stats_types.h index 79cfe3f..8d08170 100644 --- a/src/statistics/media/media_stats_types.h +++ b/src/statistics/media/media_stats_types.h @@ -17,7 +17,7 @@ #ifndef __CONTEXT_MEDIA_STATS_TYPES_H__ #define __CONTEXT_MEDIA_STATS_TYPES_H__ -#include +#include "../shared/common_types.h" #define MEDIA_HISTORY_PRIV "mediahistory.read" #define MEDIA_SUBJ_PEAK_TIME_FOR_MUSIC "stats/music/peak_time" diff --git a/src/statistics/social/db_handle.h b/src/statistics/social/db_handle.h index 8254f41..a8eecb1 100644 --- a/src/statistics/social/db_handle.h +++ b/src/statistics/social/db_handle.h @@ -19,7 +19,7 @@ #include #include -#include +#include "../shared/db_handle_base.h" namespace ctx { class social_db_handle : public stats_db_handle_base { diff --git a/src/statistics/social/social_stats_types.h b/src/statistics/social/social_stats_types.h index b627c67..ae52986 100644 --- a/src/statistics/social/social_stats_types.h +++ b/src/statistics/social/social_stats_types.h @@ -17,7 +17,7 @@ #ifndef __CONTEXT_SOCIAL_STATS_TYPES_H__ #define __CONTEXT_SOCIAL_STATS_TYPES_H__ -#include +#include "../shared/common_types.h" #define SOCIAL_HISTORY_PRIV "callhistory.read" #define SOCIAL_SUBJ_FREQ_ADDRESS "stats/contact/often" -- 2.7.4 From 815838de3a66b3cda1ae4c7ea67ea9c5d745a9fe Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Thu, 18 Feb 2016 21:14:47 +0900 Subject: [PATCH 04/16] Replace namespace ctx::shared with class ctx::SharedVars Change-Id: I2ec7511ddaa05eea4ff0a885a8a069d6701f2c7e Signed-off-by: Mu-Woong Lee --- src/device/system/wifi.cpp | 6 +++--- src/statistics/shared/system_info.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/device/system/wifi.cpp b/src/device/system/wifi.cpp index fde2d8c..3680768 100644 --- a/src/device/system/wifi.cpp +++ b/src/device/system/wifi.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include "system_types.h" #include "wifi.h" @@ -122,7 +122,7 @@ bool ctx::device_status_wifi::get_bssid() if (bssid.empty()) _W("Failed to get BSSID"); - ctx::shared::wifi_bssid = bssid; + SharedVars().set(ctx::SharedVars::WIFI_BSSID, bssid); _D("BSSID: %s", bssid.c_str()); return !bssid.empty(); @@ -131,7 +131,7 @@ bool ctx::device_status_wifi::get_bssid() void ctx::device_status_wifi::clear_bssid() { bssid.clear(); - ctx::shared::wifi_bssid.clear(); + SharedVars().clear(ctx::SharedVars::WIFI_BSSID); _D("No WiFi connection"); } diff --git a/src/statistics/shared/system_info.cpp b/src/statistics/shared/system_info.cpp index 548e328..3437d69 100644 --- a/src/statistics/shared/system_info.cpp +++ b/src/statistics/shared/system_info.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include "system_info.h" #define CONNECTED 1 @@ -75,6 +75,6 @@ bool ctx::system_info::get_wifi_bssid(std::string& bssid) return !bssid.empty(); #endif - bssid = ctx::shared::wifi_bssid; + bssid = ctx::SharedVars().get(ctx::SharedVars::WIFI_BSSID); return true; } -- 2.7.4 From f81c0b06ce5734f80edb6e02ec6a0ac0a195a426 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Fri, 19 Feb 2016 16:37:27 +0900 Subject: [PATCH 05/16] cmake: switch the dependencies variable to list, from space separated string Change-Id: Ic503d5f361902314af83c23e8edb939d343cb23c Signed-off-by: Mu-Woong Lee --- CMakeLists.txt | 8 ++++++-- src/CMakeLists.txt | 7 +------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5e59aa..ff1cbd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ INCLUDE_DIRECTORIES( ADD_DEFINITIONS(-O2 -Wall -fPIC -fvisibility=hidden -Wl,--as-needed) # Base Dependency -SET(dependencies "libcontext-shared libcontext-server") +SET(dependencies libcontext-shared libcontext-server) # Profiles IF("${PROFILE}" STREQUAL "mobile") @@ -46,6 +46,10 @@ SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER}) SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER}) # Package Config +FOREACH(item IN LISTS dependencies) + SET(deps_str "${deps_str} ${item}") +ENDFOREACH(item) + SET(VERSION ${FULLVER}) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(PC_NAME ${PROJECT_NAME}) @@ -54,7 +58,7 @@ SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/context-serv SET(PC_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") SET(PC_CFLAGS "-I\${includedir}/context-service") SET(PC_LDFLAGS "-l${target}") -SET(PC_REQUIRED "${dependencies}") +SET(PC_REQUIRED "${deps_str}") CONFIGURE_FILE( ${PROJECT_NAME}.pc.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9d45a9a..ed647fd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,12 +18,7 @@ add_provider(custom) LIST(REMOVE_DUPLICATES deps_collected) -FOREACH(item IN LISTS deps_collected) - SET(deps_filtered "${deps_filtered} ${item}") -ENDFOREACH(item) - -STRING(STRIP "${deps_filtered}" deps_filtered) SET(sources ${sources} ${srcs_collected} PARENT_SCOPE) -SET(dependencies "${dependencies} ${deps_filtered}" PARENT_SCOPE) +SET(dependencies ${dependencies} ${deps_collected} PARENT_SCOPE) SET(compile_defs ${compile_defs} ${cdef_collected} PARENT_SCOPE) -- 2.7.4 From 70475fafce975d5520fe5f7de9a90b995129d774 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 23 Feb 2016 14:01:16 +0900 Subject: [PATCH 06/16] device: update cmake script to support common profile Change-Id: I35044ae9039f0bf2e08808aa239b59a195875c11 Signed-off-by: Mu-Woong Lee --- src/device/CMakeLists.txt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt index d7e66ef..22f35bc 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) +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,18 +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) - SET(prvd_srcs ${prvd_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/social/call.cpp) - SET(prvd_srcs ${prvd_srcs} ${CMAKE_CURRENT_SOURCE_DIR}/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) - SET(prvd_srcs - ${prvd_srcs} - ${CMAKE_CURRENT_SOURCE_DIR}/system/headphone.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/system/wifi.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/system/alarm.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/system/time.cpp - ) + FILE(GLOB prvd_srcs ${prvd_srcs} system/headphone.cpp system/wifi.cpp) ENDIF("${PROFILE}" STREQUAL "tv") -- 2.7.4 From 89fec8b7e1d19aae2525c09d673080b94a251395 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Tue, 23 Feb 2016 16:41:24 +0900 Subject: [PATCH 07/16] Replace ctx::json with ctx:Json Change-Id: I71196345c2b860cca85701bd8d949f2a43b73e2d Signed-off-by: Mu-Woong Lee --- include/custom_context_provider.h | 4 +-- src/custom/custom_base.cpp | 16 ++++----- src/custom/custom_base.h | 20 ++++++------ src/custom/custom_context_provider.cpp | 38 +++++++++++----------- src/device/activity/activity_base.cpp | 2 +- src/device/provider_base.cpp | 8 ++--- src/device/provider_base.h | 10 +++--- src/device/social/call.cpp | 10 +++--- src/device/social/call.h | 2 +- src/device/social/email.cpp | 4 +-- src/device/social/message.cpp | 4 +-- src/device/system/alarm.cpp | 34 +++++++++---------- src/device/system/alarm.h | 20 ++++++------ src/device/system/battery.cpp | 4 +-- src/device/system/headphone.cpp | 6 ++-- src/device/system/headphone.h | 2 +- src/device/system/psmode.cpp | 4 +-- src/device/system/runtime-info/charger.cpp | 4 +-- src/device/system/runtime-info/gps.cpp | 4 +-- src/device/system/runtime-info/usb.cpp | 4 +-- src/device/system/time.cpp | 2 +- src/device/system/wifi.cpp | 6 ++-- src/device/system/wifi.h | 2 +- src/place/geofence/myplace_handle.cpp | 6 ++-- src/place/geofence/place_geofence.cpp | 14 ++++---- src/place/geofence/place_geofence.h | 12 +++---- src/place/recognition/place_recognition.cpp | 10 +++--- src/place/recognition/place_recognition.h | 8 ++--- .../recognition/user_places/location_logger.cpp | 4 +-- .../recognition/user_places/places_detector.cpp | 22 ++++++------- .../recognition/user_places/places_detector.h | 14 ++++---- src/place/recognition/user_places/user_places.cpp | 8 ++--- src/place/recognition/user_places/user_places.h | 4 +-- .../recognition/user_places/visit_detector.cpp | 8 ++--- src/place/recognition/user_places/visit_detector.h | 6 ++-- src/statistics/app/active_window_monitor.cpp | 4 +-- src/statistics/app/app_stats_provider.cpp | 10 +++--- src/statistics/app/app_stats_provider.h | 8 ++--- src/statistics/app/db_handle.cpp | 22 ++++++------- src/statistics/app/db_handle.h | 20 ++++++------ src/statistics/app/db_init.cpp | 6 ++-- src/statistics/app/db_init.h | 2 +- src/statistics/app/install_monitor.cpp | 4 +-- src/statistics/app/install_monitor.h | 2 +- src/statistics/media/db_handle.cpp | 16 ++++----- src/statistics/media/db_handle.h | 14 ++++---- src/statistics/media/media_content_monitor.cpp | 4 +-- src/statistics/media/media_content_monitor.h | 2 +- src/statistics/media/media_stats_provider.cpp | 8 ++--- src/statistics/media/media_stats_provider.h | 8 ++--- src/statistics/shared/db_handle_base.cpp | 24 +++++++------- src/statistics/shared/db_handle_base.h | 18 +++++----- src/statistics/social/db_handle.cpp | 14 ++++---- src/statistics/social/db_handle.h | 12 +++---- src/statistics/social/log_aggregator.cpp | 6 ++-- src/statistics/social/log_aggregator.h | 2 +- src/statistics/social/social_stats_provider.cpp | 10 +++--- src/statistics/social/social_stats_provider.h | 8 ++--- 58 files changed, 275 insertions(+), 275 deletions(-) diff --git a/include/custom_context_provider.h b/include/custom_context_provider.h index 10e4275..17c8cc4 100644 --- a/include/custom_context_provider.h +++ b/include/custom_context_provider.h @@ -21,9 +21,9 @@ 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 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 publish_data(std::string subject, ctx::Json fact); context_provider_iface* create(void* data); void destroy(void* data); diff --git a/src/custom/custom_base.cpp b/src/custom/custom_base.cpp index 59cbec9..c5ac58d 100644 --- a/src/custom/custom_base.cpp +++ b/src/custom/custom_base.cpp @@ -17,7 +17,7 @@ #include #include "custom_base.h" -ctx::custom_base::custom_base(std::string subject, std::string name, ctx::json tmpl, std::string owner) : +ctx::custom_base::custom_base(std::string subject, std::string name, ctx::Json tmpl, std::string owner) : _subject(subject), _name(name), _tmpl(tmpl), @@ -45,30 +45,30 @@ void ctx::custom_base::unsubmit_trigger_item() context_manager::unregister_trigger_item(_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 *request_result) { return ERR_NONE; } -int ctx::custom_base::unsubscribe(const char *subject, ctx::json option) +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 *request_result) { - ctx::json data = latest.str(); + ctx::Json data = latest.str(); ctx::context_manager::reply_to_read(_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 *request_result) { return ERR_NONE; } -void ctx::custom_base::handle_update(ctx::json data) +void ctx::custom_base::handle_update(ctx::Json data) { // Store latest state latest = data.str(); @@ -85,7 +85,7 @@ std::string ctx::custom_base::get_owner() return _owner; } -ctx::json ctx::custom_base::get_template() +ctx::Json ctx::custom_base::get_template() { return _tmpl; } diff --git a/src/custom/custom_base.h b/src/custom/custom_base.h index e2e8bce..0278e0f 100644 --- a/src/custom/custom_base.h +++ b/src/custom/custom_base.h @@ -17,7 +17,7 @@ #ifndef _CUSTOM_BASE_H_ #define _CUSTOM_BASE_H_ -#include +#include #include #include @@ -25,30 +25,30 @@ namespace ctx { class custom_base : public context_provider_iface { public: - custom_base(std::string subject, std::string name, ctx::json tmpl, std::string owner); + 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 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 subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + int unsubscribe(const char *subject, ctx::Json option); + int read(const char *subject, ctx::Json option, ctx::Json *request_result); + int write(const char *subject, ctx::Json data, ctx::Json *request_result); static bool is_supported(); void submit_trigger_item(); void unsubmit_trigger_item(); - void handle_update(ctx::json data); + void handle_update(ctx::Json data); const char* get_subject(); std::string get_owner(); - ctx::json get_template(); + ctx::Json get_template(); private: std::string _subject; std::string _name; - ctx::json _tmpl; + ctx::Json _tmpl; std::string _owner; - ctx::json latest; + ctx::Json latest; }; } diff --git a/src/custom/custom_context_provider.cpp b/src/custom/custom_context_provider.cpp index dd79fd5..29c9100 100644 --- a/src/custom/custom_context_provider.cpp +++ b/src/custom/custom_context_provider.cpp @@ -25,9 +25,9 @@ std::map custom_map; -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 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) { @@ -66,7 +66,7 @@ EXTAPI bool ctx::init_custom_context_provider() + "(subject TEXT DEFAULT '' NOT NULL PRIMARY KEY, name TEXT DEFAULT '' NOT NULL, operation INTEGER DEFAULT 3 NOT NULL, " + "attributes TEXT DEFAULT '' NOT NULL, owner TEXT DEFAULT '' NOT NULL)"; - std::vector record; + std::vector record; bool ret = db_manager::execute_sync(q.c_str(), &record); IF_FAIL_RETURN_TAG(ret, false, _E, "Create template table failed"); @@ -77,9 +77,9 @@ EXTAPI bool ctx::init_custom_context_provider() 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 vec_end = record.end(); + for (std::vector::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) { + ctx::Json elem = *vec_pos; std::string subject; std::string name; std::string attributes; @@ -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::add_item(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::add_item(std::string subject, std::string name, ctx::Json tmpl, const char* owner, bool is_init) { std::map::iterator it; it = custom_map.find(subject); @@ -122,7 +122,7 @@ EXTAPI int ctx::custom_context_provider::add_item(std::string subject, std::stri if (!is_init) { std::string q = "INSERT OR IGNORE INTO context_trigger_custom_template (subject, name, attributes, owner) VALUES ('" + subject + "', '" + name + "', '" + tmpl.str() + "', '" + owner + "'); "; - std::vector record; + std::vector record; bool ret = db_manager::execute_sync(q.c_str(), &record); IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to query custom templates"); } @@ -140,14 +140,14 @@ EXTAPI int ctx::custom_context_provider::remove_item(std::string subject) // Remove item from custom template db std::string q = "DELETE FROM context_trigger_custom_template WHERE subject = '" + subject + "'"; - std::vector record; + std::vector record; bool ret = db_manager::execute_sync(q.c_str(), &record); IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to query custom templates"); return ERR_NONE; } -EXTAPI int ctx::custom_context_provider::publish_data(std::string subject, ctx::json fact) +EXTAPI int ctx::custom_context_provider::publish_data(std::string subject, ctx::Json fact) { std::map::iterator it; it = custom_map.find(subject); @@ -160,14 +160,14 @@ EXTAPI int ctx::custom_context_provider::publish_data(std::string subject, ctx:: return ERR_NONE; } -bool is_valid_fact(std::string subject, ctx::json& fact) +bool is_valid_fact(std::string subject, ctx::Json& fact) { - ctx::json tmpl = custom_map[subject]->get_template(); + ctx::Json tmpl = custom_map[subject]->get_template(); IF_FAIL_RETURN_TAG(tmpl != EMPTY_JSON_OBJECT, false, _E, "Failed to get template"); bool ret; std::list keys; - fact.get_keys(&keys); + fact.getKeys(&keys); for (std::list::iterator it = keys.begin(); it != keys.end(); it++) { std::string key = *it; @@ -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 check_value_int(ctx::Json& tmpl, std::string key, int value) { int min, max; @@ -212,15 +212,15 @@ 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 check_value_string(ctx::Json& tmpl, std::string key, std::string value) { // case1: any value is accepted - if (tmpl.array_get_size(key.c_str(), "values") <= 0) + if (tmpl.getSize(key.c_str(), "values") <= 0) return true; // case2: check acceptable value std::string t_val; - for (int i = 0; tmpl.get_array_elem(key.c_str(), "values", i, &t_val); i++) { + for (int i = 0; tmpl.getAt(key.c_str(), "values", i, &t_val); i++) { if (t_val == value) return true; } diff --git a/src/device/activity/activity_base.cpp b/src/device/activity/activity_base.cpp index 1b834fd..e0a9027 100644 --- a/src/device/activity/activity_base.cpp +++ b/src/device/activity/activity_base.cpp @@ -44,7 +44,7 @@ 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; + ctx::Json data_read; data_read.set(NULL, USER_ACT_EVENT, USER_ACT_DETECTED); activity_accuracy_e accuracy = ACTIVITY_ACCURACY_LOW; diff --git a/src/device/provider_base.cpp b/src/device/provider_base.cpp index acc61cd..fefe212 100644 --- a/src/device/provider_base.cpp +++ b/src/device/provider_base.cpp @@ -22,7 +22,7 @@ ctx::device_provider_base::device_provider_base() { } -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 *request_result) { IF_FAIL_RETURN(!being_subscribed, ERR_NONE); @@ -36,7 +36,7 @@ int ctx::device_provider_base::subscribe(const char *subject, ctx::json option, return ret; } -int ctx::device_provider_base::unsubscribe(const char *subject, ctx::json option) +int ctx::device_provider_base::unsubscribe(const char *subject, ctx::Json option) { int ret = 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 *request_result) { 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 *request_result) { int ret = write(); diff --git a/src/device/provider_base.h b/src/device/provider_base.h index c05f4c7..39983b1 100644 --- a/src/device/provider_base.h +++ b/src/device/provider_base.h @@ -18,7 +18,7 @@ #define __CONTEXT_DEVICE_PROVIDER_BASE_H__ #include -#include +#include #include #define CREATE_INSTANCE(prvd) \ @@ -66,10 +66,10 @@ namespace ctx { class device_provider_base : public context_provider_iface { public: - int subscribe(const char *subject, ctx::json option, ctx::json *request_result); - int unsubscribe(const char *subject, ctx::json option); - int read(const char *subject, ctx::json option, ctx::json *request_result); - int write(const char *subject, ctx::json data, ctx::json *request_result); + int subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + int unsubscribe(const char *subject, ctx::Json option); + int read(const char *subject, ctx::Json option, ctx::Json *request_result); + int write(const char *subject, ctx::Json data, ctx::Json *request_result); protected: bool being_subscribed; diff --git a/src/device/social/call.cpp b/src/device/social/call.cpp index 52e6aa3..745442c 100644 --- a/src/device/social/call.cpp +++ b/src/device/social/call.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include #include "social_types.h" #include "call.h" @@ -38,7 +38,7 @@ 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() { @@ -76,7 +76,7 @@ void ctx::social_status_call::call_event_cb(telephony_h handle, telephony_noti_e void ctx::social_status_call::handle_call_event(telephony_h handle, telephony_noti_e noti_id, void* id) { - json data; + Json data; unsigned int count; telephony_call_h *call_list; @@ -311,7 +311,7 @@ int ctx::social_status_call::unsubscribe() return ERR_NONE; } -bool ctx::social_status_call::read_current_status(telephony_h& handle, ctx::json& data) +bool ctx::social_status_call::read_current_status(telephony_h& handle, ctx::Json& data) { unsigned int count = 0; telephony_call_h *call_list = NULL; @@ -362,7 +362,7 @@ int ctx::social_status_call::read() } bool ret = true; - json data; + Json data; data.set(NULL, SOCIAL_ST_STATE, SOCIAL_ST_IDLE); for (unsigned int i = 0; i < handle_list.count; i++) { diff --git a/src/device/social/call.h b/src/device/social/call.h index a67eaa1..cdd906c 100644 --- a/src/device/social/call.h +++ b/src/device/social/call.h @@ -43,7 +43,7 @@ namespace ctx { void release_telephony(); bool set_callback(); void unset_callback(); - bool read_current_status(telephony_h& handle, ctx::json& data); + 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); diff --git a/src/device/social/email.cpp b/src/device/social/email.cpp index 90a4efb..831a963 100644 --- a/src/device/social/email.cpp +++ b/src/device/social/email.cpp @@ -60,13 +60,13 @@ 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; + 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); } 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; + 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); } diff --git a/src/device/social/message.cpp b/src/device/social/message.cpp index 5d091fb..4d46fe9 100644 --- a/src/device/social/message.cpp +++ b/src/device/social/message.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include "social_types.h" #include "message.h" @@ -59,7 +59,7 @@ void ctx::social_status_message::handle_state_change(msg_struct_t msg) int err; int type; char address[MAX_ADDR_SIZE]; - ctx::json data; + ctx::Json data; err = msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &type); IF_FAIL_VOID_TAG(err == MSG_SUCCESS, _W, "Getting message type failed"); diff --git a/src/device/system/alarm.cpp b/src/device/system/alarm.cpp index 0b75fb5..bd800ee 100644 --- a/src/device/system/alarm.cpp +++ b/src/device/system/alarm.cpp @@ -51,42 +51,42 @@ 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 *request_result) { int ret = subscribe(option); destroy_if_unused(); return ret; } -int ctx::device_status_alarm::unsubscribe(const char *subject, ctx::json option) +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 *request_result) +int ctx::device_status_alarm::read(const char *subject, ctx::Json option, ctx::Json *request_result) { 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 *request_result) { destroy_if_unused(); return ERR_NOT_SUPPORTED; } -int ctx::device_status_alarm::subscribe(ctx::json option) +int ctx::device_status_alarm::subscribe(ctx::Json option) { int dow = get_arranged_day_of_week(option); int time; - for (int i = 0; option.get_array_elem(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) { + 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); + ctx::Json* elem = new(std::nothrow) ctx::Json(option); if (elem) { option_set.insert(elem); } else { @@ -98,12 +98,12 @@ int ctx::device_status_alarm::subscribe(ctx::json option) return ERR_NONE; } -int ctx::device_status_alarm::unsubscribe(ctx::json option) +int ctx::device_status_alarm::unsubscribe(ctx::Json option) { int dow = get_arranged_day_of_week(option); int time; - for (int i = 0; option.get_array_elem(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) { + for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &time); i++) { remove(time, dow); } @@ -116,12 +116,12 @@ int ctx::device_status_alarm::unsubscribe(ctx::json option) return ERR_NONE; } -int ctx::device_status_alarm::get_arranged_day_of_week(ctx::json& option) +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.get_array_elem(NULL, DEVICE_ST_DAY_OF_WEEK, i, &tmp_d); i++) { + 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); } _D("Requested day of week (%#x)", dow); @@ -252,25 +252,25 @@ 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 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); data_read.set(NULL, DEVICE_ST_TIME_OF_DAY, result_time); data_read.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); + ctx::Json option = (**it); if (is_matched(option, result_time, result_day)) { context_manager::publish(DEVICE_ST_SUBJ_ALARM, option, ERR_NONE, data_read); } } } -bool ctx::device_status_alarm::is_matched(ctx::json& option, int time, std::string day) +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.get_array_elem(NULL, DEVICE_ST_TIME_OF_DAY, i, &opt_time); i++){ + for (int i = 0; option.getAt(NULL, DEVICE_ST_TIME_OF_DAY, i, &opt_time); i++){ if (time == opt_time) { ret = true; break; @@ -279,7 +279,7 @@ bool ctx::device_status_alarm::is_matched(ctx::json& option, int time, std::stri IF_FAIL_RETURN(ret, false); std::string opt_day; - for (int i = 0; option.get_array_elem(NULL, DEVICE_ST_DAY_OF_WEEK, i, &opt_day); i++){ + for (int i = 0; option.getAt(NULL, DEVICE_ST_DAY_OF_WEEK, i, &opt_day); i++){ if (day == opt_day) { return true; } @@ -288,7 +288,7 @@ bool ctx::device_status_alarm::is_matched(ctx::json& option, int time, std::stri return false; } -ctx::device_status_alarm::option_t::iterator ctx::device_status_alarm::find_option(ctx::json& option) +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)) diff --git a/src/device/system/alarm.h b/src/device/system/alarm.h index 7596f74..8f51836 100644 --- a/src/device/system/alarm.h +++ b/src/device/system/alarm.h @@ -30,13 +30,13 @@ namespace ctx { GENERATE_PROVIDER_COMMON_DECL(device_status_alarm); public: - int subscribe(const char *subject, ctx::json option, ctx::json *request_result); - int unsubscribe(const char *subject, ctx::json option); - int read(const char *subject, ctx::json option, ctx::json *request_result); - int write(const char *subject, ctx::json data, ctx::json *request_result); + int subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + int unsubscribe(const char *subject, ctx::Json option); + int read(const char *subject, ctx::Json option, ctx::Json *request_result); + int write(const char *subject, ctx::Json data, ctx::Json *request_result); - int subscribe(ctx::json option); - int unsubscribe(ctx::json option); + int subscribe(ctx::Json option); + int unsubscribe(ctx::Json option); static bool is_supported(); static void submit_trigger_item(); @@ -45,7 +45,7 @@ namespace ctx { ~device_status_alarm(); void handle_update(); static void update_cb(void* user_data); - int get_arranged_day_of_week(ctx::json& option); + int get_arranged_day_of_week(ctx::Json& option); struct ref_count_array_s { int count[7]; /* reference counts for days of week*/ @@ -60,7 +60,7 @@ namespace ctx { typedef std::map ref_count_map_t; typedef std::map timer_state_map_t; - typedef std::set option_t; + typedef std::set option_t; ref_count_map_t ref_count_map; timer_state_map_t timer_state_map; @@ -76,8 +76,8 @@ namespace ctx { void on_timer_expired(int hour, int min, int day_of_week); bool on_timer_expired(int timer_id, void *user_data); - bool is_matched(ctx::json& option, int time, std::string day); - option_t::iterator find_option(ctx::json& option); + bool is_matched(ctx::Json& option, int time, std::string day); + option_t::iterator find_option(ctx::Json& option); void destroy_if_unused(); diff --git a/src/device/system/battery.cpp b/src/device/system/battery.cpp index 0060955..5be24b6 100644 --- a/src/device/system/battery.cpp +++ b/src/device/system/battery.cpp @@ -58,7 +58,7 @@ 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; + ctx::Json data_read; data_read.set(NULL, DEVICE_ST_LEVEL, level_string); bool charging_state = false; @@ -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 data_read; int ret = device_battery_get_level_status(&level); IF_FAIL_RETURN(ret == DEVICE_ERROR_NONE, ERR_OPERATION_FAILED); diff --git a/src/device/system/headphone.cpp b/src/device/system/headphone.cpp index 2160cdc..ac3d5db 100644 --- a/src/device/system/headphone.cpp +++ b/src/device/system/headphone.cpp @@ -79,7 +79,7 @@ int ctx::device_status_headphone::read() if (!being_subscribed) connected = get_current_status(); - json data; + Json data; generate_data_packet(data); ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data); @@ -140,7 +140,7 @@ bool ctx::device_status_headphone::get_current_status() return ((audio_jack_state != RUNTIME_INFO_AUDIO_JACK_STATUS_UNCONNECTED) || bt_audio_state); } -void ctx::device_status_headphone::generate_data_packet(ctx::json &data) +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); @@ -165,7 +165,7 @@ bool ctx::device_status_headphone::handle_event() IF_FAIL_RETURN(prev_state != connected, false); - ctx::json data; + ctx::Json data; generate_data_packet(data); ctx::context_manager::publish(DEVICE_ST_SUBJ_HEADPHONE, NULL, ERR_NONE, data); return true; diff --git a/src/device/system/headphone.h b/src/device/system/headphone.h index 16c2f1e..f451d52 100644 --- a/src/device/system/headphone.h +++ b/src/device/system/headphone.h @@ -51,7 +51,7 @@ namespace ctx { void unset_bt_audio_callback(); void set_bt_audio_state(bool state); - void generate_data_packet(json &data); + void generate_data_packet(Json &data); bool handle_event(); void handle_audio_jack_event(); diff --git a/src/device/system/psmode.cpp b/src/device/system/psmode.cpp index 90980d0..dcfc359 100644 --- a/src/device/system/psmode.cpp +++ b/src/device/system/psmode.cpp @@ -48,7 +48,7 @@ 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 data_read; status = vconf_keynode_get_int(node); IF_FAIL_VOID_TAG(status >= 0, _E, "Getting state failed"); @@ -78,7 +78,7 @@ 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; + ctx::Json data_read; data_read.set(NULL, DEVICE_ST_IS_ENABLED, mode == 0 ? DEVICE_ST_FALSE : DEVICE_ST_TRUE); ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_PSMODE, NULL, ERR_NONE, data_read); diff --git a/src/device/system/runtime-info/charger.cpp b/src/device/system/runtime-info/charger.cpp index 821a9b5..ae16d8c 100644 --- a/src/device/system/runtime-info/charger.cpp +++ b/src/device/system/runtime-info/charger.cpp @@ -47,7 +47,7 @@ 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; + ctx::Json data_read; data_read.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); @@ -56,7 +56,7 @@ void ctx::device_status_charger::handle_update() int ctx::device_status_charger::read() { bool charger_status = false; - ctx::json data_read; + ctx::Json data_read; 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"); diff --git a/src/device/system/runtime-info/gps.cpp b/src/device/system/runtime-info/gps.cpp index 74ebb3c..80aa16c 100644 --- a/src/device/system/runtime-info/gps.cpp +++ b/src/device/system/runtime-info/gps.cpp @@ -67,7 +67,7 @@ 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 data_read; const char* state_str = get_state_string(gps_status); IF_FAIL_VOID(state_str); @@ -80,7 +80,7 @@ void ctx::device_status_gps::handle_update() int ctx::device_status_gps::read() { int gps_status; - ctx::json data_read; + ctx::Json data_read; 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"); diff --git a/src/device/system/runtime-info/usb.cpp b/src/device/system/runtime-info/usb.cpp index 77d19ad..0ab4d0d 100644 --- a/src/device/system/runtime-info/usb.cpp +++ b/src/device/system/runtime-info/usb.cpp @@ -47,7 +47,7 @@ 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; + ctx::Json data_read; data_read.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); @@ -56,7 +56,7 @@ void ctx::device_status_usb::handle_update() int ctx::device_status_usb::read() { bool status = false; - ctx::json data_read; + ctx::Json data_read; 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"); diff --git a/src/device/system/time.cpp b/src/device/system/time.cpp index c4166a9..65ba55a 100644 --- a/src/device/system/time.cpp +++ b/src/device/system/time.cpp @@ -68,7 +68,7 @@ int ctx::device_status_time::read() 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); - ctx::json data_read; + 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); diff --git a/src/device/system/wifi.cpp b/src/device/system/wifi.cpp index 3680768..a40c179 100644 --- a/src/device/system/wifi.cpp +++ b/src/device/system/wifi.cpp @@ -135,7 +135,7 @@ void ctx::device_status_wifi::clear_bssid() _D("No WiFi connection"); } -bool ctx::device_status_wifi::get_response_packet(ctx::json &data) +bool ctx::device_status_wifi::get_response_packet(ctx::Json &data) { switch (last_state) { case _DISABLED: @@ -162,7 +162,7 @@ int ctx::device_status_wifi::read() { IF_FAIL_RETURN(get_current_state(), ERR_OPERATION_FAILED); - ctx::json data_read; + ctx::Json data_read; if (get_response_packet(data_read)) { ctx::context_manager::reply_to_read(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, data_read); @@ -246,7 +246,7 @@ void ctx::device_status_wifi::aggregate_updated_data() clear_bssid(); } - ctx::json data; + ctx::Json data; if (being_subscribed && get_response_packet(data)) context_manager::publish(DEVICE_ST_SUBJ_WIFI, NULL, ERR_NONE, data); } diff --git a/src/device/system/wifi.h b/src/device/system/wifi.h index 6dc505d..6bd81c1 100644 --- a/src/device/system/wifi.h +++ b/src/device/system/wifi.h @@ -54,7 +54,7 @@ namespace ctx { bool get_current_state(); bool get_bssid(); void clear_bssid(); - bool get_response_packet(json &data); + bool get_response_packet(Json &data); void aggregate_updated_data(); bool start_monitor(); void stop_monitor(); diff --git a/src/place/geofence/myplace_handle.cpp b/src/place/geofence/myplace_handle.cpp index cb830ff..8ea7684 100644 --- a/src/place/geofence/myplace_handle.cpp +++ b/src/place/geofence/myplace_handle.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include #include "place_geofence_types.h" #include "myplace_handle.h" @@ -180,10 +180,10 @@ void ctx::myplace_handle::emit_state_change() prev_state = current_state; - json option; + Json option; option.set(NULL, PLACE_STATUS_DATA_MYPLACE_ID, _place_id); - json data; + 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)); diff --git a/src/place/geofence/place_geofence.cpp b/src/place/geofence/place_geofence.cpp index 53fb40b..c1525a1 100644 --- a/src/place/geofence/place_geofence.cpp +++ b/src/place/geofence/place_geofence.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include "place_geofence.h" @@ -79,33 +79,33 @@ 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 *request_result) { int ret = __subscribe(option); __destroy_if_unused(); return ret; } -int ctx::place_geofence_provider::unsubscribe(const char *subject, ctx::json option) +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 *request_result) +int ctx::place_geofence_provider::read(const char *subject, ctx::Json option, ctx::Json *request_result) { __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 *request_result) { __destroy_if_unused(); return ERR_NOT_SUPPORTED; } -int ctx::place_geofence_provider::__subscribe(ctx::json option) +int ctx::place_geofence_provider::__subscribe(ctx::Json option) { int pid = -1; option.get(NULL, PLACE_STATUS_OPT_MYPLACE_ID, &pid); @@ -132,7 +132,7 @@ int ctx::place_geofence_provider::__subscribe(ctx::json option) return ERR_NONE; } -int ctx::place_geofence_provider::__unsubscribe(ctx::json option) +int ctx::place_geofence_provider::__unsubscribe(ctx::Json option) { int pid = -1; option.get(NULL, PLACE_STATUS_OPT_MYPLACE_ID, &pid); diff --git a/src/place/geofence/place_geofence.h b/src/place/geofence/place_geofence.h index 9fb8ae8..05de007 100644 --- a/src/place/geofence/place_geofence.h +++ b/src/place/geofence/place_geofence.h @@ -33,10 +33,10 @@ namespace ctx { static bool is_supported(); static void submit_trigger_item(); - int subscribe(const char *subject, ctx::json option, ctx::json *request_result); - int unsubscribe(const char *subject, ctx::json option); - int read(const char *subject, ctx::json option, ctx::json *request_result); - int write(const char *subject, ctx::json data, ctx::json *request_result); + int subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + int unsubscribe(const char *subject, ctx::Json option); + int read(const char *subject, ctx::Json option, ctx::Json *request_result); + int write(const char *subject, ctx::Json data, ctx::Json *request_result); private: static place_geofence_provider *__instance; @@ -45,8 +45,8 @@ namespace ctx { place_geofence_provider(); ~place_geofence_provider(); - int __subscribe(ctx::json option); - int __unsubscribe(ctx::json option); + int __subscribe(ctx::Json option); + int __unsubscribe(ctx::Json option); void __destroy_if_unused(); }; diff --git a/src/place/recognition/place_recognition.cpp b/src/place/recognition/place_recognition.cpp index 137d3b6..7fb092f 100644 --- a/src/place/recognition/place_recognition.cpp +++ b/src/place/recognition/place_recognition.cpp @@ -38,23 +38,23 @@ 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* request_result) { return ERR_NOT_SUPPORTED; } -int ctx::place_recognition_provider::unsubscribe(const char *subject, ctx::json option) +int ctx::place_recognition_provider::unsubscribe(const char *subject, ctx::Json option) { 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* request_result) { _I(BLUE("Read")); _J("Option", option); std::vector> places = engine.get_places(); - json data_read = engine.compose_json(places); + Json data_read = engine.compose_json(places); // The below function needs to be called once. // It does not need to be called within this read() function. @@ -66,7 +66,7 @@ int ctx::place_recognition_provider::read(const char *subject, ctx::json option, 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* request_result) { return ERR_NOT_SUPPORTED; } diff --git a/src/place/recognition/place_recognition.h b/src/place/recognition/place_recognition.h index 1f870af..8f25424 100644 --- a/src/place/recognition/place_recognition.h +++ b/src/place/recognition/place_recognition.h @@ -30,10 +30,10 @@ namespace ctx { static void destroy(void *data); static bool is_supported(); - int subscribe(const char *subject, ctx::json option, ctx::json *request_result); - int unsubscribe(const char *subject, ctx::json option); - int read(const char *subject, ctx::json option, ctx::json *request_result); - int write(const char *subject, ctx::json data, ctx::json *request_result); + int subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + int unsubscribe(const char *subject, ctx::Json option); + int read(const char *subject, ctx::Json option, ctx::Json *request_result); + int write(const char *subject, ctx::Json data, ctx::Json *request_result); private: static place_recognition_provider *__instance; diff --git a/src/place/recognition/user_places/location_logger.cpp b/src/place/recognition/user_places/location_logger.cpp index 4adc07c..eddf0dc 100644 --- a/src/place/recognition/user_places/location_logger.cpp +++ b/src/place/recognition/user_places/location_logger.cpp @@ -19,7 +19,7 @@ #include "../place_recognition_types.h" #include #include -#include +#include #include "user_places_params.h" #include "debug_utils.h" @@ -182,7 +182,7 @@ int ctx::LocationLogger::create_table() int ctx::LocationLogger::db_insert_log(location_event_s location_event) { - json data; + Json data; data.set(NULL, LOCATION_COLUMN_LATITUDE, location_event.coordinates.latitude, GEO_LOCATION_PRECISION); data.set(NULL, LOCATION_COLUMN_LONGITUDE, location_event.coordinates.longitude, GEO_LOCATION_PRECISION); data.set(NULL, LOCATION_COLUMN_ACCURACY, location_event.coordinates.accuracy, GEO_LOCATION_PRECISION); diff --git a/src/place/recognition/user_places/places_detector.cpp b/src/place/recognition/user_places/places_detector.cpp index 974fd7b..1530ef9 100644 --- a/src/place/recognition/user_places/places_detector.cpp +++ b/src/place/recognition/user_places/places_detector.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include "similar.h" #include "places_detector.h" #include "place_categer.h" @@ -77,7 +77,7 @@ bool ctx::PlacesDetector::on_timer_expired(int timer_id, void* user_data) return true; } -void ctx::PlacesDetector::on_query_result_received(unsigned int query_id, int error, std::vector& records) +void ctx::PlacesDetector::on_query_result_received(unsigned int query_id, int error, std::vector& records) { // TODO: // The below "state machine" approach was choosen because it is not possible to use synchronized database queries in the main thread. @@ -123,7 +123,7 @@ void ctx::PlacesDetector::db_get_places() _D("load places execute query result: %s", ret ? "SUCCESS" : "FAIL"); } -double ctx::PlacesDetector::double_value_from_json(json &row, const char* key) +double ctx::PlacesDetector::double_value_from_json(Json &row, const char* key) { double value; row.get(NULL, key, &value); @@ -131,7 +131,7 @@ double ctx::PlacesDetector::double_value_from_json(json &row, const char* key) return value; } -ctx::categs_t ctx::PlacesDetector::visit_categs_from_json(json &row) +ctx::categs_t ctx::PlacesDetector::visit_categs_from_json(Json &row) { categs_t categs; categs[PLACE_CATEG_ID_HOME] = double_value_from_json(row, VISIT_COLUMN_CATEG_HOME); @@ -140,7 +140,7 @@ ctx::categs_t ctx::PlacesDetector::visit_categs_from_json(json &row) return categs; } -ctx::visit_s ctx::PlacesDetector::visit_from_json(json &row) +ctx::visit_s ctx::PlacesDetector::visit_from_json(Json &row) { int start_time; int end_time; @@ -170,12 +170,12 @@ ctx::visit_s ctx::PlacesDetector::visit_from_json(json &row) return visit; } -ctx::visits_t ctx::PlacesDetector::visits_from_jsons(std::vector& records) +ctx::visits_t ctx::PlacesDetector::visits_from_jsons(std::vector& records) { visits_t visits; _D("db_result: number of all visits: %d", records.size()); - for (json &row : records) { + for (Json &row : records) { visit_s visit = visit_from_json(row); visits.push_back(visit); } @@ -183,7 +183,7 @@ ctx::visits_t ctx::PlacesDetector::visits_from_jsons(std::vector& records) return visits; } -std::shared_ptr ctx::PlacesDetector::place_from_json(json &row) +std::shared_ptr ctx::PlacesDetector::place_from_json(Json &row) { std::shared_ptr place = std::make_shared(); { // category @@ -211,12 +211,12 @@ std::shared_ptr ctx::PlacesDetector::place_from_json(json &row) return place; } -std::vector> ctx::PlacesDetector::places_from_jsons(std::vector& records) +std::vector> ctx::PlacesDetector::places_from_jsons(std::vector& records) { std::vector> places; _D("db_result: number of all places: %d", records.size()); - for (json &row : records) { + for (Json &row : records) { std::shared_ptr place = place_from_json(row); places.push_back(place); } @@ -432,7 +432,7 @@ void ctx::PlacesDetector::db_create_table() void ctx::PlacesDetector::db_insert_place(const Place &place) { - json data; + Json data; data.set(NULL, PLACE_COLUMN_CATEG_ID, place.categ_id); data.set(NULL, PLACE_COLUMN_CATEG_CONFIDENCE, place.categ_confidence); data.set(NULL, PLACE_COLUMN_NAME, place.name); diff --git a/src/place/recognition/user_places/places_detector.h b/src/place/recognition/user_places/places_detector.h index 72767c4..9adeb92 100644 --- a/src/place/recognition/user_places/places_detector.h +++ b/src/place/recognition/user_places/places_detector.h @@ -40,12 +40,12 @@ namespace ctx { private: bool test_mode; - double double_value_from_json(json &row, const char* key); - categs_t visit_categs_from_json(json &row); - visit_s visit_from_json(json &row); - visits_t visits_from_jsons(std::vector& records); - std::shared_ptr place_from_json(json &row); - std::vector> places_from_jsons(std::vector& records); + double double_value_from_json(Json &row, const char* key); + categs_t visit_categs_from_json(Json &row); + visit_s visit_from_json(Json &row); + visits_t visits_from_jsons(std::vector& records); + std::shared_ptr place_from_json(Json &row); + std::vector> places_from_jsons(std::vector& records); std::shared_ptr graph_from_visits(const std::vector &visits); void db_create_table(); void db_delete_places(); @@ -68,7 +68,7 @@ namespace ctx { bool on_timer_expired(int timer_id, void* user_data); 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); + 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/user_places.cpp b/src/place/recognition/user_places/user_places.cpp index 4747ed1..46c8d31 100644 --- a/src/place/recognition/user_places/user_places.cpp +++ b/src/place/recognition/user_places/user_places.cpp @@ -111,11 +111,11 @@ std::vector> ctx::UserPlaces::get_places() * ] * } */ -ctx::json ctx::UserPlaces::compose_json(std::vector> places) +ctx::Json ctx::UserPlaces::compose_json(std::vector> places) { - ctx::json data; + ctx::Json data; for (std::shared_ptr place : places) { - ctx::json place_j; + ctx::Json place_j; place_j.set(NULL, PLACE_CATEG_ID, place->categ_id); place_j.set(NULL, PLACE_CATEG_CONFIDENCE, place->categ_confidence); place_j.set(NULL, PLACE_NAME, place->name); @@ -125,7 +125,7 @@ ctx::json ctx::UserPlaces::compose_json(std::vector> plac } place_j.set(NULL, PLACE_WIFI_APS, place->wifi_aps); place_j.set(NULL, PLACE_CREATE_DATE, static_cast(place->create_date)); - data.array_append(NULL, DATA_READ, place_j); + data.append(NULL, DATA_READ, place_j); } return data; } diff --git a/src/place/recognition/user_places/user_places.h b/src/place/recognition/user_places/user_places.h index 2ad10ce..d2c66da 100644 --- a/src/place/recognition/user_places/user_places.h +++ b/src/place/recognition/user_places/user_places.h @@ -21,7 +21,7 @@ #include "places_detector.h" #include #include "user_places_types.h" -#include +#include namespace ctx { @@ -38,7 +38,7 @@ namespace ctx { void set_mode(place_recog_mode_e energy_mode); std::vector> get_places(); - static json compose_json(std::vector> places); + static Json compose_json(std::vector> places); }; /* class UserPlaces */ diff --git a/src/place/recognition/user_places/visit_detector.cpp b/src/place/recognition/user_places/visit_detector.cpp index 0123b93..ccd9cb7 100644 --- a/src/place/recognition/user_places/visit_detector.cpp +++ b/src/place/recognition/user_places/visit_detector.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include "../place_recognition_types.h" #include "visit_detector.h" #include "user_places_params.h" @@ -372,7 +372,7 @@ void ctx::VisitDetector::db_create_table() _D("db: visit Table Creation Result: %s", ret ? "SUCCESS" : "FAIL"); } -void ctx::VisitDetector::json_put_visit_categ(json &data, const char* key, const categs_t &categs, int categ_type) +void ctx::VisitDetector::json_put_visit_categ(Json &data, const char* key, const categs_t &categs, int categ_type) { auto categ_p = categs.find(categ_type); if (categ_p == categs.end()) { @@ -382,7 +382,7 @@ void ctx::VisitDetector::json_put_visit_categ(json &data, const char* key, const } } -void ctx::VisitDetector::json_put_visit_categs(json &data, const categs_t &categs) +void ctx::VisitDetector::json_put_visit_categs(Json &data, const categs_t &categs) { json_put_visit_categ(data, VISIT_COLUMN_CATEG_HOME, categs, PLACE_CATEG_ID_HOME); json_put_visit_categ(data, VISIT_COLUMN_CATEG_WORK, categs, PLACE_CATEG_ID_WORK); @@ -394,7 +394,7 @@ int ctx::VisitDetector::db_insert_visit(visit_s visit) std::stringstream macs_ss; macs_ss << *visit.mac_set; - json data; + Json data; data.set(NULL, VISIT_COLUMN_WIFI_APS, macs_ss.str().c_str()); data.set(NULL, VISIT_COLUMN_LOCATION_VALID, visit.location_valid); diff --git a/src/place/recognition/user_places/visit_detector.h b/src/place/recognition/user_places/visit_detector.h index ccde0b2..52d0b20 100644 --- a/src/place/recognition/user_places/visit_detector.h +++ b/src/place/recognition/user_places/visit_detector.h @@ -23,7 +23,7 @@ #include #include #include "user_places_types.h" -#include +#include #include "visit_listener_iface.h" #include "location_logger.h" #include "location_listener_iface.h" @@ -80,8 +80,8 @@ namespace ctx { bool protrudes_from(const mac_counts_t &mac_counts, const mac_set_t &mac_set); void db_create_table(); - void json_put_visit_categ(json &data, const char* key, const categs_t &categs, int categ_type); - void json_put_visit_categs(json &data, const categs_t &categs); + void json_put_visit_categ(Json &data, const char* key, const categs_t &categs, int categ_type); + void json_put_visit_categs(Json &data, const categs_t &categs); int db_insert_visit(visit_s visit); void set_period(place_recog_mode_e mode); diff --git a/src/statistics/app/active_window_monitor.cpp b/src/statistics/app/active_window_monitor.cpp index 701209b..f429a9c 100644 --- a/src/statistics/app/active_window_monitor.cpp +++ b/src/statistics/app/active_window_monitor.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include "../shared/system_info.h" #include "app_stats_types.h" @@ -85,7 +85,7 @@ void ctx::app_use_monitor::create_record(std::string app_id) int system_volume; int media_volume; std::string bssid; - json data; + Json data; data.set(NULL, STATS_APP_ID, app_id); if (ctx::system_info::get_audio_jack_state(&audiojack)) diff --git a/src/statistics/app/app_stats_provider.cpp b/src/statistics/app/app_stats_provider.cpp index 06aa468..cdb53f4 100644 --- a/src/statistics/app/app_stats_provider.cpp +++ b/src/statistics/app/app_stats_provider.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include #include "app_stats_provider.h" #include "db_handle.h" @@ -98,17 +98,17 @@ 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* request_result) { return ERR_NOT_SUPPORTED; } -int ctx::app_statistics_provider::unsubscribe(const char* subject, ctx::json option) +int ctx::app_statistics_provider::unsubscribe(const char* subject, ctx::Json option) { 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* request_result) { 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* request_result) { return ERR_NOT_SUPPORTED; } diff --git a/src/statistics/app/app_stats_provider.h b/src/statistics/app/app_stats_provider.h index f5804bd..7735fd2 100644 --- a/src/statistics/app/app_stats_provider.h +++ b/src/statistics/app/app_stats_provider.h @@ -29,10 +29,10 @@ namespace ctx { 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 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 subscribe(const char *subject, ctx::Json option, ctx::Json *request_result); + int unsubscribe(const char *subject, ctx::Json option); + int read(const char *subject, ctx::Json option, ctx::Json *request_result); + int write(const char *subject, ctx::Json data, ctx::Json *request_result); private: static app_statistics_provider *__instance; diff --git a/src/statistics/app/db_handle.cpp b/src/statistics/app/db_handle.cpp index 5491d24..d293ed4 100644 --- a/src/statistics/app/db_handle.cpp +++ b/src/statistics/app/db_handle.cpp @@ -29,7 +29,7 @@ ctx::app_db_handle::~app_db_handle() { } -int ctx::app_db_handle::read(const char* subject, ctx::json filter) +int ctx::app_db_handle::read(const char* subject, ctx::Json filter) { std::string query; @@ -61,7 +61,7 @@ int ctx::app_db_handle::read(const char* subject, ctx::json filter) return ERR_NONE; } -std::string ctx::app_db_handle::create_where_clause_with_device_status(ctx::json filter) +std::string ctx::app_db_handle::create_where_clause_with_device_status(ctx::Json filter) { std::stringstream where_clause; std::string bssid; @@ -78,19 +78,19 @@ std::string ctx::app_db_handle::create_where_clause_with_device_status(ctx::json return where_clause.str(); } -std::string ctx::app_db_handle::create_sql_peak_time(ctx::json filter) +std::string ctx::app_db_handle::create_sql_peak_time(ctx::Json filter) { return stats_db_handle_base::create_sql_peak_time(filter, APP_TABLE_USAGE_LOG, create_where_clause(filter)); } -std::string ctx::app_db_handle::create_sql_common_setting(ctx::json filter) +std::string ctx::app_db_handle::create_sql_common_setting(ctx::Json filter) { return stats_db_handle_base::create_sql_common_setting(filter, APP_TABLE_USAGE_LOG, create_where_clause(filter)); } -std::string ctx::app_db_handle::create_sql_frequency(ctx::json filter) +std::string ctx::app_db_handle::create_sql_frequency(ctx::Json filter) { - ctx::json filter_cleaned; + ctx::Json filter_cleaned; std::string week_str; std::string time_of_day; std::string app_id; @@ -134,7 +134,7 @@ std::string ctx::app_db_handle::create_sql_frequency(ctx::json filter) return query.str(); } -std::string ctx::app_db_handle::create_sql_recently_used(ctx::json filter) +std::string ctx::app_db_handle::create_sql_recently_used(ctx::Json filter) { std::stringstream query; int limit = DEFAULT_LIMIT; @@ -155,7 +155,7 @@ std::string ctx::app_db_handle::create_sql_recently_used(ctx::json filter) return query.str(); } -std::string ctx::app_db_handle::create_sql_frequently_used(ctx::json filter) +std::string ctx::app_db_handle::create_sql_frequently_used(ctx::Json filter) { std::stringstream query; int limit = DEFAULT_LIMIT; @@ -176,7 +176,7 @@ std::string ctx::app_db_handle::create_sql_frequently_used(ctx::json filter) return query.str(); } -std::string ctx::app_db_handle::create_sql_rarely_used(ctx::json filter) +std::string ctx::app_db_handle::create_sql_rarely_used(ctx::Json filter) { std::stringstream query; int limit = DEFAULT_LIMIT; @@ -199,11 +199,11 @@ std::string ctx::app_db_handle::create_sql_rarely_used(ctx::json filter) return query.str(); } -void ctx::app_db_handle::reply_trigger_item(int error, ctx::json &json_result) +void ctx::app_db_handle::reply_trigger_item(int error, ctx::Json &json_result) { IF_FAIL_VOID_TAG(STR_EQ(req_subject.c_str(), APP_SUBJ_FREQUENCY), _E, "Invalid subject"); - ctx::json results; + ctx::Json results; std::string val_str; int val; diff --git a/src/statistics/app/db_handle.h b/src/statistics/app/db_handle.h index f629f00..c4cc79e 100644 --- a/src/statistics/app/db_handle.h +++ b/src/statistics/app/db_handle.h @@ -18,7 +18,7 @@ #define __CONTEXT_APP_DB_HANDLE_H__ #include -#include +#include #include "../shared/db_handle_base.h" namespace ctx { @@ -27,17 +27,17 @@ namespace ctx { app_db_handle(); ~app_db_handle(); - int read(const char* subject, ctx::json filter); + int read(const char* subject, ctx::Json filter); private: - std::string create_where_clause_with_device_status(ctx::json filter); - std::string create_sql_recently_used(ctx::json filter); - std::string create_sql_frequently_used(ctx::json filter); - std::string create_sql_rarely_used(ctx::json filter); - std::string create_sql_peak_time(ctx::json filter); - std::string create_sql_common_setting(ctx::json filter); - std::string create_sql_frequency(ctx::json filter); - void reply_trigger_item(int error, ctx::json &json_result); + std::string create_where_clause_with_device_status(ctx::Json filter); + std::string create_sql_recently_used(ctx::Json filter); + std::string create_sql_frequently_used(ctx::Json filter); + std::string create_sql_rarely_used(ctx::Json filter); + std::string create_sql_peak_time(ctx::Json filter); + std::string create_sql_common_setting(ctx::Json filter); + std::string create_sql_frequency(ctx::Json filter); + void reply_trigger_item(int error, ctx::Json &json_result); }; } diff --git a/src/statistics/app/db_init.cpp b/src/statistics/app/db_init.cpp index a5a7af9..1701585 100644 --- a/src/statistics/app/db_init.cpp +++ b/src/statistics/app/db_init.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include #include #include "app_stats_types.h" @@ -78,7 +78,7 @@ bool ctx::app_db_initializer::package_info_cb(package_info_h package_info, void bool ctx::app_db_initializer::app_info_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data) { - json data; + Json data; data.set(NULL, STATS_APP_ID, app_id); return db_manager::insert(0, APP_TABLE_REMOVABLE_APP, data, NULL); } @@ -91,7 +91,7 @@ void ctx::app_db_initializer::on_insertion_result_received(unsigned int query_id { } -void ctx::app_db_initializer::on_query_result_received(unsigned int query_id, int error, std::vector& records) +void ctx::app_db_initializer::on_query_result_received(unsigned int query_id, int error, std::vector& records) { if (query_id != EMPTY_CHECKER_QID) { _E("Unknown Query ID: %d", query_id); diff --git a/src/statistics/app/db_init.h b/src/statistics/app/db_init.h index b042675..2bd20ad 100644 --- a/src/statistics/app/db_init.h +++ b/src/statistics/app/db_init.h @@ -30,7 +30,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); + void on_query_result_received(unsigned int query_id, int error, std::vector& records); static bool package_info_cb(package_info_h package_info, void *user_data); static bool app_info_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data); diff --git a/src/statistics/app/install_monitor.cpp b/src/statistics/app/install_monitor.cpp index 7cec212..d4b92ce 100644 --- a/src/statistics/app/install_monitor.cpp +++ b/src/statistics/app/install_monitor.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include #include "app_stats_types.h" @@ -81,7 +81,7 @@ void ctx::app_install_monitor::package_event_cb(const char *type, const char *pa bool ctx::app_install_monitor::app_info_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data) { if (last_event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL) { - json data; + Json data; data.set(NULL, STATS_APP_ID, app_id); db_manager::insert(0, APP_TABLE_REMOVABLE_APP, data, NULL); } else if (last_event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL) { diff --git a/src/statistics/app/install_monitor.h b/src/statistics/app/install_monitor.h index 0bfee65..cba445d 100644 --- a/src/statistics/app/install_monitor.h +++ b/src/statistics/app/install_monitor.h @@ -31,7 +31,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) {} + void on_query_result_received(unsigned int query_id, int error, std::vector& records) {} static std::string create_deletion_query(const char* table_name, const char* app_id); static void package_event_cb(const char *type, const char *package, package_manager_event_type_e event_type, package_manager_event_state_e event_state, int progress, package_manager_error_e error, void *user_data); diff --git a/src/statistics/media/db_handle.cpp b/src/statistics/media/db_handle.cpp index 6515c9f..bc74429 100644 --- a/src/statistics/media/db_handle.cpp +++ b/src/statistics/media/db_handle.cpp @@ -30,7 +30,7 @@ ctx::media_db_handle::~media_db_handle() { } -int ctx::media_db_handle::read(const char* subject, ctx::json filter) +int ctx::media_db_handle::read(const char* subject, ctx::Json filter) { //TODO: filter validation (in the API side?) std::string query; @@ -64,7 +64,7 @@ int ctx::media_db_handle::read(const char* subject, ctx::json filter) return ERR_NONE; } -std::string ctx::media_db_handle::create_where_clause(int media_type, ctx::json filter) +std::string ctx::media_db_handle::create_where_clause(int media_type, ctx::Json filter) { std::stringstream where_clause; @@ -74,21 +74,21 @@ std::string ctx::media_db_handle::create_where_clause(int media_type, ctx::json return where_clause.str(); } -std::string ctx::media_db_handle::create_sql_peak_time(int media_type, ctx::json filter) +std::string ctx::media_db_handle::create_sql_peak_time(int media_type, ctx::Json filter) { std::string where = create_where_clause(media_type, filter); return stats_db_handle_base::create_sql_peak_time(filter, MEDIA_TABLE_NAME, where); } -std::string ctx::media_db_handle::create_sql_common_setting(int media_type, ctx::json filter) +std::string ctx::media_db_handle::create_sql_common_setting(int media_type, ctx::Json filter) { std::string where = create_where_clause(media_type, filter); return stats_db_handle_base::create_sql_common_setting(filter, MEDIA_TABLE_NAME, where); } -std::string ctx::media_db_handle::create_sql_frequency(int media_type, ctx::json filter) +std::string ctx::media_db_handle::create_sql_frequency(int media_type, ctx::Json filter) { - ctx::json filter_cleaned; + ctx::Json filter_cleaned; std::string week_str; std::string time_of_day; @@ -109,12 +109,12 @@ std::string ctx::media_db_handle::create_sql_frequency(int media_type, ctx::json return query.str(); } -void ctx::media_db_handle::reply_trigger_item(int error, ctx::json &json_result) +void ctx::media_db_handle::reply_trigger_item(int error, ctx::Json &json_result) { IF_FAIL_VOID_TAG(STR_EQ(req_subject.c_str(), MEDIA_SUBJ_MUSIC_FREQUENCY) || STR_EQ(req_subject.c_str(), MEDIA_SUBJ_VIDEO_FREQUENCY), _E, "Invalid subject"); - ctx::json results; + ctx::Json results; int val; json_result.get(NULL, STATS_TOTAL_COUNT, &val); diff --git a/src/statistics/media/db_handle.h b/src/statistics/media/db_handle.h index 8fbe72a..deb3ded 100644 --- a/src/statistics/media/db_handle.h +++ b/src/statistics/media/db_handle.h @@ -18,7 +18,7 @@ #define __CONTEXT_MEDIA_DB_HANDLE_H__ #include -#include +#include #include "../shared/db_handle_base.h" namespace ctx { @@ -27,14 +27,14 @@ namespace ctx { media_db_handle(); ~media_db_handle(); - int read(const char* subject, ctx::json filter); + int read(const char* subject, ctx::Json filter); private: - std::string create_where_clause(int media_type, ctx::json filter); - std::string create_sql_peak_time(int media_type, ctx::json filter); - std::string create_sql_common_setting(int media_type, ctx::json filter); - std::string create_sql_frequency(int media_type, ctx::json filter); - void reply_trigger_item(int error, ctx::json &json_result); + std::string create_where_clause(int media_type, ctx::Json filter); + std::string create_sql_peak_time(int media_type, ctx::Json filter); + std::string create_sql_common_setting(int media_type, ctx::Json filter); + std::string create_sql_frequency(int media_type, ctx::Json filter); + void reply_trigger_item(int error, ctx::Json &json_result); }; } diff --git a/src/statistics/media/media_content_monitor.cpp b/src/statistics/media/media_content_monitor.cpp index 9c945d7..156d9b5 100644 --- a/src/statistics/media/media_content_monitor.cpp +++ b/src/statistics/media/media_content_monitor.cpp @@ -121,7 +121,7 @@ void ctx::media_content_monitor::update_play_count(const char *uuid, int type, i db_manager::execute(0, query.str().c_str(), this); } -void ctx::media_content_monitor::on_query_result_received(unsigned int query_id, int error, std::vector& records) +void ctx::media_content_monitor::on_query_result_received(unsigned int query_id, int error, std::vector& records) { IF_FAIL_VOID(!records.empty()); @@ -135,7 +135,7 @@ void ctx::media_content_monitor::insert_log(int media_type) { int system_volume = -1, media_volume = -1, audiojack = -1; - json data; + Json data; data.set(NULL, CX_MEDIA_TYPE, media_type); if (ctx::system_info::get_audio_jack_state(&audiojack)) diff --git a/src/statistics/media/media_content_monitor.h b/src/statistics/media/media_content_monitor.h index d51d54c..4bd97db 100644 --- a/src/statistics/media/media_content_monitor.h +++ b/src/statistics/media/media_content_monitor.h @@ -37,7 +37,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); + void on_query_result_received(unsigned int query_id, int error, std::vector& records); static void on_media_content_db_updated(media_content_error_e error, int pid, media_content_db_update_item_type_e update_item, diff --git a/src/statistics/media/media_stats_provider.cpp b/src/statistics/media/media_stats_provider.cpp index d6ad2b7..e68fe6b 100644 --- a/src/statistics/media/media_stats_provider.cpp +++ b/src/statistics/media/media_stats_provider.cpp @@ -83,17 +83,17 @@ 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* request_result) { return ERR_NOT_SUPPORTED; } -int ctx::media_statistics_provider::unsubscribe(const char* subject, ctx::json option) +int ctx::media_statistics_provider::unsubscribe(const char* subject, ctx::Json option) { 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* request_result) { 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* request_result) { return ERR_NOT_SUPPORTED; } diff --git a/src/statistics/media/media_stats_provider.h b/src/statistics/media/media_stats_provider.h index 49949c3..72bb198 100644 --- a/src/statistics/media/media_stats_provider.h +++ b/src/statistics/media/media_stats_provider.h @@ -29,10 +29,10 @@ namespace ctx { 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 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 subscribe(const char* subject, ctx::Json option, ctx::Json* request_result); + int unsubscribe(const char* subject, ctx::Json option); + int read(const char* subject, ctx::Json option, ctx::Json* request_result); + int write(const char* subject, ctx::Json data, ctx::Json* request_result); 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 e3d0602..f525b3d 100644 --- a/src/statistics/shared/db_handle_base.cpp +++ b/src/statistics/shared/db_handle_base.cpp @@ -41,7 +41,7 @@ int ctx::stats_db_handle_base::generate_qid() return qid; } -bool ctx::stats_db_handle_base::execute_query(const char* subject, ctx::json filter, const char* query) +bool ctx::stats_db_handle_base::execute_query(const char* subject, ctx::Json filter, const char* query) { bool ret = db_manager::execute(generate_qid(), query, this); IF_FAIL_RETURN(ret, false); @@ -52,7 +52,7 @@ bool ctx::stats_db_handle_base::execute_query(const char* subject, ctx::json fil return true; } -std::string ctx::stats_db_handle_base::create_where_clause(ctx::json filter) +std::string ctx::stats_db_handle_base::create_where_clause(ctx::Json filter) { std::stringstream where_clause; int week = 0; @@ -142,7 +142,7 @@ std::string ctx::stats_db_handle_base::create_where_clause(ctx::json filter) return where_clause.str(); } -std::string ctx::stats_db_handle_base::create_sql_peak_time(ctx::json filter, const char* table_name, std::string where_clause) +std::string ctx::stats_db_handle_base::create_sql_peak_time(ctx::Json filter, const char* table_name, std::string where_clause) { std::stringstream query; int limit = DEFAULT_LIMIT; @@ -161,7 +161,7 @@ std::string ctx::stats_db_handle_base::create_sql_peak_time(ctx::json filter, co return query.str(); } -std::string ctx::stats_db_handle_base::create_sql_common_setting(ctx::json filter, const char* table_name, std::string where_clause) +std::string ctx::stats_db_handle_base::create_sql_common_setting(ctx::Json filter, const char* table_name, std::string where_clause) { std::stringstream query; @@ -197,28 +197,28 @@ void ctx::stats_db_handle_base::on_insertion_result_received(unsigned int query_ delete this; } -void ctx::stats_db_handle_base::json_vector_to_array(std::vector &vec_json, ctx::json &json_result) +void ctx::stats_db_handle_base::json_vector_to_array(std::vector &vec_json, ctx::Json &json_result) { - std::vector::iterator json_vec_end = vec_json.end(); + std::vector::iterator json_vec_end = vec_json.end(); - for(std::vector::iterator json_vec_pos = vec_json.begin(); json_vec_pos != json_vec_end; ++json_vec_pos) { - json origin_j = *json_vec_pos; - json_result.array_append(NULL, STATS_QUERY_RESULT, origin_j); + for(std::vector::iterator json_vec_pos = vec_json.begin(); json_vec_pos != json_vec_end; ++json_vec_pos) { + Json origin_j = *json_vec_pos; + json_result.append(NULL, STATS_QUERY_RESULT, origin_j); } } -void ctx::stats_db_handle_base::on_query_result_received(unsigned int query_id, int error, std::vector& records) +void ctx::stats_db_handle_base::on_query_result_received(unsigned int query_id, int error, std::vector& records) { if (is_trigger_item) { if (records.size() == 1) { reply_trigger_item(error, records[0]); } else { _E("Invalid query result"); - json dummy; + Json dummy; context_manager::reply_to_read(req_subject.c_str(), req_filter, ERR_OPERATION_FAILED, dummy); } } else { - json results = "{\"" STATS_QUERY_RESULT "\":[]}"; + Json results = "{\"" STATS_QUERY_RESULT "\":[]}"; json_vector_to_array(records, results); context_manager::reply_to_read(req_subject.c_str(), req_filter, error, results); } diff --git a/src/statistics/shared/db_handle_base.h b/src/statistics/shared/db_handle_base.h index 6e05696..7c88380 100644 --- a/src/statistics/shared/db_handle_base.h +++ b/src/statistics/shared/db_handle_base.h @@ -18,7 +18,7 @@ #define __CONTEXT_STATS_DB_HANDLE_BASE_H__ #include -#include +#include #include namespace ctx { @@ -26,25 +26,25 @@ namespace ctx { protected: bool is_trigger_item; std::string req_subject; - ctx::json req_filter; + ctx::Json req_filter; stats_db_handle_base(); ~stats_db_handle_base(); - std::string create_where_clause(ctx::json filter); - std::string create_sql_peak_time(ctx::json filter, const char* table_name, std::string where_clause); - std::string create_sql_common_setting(ctx::json filter, const char* table_name, std::string where_clause); + std::string create_where_clause(ctx::Json filter); + std::string create_sql_peak_time(ctx::Json filter, const char* table_name, std::string where_clause); + std::string create_sql_common_setting(ctx::Json filter, const char* table_name, std::string where_clause); - bool execute_query(const char* subject, ctx::json filter, const char* query); - virtual void reply_trigger_item(int error, ctx::json &json_result) = 0; + bool execute_query(const char* subject, ctx::Json filter, const char* query); + virtual void reply_trigger_item(int error, ctx::Json &json_result) = 0; static int generate_qid(); private: - void json_vector_to_array(std::vector &vec_json, ctx::json &json_result); + void json_vector_to_array(std::vector &vec_json, ctx::Json &json_result); 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); + void on_query_result_received(unsigned int query_id, int error, std::vector& records); }; } diff --git a/src/statistics/social/db_handle.cpp b/src/statistics/social/db_handle.cpp index e6a1a01..a42e625 100644 --- a/src/statistics/social/db_handle.cpp +++ b/src/statistics/social/db_handle.cpp @@ -30,7 +30,7 @@ ctx::social_db_handle::~social_db_handle() { } -int ctx::social_db_handle::read(const char* subject, ctx::json filter) +int ctx::social_db_handle::read(const char* subject, ctx::Json filter) { std::string query; @@ -50,7 +50,7 @@ int ctx::social_db_handle::read(const char* subject, ctx::json filter) return ERR_NONE; } -std::string ctx::social_db_handle::create_where_clause(ctx::json filter) +std::string ctx::social_db_handle::create_where_clause(ctx::Json filter) { std::stringstream where_clause; int comm_type = -1; @@ -77,7 +77,7 @@ std::string ctx::social_db_handle::create_where_clause(ctx::json filter) return where_clause.str(); } -std::string ctx::social_db_handle::create_sql_freq_address(ctx::json filter) +std::string ctx::social_db_handle::create_sql_freq_address(ctx::Json filter) { std::stringstream query; int limit = DEFAULT_LIMIT; @@ -98,9 +98,9 @@ std::string ctx::social_db_handle::create_sql_freq_address(ctx::json filter) return query.str(); } -std::string ctx::social_db_handle::create_sql_frequency(ctx::json filter) +std::string ctx::social_db_handle::create_sql_frequency(ctx::Json filter) { - ctx::json filter_cleaned; + ctx::Json filter_cleaned; std::string week_str; std::string time_of_day; std::string address; @@ -143,11 +143,11 @@ std::string ctx::social_db_handle::create_sql_frequency(ctx::json filter) return query.str(); } -void ctx::social_db_handle::reply_trigger_item(int error, ctx::json &json_result) +void ctx::social_db_handle::reply_trigger_item(int error, ctx::Json &json_result) { IF_FAIL_VOID_TAG(STR_EQ(req_subject.c_str(), SOCIAL_SUBJ_FREQUENCY), _E, "Invalid subject"); - ctx::json results; + ctx::Json results; std::string val_str; int val; diff --git a/src/statistics/social/db_handle.h b/src/statistics/social/db_handle.h index a8eecb1..1bf88fd 100644 --- a/src/statistics/social/db_handle.h +++ b/src/statistics/social/db_handle.h @@ -18,7 +18,7 @@ #define __CONTEXT_SOCIAL_DB_HANDLE_H__ #include -#include +#include #include "../shared/db_handle_base.h" namespace ctx { @@ -27,13 +27,13 @@ namespace ctx { social_db_handle(); ~social_db_handle(); - int read(const char* subject, ctx::json filter); + int read(const char* subject, ctx::Json filter); private: - std::string create_where_clause(ctx::json filter); - std::string create_sql_freq_address(ctx::json filter); - std::string create_sql_frequency(ctx::json filter); - void reply_trigger_item(int error, ctx::json &json_result); + std::string create_where_clause(ctx::Json filter); + std::string create_sql_freq_address(ctx::Json filter); + std::string create_sql_frequency(ctx::Json filter); + void reply_trigger_item(int error, ctx::Json &json_result); }; } diff --git a/src/statistics/social/log_aggregator.cpp b/src/statistics/social/log_aggregator.cpp index 2c4af98..309316f 100644 --- a/src/statistics/social/log_aggregator.cpp +++ b/src/statistics/social/log_aggregator.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include #include #include @@ -60,7 +60,7 @@ void ctx::contact_log_aggregator::aggregate_contact_log() " FROM " SOCIAL_TABLE_CONTACT_LOG, this); } -void ctx::contact_log_aggregator::on_query_result_received(unsigned int query_id, int error, std::vector& records) +void ctx::contact_log_aggregator::on_query_result_received(unsigned int query_id, int error, std::vector& records) { IF_FAIL_VOID_TAG(!records.empty(), _E, "Invalid query result"); @@ -131,7 +131,7 @@ void ctx::contact_log_aggregator::insert_contact_log_list(contacts_list_h list) contacts_list_get_current_record_p(list, &record); if (record == NULL) break; - ctx::json data; + ctx::Json data; char* address = NULL; int log_type; diff --git a/src/statistics/social/log_aggregator.h b/src/statistics/social/log_aggregator.h index 57c154f..e7aefb7 100644 --- a/src/statistics/social/log_aggregator.h +++ b/src/statistics/social/log_aggregator.h @@ -41,7 +41,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); + void on_query_result_received(unsigned int query_id, int error, std::vector& records); bool on_timer_expired(int timer_id, void* user_data); }; /* class phone_contact_log_aggregator */ diff --git a/src/statistics/social/social_stats_provider.cpp b/src/statistics/social/social_stats_provider.cpp index 92bb856..90aa35b 100644 --- a/src/statistics/social/social_stats_provider.cpp +++ b/src/statistics/social/social_stats_provider.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #include #include "social_stats_provider.h" #include "db_handle.h" @@ -81,17 +81,17 @@ 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* request_result) { return ERR_NOT_SUPPORTED; } -int ctx::social_statistics_provider::unsubscribe(const char* subject, ctx::json option) +int ctx::social_statistics_provider::unsubscribe(const char* subject, ctx::Json option) { 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* request_result) { 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* request_result) { return ERR_NOT_SUPPORTED; } diff --git a/src/statistics/social/social_stats_provider.h b/src/statistics/social/social_stats_provider.h index 64ab059..7ba803d 100644 --- a/src/statistics/social/social_stats_provider.h +++ b/src/statistics/social/social_stats_provider.h @@ -29,10 +29,10 @@ namespace ctx { 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 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 subscribe(const char* subject, ctx::Json option, ctx::Json* request_result); + int unsubscribe(const char* subject, ctx::Json option); + int read(const char* subject, ctx::Json option, ctx::Json* request_result); + int write(const char* subject, ctx::Json data, ctx::Json* request_result); private: static social_statistics_provider *__instance; -- 2.7.4 From 08e77c551c3c2991885aa61af0bced8dd41b2132 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Mon, 29 Feb 2016 10:50:05 +0900 Subject: [PATCH 08/16] Remove GEO_LOCATION_PRECISION parameter from Json::set() Change-Id: I0a4d3d8e66b31484c8ee8d749ceddc8461938096 Signed-off-by: Mu-Woong Lee --- src/place/recognition/user_places/location_logger.cpp | 6 +++--- src/place/recognition/user_places/places_detector.cpp | 4 ++-- src/place/recognition/user_places/user_places.cpp | 4 ++-- src/place/recognition/user_places/visit_detector.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/place/recognition/user_places/location_logger.cpp b/src/place/recognition/user_places/location_logger.cpp index eddf0dc..1a5ef29 100644 --- a/src/place/recognition/user_places/location_logger.cpp +++ b/src/place/recognition/user_places/location_logger.cpp @@ -183,9 +183,9 @@ int ctx::LocationLogger::create_table() int ctx::LocationLogger::db_insert_log(location_event_s location_event) { Json data; - data.set(NULL, LOCATION_COLUMN_LATITUDE, location_event.coordinates.latitude, GEO_LOCATION_PRECISION); - data.set(NULL, LOCATION_COLUMN_LONGITUDE, location_event.coordinates.longitude, GEO_LOCATION_PRECISION); - data.set(NULL, LOCATION_COLUMN_ACCURACY, location_event.coordinates.accuracy, GEO_LOCATION_PRECISION); + data.set(NULL, LOCATION_COLUMN_LATITUDE, location_event.coordinates.latitude); + data.set(NULL, LOCATION_COLUMN_LONGITUDE, location_event.coordinates.longitude); + data.set(NULL, LOCATION_COLUMN_ACCURACY, location_event.coordinates.accuracy); data.set(NULL, LOCATION_COLUMN_TIMESTAMP, static_cast(location_event.timestamp)); #ifdef TIZEN_ENGINEER_MODE std::string time_human = DebugUtils::human_readable_date_time(location_event.timestamp, "%F %T", 80); diff --git a/src/place/recognition/user_places/places_detector.cpp b/src/place/recognition/user_places/places_detector.cpp index 1530ef9..a5163e4 100644 --- a/src/place/recognition/user_places/places_detector.cpp +++ b/src/place/recognition/user_places/places_detector.cpp @@ -438,8 +438,8 @@ void ctx::PlacesDetector::db_insert_place(const Place &place) data.set(NULL, PLACE_COLUMN_NAME, place.name); data.set(NULL, PLACE_COLUMN_LOCATION_VALID, place.location_valid); - data.set(NULL, PLACE_COLUMN_LOCATION_LATITUDE, place.location.latitude, GEO_LOCATION_PRECISION); - data.set(NULL, PLACE_COLUMN_LOCATION_LONGITUDE, place.location.longitude, GEO_LOCATION_PRECISION); + data.set(NULL, PLACE_COLUMN_LOCATION_LATITUDE, place.location.latitude); + data.set(NULL, PLACE_COLUMN_LOCATION_LONGITUDE, place.location.longitude); data.set(NULL, PLACE_COLUMN_WIFI_APS, place.wifi_aps); data.set(NULL, PLACE_COLUMN_CREATE_DATE, static_cast(place.create_date)); diff --git a/src/place/recognition/user_places/user_places.cpp b/src/place/recognition/user_places/user_places.cpp index 46c8d31..bba0f1d 100644 --- a/src/place/recognition/user_places/user_places.cpp +++ b/src/place/recognition/user_places/user_places.cpp @@ -120,8 +120,8 @@ ctx::Json ctx::UserPlaces::compose_json(std::vector> plac place_j.set(NULL, PLACE_CATEG_CONFIDENCE, place->categ_confidence); place_j.set(NULL, PLACE_NAME, place->name); if (place->location_valid) { - place_j.set(NULL, PLACE_GEO_LATITUDE, place->location.latitude, GEO_LOCATION_PRECISION); - place_j.set(NULL, PLACE_GEO_LONGITUDE, place->location.longitude, GEO_LOCATION_PRECISION); + place_j.set(NULL, PLACE_GEO_LATITUDE, place->location.latitude); + place_j.set(NULL, PLACE_GEO_LONGITUDE, place->location.longitude); } place_j.set(NULL, PLACE_WIFI_APS, place->wifi_aps); place_j.set(NULL, PLACE_CREATE_DATE, static_cast(place->create_date)); diff --git a/src/place/recognition/user_places/visit_detector.cpp b/src/place/recognition/user_places/visit_detector.cpp index ccd9cb7..84abb5e 100644 --- a/src/place/recognition/user_places/visit_detector.cpp +++ b/src/place/recognition/user_places/visit_detector.cpp @@ -398,8 +398,8 @@ int ctx::VisitDetector::db_insert_visit(visit_s visit) data.set(NULL, VISIT_COLUMN_WIFI_APS, macs_ss.str().c_str()); data.set(NULL, VISIT_COLUMN_LOCATION_VALID, visit.location_valid); - data.set(NULL, VISIT_COLUMN_LOCATION_LATITUDE, visit.location.latitude, GEO_LOCATION_PRECISION); - data.set(NULL, VISIT_COLUMN_LOCATION_LONGITUDE, visit.location.longitude, GEO_LOCATION_PRECISION); + data.set(NULL, VISIT_COLUMN_LOCATION_LATITUDE, visit.location.latitude); + data.set(NULL, VISIT_COLUMN_LOCATION_LONGITUDE, visit.location.longitude); data.set(NULL, VISIT_COLUMN_START_TIME, static_cast(visit.interval.start)); data.set(NULL, VISIT_COLUMN_END_TIME, static_cast(visit.interval.end)); -- 2.7.4 From 2cfeeeed9120711c0b1dab359e22602b904b1866 Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Wed, 24 Feb 2016 15:24:36 +0900 Subject: [PATCH 09/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 10/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 11/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 12/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 13/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 14/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 15/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 16/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