From 3a175e3927e8a4fdc118f7f277da989708e1dc5a Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Fri, 3 Aug 2012 13:19:59 -0700 Subject: [PATCH] a bit more progress on the plugin loader --- CMakeLists.txt | 5 +++-- ambd/main.cpp | 5 +++-- ambd/pluginloader.cpp | 41 +++++++++---------------------------- ambd/pluginloader.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++--- lib/abstractsink.h | 10 +++++++++ lib/abstractsource.h | 4 ++++ 6 files changed, 83 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc395a4..b003357 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,12 +22,13 @@ find_package(Boost REQUIRED) pkg_check_modules(glib REQUIRED glib-2.0) pkg_check_modules(gio REQUIRED gio-2.0) +pkg_check_modules(json REQUIRED json-glib-1.0) add_definitions(-std=c++0x) add_definitions(-DDBusServiceName="org.automotive.message.broker") -set(include_dirs ${libtool_INCLUDE_DIR} ${glib_INCLUDE_DIRS} ${gio_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/lib) -set(link_libraries -lamb ${libtool_LIBRARY} ${glib_LIBRARIES} ${gio_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib) +set(include_dirs ${libtool_INCLUDE_DIR} ${glib_INCLUDE_DIRS} ${gio_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${json_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/lib) +set(link_libraries -lamb ${libtool_LIBRARY} ${glib_LIBRARIES} ${gio_LIBRARIES} ${json_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib) if(use_qtcore) diff --git a/ambd/main.cpp b/ambd/main.cpp index 9af9670..50d487a 100644 --- a/ambd/main.cpp +++ b/ambd/main.cpp @@ -123,11 +123,12 @@ int main(int argc, char **argv) #endif - PluginLoader loader(plugin); + /*PluginLoader loader; - AbstractSource* source = loader.loadSource(); + AbstractSource* source = loader.sources(); if(source == nullptr) return -1; + */ #ifdef USE_QT_CORE diff --git a/ambd/pluginloader.cpp b/ambd/pluginloader.cpp index 1329740..5871a21 100644 --- a/ambd/pluginloader.cpp +++ b/ambd/pluginloader.cpp @@ -19,47 +19,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "pluginloader.h" #include +#include using namespace std; -PluginLoader::PluginLoader(std::string pluginPath) -:mPluginPath(pluginPath),f_create(NULL) +PluginLoader::PluginLoader(string configFile):f_create(NULL) { - -} - -AbstractSource* PluginLoader::loadSource() -{ - if(lt_dlinit()) - { - mErrorString = lt_dlerror(); - cerr<<"error initializing libtool: "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "< +#include #include +#include + #include "abstractsource.h" +#include "abstractsink.h" + + +using namespace std; + +typedef void* create_t(); -typedef AbstractSource* create_t(); class PluginLoader { public: - PluginLoader(std::string pluginPath); + PluginLoader(string configFile); - AbstractSource * loadSource(); + SourceList sources(); + SinkList sinks(); std::string errorString(); + void setSinkCreatedCb(SinkSignal cb); + void setSinkRemovedCb(SinkSignal cb); + +private: ///methods: + + template + T* loadPlugin(string pluginName) + { + if(lt_dlinit()) + { + mErrorString = lt_dlerror(); + cerr<<"error initializing libtool: "<<__FILE__<<" - "<<__FUNCTION__<<":"<<__LINE__<<" "<( f_create() ); + } + + return nullptr; + } + private: + std::string mPluginPath; std::string mErrorString; + SinkSignal sinkCreatedCb; + SinkSignal sinkRemovedCb; + create_t * f_create; }; diff --git a/lib/abstractsink.h b/lib/abstractsink.h index 4d9a378..1ef2ad9 100644 --- a/lib/abstractsink.h +++ b/lib/abstractsink.h @@ -23,11 +23,14 @@ #include #include #include +#include #include "vehicleproperty.h" using namespace std; +class AbstractSink; + typedef function SetPropertySignal; typedef function SubscriptionSignal; @@ -47,6 +50,12 @@ public: void setSupported(PropertyList properties); + ///callback setters: + void setSetPropertyCb(SetPropertySignal cb); + void setSubcribeToPropertyCb(SubscriptionSignal cb); + void setUnsubscribeToPropertyCb(SubscriptionSignal cb); + + ///Pure virtual methods: virtual string name() = 0; @@ -58,6 +67,7 @@ private: SetPropertySignal setPropertyCb; SubscriptionSignal subscribeToPropertyCb; SubscriptionSignal unsubscribeToPropertyCb; + PropertyList mSupported; }; diff --git a/lib/abstractsource.h b/lib/abstractsource.h index 4c4c2fb..ef29df4 100644 --- a/lib/abstractsource.h +++ b/lib/abstractsource.h @@ -28,8 +28,12 @@ using namespace std; +class AbstractSource; + typedef function PropertyChangedSignal; +typedef list SourceList; + class AbstractSource { -- 2.7.4