mSinks.clear();
}
-void Core::setSupported(PropertyList supported, AbstractSource* source)
+void Core::registerSource(AbstractSource *source)
{
- if(!source)
- return;
-
- mSources[source->uuid()] = source;
-
- handleAddSupported(supported, source);
-
- /// tell all new sinks about the newly supported properties.
-
- for(auto itr = mSinks.begin(); itr != mSinks.end(); ++itr)
- {
- AbstractSink* s = (*itr);
- s->supportedChanged(this->supported());
- }
-
+ mSources.insert(source);
}
void Core::updateSupported(PropertyList added, PropertyList removed, AbstractSource* source)
{
- if(!source || mSources.find(source->uuid()) == mSources.end())
+ if(!source || mSources.find(source) == mSources.end())
return;
/// add the newly supported to master list
handleRemoveSupported(removed, source);
- /// tell all new sinks about the newly supported properties.
+ /// tell all sinks about the newly supported properties.
for(auto itr = mSinks.begin(); itr != mSinks.end(); ++itr)
{
- (*itr)->supportedChanged(supported());
+ AbstractSink* sink = *itr;
+ sink->supportedChanged(supported());
}
}
PropertyList Core::supported()
{
PropertyList supportedProperties;
- // TODO: should we care here about duplicates ?
- // (if multiple sources supports the same property ==> Property will be more than once in PropertyList)
+
transform(mMasterPropertyList.begin(), mMasterPropertyList.end(), back_inserter(supportedProperties),
[](const std::multimap<AbstractSource*, VehicleProperty::Property>::value_type& itr) { return itr.second; }
);
+
// remove duplicates:
supportedProperties.sort();
supportedProperties.unique();
- //DebugOut(1)<<__FUNCTION__<<"supported list: " << endl;
- //for_each(supportedProperties.begin(), supportedProperties.end(), [](const std::string& str){ DebugOut(1)<<__FUNCTION__<< str << endl; });
-
return supportedProperties;
}
for(auto itr = mSources.begin(); itr != mSources.end(); ++itr)
{
- AbstractSource* src = itr->second;
+ AbstractSource* src = *itr;
if(((src->supportedOperations() & AbstractSource::GetRanged) == AbstractSource::GetRanged))
{
src->getRangePropertyAsync(reply);
PropertyInfo Core::getPropertyInfo(VehicleProperty::Property property, string sourceUuid)
{
- auto srcIt = mSources.find(sourceUuid);
+ if(sourceUuid == "")
+ return PropertyInfo::invalid();
+
+ auto srcIt = find_if(mSources.begin(), mSources.end(),[&sourceUuid](const std::set<AbstractSource*>::value_type & itr)
+ {
+ return (itr)->uuid() == sourceUuid;
+ });
+
if(srcIt == mSources.end())
return PropertyInfo::invalid();
- return srcIt->second->getPropertyInfo(property);
+ return (*srcIt)->getPropertyInfo(property);
}
std::list<string> Core::sourcesForProperty(VehicleProperty::Property property)
return list;
}
+void Core::inspectSupported()
+{
+ for(AbstractSource* src : mSources)
+ {
+ updateSupported(src->supported(), PropertyList(), src);
+ }
+}
+
void Core::handleAddSupported(const PropertyList& added, AbstractSource* source)
{
if(!source)
- return;
+ throw std::runtime_error("Core::handleAddSupported passed a null source");
for(auto itr = added.begin(); itr != added.end(); ++itr)
{
);
}
else{
- auto itSource = mSources.find(sourceUuidFilter);
+ auto itSource = find_if(mSources.begin(),mSources.end(),[&sourceUuidFilter](const std::set<AbstractSource*>::value_type & it)
+ {
+ return (it)->uuid() == sourceUuidFilter;
+ });
if(itSource != mSources.end()){
- auto range = mMasterPropertyList.equal_range(itSource->second);
+ auto range = mMasterPropertyList.equal_range(*itSource);
auto temp = find_if(
range.first, // the first property in source
range.second, // one item right after the last property in source
~Core();
/// sources:
- void setSupported(PropertyList supported, AbstractSource* source);
+ void registerSource(AbstractSource *src);
void updateSupported(PropertyList added, PropertyList removed, AbstractSource* source);
void updateProperty(AbstractPropertyType* value, const std::string &uuid);
int firedPropertiesPerSecond;
};
+ void inspectSupported();
+
private:
void handleAddSupported(const PropertyList& added, AbstractSource* source);
std::multimap<AbstractSource*, VehicleProperty::Property> mMasterPropertyList;
// K = AbstractSource::uuid(), T = AbstractSource*
- std::unordered_map<std::string, AbstractSource*> mSources;
+ std::set<AbstractSource*> mSources;
std::set<AbstractSink*> mSinks;
Performance performance;
Core routingEngine;
PluginLoader loader(config, &routingEngine , argc, argv);
+
+ routingEngine.inspectSupported();
if(!loader.sources().size())
{
{
+ "mainloop" : "/usr/lib/automotive-message-broker/qtmainloopplugin.so",
"sources" : [
{
"name" : "OpenCV LUX",
"pixelUpperBound" : "255",
"device" : "0"
},
+ {
+ "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so"
+ }
],
"sinks": [
{
"interface" : "eth1",
"ssl" : "false",
"port" : "23000",
- "binaryProtocol" : "true",
+ "binaryProtocol" : "false",
"useExtensions" : "true"
}
]
"port" : "23000",
"ssl" : "false",
"ip" : "127.0.0.1",
- "binaryProtocol" : "true",
+ "binaryProtocol" : "false",
"useExtensions" : "true"
}
],
public:
virtual ~AbstractRoutingEngine();
- virtual void setSupported(PropertyList supported, AbstractSource* source) = 0;
+ virtual void registerSource(AbstractSource* src) = 0;
virtual void updateSupported(PropertyList added, PropertyList removed, AbstractSource* source) = 0;
AbstractSource::AbstractSource(AbstractRoutingEngine* engine, map<string, string> config)
: AbstractSink(engine,config), routingEngine(engine)
{
-
+ engine->registerSource(this);
}
AbstractSource::~AbstractSource()
*/
virtual PropertyInfo getPropertyInfo(VehicleProperty::Property property);
+ /*!
+ * \brief supported
+ * \return returns the supported properties.
+ */
+ virtual PropertyList supported() = 0;
protected:
/*!
PropertyInfo acInfo(0,acZones);
propertyInfoMap[VehicleProperty::AirConditioning] = acInfo;
-
- re->setSupported(supported(), this);
-
- PropertyList testSupported = re->supported();
-
- g_assert(contains(testSupported,VehicleProperty::MachineGunTurretStatus));
}
g_io_channel_set_close_on_unref(chan, true);
g_io_channel_unref(chan); //Pass ownership of the GIOChannel to the watch.
}
-
- re->setSupported(supported(), this);
}
GpsNmeaSource::~GpsNmeaSource()
OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> config)
:AbstractSource(re, config), lastLux(0), speed(0), latitude(0), longitude(0)
{
- re->setSupported(supported(), this);
- re->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
- re->subscribeToProperty(VehicleProperty::Latitude,this);
- re->subscribeToProperty(VehicleProperty::Longitude, this);
-
shared = new Shared;
shared->parent = this;
}
#endif
+ routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
+ routingEngine->subscribeToProperty(VehicleProperty::Latitude,this);
+ routingEngine->subscribeToProperty(VehicleProperty::Longitude, this);
+
}
}
}
+void OpenCvLuxPlugin::supportedChanged(PropertyList)
+{
+ DebugOut()<<"OpenCvLuxPlugin::supported changed."<<endl;
+}
+
static int grabImage(void *data)
{
OpenCvLuxPlugin::Shared* shared = static_cast<OpenCvLuxPlugin::Shared*>(data);
DebugOut()<<"we failed to open camera device ("<<device<<") or no camera found"<<endl;
return false;
}
- cv::Size s = cv::Size((int) shared->m_capture->get(CV_CAP_PROP_FRAME_WIDTH),
- (int) shared->m_capture->get(CV_CAP_PROP_FRAME_HEIGHT));
+ if(!shared->mWriter || !shared->mWriter->isOpened())
+ {
+ cv::Size s = cv::Size((int) shared->m_capture->get(CV_CAP_PROP_FRAME_WIDTH),
+ (int) shared->m_capture->get(CV_CAP_PROP_FRAME_HEIGHT));
- shared->mWriter = new cv::VideoWriter("/tmp/video.avi",CV_FOURCC('H','2','6','4'),30,s);
+ shared->mWriter = new cv::VideoWriter("/tmp/video.avi",CV_FOURCC('H','2','6','4'),30,s);
+ }
DebugOut()<<"camera frame width: "<<shared->m_capture->get(CV_CAP_PROP_FRAME_WIDTH)<<endl;
DebugOut()<<"camera frame height: "<<shared->m_capture->get(CV_CAP_PROP_FRAME_HEIGHT)<<endl;
return true;
}
+
+
void OpenCvLuxPlugin::writeVideoFrame(cv::Mat frame)
{
//if(speed > 0)
void propertyChanged(AbstractPropertyType* value);
- void supportedChanged(PropertyList) {}
+ void supportedChanged(PropertyList);
void updateProperty(uint lux);
private: /// methods:
bool init();
-
private:
uint speed;
uint latitude;
//
// CALL setSupported
//
- routingEngine->setSupported(m_supportedProperties, nullptr);// invalid input
+ routingEngine->updateSupported(m_supportedProperties, PropertyList(), nullptr);// invalid input
TEST(routingEngine->getPropertyInfo(TestProptertyName1, uuid()).isValid() == false);
// valid call
- routingEngine->setSupported(m_supportedProperties, this);// we are register as source from now
+ routingEngine->updateSupported(m_supportedProperties, PropertyList(), this);// we are register as source from now
TEST(routingEngine->getPropertyInfo(TestProptertyName1, uuid()).isValid() == true);
Zone::ZoneList zones(routingEngine->getPropertyInfo(TestProptertyName1, uuid()).zones());
context = libwebsocket_create_context(&info);
setConfiguration(config);
- re->setSupported(supported(), this);
//printf("websocketsource loaded!!!\n");
g_timeout_add(1000,checkTimeouts,this); //Do this once per second, check for functions that have timed out and reply with success = false;
WheelSourcePlugin::WheelSourcePlugin(AbstractRoutingEngine* re, map<string, string> config)
:AbstractSource(re, config)
{
- re->setSupported(supported(), this);
this->mWheel = new WheelPrivate(this, re);
}