2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "abstractsink.h"
24 #include "abstractsource.h"
25 #include "abstractroutingengine.h"
26 #include "asyncqueue.hpp"
28 #include <unordered_map>
29 #include <unordered_set>
35 struct PropertyCompare
37 bool operator()(AbstractPropertyType* const & lhs, AbstractPropertyType* & rhs) const
39 if (lhs->name == rhs->name
40 && lhs->sourceUuid == rhs->sourceUuid
41 && lhs->zone == rhs->zone)
53 class Core: public AbstractRoutingEngine
57 Core(std::map<std::string, std::string> config);
61 void registerSource(AbstractSource *src);
62 void updateSupported(PropertyList added, PropertyList removed, AbstractSource* source);
63 void updateProperty(AbstractPropertyType* value, const std::string &uuid);
67 void registerSink(AbstractSink *self);
68 void unregisterSink(AbstractSink *self);
69 AsyncPropertyReply* getPropertyAsync(AsyncPropertyRequest request);
70 AsyncRangePropertyReply* getRangePropertyAsync(AsyncRangePropertyRequest request);
71 AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
72 uint subscribeToProperty(const VehicleProperty::Property &, AbstractRoutingEngine::PropertyChangedType, std::string pid="");
73 bool subscribeToProperty(const VehicleProperty::Property &, AbstractSink* self);
74 bool subscribeToProperty(const VehicleProperty::Property &, const std::string & sourceUuidFilter, AbstractSink *self);
75 bool subscribeToProperty(const VehicleProperty::Property &, const std::string & sourceUuidFilter, Zone::Type zoneFilter, AbstractSink *self);
76 bool unsubscribeToProperty(const VehicleProperty::Property &, AbstractSink* self);
77 void unsubscribeToProperty(uint handle);
78 PropertyList supported();
80 PropertyInfo getPropertyInfo(const VehicleProperty::Property &,const std::string &sourceUuid);
81 std::list<std::string> sourcesForProperty(VehicleProperty::Property property);
84 Performance(): propertiesPerSecond(0), firedPropertiesPerSecond(0) {}
85 int propertiesPerSecond;
86 int firedPropertiesPerSecond;
89 void inspectSupported();
93 void handleAddSupported(const PropertyList& added, AbstractSource* source);
94 void handleRemoveSupported(const PropertyList& removed, AbstractSource* source);
95 AbstractSource* sourceForProperty(const VehicleProperty::Property& property, const std::string& sourceUuidFilter = "") const;
96 void updateProperty(AbstractPropertyType* value);
100 //typedef std::map< Zone::Type, AbstractPropertyType> ZonePropertyType;
102 // to support zone filtering replace VehicleProperty::Property with ZonePropertyType
103 std::multimap<AbstractSource*, VehicleProperty::Property> mMasterPropertyList;
105 // K = AbstractSource::uuid(), T = AbstractSource*
106 std::unordered_set<AbstractSource*> mSources;
107 std::unordered_set<AbstractSink*> mSinks;
109 Performance performance;
111 // std::string here is AbstractSource::uuid()
112 typedef std::map<AbstractSink*, std::string> FilteredSourceSinkMap;
114 ///uint cbHandle, std::string uuid
115 typedef std::unordered_map<uint, std::string> FilteredSourceCbMap;
117 // to support zone filtering replace VehicleProperty::Property with ZonePropertyType
118 std::unordered_map<VehicleProperty::Property, FilteredSourceSinkMap > propertySinkMap;
119 std::unordered_map<VehicleProperty::Property, FilteredSourceCbMap> propertyCbMap;
120 std::unordered_map<uint, AbstractRoutingEngine::PropertyChangedType> handleCbMap;
122 amb::Queue<AbstractPropertyType*, amb::PropertyCompare> updatePropertyQueue;
123 amb::Queue<AbstractPropertyType*, amb::PropertyCompare> updatePropertyQueueHigh;
124 amb::Queue<AbstractPropertyType*, amb::PropertyCompare> updatePropertyQueueLow;
125 amb::AsyncQueueWatcher<AbstractPropertyType*, amb::PropertyCompare>* watcherPtr;
126 amb::AsyncQueueWatcher<AbstractPropertyType*, amb::PropertyCompare>* watcherPtrHigh;
127 amb::AsyncQueueWatcher<AbstractPropertyType*, amb::PropertyCompare>* watcherPtrLow;