Skip to content

Commit

Permalink
Merge pull request Eyescale#518 from eile/master
Browse files Browse the repository at this point in the history
Enable customisation of client loop
  • Loading branch information
tribal-tec committed Nov 18, 2015
2 parents 83be58c + b7241dc commit c66fab7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# Copyright (c) 2010 Daniel Pfeifer <daniel@pfeifer-mail.de>
# 2010-2015 Stefan Eilemann <eile@eyescale.ch>
# Copyright (c) 2010-2015 Stefan Eilemann <eile@eyescale.ch>
# Daniel Pfeifer <daniel@pfeifer-mail.de>

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(Equalizer)
Expand All @@ -11,9 +11,9 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake
include(GitExternal)

set(VERSION_MAJOR "1")
set(VERSION_MINOR "10")
set(VERSION_MINOR "11")
set(VERSION_PATCH "0")
set(VERSION_ABI 192)
set(VERSION_ABI 193)

set(EQUALIZER_INCLUDE_NAME eq)
include(Common)
Expand Down
2 changes: 2 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog {#Changelog}

# git master

* [518](https://github.com/Eyescale/Equalizer/pull/518):
Enable customisation of client loop
* [511](https://github.com/Eyescale/Equalizer/pull/511):
Fix exit behaviour on config parse error
* [510](https://github.com/Eyescale/Equalizer/issues/510):
Expand Down
18 changes: 10 additions & 8 deletions eq/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class Client
Client()
: queue( co::Global::getCommandQueueLimit( ))
, modelUnit( EQ_UNDEFINED_UNIT )
, running( false )
, qtApp( 0 )
, running( false )
{}

CommandQueue queue; //!< The command->node command queue.
Expand All @@ -81,8 +81,8 @@ class Client
ServerSet localServers;
std::string gpuFilter;
float modelUnit;
bool running;
QApplication* qtApp;
bool running;

void initQt( int argc LB_UNUSED, char** argv LB_UNUSED )
{
Expand Down Expand Up @@ -240,6 +240,7 @@ bool Client::initLocal( const int argc, char** argv )
return false;
}

_impl->running = true;
clientLoop();
exitClient();
}
Expand Down Expand Up @@ -295,13 +296,8 @@ bool Client::_setupClient( const std::string& clientArgs )
void Client::clientLoop()
{
LBINFO << "Entered client loop" << std::endl;

_impl->running = true;
while( _impl->running )
while( isRunning( ))
processCommand();

// cleanup
_impl->queue.flush();
}

bool Client::exitLocal()
Expand All @@ -317,6 +313,7 @@ bool Client::exitLocal()

void Client::exitClient()
{
_impl->queue.flush();
bool ret = exitLocal();
LBINFO << "Exit " << lunchbox::className( this ) << " process used "
<< getRefCount() << std::endl;
Expand All @@ -331,6 +328,11 @@ bool Client::hasCommands()
return !_impl->queue.isEmpty();
}

bool Client::isRunning() const
{
return _impl->running;
}

co::CommandQueue* Client::getMainThreadQueue()
{
return &_impl->queue;
Expand Down
8 changes: 6 additions & 2 deletions eq/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class Client : public fabric::Client
*/
EQ_API bool hasCommands();

/** @return true if the clientLoop() should keep running. @version 1.11 */
EQ_API bool isRunning() const;

/** @internal @return the command queue to the main node thread. */
EQ_API co::CommandQueue* getMainThreadQueue() override;

Expand Down Expand Up @@ -141,9 +144,10 @@ class Client : public fabric::Client
*
* As long as the node is running, that is, between initLocal() and an exit
* send from the server, this method executes received commands using
* processCommand() and triggers the message pump between commands.
* processCommand() and triggers the message pump between commands. This
* default implementation performs 'while( isRunning( )) processCommand();'.
*
* @sa Pipe::createMessagePump()
* @sa Pipe::createMessagePump(), isRunning(), processCommand()
* @version 1.0
*/
EQ_API virtual void clientLoop();
Expand Down
4 changes: 2 additions & 2 deletions eq/fabric/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool Client::disconnectServer( co::NodePtr server )
return false;
}

if( co::LocalNode::disconnect( server ))
if( disconnect( server ))
return true;

LBWARN << "Server disconnect failed" << std::endl;
Expand All @@ -98,7 +98,7 @@ void Client::processCommand( const uint32_t timeout )
co::CommandQueue* queue = getMainThreadQueue();
LBASSERT( queue );
co::ICommand command = queue->pop( timeout );
if( !command.isValid( )) // wakeup() or timeout
if( !command.isValid( )) // wakeup() or timeout delivers invalid command
return;

LBCHECK( command( ));
Expand Down

0 comments on commit c66fab7

Please sign in to comment.