From: Marcin Masternak Date: Fri, 10 Jun 2016 17:52:59 +0000 (+0200) Subject: [my-place] Dynamic loading of PlacesDetector library. X-Git-Tag: submit/tizen/20160622.045445^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F74%2F74074%2F2;p=platform%2Fcore%2Fcontext%2Fcontext-provider.git [my-place] Dynamic loading of PlacesDetector library. Change-Id: I7b007eef5e811a6c04d4f1b1aa120e94ae713657 Signed-off-by: Marcin Masternak --- diff --git a/src/my-place/CMakeLists.txt b/src/my-place/CMakeLists.txt index c336024..7ea03ee 100644 --- a/src/my-place/CMakeLists.txt +++ b/src/my-place/CMakeLists.txt @@ -6,7 +6,7 @@ SET(DEPS ${DEPS} capi-network-wifi ) -FILE(GLOB SRCS *.cpp facade/*.cpp place/*.cpp utils/*.cpp visit-detector/*.cpp) +FILE(GLOB SRCS *.cpp facade/*.cpp utils/*.cpp visit-detector/*.cpp) INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(PKG_MYPLACE REQUIRED ${DEPS}) @@ -20,4 +20,5 @@ TARGET_LINK_LIBRARIES(${target} ${PKG_MYPLACE_LDFLAGS} ${target_shared}) INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR}/${target_dir}) +ADD_SUBDIRECTORY(place) ADD_SUBDIRECTORY(visit-categer) \ No newline at end of file diff --git a/src/my-place/facade/UserPlaces.cpp b/src/my-place/facade/UserPlaces.cpp index d0ae2fb..f29da9a 100755 --- a/src/my-place/facade/UserPlaces.cpp +++ b/src/my-place/facade/UserPlaces.cpp @@ -19,8 +19,12 @@ #include #include #include "UserPlaces.h" -#include "../place/PlacesDetector.h" #include +#include + +#define SO_PATH "/usr/lib/context-service/libctx-prvd-my-place-places-detector.so" + +typedef void (*places_detector_t)(); #define __GET_PLACES_QUERY "SELECT "\ PLACE_COLUMN_CATEG_ID ", "\ @@ -41,8 +45,7 @@ ctx::UserPlaces::UserPlaces(PlaceRecogMode energyMode): __visitDetector(nullptr), - __placesDetector(nullptr), - __placesDetectorTimerId(-1) + __timerId(-1) { time_t now = std::time(nullptr); __visitDetector = new(std::nothrow) VisitDetector(now, energyMode); @@ -51,35 +54,26 @@ ctx::UserPlaces::UserPlaces(PlaceRecogMode energyMode): return; } - __placesDetector = new(std::nothrow) PlacesDetector(); - if (__placesDetector == nullptr) { - _E("Cannot initialize __placesDetector"); - return; - } - - __placesDetectorTimerId = __timerManager.setAt( // execute once every night + __timerId = __timerManager.setAt( // execute once every night PLACES_DETECTOR_TASK_START_HOUR, PLACES_DETECTOR_TASK_START_MINUTE, DayOfWeek::EVERYDAY, - __placesDetector); - if (__placesDetectorTimerId < 0) { - _E("PlacesDetector timer set FAIL"); + this); + if (__timerId < 0) { + _E("timer set FAIL"); return; } else { - _D("PlacesDetector timer set SUCCESS"); + _D("timer set SUCCESS"); } } ctx::UserPlaces::~UserPlaces() { - if (__placesDetectorTimerId >= 0) { - __timerManager.remove(__placesDetectorTimerId); - _D("PlacesDetector timer removed"); + if (__timerId >= 0) { + __timerManager.remove(__timerId); } if (__visitDetector) delete __visitDetector; - if (__placesDetector) - delete __placesDetector; }; ctx::Json ctx::UserPlaces::getPlaces() @@ -127,6 +121,26 @@ void ctx::UserPlaces::setMode(PlaceRecogMode energyMode) __visitDetector->setMode(energyMode); } +bool ctx::UserPlaces::onTimerExpired(int timerId) +{ + _D("mmastern try to detect places from UserPlaces"); + GModule *soHandle = g_module_open(SO_PATH, G_MODULE_BIND_LAZY); + IF_FAIL_RETURN_TAG(soHandle, true, _E, "%s", g_module_error()); + + gpointer symbol; + if (!g_module_symbol(soHandle, "detectPlaces", &symbol) || symbol == NULL) { + _E("mmastern %s", g_module_error()); + g_module_close(soHandle); + return true; + } + + places_detector_t detectPlaces = reinterpret_cast(symbol); + + detectPlaces(); + g_module_close(soHandle); + return true; +} + std::vector ctx::UserPlaces::__dbGetPlaces() { std::vector records; diff --git a/src/my-place/facade/UserPlaces.h b/src/my-place/facade/UserPlaces.h index 2bcf56d..3ed19d3 100644 --- a/src/my-place/facade/UserPlaces.h +++ b/src/my-place/facade/UserPlaces.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "../visit-detector/VisitDetector.h" #include "../place/PlacesDetector.h" @@ -29,13 +30,12 @@ namespace ctx { - class UserPlaces { + class UserPlaces : public ITimerListener { private: VisitDetector *__visitDetector; - PlacesDetector *__placesDetector; DatabaseManager *__dbManager; - int __placesDetectorTimerId; + int __timerId; TimerManager __timerManager; std::vector __dbGetPlaces(); std::map __dbGetWifiAPsMap(); @@ -52,6 +52,8 @@ namespace ctx { std::vector> __getPlaces(); static Json __composeJson(std::vector> places); + bool onTimerExpired(int timerId); + public: UserPlaces(PlaceRecogMode energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE); ~UserPlaces(); diff --git a/src/my-place/place/CMakeLists.txt b/src/my-place/place/CMakeLists.txt new file mode 100644 index 0000000..fc2c120 --- /dev/null +++ b/src/my-place/place/CMakeLists.txt @@ -0,0 +1,7 @@ +SET(target "${target_prefix}-my-place-places-detector") + +FILE(GLOB SRCS *.cpp) + +ADD_LIBRARY(${target} SHARED ${SRCS}) + +INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR}/${target_dir}) \ No newline at end of file diff --git a/src/my-place/place/PlacesDetector.cpp b/src/my-place/place/PlacesDetector.cpp index e452a13..d43b86e 100644 --- a/src/my-place/place/PlacesDetector.cpp +++ b/src/my-place/place/PlacesDetector.cpp @@ -376,3 +376,9 @@ void ctx::PlacesDetector::__dbInsertPlace(const Place &place) _D("insert place execute query result: %s", ret ? "SUCCESS" : "FAIL"); } +extern "C" SO_EXPORT void detectPlaces() +{ + _D(""); + ctx::PlacesDetector placesDetector; + placesDetector.detectPlaces(); +}