for(SourceList::iterator itr = mSources.begin(); itr!=mSources.end(); itr++)
{
- auto supportedChangedCb = std::bind(&Core::supportedChanged,this, _1, _2);
+ auto supportedChangedCb = std::bind(&Core::supportedChanged, this, _1, _2);
(*itr)->setSupportedChangedCb(supportedChangedCb);
auto propChangedDb = std::bind(&Core::propertyChanged, this, _1, _2);
(*itr)->setPropertyChangedCb(propChangedDb);
}
+
+ for(SinkList::iterator itr = mSinks.begin(); itr != mSinks.end(); itr++)
+ {
+ auto setPropertyCb = std::bind(&Core::setProperty, this, _1, _2);
+ (*itr)->setSetPropertyCb(setPropertyCb);
+
+ auto subscribeToPropertyCb = std::bind(&Core::subscribeToProperty, this, _1, _2);
+ (*itr)->setSubcribeToPropertyCb(subscribeToPropertyCb);
+
+ auto unsubscribeToPropertyCb = std::bind(&Core::unsubscribeToProperty, this, _1, _2);
+ (*itr)->setUnsubscribeToPropertyCb(unsubscribeToPropertyCb);
+ }
}
void Core::supportedChanged(PropertyList added, PropertyList removed)
{
+ /// add the newly supported to master list
+
for(PropertyList::iterator itr = added.begin(); itr != added.end(); itr++)
{
- if(ListPlusPlus<VehicleProperty::Property>(added).contains(*itr))
+ if(ListPlusPlus<VehicleProperty::Property>(&added).contains(*itr))
{
mMasterPropertyList.push_back(*itr);
}
}
+ /// removed no longer supported properties from master list.
+
for(PropertyList::iterator itr = removed.begin(); itr != removed.end(); itr++)
{
- ListPlusPlus<VehicleProperty::Property>(removed).removeOne(*itr);
+ ListPlusPlus<VehicleProperty::Property>(&mMasterPropertyList).removeOne(*itr);
}
+ /// tell all new sinks about the newly supported properties.
+
+ for(SinkList::iterator itr = mSinks.begin(); itr != mSinks.end(); itr++)
+ {
+ (*itr)->setSupported(mMasterPropertyList);
+ }
+
+ /// iterate through subscribed properties and resubscribe. This catches newly supported properties in the process.
+
+ for(unordered_map<VehicleProperty::Property, SinkList>::iterator itr = propertySinkMap.begin(); itr != propertySinkMap.end(); itr++)
+ {
+ VehicleProperty::Property property = (*itr).first;
+
+ for(SourceList::iterator source = mSources.begin(); source != mSources.end(); source++)
+ {
+ PropertyList properties = (*source)->supported();
+
+ if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(property))
+ {
+ (*source)->subscribeToPropertyChanges(property);
+ }
+ }
+ }
}
void Core::propertyChanged(VehicleProperty::Property property, boost::any value)
}
+void Core::setProperty(VehicleProperty::Property , boost::any )
+{
+
+}
+
+void Core::subscribeToProperty(VehicleProperty::Property property, AbstractSink* self)
+{
+
+}
+
+void Core::unsubscribeToProperty(VehicleProperty::Property , AbstractSink* self)
+{
+
+}
+
+
#include "abstractsink.h"
#include "abstractsource.h"
+#include <unordered_map>
+
class Core
{
private: ///methods
void supportedChanged(PropertyList added, PropertyList removed);
-
void propertyChanged(VehicleProperty::Property property, boost::any value);
+
+ ///sinks:
+
+ void setProperty(VehicleProperty::Property, boost::any);
+ void subscribeToProperty(VehicleProperty::Property, AbstractSink* self);
+ void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self);
private:
PropertyList mMasterPropertyList;
SourceList mSources;
SinkList mSinks;
+
+ unordered_map<VehicleProperty::Property, SinkList> propertySinkMap;
};
void AbstractSink::subscribeToProperty(VehicleProperty::Property property)
{
- subscribeToPropertyCb(property);
+ subscribeToPropertyCb(property,this);
}
PropertyList AbstractSink::supported()
void AbstractSink::unsubscribeToProperty(VehicleProperty::Property property)
{
- unsubscribeToPropertyCb(property);
+ unsubscribeToPropertyCb(property, this);
}
void AbstractSinkManager::sinkCreated(AbstractSink* sink)
{
sinkRemovedCb(sink);
}
+
+void AbstractSink::setSetPropertyCb(SetPropertySignal cb)
+{
+ setPropertyCb = cb;
+}
+
+void AbstractSink::setSubcribeToPropertyCb(SubscriptionSignal cb)
+{
+ subscribeToPropertyCb = cb;
+}
+
+void AbstractSink::setUnsubscribeToPropertyCb(SubscriptionSignal cb)
+{
+ unsubscribeToPropertyCb = cb;
+}
{
public:
- ListPlusPlus(std::list<T> list)
+ ListPlusPlus(std::list<T> *list)
:mList(list)
{
void removeOne(T value)
{
- typename std::list<T>::iterator itr = std::find<T>(mList.begin(), mList.end(), value);
+ typename std::list<T>::iterator itr = std::find(mList->begin(), mList->end(), value);
- if (itr != mList.end())
+ if (itr != mList->end())
{
- mList.erase(itr);
+ mList->erase(itr);
}
}
bool contains(T value)
{
- return (std::find<T>(mList.begin(), mList.end(), value) != mList.end());
+ return (std::find(mList->begin(), mList->end(), value) != mList->end());
}
private:
- std::list<T> mList;
+ std::list<T> *mList;
};
#endif // LISTPLUSPLUS_H