Move .so namelinks to the devel package
[platform/core/context/context-provider.git] / src / my-place / visit-detector / VisitDetector.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_VISIT_DETECTOR_H_
18 #define _CONTEXT_PLACE_RECOGNITION_VISIT_DETECTOR_H_
19
20 #include <memory>
21 #include <vector>
22 #include <map>
23 #include <unordered_map>
24 #include <unordered_set>
25 #include <UserPlacesTypes.h>
26 #include <Json.h>
27 #include "VisitListenerIface.h"
28 #include "LocationLogger.h"
29 #include "LocationListenerIface.h"
30 #include "WifiListenerIface.h"
31 #include "WifiLogger.h"
32
33 namespace ctx {
34
35         class VisitDetector : public IWifiListener, ILocationListener {
36
37         private:
38                 bool __testMode;
39                 std::map<std::string, std::string> __wifiAPsMap;
40                 std::shared_ptr<Visits> __detectedVisits; // only used in test mode
41                 LocationLogger *__locationLogger;
42                 WifiLogger *__wifiLogger;
43                 std::vector<IVisitListener*> __listeners;
44                 std::shared_ptr<MacEvents> __currentMacEvents;
45                 Interval __currentInterval;
46                 std::vector<LocationEvent> __locationEvents;
47                 std::vector<std::shared_ptr<Frame>> __historyFrames;  // python: history_scans  + history_times
48                 std::vector<std::shared_ptr<Frame>> __bufferedFrames; // python: buffered_scans + buffered_times
49                 int __stableCounter;
50                 int __tolerance;
51                 bool __entranceToPlace;
52                 int __periodSeconds;
53
54                 // fields that  are used only in case of entrance detection
55                 std::shared_ptr<MacSet> __representativesMacs; // macs that represent the current place
56                 std::shared_ptr<MacSet> __stayMacs; // macs that can appear in the current place
57                 time_t __entranceTime;
58                 time_t __departureTime;
59
60                 bool __isValid(const Mac &mac);
61                 void __shiftCurrentInterval();
62                 void __detectEntranceOrDeparture(std::shared_ptr<Frame> frame);
63                 void __detectEntrance(std::shared_ptr<Frame> frame);
64                 void __detectDeparture(std::shared_ptr<Frame> frame);
65                 void __processBuffer(std::shared_ptr<Frame> frame); // python: buffer_analysing
66                 std::shared_ptr<Frame> __makeFrame(std::shared_ptr<MacEvents> macEvents, Interval interval);  // python: scans2fingerprint
67                 void __resetHistory();
68                 void __resetHistory(std::shared_ptr<Frame> frame);
69                 void __visitStartDetected();
70                 void __visitEndDetected();
71                 void __putLocationToVisit(Visit &visit);
72                 std::shared_ptr<MacSet> __selectRepresentatives(const std::vector<std::shared_ptr<Frame>> &frames);
73                 std::shared_ptr<MacSet> __macSetOfGreaterOrEqualShare(const Macs2Shares &macs2Shares, share_t threshold);
74                 std::shared_ptr<Macs2Shares> __macSharesFromCounts(Macs2Counts const &macs2Counts, count_t denominator); // python: response_rate
75                 share_t __calcMaxShare(const Macs2Shares &macs2Shares);
76                 bool __isDisjoint(const Macs2Counts &macs2Counts, const MacSet &macSet);
77                 bool __protrudesFrom(const Macs2Counts &macs2Counts, const MacSet &macSet);
78                 void __setPeriod(PlaceRecogMode mode);
79                 void __processCurrentLogger();
80                 std::shared_ptr<Visits> __getVisits();
81
82                 /* DATABASE */
83                 void __dbCreateTables();
84                 int __dbInsertVisit(Visit visit);
85                 int __dbInsertWifiAPsMap(Visit visit);
86                 void __putVisitCategToJson(const char* key, const Categs &categs, int categType, Json &data);
87                 void __putVisitCategsToJson(const Categs &categs, Json &data);
88
89                 /* INPUT */
90                 void onWifiScan(MacEvent event);
91                 void onNewLocation(LocationEvent location);
92
93                 void __categorize(Visit &visit);
94
95                 VisitDetector(const VisitDetector&) = delete;
96                 VisitDetector& operator=(const VisitDetector&) = delete;
97
98         public:
99                 VisitDetector(time_t startScan, PlaceRecogMode energyMode = PLACE_RECOG_HIGH_ACCURACY_MODE, bool testMode = false);
100                 ~VisitDetector();
101
102                 void setMode(PlaceRecogMode energyMode);
103
104         };      /* class VisitDetector */
105
106 }       /* namespace ctx */
107
108 #endif /* End of _CONTEXT_PLACE_RECOGNITION_VISIT_DETECTOR_H_ */