libosmscout 1.1.1
Loading...
Searching...
No Matches
DataAgent.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_NAVIGATION_DATA_AGENT_H
2#define OSMSCOUT_NAVIGATION_DATA_AGENT_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2018 Lukas Karas
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
25
26#include <list>
27
28namespace osmscout {
29
31 {
33 std::map<FileOffset,WayRef> ways;
34 std::map<FileOffset,AreaRef> areas;
35 };
36
38 {
39 std::map<DatabaseId, RoutableDBObjects> dbMap;
40 GeoBox bbox;
41
43
44 WayRef GetWay(const DatabaseId &dbId, const ObjectFileRef &objRef) const;
45
46 AreaRef GetArea(const DatabaseId &dbId, const ObjectFileRef &areaRef) const;
47 };
48
49 using RoutableObjectsRef=std::shared_ptr<RoutableObjects>;
50
51 struct OSMSCOUT_API RoutableObjectsRequestMessage CLASS_FINAL : public NavigationMessage
52 {
54
56 };
57
61 struct OSMSCOUT_API RoutableObjectsMessage CLASS_FINAL : public NavigationMessage
62 {
64
66 };
67
68 using RoutableObjectsMessageRef=std::shared_ptr<RoutableObjectsMessage>;
69
70 template <typename DataLoader>
71 class DataAgent CLASS_FINAL : public NavigationAgent
72 {
73 private:
74 std::map<std::string,DatabaseId> databaseMapping;
76 DataLoader &dataLoader;
77
78 public:
79 explicit DataAgent(DataLoader &mapServiceProvider):
80 dataLoader(mapServiceProvider)
81 {
82
83 }
84
85 std::list<NavigationMessageRef> Process(const NavigationMessageRef& message) override
86 {
87 auto result=std::list<NavigationMessageRef>();
88
89 if (auto* routeUpdateMessage = dynamic_cast<RouteUpdateMessage *>(message.get());
90 routeUpdateMessage != nullptr) {
91
92 databaseMapping.clear();
93 // build reverse mapping
94 for (auto &e:routeUpdateMessage->routeDescription->GetDatabaseMapping()){
95 databaseMapping[e.second]=e.first;
96 }
97 vehicle=routeUpdateMessage->vehicle;
98 } else if (auto* requestMessage = dynamic_cast<RoutableObjectsRequestMessage*>(message.get());
99 requestMessage != nullptr) {
100
101 if (databaseMapping.empty()){
102 return result; // no route yet
103 }
104
105 if (GetSphericalDistance(requestMessage->bbox.GetMinCoord(),
106 requestMessage->bbox.GetMaxCoord()) > Kilometers(2)){
107 log.Warn() << "Requested routable data from huge region: " << requestMessage->bbox.GetDisplayText();
108 }
109
110 auto msg=std::make_shared<RoutableObjectsMessage>(requestMessage->timestamp, std::make_shared<RoutableObjects>());
111
112 dataLoader.loadRoutableObjects(requestMessage->bbox,
113 vehicle,
114 databaseMapping,
115 msg->data);
116
117 // TODO: load all route objects too
118
119 result.push_back(msg);
120 }
121 return result;
122 }
123 };
124
125}
126#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
RoutableObjectsRequestMessage(const Timestamp &timestamp, const GeoBox &bbox)
RouteUpdateMessage(const Timestamp &timestamp, const RouteDescriptionRef &routeDescription, const osmscout::Vehicle &vehicle)
DataAgent(DataLoader &mapServiceProvider)
Definition DataAgent.h:79
RoutableObjectsMessage(const Timestamp &timestamp, const RoutableObjectsRef &data)
std::list< NavigationMessageRef > Process(const NavigationMessageRef &message) override
Definition DataAgent.h:85
std::vector< VoiceSample > message
Definition VoiceInstructionAgent.h:99
GeoBox bbox
Precomputed (cache) bounding box.
Definition DataAgent.h:53
RoutableObjectsRef data
Definition DataAgent.h:63
osmscout::Vehicle vehicle
Definition Agents.h:87
Definition Engine.h:79
OSMSCOUT_API Distance GetSphericalDistance(const GeoCoord &a, const GeoCoord &b)
OSMSCOUT_API Log log
Definition LoggerImpl.h:95
std::shared_ptr< TypeConfig > TypeConfigRef
Definition TypeConfig.h:1396
Definition Area.h:39
std::shared_ptr< Way > WayRef
Definition Way.h:213
std::chrono::system_clock::time_point Timestamp
Definition Time.h:27
std::shared_ptr< Area > AreaRef
Definition Area.h:360
Distance Kilometers(double km)
Definition Distance.h:362
uint32_t DatabaseId
Definition DBFileOffset.h:30
std::shared_ptr< RoutableObjects > RoutableObjectsRef
Definition DataAgent.h:49
Vehicle
Definition OSMScoutTypes.h:55
@ vehicleCar
Definition OSMScoutTypes.h:58
std::shared_ptr< RoutableObjectsMessage > RoutableObjectsMessageRef
Definition DataAgent.h:68
std::shared_ptr< NavigationMessage > NavigationMessageRef
Definition Engine.h:56
Definition Engine.h:49
const Timestamp timestamp
Definition Engine.h:50
Definition DataAgent.h:31
std::map< FileOffset, AreaRef > areas
Definition DataAgent.h:34
std::map< FileOffset, WayRef > ways
Definition DataAgent.h:33
TypeConfigRef typeConfig
Definition DataAgent.h:32
Definition DataAgent.h:38
WayRef GetWay(const DatabaseId &dbId, const ObjectFileRef &objRef) const
GeoBox bbox
Definition DataAgent.h:40
TypeConfigRef GetTypeConfig(const DatabaseId &dbId) const
AreaRef GetArea(const DatabaseId &dbId, const ObjectFileRef &areaRef) const
std::map< DatabaseId, RoutableDBObjects > dbMap
Definition DataAgent.h:39