diff --git a/liboncilla.pc.in b/liboncilla.pc.in index 3a6e28b..ecce5d0 100644 --- a/liboncilla.pc.in +++ b/liboncilla.pc.in @@ -1,6 +1,6 @@ Name: @LIBONCILLA_NAME@ Description: AMARSi RCI representations of the AMARSi Quadruped Robot 'Oncilla' Version: @LIBONCILLA_VERSION@ Requires: rci eigen2 -Libs: -L@CMAKE_INSTALL_PREFIX@/lib -l@LIBONCILLA_NAME@ +Libs: -L@CMAKE_INSTALL_PREFIX@/lib -l@LIBONCILLA_NAME@ -ldl Cflags: -I@CMAKE_INSTALL_PREFIX@/include diff --git a/src/BackendFactory.cpp b/src/BackendFactory.cpp index 78b8449..75f8ef8 100644 --- a/src/BackendFactory.cpp +++ b/src/BackendFactory.cpp @@ -1,36 +1,90 @@ /** * \file BackendFactory.cpp * * \date Jun 21, 2012 * \author Alexandre Tuleu */ #include "BackendFactory.h" +#include +#include namespace rci { namespace oncilla { BackendFactory & BackendFactory::Instance(){ static BackendFactory * s_rci_oncilla_backend_factory = new BackendFactory(); return *s_rci_oncilla_backend_factory; } void BackendFactory::RegisterBackend(Priority p, EntryPtr e){ EntryByPriority::const_iterator fi = d_entries.find(p); if(fi != d_entries.end()){ return; } d_entries.insert(std::make_pair(p,e)); } - BackendFactory::EntryPtr BackendFactory::HighestPriorityBackend() const{ + BackendFactory::EntryPtr BackendFactory::HighestPriorityBackend(){ + LoadExternalBackend(); EntryByPriority::const_reverse_iterator fi = d_entries.rbegin(); if (fi == d_entries.rend()){ return 0; } return fi->second; } + void BackendFactory::LoadExternalBackend(){ + for(SetOfBackendName::const_iterator n = d_unloaded.begin(); + n != d_unloaded.end(); + ++n){ + char * error; + void * module_handle = dlopen(n->c_str(),RTLD_NOW); + if((error = dlerror()) != NULL ){ + std::cerr << "Could not open module '" << *n << "'."<< std::endl + << " error : '" << error << "'." <second); + + if( (error = dlerror()) != NULL){ + std::cerr << "Could not unload module '" << b->first << "' : " + << std::endl + << " error : '" << error << "'." << std::endl; + } + } + } + + } /* namespace oncilla */ } /* namespace rci */ diff --git a/src/BackendFactory.h b/src/BackendFactory.h index 1b97564..69468ff 100644 --- a/src/BackendFactory.h +++ b/src/BackendFactory.h @@ -1,78 +1,103 @@ /** * \file BackendFactory.h * * \date Jun 21, 2012 * \author Alexandre Tuleu */ #ifndef LIBONCILLA_BACKENDFACTORY_H_ #define LIBONCILLA_BACKENDFACTORY_H_ #include #include +#include +#include +#include + +extern "C" { + typedef void (*liboncilla_backend_entry_fct)(); +} namespace rci{ namespace oncilla{ class OncillaSynchronizer; typedef std::tr1::shared_ptr OncillaSynchronizerPtr; class BackendFactory { public : /** * define the priority of the backend */ enum Priority{ HARDWARE = 0, SIMULATION = 1, USER_DEFINED_PRIORITY = 2 }; /** * Pointer to a function that will be the entry of the Backend. */ typedef OncillaSynchronizerPtr (*EntryPtr)(); static BackendFactory & Instance(); + + + void AddAdditionalBackend(const std::string & name); /** * Register a new backend. * \param p the Priority of the backend * \param entry the EntryPtr of the backend * \warning : if a backend with the same priority is already here, the call * will be silently discarded. */ void RegisterBackend(Priority p, EntryPtr entry); /** * \return the EntryPtr of the highest priority backend or 0 if none was * registered with RegisterBackend(). */ - EntryPtr HighestPriorityBackend() const; + EntryPtr HighestPriorityBackend(); + + private: typedef std::map EntryByPriority; + typedef std::set SetOfBackendName; + typedef std::map ListOfLoadedBackend; + + void LoadExternalBackend(); + + BackendFactory(); + virtual ~BackendFactory(); EntryByPriority d_entries; + SetOfBackendName d_unloaded; + ListOfLoadedBackend d_loaded; + }; template class BackendRegistrator { public : BackendRegistrator(); + void PrintAlive(); }; template inline BackendRegistrator::BackendRegistrator(){ BackendFactory::Instance().RegisterBackend(P, &(OncillaSynchronizerSubClass::Create)); } -#define LIBONCILLA_REGISTER_THIS_CLASS(ClassName,PriorityValue) public :\ - static rci::oncilla::OncillaSynchronizerPtr Create();\ - private :\ - static rci::oncilla::BackendRegistrator < ClassName , PriorityValue > s_registrator; -#endif // LIBONCILLA_BACKENDFACTORY_H_ + template + inline void BackendRegistrator::PrintAlive(){ + std::cout << "I am alive!" << std::endl; + } + } } + +#endif // LIBONCILLA_BACKENDFACTORY_H_ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7e787b7..075ed52 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,37 +1,37 @@ # Configure config header CONFIGURE_FILE("config.h.in" "${PROJECT_NAME}Config.h") SET(ONCILLAHEADERS OncillaTrunk.h OncillaL0.h OncillaL1L2.h OncillaL3.h OncillaL4.h Oncilla.h OncillaSynchronizer.h BackendFactory.h) SET(ONCILLASOURCES OncillaTrunk.cpp OncillaL0.cpp OncillaL1L2.cpp OncillaL3.cpp OncillaL4.cpp Oncilla.cpp OncillaSynchronizer.cpp BackendFactory.cpp) ADD_LIBRARY(${LIBONCILLA_NAME} SHARED ${ONCILLASOURCES}) TARGET_LINK_LIBRARIES(${LIBONCILLA_NAME} ${RSC_LIBRARIES} ${RCI_LIBRARIES} - ${LIBRARIES_LIBRARIES}) + ${LIBRARIES_LIBRARIES} -ldl) SET_TARGET_PROPERTIES(${LIBONCILLA_NAME} PROPERTIES VERSION ${LIBONCILLA_VERSION_STRING}) INSTALL(TARGETS ${LIBONCILLA_NAME} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) INSTALL_FILES_RECURSIVE(include/lib${LIBNAME} ONCILLAHEADERS)