2 #include <unordered_map>
3 #include <unordered_set>
4 #include <listplusplus.h>
5 #include <abstractsink.h>
6 #include <abstractroutingengine.h>
8 #include "varianttype.h"
10 #define DBusConnected "DBusConnected"
19 std::shared_ptr<GDBusConnection> connection;
21 std::unordered_map<std::string, std::unordered_set<Zone::Type>> getUniqueSourcesList(AbstractRoutingEngine *re, PropertyList implementedProperties)
23 std::unordered_map<std::string, std::unordered_set<Zone::Type>> uniqueSourcesList;
25 for(auto property : implementedProperties)
27 std::vector<std::string> sources = re->sourcesForProperty(property);
29 for(auto source : sources)
31 PropertyInfo info = re->getPropertyInfo(property, source);
33 std::unordered_set<Zone::Type> uniqueZoneList;
35 if(uniqueSourcesList.count(source))
37 uniqueZoneList = uniqueSourcesList[source];
40 Zone::ZoneList zoneList = info.zones();
44 uniqueZoneList.emplace(Zone::None);
47 for(auto zoneItr : zoneList)
49 uniqueZoneList.emplace(zoneItr);
52 uniqueSourcesList[source] = uniqueZoneList;
56 return uniqueSourcesList;
60 void exportProperty(std::string interfaceName, std::unordered_map<std::string, std::string> properties, AbstractRoutingEngine *re)
62 T* t = new T(interfaceName, re, connection.get());
64 std::string prop = t->objectName();
66 for(auto props : properties)
68 t->wantPropertyVariant(props.first, props.second, VariantType::ReadWrite);
71 PropertyList implementedProperties = t->wantsProperties();
73 std::unordered_map<std::string, std::unordered_set<Zone::Type> > uniqueSourcesList = getUniqueSourcesList(re, implementedProperties);
77 PropertyList supported = re->supported();
79 for(auto itr : uniqueSourcesList)
81 std::unordered_set<Zone::Type> zones = itr.second;
83 std::string source = itr.first;
85 std::string objectPath = "/" + source;
87 boost::algorithm::erase_all(objectPath, "-");
89 for(auto zone : zones)
91 T* t = new T(prop, re, connection.get());
93 for(auto props : properties)
95 t->wantPropertyVariant(props.first, props.second, VariantType::ReadWrite);
98 std::stringstream fullobjectPath;
99 fullobjectPath<< objectPath << "/" << zone << "/" <<t->objectName();
100 t->setObjectPath(fullobjectPath.str());
101 t->setSourceFilter(source);
102 t->setZoneFilter(zone);
103 t->supportedChanged(supported);
109 template <typename T>
110 void exportProperty(AbstractRoutingEngine *re)
112 exportProperty<T>("", std::unordered_map<std::string, std::string>(), re);
115 template <typename T>
116 void exportProperty(VehicleProperty::Property prop, AbstractRoutingEngine *re)
118 exportProperty<T>(prop, std::unordered_map<std::string, std::string>(), re);
121 static Exporter * instance()
125 return mInstance = new Exporter();
132 static Exporter* mInstance;