2 #include <unordered_map>
3 #include <unordered_set>
4 #include <listplusplus.h>
5 #include <abstractsink.h>
6 #include <abstractroutingengine.h>
11 std::unordered_map<std::string, std::unordered_set<Zone::Type>> getUniqueSourcesList(AbstractRoutingEngine *re, PropertyList implementedProperties)
13 std::unordered_map<std::string, std::unordered_set<Zone::Type>> uniqueSourcesList;
15 for(auto property : implementedProperties)
17 std::vector<std::string> sources = re->sourcesForProperty(property);
19 for(auto source : sources)
21 PropertyInfo info = re->getPropertyInfo(property, source);
23 std::unordered_set<Zone::Type> uniqueZoneList;
25 if(uniqueSourcesList.count(source))
27 uniqueZoneList = uniqueSourcesList[source];
30 Zone::ZoneList zoneList = info.zones();
34 uniqueZoneList.emplace(Zone::None);
37 for(auto zoneItr : zoneList)
39 uniqueZoneList.emplace(zoneItr);
42 uniqueSourcesList[source] = uniqueZoneList;
46 return uniqueSourcesList;
50 void exportProperty(VehicleProperty::Property prop, AbstractRoutingEngine *re, GDBusConnection *connection)
52 T* t = new T(prop, re, connection);
54 prop = t->objectName();
56 /// check if we need more than one instance:
58 PropertyList implementedProperties = t->wantsProperties();
60 std::unordered_map<std::string, std::unordered_set<Zone::Type> > uniqueSourcesList = getUniqueSourcesList(re, implementedProperties);
64 PropertyList supported = re->supported();
66 for(auto itr : uniqueSourcesList)
68 std::unordered_set<Zone::Type> zones = itr.second;
70 std::string source = itr.first;
72 std::string objectPath = "/" + source;
74 boost::algorithm::erase_all(objectPath, "-");
76 for(auto zone : zones)
78 T* t = new T(prop, re, connection);
79 std::stringstream fullobjectPath;
80 fullobjectPath<< objectPath << "/" << zone << "/" <<t->objectName();
81 t->setObjectPath(fullobjectPath.str());
82 t->setSourceFilter(source);
83 t->setZoneFilter(zone);
84 t->supportedChanged(supported);
91 void exportProperty(AbstractRoutingEngine *re, GDBusConnection *connection)
93 exportProperty<T>("", re, connection);