From 1b5ba019c3c0d8190c5b506611cccb02c014bcab Mon Sep 17 00:00:00 2001 From: Timo Lotterbach Date: Wed, 28 Nov 2012 02:49:36 -0800 Subject: [PATCH] GenericCommunicator: updated to new IPlugin interface GenericCommuncator is now based on the updated IPlugin interface to support static linking. Signed-off-by: Timo Lotterbach --- .../GenericCommunicator/CMakeLists.txt | 36 ++++++++++++++++------ .../include/GenericCommunicator.h | 13 +++++--- .../src/GenericCommunicator.cpp | 30 +++++++++--------- .../test/DBUSCommunicatorTest.cpp | 3 +- LayerManagerService/include/ICommunicator.h | 4 +-- 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/LayerManagerPlugins/Communicators/GenericCommunicator/CMakeLists.txt b/LayerManagerPlugins/Communicators/GenericCommunicator/CMakeLists.txt index 418b268..c9cf975 100644 --- a/LayerManagerPlugins/Communicators/GenericCommunicator/CMakeLists.txt +++ b/LayerManagerPlugins/Communicators/GenericCommunicator/CMakeLists.txt @@ -19,40 +19,56 @@ cmake_minimum_required (VERSION 2.6) +project(GenericCommunicator) + find_package(Threads) include_directories( "include" "${CMAKE_SOURCE_DIR}/LayerManagerClient/ilmClient/include" - "${PROJECT_SOURCE_DIR}/LayerManagerService/include" - "${PROJECT_SOURCE_DIR}/LayerManagerUtils/include" - "${PROJECT_SOURCE_DIR}/LayerManagerCommands/include" - "${PROJECT_SOURCE_DIR}/LayerManagerPlugins/IpcModules/IpcModuleLoader/include" + "${CMAKE_SOURCE_DIR}/LayerManagerService/include" + "${CMAKE_SOURCE_DIR}/LayerManagerUtils/include" + "${CMAKE_SOURCE_DIR}/LayerManagerCommands/include" + "${CMAKE_SOURCE_DIR}/LayerManagerPlugins/IpcModules/IpcModuleLoader/include" ) set(LIBS ${LIBS} IpcModuleLoader LayerManagerCommands - ${CMAKE_THREAD_LIBS_INIT} ) -add_library(GenericCommunicator SHARED +set(SRC_FILES src/GenericCommunicator.cpp ) -target_link_libraries(GenericCommunicator + +if (WITH_STATIC_PLUGINS) + + add_library(${PROJECT_NAME} STATIC ${SRC_FILES}) + set (STATICALLY_LINKED_PLUGINS ${STATICALLY_LINKED_PLUGINS} + ${PROJECT_NAME} CACHE INTERNAL "list of static plugins") + +else(WITH_STATIC_PLUGINS) + + add_library(${PROJECT_NAME} SHARED ${SRC_FILES}) + +endif(WITH_STATIC_PLUGINS) + +target_link_libraries(${PROJECT_NAME} ${LIBS} ) -add_dependencies(GenericCommunicator - LayerManagerService +add_dependencies(${PROJECT_NAME} LayerManagerUtils LayerManagerCommands IpcModuleLoader ) -install (TARGETS GenericCommunicator LIBRARY DESTINATION lib/layermanager/communicator) +install (TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION lib/layermanager/communicator + ARCHIVE DESTINATION lib/layermanager/static +) if (WITH_TESTS) enable_testing() diff --git a/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h b/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h index bbe2892..c54abba 100644 --- a/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h +++ b/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h @@ -25,6 +25,7 @@ */ #include "ICommunicator.h" +#include "PluginBase.h" #include "Log.h" #include "IpcModuleLoader.h" #include "ObjectType.h" @@ -35,6 +36,8 @@ class GenericCommunicator; class GraphicalObject; +class ICommandExecutor; +class Configuration; //============================================================================= // internal types @@ -52,10 +55,10 @@ typedef std::map CallBackTable; //============================================================================= // interface //============================================================================= -class GenericCommunicator: public ICommunicator, protected ThreadBase +class GenericCommunicator: public ICommunicator, protected ThreadBase, public PluginBase { public: - GenericCommunicator(ICommandExecutor* executor); + GenericCommunicator(ICommandExecutor& executor, Configuration& config); virtual ~GenericCommunicator() {} // from ICommunicator @@ -67,6 +70,10 @@ public: // from ThreadBase virtual t_ilm_bool threadMainLoop(); + // from PluginBase + virtual t_ilm_const_string pluginGetName() const; + virtual HealthCondition pluginGetHealth(); + private: void ServiceConnect(t_ilm_message message); void ServiceDisconnect(t_ilm_message message); @@ -168,8 +175,6 @@ private: void SetOptimizationMode(t_ilm_message message); void GetOptimizationMode(t_ilm_message message); - virtual HealthCondition getHealth(); - private: void RemoveApplicationReference(char* owner); void processNotificationQueue(); diff --git a/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp b/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp index 319cbfa..0fab553 100644 --- a/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp +++ b/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp @@ -20,6 +20,7 @@ #include "GenericCommunicator.h" #include "ilm_types.h" #include "Log.h" +#include "Configuration.h" #include "ICommandExecutor.h" #include "CommitCommand.h" @@ -103,8 +104,9 @@ const char* RESOURCE_NOT_FOUND = "Ressource not found"; const char* NOT_IMPLEMENTED = "Feature not implemented"; -GenericCommunicator::GenericCommunicator(ICommandExecutor* executor) -: ICommunicator(executor) +GenericCommunicator::GenericCommunicator(ICommandExecutor& executor, Configuration& config) +: ICommunicator(&executor) +, PluginBase(executor, config, Communicator_Api_v1) , m_running(ILM_FALSE) { MethodTable manager_methods[] = @@ -241,7 +243,7 @@ bool GenericCommunicator::start() LOG_DEBUG("GenericCommunicator", "Initializing IpcModule success."); m_running = ILM_TRUE; - setHealth(HealthRunning); + pluginSetHealth(HealthRunning); threadCreate(); threadInit(); @@ -260,7 +262,7 @@ void GenericCommunicator::stop() { m_ipcModule.destroy(); } - setHealth(HealthStopped); + pluginSetHealth(HealthStopped); } void GenericCommunicator::process(int timeout_ms) @@ -354,6 +356,11 @@ t_ilm_bool GenericCommunicator::threadMainLoop() return ILM_TRUE; } +t_ilm_const_string GenericCommunicator::pluginGetName() const +{ + return "GenericCommunicator"; +} + void GenericCommunicator::ServiceConnect(t_ilm_message message) { LOG_DEBUG("GenericCommunicator", "ServiceConnect called"); @@ -2957,9 +2964,9 @@ void GenericCommunicator::sendNotification(GraphicalObject* object, t_ilm_notifi } } -HealthCondition GenericCommunicator::getHealth() +HealthCondition GenericCommunicator::pluginGetHealth() { - HealthCondition health = PluginBase::getHealth(); + HealthCondition health = PluginBase::pluginGetHealth(); if (0 != pthread_kill(mThreadId, 0)) { health = HealthDead; @@ -3024,13 +3031,4 @@ void GenericCommunicator::GetOptimizationMode(t_ilm_message message) } -extern "C" ICommunicator* createGenericCommunicator(ICommandExecutor* executor) -{ - return new GenericCommunicator(executor); -} - -extern "C" void destroyGenericCommunicator(GenericCommunicator* p) -{ - delete p; -} - +DECLARE_LAYERMANAGEMENT_PLUGIN(GenericCommunicator) diff --git a/LayerManagerPlugins/Communicators/GenericCommunicator/test/DBUSCommunicatorTest.cpp b/LayerManagerPlugins/Communicators/GenericCommunicator/test/DBUSCommunicatorTest.cpp index 43b86c7..0d88765 100644 --- a/LayerManagerPlugins/Communicators/GenericCommunicator/test/DBUSCommunicatorTest.cpp +++ b/LayerManagerPlugins/Communicators/GenericCommunicator/test/DBUSCommunicatorTest.cpp @@ -145,7 +145,8 @@ public: } else { DBUSCOMMAND = DBUSCOMMAND_SYSTEM; } - communicatorUnderTest = new GenericCommunicator(&mockCommandExecutor); + Configuration config(0, NULL); + communicatorUnderTest = new GenericCommunicator(mockCommandExecutor, config); this->communicatorUnderTest->start(); DefaultValue::Set((ApplicationReferenceMap*) &this->refmap); diff --git a/LayerManagerService/include/ICommunicator.h b/LayerManagerService/include/ICommunicator.h index 02e1f50..61b3053 100644 --- a/LayerManagerService/include/ICommunicator.h +++ b/LayerManagerService/include/ICommunicator.h @@ -20,15 +20,13 @@ #ifndef _ICOMMUNICATOR_H_ #define _ICOMMUNICATOR_H_ -#include "PluginBase.h" - class ICommandExecutor; /** * Abstract Base of all Communicator plugins. * \defgroup CommunicatorAPI Layer Management Communicator API */ -class ICommunicator : public PluginBase +class ICommunicator { public: /** -- 2.7.4