return ret;
}
-ctx::LocationLogger::LocationLogger(ILocationListener *listener, bool testMode) :
+ctx::LocationLogger::LocationLogger(ILocationListener *listener) :
__listener(listener),
- __testMode(testMode),
__activeRequestAttempts(0),
__activeAttempts(0),
__allAttempts(0),
__locationManagerCreate();
- if (__testMode) {
- return;
- }
if (LOCATION_LOGGER_DATABASE) {
__dbCreateTable();
}
void ctx::LocationLogger::onVisitStart()
{
_D("");
- if (!__testMode) {
- __startLogging();
- }
+ __startLogging();
}
void ctx::LocationLogger::onVisitEnd()
{
_D("");
- if (!__testMode) {
- __stopLogging();
- }
+ __stopLogging();
}
#undef __LOCATION_ERROR_LOG
class LocationLogger : public ITimerListener, public IVisitListener {
public:
- LocationLogger(ILocationListener *listener = nullptr, bool testMode = false);
+ LocationLogger(ILocationListener *listener = nullptr);
~LocationLogger();
private:
void __broadcast(LocationEvent locationEvent);
/* INTERNAL */
- bool __testMode;
void __startLogging();
void __stopLogging();
void __locationRequest();
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;
}
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;
}
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");
}
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;
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");
}
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");
}
private:
bool __testMode;
- DatabaseManager __dbManager;
+ DatabaseManager *__dbManager;
double __doubleValueFromJson(Json &row, const char* key);
Categs __visitCategsFromJson(Json &row);
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)
{
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()
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");
}
__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;
}
{
_D("");
__setPeriod(energyMode);
- __wifiLogger.setMode(energyMode);
+ if (__wifiLogger) {
+ __wifiLogger->setMode(energyMode);
+ }
}
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;
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
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)),
__running(false)
{
_D("CONSTRUCTOR");
- if (testMode) {
- return;
- }
+
__setInterval(energyMode);
if (WIFI_LOGGER_DATABASE) {
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();
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;