2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef _CONTEXT_PLACE_RECOGNITION_WIFI_LOGGER_H_
18 #define _CONTEXT_PLACE_RECOGNITION_WIFI_LOGGER_H_
20 #include <WifiWrapper.h>
24 #include <TimerManager.h>
25 #include "WifiListenerIface.h"
26 #include "VisitListenerIface.h"
27 #include "../facade/UserPlacesParams.h"
29 /* Database usage flag */
30 #define WIFI_LOGGER_DATABASE false
32 /* Active scanning usage flag */
33 #define WIFI_LOGGER_ACTIVE_SCANNING true
35 /* Passive scanning usage flag */
36 #define WIFI_LOGGER_PASSIVE_SCANNING true
38 /* Active scanning minimum interval in seconds */
39 #define WIFI_LOGGER_ACTIVE_SCANNING_MIN_INTERVAL 10
42 * Low power scanning usage flag
43 * (When phone is connected to some WiFi Access Point
44 * last scan data is returned instead of new scan triggering)
46 #define WIFI_LOGGER_LOW_POWER_MODE false
50 class WifiLogger : public ITimerListener, public IVisitListener {
53 WifiLogger(IWifiListener * listener = nullptr,
54 PlaceRecogMode energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE);
59 void setMode(PlaceRecogMode energyMode);
66 bool onTimerExpired(int timerId);
71 int __intervalMinutes;
72 TimerManager __timerManager;
73 void __setInterval(PlaceRecogMode energyMode);
74 bool __checkTimerId(int id);
75 bool __checkTimerTime(time_t now);
76 void __timerStart(time_t minutes);
77 void __timerRestart();
80 static int __dbCreateTable();
83 /* SYSTEM CAPI WRAPPERS */
84 WifiWrapper __wifiWrapper;
85 void __wifiSetBackgroundScanCbRequest();
86 void __wifiSetDeviceStateChangedCbRequest();
87 void __wifiSetConnectionStateChangedCbRequest();
88 bool __checkWifiIsActivated();
89 void __wifiScanRequest();
90 int __wifiForeachFoundApsRequest(void *userData);
91 wifi_connection_state_e __wifiGetConnectionStateRequest();
92 int __wifiApGetEssidRequest(wifi_ap_h ap, char **essid);
93 int __wifiApGetBssidRequest(wifi_ap_h ap, char **bssid);
95 /* SYSTEM CAPI CALLBACKS */
96 static void __wifiDeviceStateChangedCb(wifi_device_state_e state, void *userData);
97 static void __wifiConnectionStateChangedCb(wifi_connection_state_e state, wifi_ap_h ap, void *userData);
98 static bool __wifiFoundApCb(wifi_ap_h ap, void *userData);
99 static void __wifiScanFinishedCb(wifi_error_e errorCode, void *userData);
101 IWifiListener * const __listener;
102 std::vector<MacEvent> __logs;
103 std::map<std::string, std::string> __lastScansPool; // Mac address to network name map
104 time_t __lastScanTime;
105 time_t __lasTimerCallbackTime;
107 bool __connectedToWifiAp;
111 void __startLogging();
112 void __stopLogging();
113 static const char* __wifiError2Str(int error);
115 }; /* class WifiLogger */
117 } /* namespace ctx */
119 #endif /* End of _CONTEXT_PLACE_RECOGNITION_WIFI_LOGGER_H_ */