diff options
author | Kevron Rees <kevron.m.rees@intel.com> | 2014-12-16 17:33:52 -0800 |
---|---|---|
committer | Kevron Rees <kevron.m.rees@intel.com> | 2014-12-16 17:33:52 -0800 |
commit | 77274226710de3b6cc4dc280e4648b24adccbc33 (patch) | |
tree | ad80bdaba809df22f3d25dc259858b48933b1695 | |
parent | e9e8281a67c5e2488db581abfc5e1972a9da0c72 (diff) | |
download | automotive-message-broker-77274226710de3b6cc4dc280e4648b24adccbc33.tar.gz |
fixed issue where database plugin was not properly exporting zones for supported properties
-rw-r--r-- | ambd/main.cpp | 8 | ||||
-rw-r--r-- | examples/CMakeLists.txt | 1 | ||||
-rw-r--r-- | examples/databaseconfig.in | 28 | ||||
-rw-r--r-- | lib/abstractsource.cpp | 25 | ||||
-rw-r--r-- | lib/debugout.h | 11 | ||||
-rw-r--r-- | plugins/bluemonkey/bluemonkey.cpp | 3 | ||||
-rw-r--r-- | plugins/common/bluetooth5.cpp | 2 | ||||
-rw-r--r-- | plugins/database/CMakeLists.txt | 4 | ||||
-rw-r--r-- | plugins/database/databasesink.cpp | 53 | ||||
-rw-r--r-- | plugins/database/databasesink.h | 25 | ||||
-rw-r--r-- | plugins/dbus/CMakeLists.txt | 2 | ||||
-rw-r--r-- | plugins/dbus/abstractdbusinterface.cpp | 25 | ||||
-rw-r--r-- | plugins/dbus/abstractdbusinterface.h | 2 | ||||
-rw-r--r-- | plugins/dbus/automotivemanager.cpp | 18 |
14 files changed, 92 insertions, 115 deletions
diff --git a/ambd/main.cpp b/ambd/main.cpp index f6f1b407..58a8abde 100644 --- a/ambd/main.cpp +++ b/ambd/main.cpp @@ -155,7 +155,7 @@ int main(int argc, char **argv) if(getuid() == 0) { - DebugOut(DebugOut::Error)<<"Running as root. This is dangerous."<<endl; + DebugOut(DebugOut::Warning)<<"Running as root. This is dangerous."<<endl; } #ifndef GLIB_VERSION_2_36 @@ -207,9 +207,9 @@ void daemonize() close(i); // close all descriptors } { // handle standard I/O - i = open("/dev/null", O_RDWR); - dup(i); - dup(i); + i = open("/dev/null", O_RDWR); + dup(i); + dup(i); } // first instance continues } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 28ff5a33..4313156e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,7 +4,6 @@ set(amb_examples configwheel databaseconfig databasesource dbusconfig examplecon configure_file (${CMAKE_CURRENT_SOURCE_DIR}/configwheel.in ${CMAKE_CURRENT_SOURCE_DIR}/configwheel @ONLY) -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/databaseconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/databaseconfig @ONLY) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/databasesource.in ${CMAKE_CURRENT_SOURCE_DIR}/databasesource @ONLY) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/dbusconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/dbusconfig @ONLY) configure_file (${CMAKE_CURRENT_SOURCE_DIR}/exampleconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/exampleconfig @ONLY) diff --git a/examples/databaseconfig.in b/examples/databaseconfig.in deleted file mode 100644 index 577c82ee..00000000 --- a/examples/databaseconfig.in +++ /dev/null @@ -1,28 +0,0 @@ -{ - "sources" : [ - { - "name" : "ExampleSouce", - "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so" - } - ], - "sinks": [ - { - "name" : "Database", - "path" : "@PLUGIN_INSTALL_PATH@/databasesinkplugin.so", - "properties" : "{ 'properties' : ['VehicleSpeed','EngineSpeed'] }", - "databaseFile" : "/tmp/storage", - "startOnLoad" : "true", - "bufferLength" : "1", - "frequency" : "1" - }, - { - "name" : "Example Sink", - "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so" - }, - { - "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so" - } - - ] -} - diff --git a/lib/abstractsource.cpp b/lib/abstractsource.cpp index 26fc07c8..db804fa1 100644 --- a/lib/abstractsource.cpp +++ b/lib/abstractsource.cpp @@ -1,19 +1,19 @@ /* - Copyright (C) 2012 Intel Corporation + Copyright (C) 2012 Intel Corporation - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -33,6 +33,7 @@ AbstractSource::~AbstractSource() PropertyInfo AbstractSource::getPropertyInfo(const VehicleProperty::Property & property) { + DebugOut(DebugOut::Error) << "getPropertyInfo is not implemented in this source plugin." << endl; return PropertyInfo::invalid(); } diff --git a/lib/debugout.h b/lib/debugout.h index 4644ef73..b8030ee9 100644 --- a/lib/debugout.h +++ b/lib/debugout.h @@ -30,11 +30,18 @@ using namespace std; void debugOut(const string &message); -class DebugOut +class DebugOut { public: + /*! + * \brief Error use when essential functionality is blocked + */ static const int Error; + + /*! + * \brief Warning use when non-essential functionality is bocked, or when workarounds exist. + */ static const int Warning; DebugOut(int debugLevel = 4) @@ -85,7 +92,7 @@ public: } return *this; } - + DebugOut const & operator << (double val) const { if(mDebugLevel <= debugThreshhold || mDebugLevel == Error || mDebugLevel == Warning) diff --git a/plugins/bluemonkey/bluemonkey.cpp b/plugins/bluemonkey/bluemonkey.cpp index 38d39a6d..b8c98168 100644 --- a/plugins/bluemonkey/bluemonkey.cpp +++ b/plugins/bluemonkey/bluemonkey.cpp @@ -127,7 +127,8 @@ AbstractPropertyType* qVariantToAbstractPropertyType(QString name, QVariant var) return nullptr; } -BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map<string, string> config, AbstractSource &parent): QObject(0), AmbPluginImpl(e, config, parent), engine(nullptr), mSilentMode(false) +BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map<string, string> config, AbstractSource &parent) + : QObject(0), AmbPluginImpl(e, config, parent), engine(nullptr), mSilentMode(false) { QTimer::singleShot(1,this,SLOT(reloadEngine())); diff --git a/plugins/common/bluetooth5.cpp b/plugins/common/bluetooth5.cpp index 06f0e0f1..f836b422 100644 --- a/plugins/common/bluetooth5.cpp +++ b/plugins/common/bluetooth5.cpp @@ -331,7 +331,7 @@ void Bluetooth5::connect(ConnectedCallback onconnectedCallback) if(errorPtr) { - DebugOut(DebugOut::Error) << "error trying to connect profile: " << errorPtr->message << endl; + DebugOut(DebugOut::Warning) << "error trying to connect profile: " << errorPtr->message << endl; } }, this); diff --git a/plugins/database/CMakeLists.txt b/plugins/database/CMakeLists.txt index 3db25adb..4d94b89c 100644 --- a/plugins/database/CMakeLists.txt +++ b/plugins/database/CMakeLists.txt @@ -4,13 +4,13 @@ include(CheckIncludeFiles) pkg_check_modules(sqlite REQUIRED sqlite3) -include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${sqlite_INCLUDE_DIRS}) +include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${sqlite_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/plugins/common) set(databasesinkplugin_headers databasesink.h utils.h basedb.hpp baseobject.h sqlitedatabase.h sqlitequery.h) set(databasesinkplugin_sources databasesink.cpp utils.cpp sqlitedatabase.cpp sqlitequery.cpp basedb.hpp) add_library(databasesinkplugin MODULE ${databasesinkplugin_sources}) set_target_properties(databasesinkplugin PROPERTIES PREFIX "") -target_link_libraries(databasesinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${sqlite_LIBRARIES}) +target_link_libraries(databasesinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${sqlite_LIBRARIES} amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common) install(TARGETS databasesinkplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) diff --git a/plugins/database/databasesink.cpp b/plugins/database/databasesink.cpp index 75d7033e..f53a174b 100644 --- a/plugins/database/databasesink.cpp +++ b/plugins/database/databasesink.cpp @@ -3,15 +3,19 @@ #include "listplusplus.h" #include "superptr.hpp" #include "uuidhelper.h" +#include "ambplugin.h" #include <thread> int bufferLength = 100; int timeout=1000; -extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config) +extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config) { - return new DatabaseSinkManager(routingengine, config); + auto plugin = new AmbPlugin<DatabaseSink>(routingengine, config); + plugin->init(); + + return plugin; } void * cbFunc(Shared* shared) @@ -132,8 +136,8 @@ int getNextEvent(gpointer data) return 0; } -DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::string> config) - :AbstractSource(engine,config),shared(nullptr),playback(false),playbackShared(nullptr), playbackMultiplier(1) +DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::string> config, AbstractSource &parent) + :AmbPluginImpl(engine, config, parent), shared(nullptr), playback(false), playbackShared(nullptr), playbackMultiplier(1) { databaseName = "storage"; tablename = "data"; @@ -168,16 +172,16 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std:: parseConfig(); } - for(auto itr=propertiesToSubscribeTo.begin();itr!=propertiesToSubscribeTo.end();itr++) + for(auto itr : propertiesToSubscribeTo) { - engine->subscribeToProperty(*itr,this); + engine->subscribeToProperty(itr, &parent); } - mSupported.push_back(DatabaseFile); - mSupported.push_back(DatabaseLogging); - mSupported.push_back(DatabasePlayback); + addPropertySupport(Zone::None, [](){return new DatabaseFileType("storage");}); + addPropertySupport(Zone::None, [](){return new DatabasePlaybackType(false);}); + addPropertySupport(Zone::None, [](){return new DatabaseLoggingType(false);}); - routingEngine->updateSupported(supported(), PropertyList(), this); + routingEngine->updateSupported(supported(), PropertyList(), &parent); if(config.find("startOnLoad")!= config.end()) { @@ -216,17 +220,6 @@ void DatabaseSink::supportedChanged(const PropertyList &supportedProperties) } -PropertyList DatabaseSink::supported() -{ - return mSupported; -} - -PropertyInfo DatabaseSink::getPropertyInfo(VehicleProperty::Property property) -{ - /// TODO: Compute update frequency for properties in the database - return PropertyInfo::invalid(); -} - void DatabaseSink::parseConfig() { json_object *rootobject; @@ -381,14 +374,18 @@ void DatabaseSink::setDatabaseFileName(string filename) for(int i=0; i < supportedStr.size(); i++) { - if(!contains(mSupported, supportedStr[i][0])) - mSupported.push_back(supportedStr[i][0]); + if(!contains(supported(), supportedStr[i][0])) + { + std::string name = supportedStr[i][0]; + Zone::Type zone = boost::lexical_cast<int, std::string>(supportedStr[i][3]); + addPropertySupport(zone, [name]() { return VehicleProperty::getPropertyTypeForPropertyNameValue(name); }); + } } delete shared; shared = NULL; - routingEngine->updateSupported(mSupported, PropertyList(), this); + routingEngine->updateSupported(mSupported, PropertyList(), &source); } void DatabaseSink::propertyChanged(AbstractPropertyType *value) @@ -398,10 +395,10 @@ void DatabaseSink::propertyChanged(AbstractPropertyType *value) if(!shared) return; - if(!contains(mSupported, property)) + if(!contains(supported(), property)) { - mSupported.push_back(property); - routingEngine->updateSupported(mSupported, PropertyList(), this); + addPropertySupport(value->zone, [property]() { return VehicleProperty::getPropertyTypeForPropertyNameValue(property);}); + routingEngine->updateSupported(mSupported, PropertyList(), &source); } DBObject obj; @@ -416,7 +413,7 @@ void DatabaseSink::propertyChanged(AbstractPropertyType *value) } -const string DatabaseSink::uuid() +const std::string DatabaseSink::uuid() const { return "9f88156e-cb92-4472-8775-9c08addf50d3"; } diff --git a/plugins/database/databasesink.h b/plugins/database/databasesink.h index 6933612c..a9112df2 100644 --- a/plugins/database/databasesink.h +++ b/plugins/database/databasesink.h @@ -25,6 +25,7 @@ #include "basedb.hpp" #include <asyncqueue.hpp> #include "listplusplus.h" +#include "ambpluginimpl.h" #include <glib.h> @@ -136,15 +137,15 @@ PROPERTYTYPEBASIC(DatabaseLogging, bool) PROPERTYTYPEBASIC(DatabasePlayback, bool) PROPERTYTYPE(DatabaseFile, DatabaseFileType, StringPropertyType, std::string) -class DatabaseSink : public AbstractSource +class DatabaseSink : public AmbPluginImpl { public: - DatabaseSink(AbstractRoutingEngine* engine, map<string, string> config); + DatabaseSink(AbstractRoutingEngine* engine, map<string, string> config, AbstractSource &parent); ~DatabaseSink(); virtual void supportedChanged(const PropertyList & supportedProperties); virtual void propertyChanged(AbstractPropertyType *value); - const std::string uuid(); + const std::string uuid() const; ///source role: virtual void getPropertyAsync(AsyncPropertyReply *reply); @@ -153,9 +154,7 @@ public: virtual void subscribeToPropertyChanges(VehicleProperty::Property property); virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property); virtual PropertyList supported(); - int supportedOperations() { return GetRanged | Get | Set;} - - PropertyInfo getPropertyInfo(VehicleProperty::Property property); + int supportedOperations() const { return AbstractSource::GetRanged | AbstractSource::Get | AbstractSource::Set;} private: //methods: @@ -184,18 +183,4 @@ private: DatabaseLoggingType databaseLogging; }; - -class DatabaseSinkManager: public AbstractSinkManager -{ -public: - DatabaseSinkManager(AbstractRoutingEngine* engine, map<string, string> config) - :AbstractSinkManager(engine, config) - { - new DatabaseSink(routingEngine, config); - VehicleProperty::registerProperty(DatabaseLogging, [](){return new DatabaseLoggingType(false);}); - VehicleProperty::registerProperty(DatabasePlayback, [](){return new DatabasePlaybackType(false);}); - VehicleProperty::registerProperty(DatabaseFile, [](){return new DatabaseFileType("storage");}); - } -}; - #endif // DATABASESINK_H diff --git a/plugins/dbus/CMakeLists.txt b/plugins/dbus/CMakeLists.txt index aab7e90f..7bc4fd79 100644 --- a/plugins/dbus/CMakeLists.txt +++ b/plugins/dbus/CMakeLists.txt @@ -15,4 +15,6 @@ target_link_libraries(dbussinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${lin install (TARGETS dbussinkplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/amb.conf DESTINATION /etc/dbus-1/system.d ) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/amb.conf ${CMAKE_CURRENT_SOURCE_DIR}/amb.conf) + add_subdirectory(amb-qt) diff --git a/plugins/dbus/abstractdbusinterface.cpp b/plugins/dbus/abstractdbusinterface.cpp index 86739c0a..dce2888b 100644 --- a/plugins/dbus/abstractdbusinterface.cpp +++ b/plugins/dbus/abstractdbusinterface.cpp @@ -223,7 +223,7 @@ void AbstractDBusInterface::addProperty(AbstractProperty* property) { string nameToLower = property->name(); boost::algorithm::to_lower<string>(nameToLower); - + string access; if(property->access() == AbstractProperty::Read) @@ -250,7 +250,7 @@ void AbstractDBusInterface::addProperty(AbstractProperty* property) " <arg type='d' name='timestamp' direction='out' />" "</signal>" "<property type='i' name='" + property->name() + "Sequence' access='read' />"; - + properties[property->name()] = property; if(!contains(mimplementedProperties, property->ambPropertyName())) @@ -266,7 +266,7 @@ void AbstractDBusInterface::registerObject() { throw std::runtime_error("forgot to call setDBusConnection on AbstractDBusInterface"); } - + if(introspectionXml.empty()) { cerr<<"no interface to export: "<<mInterfaceName<<endl; @@ -278,11 +278,11 @@ void AbstractDBusInterface::registerObject() introspectionXml += "</interface>" "</node>"; } - + GError* error=NULL; GDBusNodeInfo* introspection = g_dbus_node_info_new_for_xml(introspectionXml.c_str(), &error); - + if(!introspection || error) { @@ -312,7 +312,7 @@ void AbstractDBusInterface::registerObject() DebugOut(DebugOut::Error)<<error2->message<<endl; g_error_free(error2); } - + if(regId == 0) { DebugOut(DebugOut::Error)<<"We failed to register on DBus"<<endl; @@ -365,6 +365,19 @@ list<AbstractDBusInterface *> AbstractDBusInterface::interfaces() return ifaces; } +std::vector<std::string> AbstractDBusInterface::supportedInterfaces() +{ + std::vector<std::string> ifaces; + + for(auto itr : objectMap) + { + if(itr.second->isSupported()) + ifaces.push_back(itr.second->objectName()); + } + + return ifaces; +} + bool AbstractDBusInterface::implementsProperty(string property) { for(auto itr = properties.begin(); itr != properties.end(); itr++) diff --git a/plugins/dbus/abstractdbusinterface.h b/plugins/dbus/abstractdbusinterface.h index 7b13a57d..2223ea4f 100644 --- a/plugins/dbus/abstractdbusinterface.h +++ b/plugins/dbus/abstractdbusinterface.h @@ -62,6 +62,8 @@ public: static list<AbstractDBusInterface*> interfaces(); + static std::vector<string> supportedInterfaces(); + std::string interfaceName() { return mInterfaceName; } bool implementsProperty(std::string property); diff --git a/plugins/dbus/automotivemanager.cpp b/plugins/dbus/automotivemanager.cpp index 6a77bc42..a6b1ca25 100644 --- a/plugins/dbus/automotivemanager.cpp +++ b/plugins/dbus/automotivemanager.cpp @@ -206,29 +206,27 @@ static void handleMethodCall(GDBusConnection *connection, else if(method == "List") { - std::list<AbstractDBusInterface*> list = AbstractDBusInterface::interfaces(); + std::vector<std::string> supportedProperties = AbstractDBusInterface::supportedInterfaces(); - if(!list.size()) + if(!supportedProperties.size()) { g_dbus_method_invocation_return_dbus_error(invocation,"org.automotive.Manager.Error", "No supported objects"); return; } + std::sort(supportedProperties.begin(), supportedProperties.end()); + auto itr = std::unique(supportedProperties.begin(), supportedProperties.end()); + + supportedProperties.erase(itr, supportedProperties.end()); + GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); - - for(auto itr = list.begin(); itr != list.end(); itr++) + for(auto objectName : supportedProperties) { - if(!(*itr)->isSupported()) - continue; - - std::string objectName = (*itr)->objectName(); - g_variant_builder_add(&builder, "s", objectName.c_str()); } - g_dbus_method_invocation_return_value(invocation,g_variant_new("(as)",&builder)); } else if(method == "SourcesForObjectName") |