Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE > Class Template Reference

A server which can be reached by TCP (nc, telnet, ...). More...

#include <commandserver.h>

Collaboration diagram for LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >:
Collaboration graph
[legend]

List of all members.

Classes

class  PingAction
 This class is just a NOP, which may be used by the client to retrieve new steering feedback. More...
class  QuitAction
 This helper class lets us and the user safely close the CommandServer's network service, which is nice as it is using blocking IO and it's a major PITA to cancel that. More...

Public Types

typedef std::map< std::string,
boost::shared_ptr< Action
< CELL_TYPE > > > 
ActionMap

Public Member Functions

 CommandServer (int port, boost::shared_ptr< Pipe > pipe)
 ~CommandServer ()
void sendMessage (const std::string &message)
 Sends a message back to the end user.
void addAction (Action< CELL_TYPE > *action)
 Register a server-side callback for handling user input.

Static Public Member Functions

static void sendCommand (const std::string &command, int port, const std::string &host="127.0.0.1")
 A convenience method to send a string to a CommandServer listeting on the given host/port combination.
static StringVec sendCommandWithFeedback (const std::string &command, int feedbackLines, int port, const std::string &host="127.0.0.1")

Private Member Functions

void runSession ()
void handleInput (const std::string &input)
int runServer ()
void signalClose ()

Private Attributes

int port
boost::shared_ptr< Pipepipe
boost::asio::io_service ioService
boost::shared_ptr< tcp::acceptor > acceptor
boost::shared_ptr< tcp::socket > socket
boost::thread serverThread
boost::condition_variable threadCreationVar
boost::mutex mutex
ActionMap actions
bool continueFlag

Detailed Description

template<typename CELL_TYPE>
class LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >

A server which can be reached by TCP (nc, telnet, ...).

Its purpose is to do connection handling and parsing of incoming user commands. Action objects can be bound to certain commands and will be invoked. This allows a flexible extension of the CommandServer's functionality by composition, without having to resort to inheritance.


Member Typedef Documentation

template<typename CELL_TYPE >
typedef std::map<std::string, boost::shared_ptr<Action<CELL_TYPE> > > LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::ActionMap

Constructor & Destructor Documentation

template<typename CELL_TYPE >
LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::CommandServer ( int  port,
boost::shared_ptr< Pipe pipe 
) [inline]
template<typename CELL_TYPE >
LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::~CommandServer (  )  [inline]

Member Function Documentation

template<typename CELL_TYPE >
void LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::addAction ( Action< CELL_TYPE > *  action  )  [inline]

Register a server-side callback for handling user input.

The CommandServer will assume ownership of the action and free its memory upon destruction.

template<typename CELL_TYPE >
void LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::handleInput ( const std::string &  input  )  [inline, private]
template<typename CELL_TYPE >
int LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::runServer (  )  [inline, private]
template<typename CELL_TYPE >
void LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::runSession (  )  [inline, private]
template<typename CELL_TYPE >
static void LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::sendCommand ( const std::string &  command,
int  port,
const std::string &  host = "127.0.0.1" 
) [inline, static]

A convenience method to send a string to a CommandServer listeting on the given host/port combination.

template<typename CELL_TYPE >
static StringVec LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::sendCommandWithFeedback ( const std::string &  command,
int  feedbackLines,
int  port,
const std::string &  host = "127.0.0.1" 
) [inline, static]
template<typename CELL_TYPE >
void LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::sendMessage ( const std::string &  message  )  [inline]

Sends a message back to the end user.

This is the primary way for (user-defined) Actions to give feedback.

template<typename CELL_TYPE >
void LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::signalClose (  )  [inline, private]

Member Data Documentation

template<typename CELL_TYPE >
boost::shared_ptr<tcp::acceptor> LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::acceptor [private]
template<typename CELL_TYPE >
ActionMap LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::actions [private]
template<typename CELL_TYPE >
bool LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::continueFlag [private]
template<typename CELL_TYPE >
boost::asio::io_service LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::ioService [private]
template<typename CELL_TYPE >
boost::mutex LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::mutex [private]
template<typename CELL_TYPE >
boost::shared_ptr<Pipe> LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::pipe [private]
template<typename CELL_TYPE >
int LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::port [private]
template<typename CELL_TYPE >
boost::thread LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::serverThread [private]
template<typename CELL_TYPE >
boost::shared_ptr<tcp::socket> LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::socket [private]
template<typename CELL_TYPE >
boost::condition_variable LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::threadCreationVar [private]

The documentation for this class was generated from the following file: