[my-place] Testing possibilities fix / simplification. 05/70805/2
authorMarcin Masternak <m.masternak@samsung.com>
Fri, 20 May 2016 16:40:58 +0000 (18:40 +0200)
committerMarcin Masternak <m.masternak@samsung.com>
Tue, 24 May 2016 08:07:01 +0000 (10:07 +0200)
Change-Id: I77e4e4870575190fe9014cd3416eb75bc62458ae
Signed-off-by: Marcin Masternak <m.masternak@samsung.com>
src/my-place/user_places/location_logger.cpp
src/my-place/user_places/location_logger.h
src/my-place/user_places/places_detector.cpp
src/my-place/user_places/places_detector.h
src/my-place/user_places/visit_detector.cpp
src/my-place/user_places/visit_detector.h
src/my-place/user_places/wifi_logger.cpp
src/my-place/user_places/wifi_logger.h

index 1331740..3d611e2 100644 (file)
@@ -201,9 +201,8 @@ int ctx::LocationLogger::__dbInsertLog(LocationEvent locationEvent)
        return ret;
 }
 
-ctx::LocationLogger::LocationLogger(ILocationListener *listener, bool testMode) :
+ctx::LocationLogger::LocationLogger(ILocationListener *listener) :
        __listener(listener),
-       __testMode(testMode),
        __activeRequestAttempts(0),
        __activeAttempts(0),
        __allAttempts(0),
@@ -221,9 +220,6 @@ ctx::LocationLogger::LocationLogger(ILocationListener *listener, bool testMode)
 
        __locationManagerCreate();
 
-       if (__testMode) {
-               return;
-       }
        if (LOCATION_LOGGER_DATABASE) {
                __dbCreateTable();
        }
@@ -601,17 +597,13 @@ void ctx::LocationLogger::__stopLogging()
 void ctx::LocationLogger::onVisitStart()
 {
        _D("");
-       if (!__testMode) {
-               __startLogging();
-       }
+       __startLogging();
 }
 
 void ctx::LocationLogger::onVisitEnd()
 {
        _D("");
-       if (!__testMode) {
-               __stopLogging();
-       }
+       __stopLogging();
 }
 
 #undef __LOCATION_ERROR_LOG
