A server which can be reached by TCP (nc, telnet, ...). More...
#include <commandserver.h>
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< Pipe > | pipe |
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 |
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.
typedef std::map<std::string, boost::shared_ptr<Action<CELL_TYPE> > > LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::ActionMap |
LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::CommandServer | ( | int | port, | |
boost::shared_ptr< Pipe > | pipe | |||
) | [inline] |
LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::~CommandServer | ( | ) | [inline] |
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.
void LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::handleInput | ( | const std::string & | input | ) | [inline, private] |
int LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::runServer | ( | ) | [inline, private] |
void LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::runSession | ( | ) | [inline, private] |
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.
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] |
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.
void LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::signalClose | ( | ) | [inline, private] |
boost::shared_ptr<tcp::acceptor> LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::acceptor [private] |
ActionMap LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::actions [private] |
bool LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::continueFlag [private] |
boost::asio::io_service LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::ioService [private] |
boost::mutex LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::mutex [private] |
boost::shared_ptr<Pipe> LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::pipe [private] |
int LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::port [private] |
boost::thread LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::serverThread [private] |
boost::shared_ptr<tcp::socket> LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::socket [private] |
boost::condition_variable LibGeoDecomp::RemoteSteererHelpers::CommandServer< CELL_TYPE >::threadCreationVar [private] |