[my-place] Refactoring: Tizen C++ convention - File names chenge.
[platform/core/context/context-provider.git] / src / my-place / visit-detector / WifiLogger.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef _CONTEXT_PLACE_RECOGNITION_WIFI_LOGGER_H_
18 #define _CONTEXT_PLACE_RECOGNITION_WIFI_LOGGER_H_
19
20 #include <WifiWrapper.h>
21 #include <time.h>
22 #include <vector>
23 #include <map>
24 #include <TimerManager.h>
25 #include "WifiListenerIface.h"
26 #include "VisitListenerIface.h"
27 #include "../facade/UserPlacesParams.h"
28
29 /* Database usage flag */
30 #define WIFI_LOGGER_DATABASE false
31
32 /* Active scanning usage flag */
33 #define WIFI_LOGGER_ACTIVE_SCANNING true
34
35 /* Passive scanning usage flag */
36 #define WIFI_LOGGER_PASSIVE_SCANNING true
37
38 /* Active scanning minimum interval in seconds */
39 #define WIFI_LOGGER_ACTIVE_SCANNING_MIN_INTERVAL 10
40
41 /*
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)
45  */
46 #define WIFI_LOGGER_LOW_POWER_MODE false
47
48 namespace ctx {
49
50         class WifiLogger : public ITimerListener, public IVisitListener {
51
52         public:
53                 WifiLogger(IWifiListener * listener = nullptr,
54                                 PlaceRecogMode energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE);
55                 ~WifiLogger();
56
57                 void startLogging();
58                 void stopLogging();
59                 void setMode(PlaceRecogMode energyMode);
60
61         private:
62                 /* INPUT */
63                 void onVisitStart();
64                 void onVisitEnd();
65
66                 bool onTimerExpired(int timerId);
67
68                 /* TIMER */
69                 bool __timerOn;
70                 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();
78
79                 /* DATABASE */
80                 static int __dbCreateTable();
81                 int __dbInsertLogs();
82
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);
94
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);
100
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;
106                 bool __duringVisit;
107                 bool __connectedToWifiAp;
108                 bool __started;
109                 bool __running;
110
111                 void __startLogging();
112                 void __stopLogging();
113                 static const char* __wifiError2Str(int error);
114
115         };      /* class WifiLogger */
116
117 }       /* namespace ctx */
118
119 #endif /* End of _CONTEXT_PLACE_RECOGNITION_WIFI_LOGGER_H_ */