index c5cb74a..0ffb4d2 100644 (file)
@@ -65,7 +65,7 @@ namespace ctx {
        class LocationLogger : public ITimerListener, public IVisitListener {
 
        public:
-               LocationLogger(ILocationListener *listener = nullptr, bool testMode = false);
+               LocationLogger(ILocationListener *listener = nullptr);
                ~LocationLogger();
 
        private:
@@ -78,7 +78,6 @@ namespace ctx {
                void __broadcast(LocationEvent locationEvent);
 
                /* INTERNAL */
-               bool __testMode;
                void __startLogging();
                void __stopLogging();
                void __locationRequest();
index 0077769..a324984 100644 (file)
@@ -83,7 +83,7 @@ bool ctx::PlacesDetector::onTimerExpired(int timerId)
 std::vector<ctx::Json> ctx::PlacesDetector::__dbGetVisits()
 {
        std::vector<Json> records;
-       bool ret = __dbManager.executeSync(__GET_VISITS_QUERY, &records);
+       bool ret = __dbManager->executeSync(__GET_VISITS_QUERY, &records);
        _D("load visits execute query result: %s", ret ? "SUCCESS" : "FAIL");
        return records;
 }
@@ -91,7 +91,7 @@ std::vector<ctx::Json> ctx::PlacesDetector::__dbGetVisits()
 std::vector<ctx::Json> ctx::PlacesDetector::__dbGetPlaces()
 {
        std::vector<Json> records;
-       bool ret = __dbManager.executeSync(__GET_PLACES_QUERY, &records);
+       bool ret = __dbManager->executeSync(__GET_PLACES_QUERY, &records);
        _D("load places execute query result: %s", ret ? "SUCCESS" : "FAIL");
        return records;
 }
@@ -363,7 +363,7 @@ std::shared_ptr<ctx::graph::Graph> ctx::PlacesDetector::__graphFromVisits(const
 void ctx::PlacesDetector::__dbDeletePlaces()
 {
        std::vector<Json> records;
-       bool ret = __dbManager.executeSync(__DELETE_PLACES_QUERY, &records);
+       bool ret = __dbManager->executeSync(__DELETE_PLACES_QUERY, &records);
        _D("delete places execute query result: %s", ret ? "SUCCESS" : "FAIL");
 }
 
@@ -383,12 +383,13 @@ void ctx::PlacesDetector::__dbDeleteOlderVisitsThan(time_t threshold)
        query << " WHERE " << VISIT_COLUMN_END_TIME << " < " << threshold;
        // query << " AND 0"; // XXX: Always false condition. Uncomment it for not deleting any visit during development.
        std::vector<Json> records;
-       bool ret = __dbManager.executeSync(query.str().c_str(), &records);
+       bool ret = __dbManager->executeSync(query.str().c_str(), &records);
        _D("delete old visits execute query result: %s", ret ? "SUCCESS" : "FAIL");
 }
 
-ctx::PlacesDetector::PlacesDetector(bool testMode) :
-       __testMode(testMode)
+ctx::PlacesDetector::PlacesDetector(bool testMode):
+       __testMode(testMode),
+       __dbManager(testMode ? nullptr : new DatabaseManager())
 {
        if (testMode) {
                return;
@@ -401,7 +402,7 @@ ctx::PlacesDetector::PlacesDetector(bool testMode) :
 
 void ctx::PlacesDetector::__dbCreateTable()
 {
-       bool ret = __dbManager.createTable(0, PLACE_TABLE, __PLACE_TABLE_COLUMNS);
+       bool ret = __dbManager->createTable(0, PLACE_TABLE, __PLACE_TABLE_COLUMNS);
        _D("db: place Table Creation Result: %s", ret ? "SUCCESS" : "FAIL");
 }
 
@@ -420,7 +421,7 @@ void ctx::PlacesDetector::__dbInsertPlace(const Place &place)
        data.set(NULL, PLACE_COLUMN_CREATE_DATE, static_cast<int>(place.createDate));
 
        int64_t rowId;
-       bool ret = __dbManager.insertSync(PLACE_TABLE, data, &rowId);
+       bool ret = __dbManager->insertSync(PLACE_TABLE, data, &rowId);
        _D("insert place execute query result: %s", ret ? "SUCCESS" : "FAIL");
 }
 
index 734c89d..2cb0e41 100644 (file)
@@ -30,7 +30,7 @@ namespace ctx {
 
        private:
                bool __testMode;
-               DatabaseManager __dbManager;
+               DatabaseManager *__dbManager;
 
                double __doubleValueFromJson(Json &row, const char* key);
                Categs __visitCategsFromJson(Json &row);
index 5b6852c..8cb287f 100644 (file)
 
 ctx::VisitDetector::VisitDetector(time_t startScan, PlaceRecogMode energyMode, bool testMode) :
        __testMode(testMode),
-       __locationLogger(this, testMode),
-       __wifiLogger(this, energyMode, testMode),
+       __locationLogger(testMode ? nullptr : new LocationLogger(this)),
+       __wifiLogger(testMode ? nullptr : new WifiLogger(this, energyMode)),
        __currentInterval(startScan, startScan + VISIT_DETECTOR_PERIOD_SECONDS_HIGH_ACCURACY),
        __stableCounter(0),
        __tolerance(VISIT_DETECTOR_TOLERANCE_DEPTH),
        __entranceToPlace(false),
        __periodSeconds(VISIT_DETECTOR_PERIOD_SECONDS_HIGH_ACCURACY),
+       __dbManager(testMode ? nullptr : new DatabaseManager()),
        __entranceTime(0),
        __departureTime(0)
 {
@@ -76,10 +77,11 @@ ctx::VisitDetector::VisitDetector(time_t startScan, PlaceRecogMode energyMode, b
                return;
        }
 
-       __listeners.push_back(&__locationLogger);
-       __listeners.push_back(&__wifiLogger);
+       __listeners.push_back(__locationLogger);
+       __listeners.push_back(__wifiLogger);
+
        __dbCreateTable();
-       __wifiLogger.startLogging();
+       __wifiLogger->startLogging();
 }
 
 ctx::VisitDetector::~VisitDetector()
@@ -360,7 +362,7 @@ std::shared_ptr<ctx::Visits> ctx::VisitDetector::getVisits()
 
 void ctx::VisitDetector::__dbCreateTable()
 {
-       bool ret = __dbManager.createTable(0, VISIT_TABLE, __VISIT_TABLE_COLUMNS);
+       bool ret = __dbManager->createTable(0, VISIT_TABLE, __VISIT_TABLE_COLUMNS);
        _D("db: visit Table Creation Result: %s", ret ? "SUCCESS" : "FAIL");
 }
 
@@ -410,7 +412,7 @@ int ctx::VisitDetector::__dbInsertVisit(Visit visit)
        __putVisitCategsToJson(visit.categs, data);
 
        int64_t rowId;
-       bool ret = __dbManager.insertSync(VISIT_TABLE, data, &rowId);
+       bool ret = __dbManager->insertSync(VISIT_TABLE, data, &rowId);
        _D("db: visit table insert result: %s", ret ? "SUCCESS" : "FAIL");
        return ret;
 }
@@ -440,5 +442,7 @@ void ctx::VisitDetector::setMode(PlaceRecogMode energyMode)
 {
        _D("");
        __setPeriod(energyMode);
-       __wifiLogger.setMode(energyMode);
+       if (__wifiLogger) {
+               __wifiLogger->setMode(energyMode);
+       }
 }
index 0078553..0fa6ad6 100644 (file)
@@ -38,8 +38,8 @@ namespace ctx {
        private:
                bool __testMode;
                std::shared_ptr<Visits> __detectedVisits; // only used in test mode
-               LocationLogger __locationLogger;
-               WifiLogger __wifiLogger;
+               LocationLogger *__locationLogger;
+               WifiLogger *__wifiLogger;
                std::vector<IVisitListener*> __listeners;
                std::shared_ptr<MacEvents> __currentMacEvents;
                Interval __currentInterval;
@@ -50,7 +50,7 @@ namespace ctx {
                int __tolerance;
                bool __entranceToPlace;
                int __periodSeconds;
-               DatabaseManager __dbManager;
+               DatabaseManager *__dbManager;
 
                // fields that  are used only in case of entrance detection
                std::shared_ptr<MacSet> __representativesMacs; // macs that represent the current place
index 46ce368..978361e 100644 (file)
@@ -66,10 +66,9 @@ int ctx::WifiLogger::__dbInsertLogs()
        return 0;
 }
 
-ctx::WifiLogger::WifiLogger(IWifiListener * listener, PlaceRecogMode energyMode, bool testMode) :
+ctx::WifiLogger::WifiLogger(IWifiListener * listener, PlaceRecogMode energyMode) :
        __timerOn(false),
        __intervalMinutes(WIFI_LOGGER_INTERVAL_MINUTES_HIGH_ACCURACY),
-       __testMode(testMode),
        __listener(listener),
        __lastScanTime(time_t(0)),
        __lasTimerCallbackTime(time_t(0)),
@@ -79,9 +78,7 @@ ctx::WifiLogger::WifiLogger(IWifiListener * listener, PlaceRecogMode energyMode,
        __running(false)
 {
        _D("CONSTRUCTOR");
-       if (testMode) {
-               return;
-       }
+
        __setInterval(energyMode);
 
        if (WIFI_LOGGER_DATABASE) {
index f09fdec..d372674 100644 (file)
@@ -51,8 +51,7 @@ namespace ctx {
 
        public:
                WifiLogger(IWifiListener * listener = nullptr,
-                               PlaceRecogMode energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE,
-                               bool testMode = false);
+                               PlaceRecogMode energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE);
                ~WifiLogger();
 
                void startLogging();
@@ -98,7 +97,6 @@ namespace ctx {
                static bool __wifiFoundApCb(wifi_ap_h ap, void *userData);
                static void __wifiScanFinishedCb(wifi_error_e errorCode, void *userData);
 
-               bool __testMode;
                IWifiListener * const __listener;
                std::vector<MacEvent> __logs;
                std::set<std::string> __lastScansPool;