From 4b91f54c4454396211a99928cf637a03962878cc Mon Sep 17 00:00:00 2001 From: Timo Lotterbach Date: Mon, 26 Nov 2012 02:55:43 -0800 Subject: [PATCH] GenericCommunicator: now using ThreadBase as receive thread GenericCommunicator now uses an internal thread to receive incoming messages. It is not running in main thread anymore. This allows having multiple Communicators at once. Signed-off-by: Timo Lotterbach --- .../GenericCommunicator/include/GenericCommunicator.h | 8 +++++++- .../GenericCommunicator/src/GenericCommunicator.cpp | 12 ++++++++++++ LayerManagerService/src/main.cpp | 9 +++------ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h b/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h index 0ae1321..bbe2892 100644 --- a/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h +++ b/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h @@ -28,6 +28,7 @@ #include "Log.h" #include "IpcModuleLoader.h" #include "ObjectType.h" +#include "ThreadBase.h" #include #include #include @@ -51,16 +52,21 @@ typedef std::map CallBackTable; //============================================================================= // interface //============================================================================= -class GenericCommunicator: public ICommunicator +class GenericCommunicator: public ICommunicator, protected ThreadBase { public: GenericCommunicator(ICommandExecutor* executor); virtual ~GenericCommunicator() {} + + // from ICommunicator virtual bool start(); virtual void stop(); virtual void process(int timeout_ms); virtual void setdebug(bool onoff); + // from ThreadBase + virtual t_ilm_bool threadMainLoop(); + private: void ServiceConnect(t_ilm_message message); void ServiceDisconnect(t_ilm_message message); diff --git a/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp b/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp index 99687d9..319cbfa 100644 --- a/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp +++ b/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp @@ -243,6 +243,10 @@ bool GenericCommunicator::start() m_running = ILM_TRUE; setHealth(HealthRunning); + threadCreate(); + threadInit(); + threadStart(); + return ILM_TRUE; } @@ -250,6 +254,8 @@ void GenericCommunicator::stop() { LOG_INFO("GenericCommunicator","stopping"); + threadStop(); + if (m_running) { m_ipcModule.destroy(); @@ -342,6 +348,12 @@ void GenericCommunicator::setdebug(bool onoff) (void)onoff; // TODO: remove, only prevents warning } +t_ilm_bool GenericCommunicator::threadMainLoop() +{ + process(-1); + return ILM_TRUE; +} + void GenericCommunicator::ServiceConnect(t_ilm_message message) { LOG_DEBUG("GenericCommunicator", "ServiceConnect called"); diff --git a/LayerManagerService/src/main.cpp b/LayerManagerService/src/main.cpp index 3448a5a..184b747 100644 --- a/LayerManagerService/src/main.cpp +++ b/LayerManagerService/src/main.cpp @@ -28,6 +28,8 @@ #include "Scene.h" #include "Log.h" +#include // todo: remove + int main(int argc, char **argv) { // collect all configuration settings @@ -53,12 +55,7 @@ int main(int argc, char **argv) while (!signalHandler.shutdownSignalReceived()) { - CommunicatorListIterator commIter = layermanager.getCommunicatorList()->begin(); - CommunicatorListIterator commIterEnd = layermanager.getCommunicatorList()->end(); - for (; commIter != commIterEnd; ++commIter) - { - (*commIter)->process(-1); - } + sleep(1); } LOG_DEBUG("LayerManagerService", "Stopping service."); layermanager.stopManagement(); -- 2.7.4