hardcoded so files path fix
[platform/core/context/context-provider.git] / src / my-place / facade / UserPlacesTypes.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_USER_PLACES_TYPES_H_
18 #define _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_
19
20 #include <memory>
21 #include <vector>
22 #include <map>
23 #include <unordered_map>
24 #include <unordered_set>
25 #include <string>
26 #include <ctime>
27 #include <MyPlaceTypes.h>
28
29 // Database
30 #define VISIT_TABLE                            "Log_Myplace_Visit"
31 #define VISIT_COLUMN_START_TIME                "start_time"
32 #define VISIT_COLUMN_END_TIME                  "end_time"
33 #define VISIT_COLUMN_WIFI_APS                  "wifi_aps"
34 #define VISIT_COLUMN_CATEGORY                  "category"
35 #ifdef TIZEN_ENGINEER_MODE
36 #define VISIT_COLUMN_START_TIME_HUMAN          "start_time_human" // only for debug: human readable time data:
37 #define VISIT_COLUMN_END_TIME_HUMAN            "end_time_human" // only for debug: human readable time data:
38 #endif /* TIZEN_ENGINEER_MODE */
39 #define VISIT_COLUMN_LOCATION_VALID            "location_valid"
40 #define VISIT_COLUMN_LOCATION_LATITUDE         "location_latitude"
41 #define VISIT_COLUMN_LOCATION_LONGITUDE        "location_longitude"
42 #define VISIT_COLUMN_LOCATION_ACCURACY         "location_accuracy"
43 #define VISIT_COLUMN_CATEG_HOME                "categ_home"
44 #define VISIT_COLUMN_CATEG_WORK                "categ_work"
45 #define VISIT_COLUMN_CATEG_OTHER               "categ_other"
46
47 #define WIFI_APS_MAP_TABLE                     "Log_Myplace_WifiAPsMap"
48 #define WIFI_APS_MAP_COLUMN_MAC                "mac"
49 #define WIFI_APS_MAP_COLUMN_NETWORK_NAME       "network_name"
50 #define WIFI_APS_MAP_COLUMN_INSERT_TIME        "insert_time"
51
52 #define PLACE_TABLE                            "Log_Myplace_Place"
53 #define PLACE_COLUMN_CATEG_ID                  "categ_id"
54 #define PLACE_COLUMN_CATEG_CONFIDENCE          "categ_confidence"
55 #define PLACE_COLUMN_NAME                      "name"
56 #define PLACE_COLUMN_LOCATION_VALID            "location_valid"
57 #define PLACE_COLUMN_LOCATION_LATITUDE         "location_latitude"
58 #define PLACE_COLUMN_LOCATION_LONGITUDE        "location_longitude"
59 #define PLACE_COLUMN_LOCATION_ACCURACY         "location_accuracy"
60 #define PLACE_COLUMN_WIFI_APS                  "wifi_aps"
61 #define PLACE_COLUMN_CREATE_DATE               "create_date"
62
63 #define WIFI_TABLE                             "Log_Myplace_Wifi"
64 #define WIFI_COLUMN_TIMESTAMP                  "timestamp"
65 #define WIFI_COLUMN_BSSID                      "bssid"
66 #define WIFI_COLUMN_ESSID                      "essid"
67
68 #define LOCATION_TABLE                         "Log_Myplace_Location"
69 #define LOCATION_COLUMN_LATITUDE               "latitude"
70 #define LOCATION_COLUMN_LONGITUDE              "longitude"
71 #define LOCATION_COLUMN_ACCURACY               "accuracy"
72 #define LOCATION_COLUMN_TIMESTAMP              "timestamp"
73 #ifdef TIZEN_ENGINEER_MODE
74 #define LOCATION_COLUMN_TIMESTAMP_HUMAN        "time_human" // only for debug: human readable time data:
75 #define LOCATION_COLUMN_METHOD                 "method"
76 #endif /* TIZEN_ENGINEER_MODE */
77
78 #define MYPLACE_SETTINGS_TABLE                 "Myplace_Settings"
79 #define MYPLACE_SETTINGS_COLUMN_KEY            "key"
80 #define MYPLACE_SETTINGS_COLUMN_VALUE          "value"
81 #define MYPLACE_SETTING_KEY_USER_CONSENT       PLACE_DETECTION_REQUEST_CONSENT
82
83 enum PlaceRecogMode {
84         PLACE_RECOG_HIGH_ACCURACY_MODE = 0,
85         PLACE_RECOG_LOW_POWER_MODE = 1
86 };
87
88 namespace ctx {
89
90         /*
91          * type for numerical computations
92          */
93         typedef double num_t;
94
95         /*
96          * mac address
97          */
98         class Mac {
99
100         public:
101                 const static size_t MAC_SIZE = 6;  // number of bytes for mac address.
102                 unsigned char c[MAC_SIZE];
103
104                 Mac() {};
105                 Mac(const std::string &str);
106                 Mac(const char *str);
107                 operator std::string() const;
108
109         };      /* class Mac */
110
111         std::istream &operator>>(std::istream &input, ctx::Mac &mac);
112         std::ostream &operator<<(std::ostream &output, const ctx::Mac &mac);
113         bool operator==(const ctx::Mac &m1, const ctx::Mac &m2);
114         bool operator!=(const ctx::Mac &m1, const ctx::Mac &m2);
115         bool operator<(const ctx::Mac &m1, const ctx::Mac &m2);
116         bool operator>(const ctx::Mac &m1, const ctx::Mac &m2);
117
118 }       /* namespace ctx */
119
120 namespace std {
121
122         template <> struct hash<ctx::Mac> {
123                 size_t operator()(const ctx::Mac & m) const {
124                         size_t h = 1;
125                         for (size_t i = 0; i < ctx::Mac::MAC_SIZE; i++) {
126                                 h = h * 37 + m.c[i];
127                         }
128                         return h;
129                 }
130         };
131
132 }       /* namespace std */
133
134 namespace ctx {
135
136         typedef float share_t;
137         typedef int count_t;
138
139         typedef std::unordered_map<ctx::Mac, ctx::count_t> Macs2Counts;
140         typedef std::unordered_map<ctx::Mac, ctx::share_t> Macs2Shares;
141
142         typedef std::unordered_set<ctx::Mac> MacSet;
143
144         std::istream &operator>>(std::istream &input, ctx::MacSet &macSet);
145         std::ostream &operator<<(std::ostream &output, const ctx::MacSet &macSet);
146         ctx::MacSet macSetFromString(const std::string &str);
147
148         std::shared_ptr<MacSet> macSetsUnion(const std::vector<std::shared_ptr<MacSet>> &macSets);
149
150         struct Interval {
151                 time_t start;
152                 time_t end;
153
154                 Interval(time_t start, time_t end);
155         };
156
157 }       /* namespace ctx */
158
159 namespace std {
160
161         template <> struct hash<ctx::Interval> {
162                 size_t operator()(const ctx::Interval & interval) const {
163                         return interval.end * interval.start;
164                 }
165         };
166
167 }       /* namespace std */
168
169 namespace ctx {
170
171         /*
172          * fully describes interval data after the interval is finished
173          */
174         struct Frame {
175                 Interval interval;
176                 count_t numberOfTimestamps;
177                 Macs2Counts macs2Counts;
178
179                 Frame(Interval interval_) : interval(interval_), numberOfTimestamps(0) {};
180         };
181
182         /*
183          * mac address + its timestamp
184          */
185         struct MacEvent {
186                 time_t timestamp;
187                 Mac mac;
188                 std::string networkName;
189
190                 MacEvent(time_t timestamp_, Mac mac_, std::string networkName_ = "")
191                         : timestamp(timestamp_)
192                         , mac(mac_)
193                         , networkName(networkName_) {}
194         };
195
196         typedef std::map<int, num_t> Categs; // scores of categories
197
198 #ifdef TIZEN_ENGINEER_MODE
199         enum LocationSource {
200                 LOCATION_METHOD_REQUEST = 0,
201                 LOCATION_METHOD_GET_LOCATION = 1,
202                 LOCATION_METHOD_GET_LAST_LOCATION = 2
203         };
204 #endif /* TIZEN_ENGINEER_MODE */
205
206         /*
207          * location + timestamp + method
208          */
209         struct LocationEvent {
210                 Location coordinates;
211                 time_t timestamp;
212
213 #ifdef TIZEN_ENGINEER_MODE
214                 LocationSource method;
215
216                 LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_, LocationSource method_) :
217                         coordinates(latitude_, longitude_, accuracy_),
218                         timestamp(timestamp_), method(method_) {}
219 #else /* TIZEN_ENGINEER_MODE */
220                 LocationEvent(double latitude_, double longitude_, double accuracy_, time_t timestamp_) :
221                         coordinates(latitude_, longitude_, accuracy_),
222                         timestamp(timestamp_) {}
223 #endif /* TIZEN_ENGINEER_MODE */
224
225                 void log();
226
227         };      /* struct LocationEvent */
228
229         struct Visit {
230                 Interval interval;
231                 std::shared_ptr<MacSet> macSet;
232                 Categs categs;
233                 bool locationValid;
234                 Location location; // makes sense if locationValid == true;
235
236                 Visit(Interval interval_, std::shared_ptr<MacSet> macSet_ = std::make_shared<MacSet>(), Categs categs_ = Categs()) :
237                         interval(interval_),
238                         macSet(macSet_),
239                         categs(categs_),
240                         locationValid(false) {}
241                 void setLocation(Location location);
242                 void printShort2Stream(std::ostream &out) const;
243
244         };      /* struct Visit */
245
246         bool operator==(const Visit &v1, const Visit &v2);
247         typedef std::vector<Visit> Visits;
248         typedef std::vector<MacEvent> MacEvents; // used to store current interval logs
249
250         std::shared_ptr<MacSet> macSetFromMacs2Counts(const Macs2Counts &macs2Counts);
251
252 }       /* namespace ctx */
253
254 #endif /* End of _CONTEXT_PLACE_RECOGNITION_USER_PLACES_TYPES_H_ */