mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-04 07:47:59 +03:00
Add simple external console server/client
This commit is contained in:
parent
de7087caf4
commit
7357ea2102
8 changed files with 433 additions and 9 deletions
62
components/commandserver/server.hpp
Executable file
62
components/commandserver/server.hpp
Executable file
|
@ -0,0 +1,62 @@
|
|||
#ifndef CONSOLESERVER_H
|
||||
#define CONSOLESERVER_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <deque>
|
||||
#include <set>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include "components/misc/tsdeque.hpp"
|
||||
|
||||
namespace OMW { namespace CommandServer
|
||||
{
|
||||
//
|
||||
// Forward Declarations
|
||||
//
|
||||
namespace Detail
|
||||
{
|
||||
class Connection;
|
||||
}
|
||||
|
||||
//
|
||||
// Server that opens a port to listen for string commands which will be
|
||||
// put into the deque provided in the Server constructor.
|
||||
//
|
||||
class Server
|
||||
{
|
||||
public:
|
||||
typedef TsDeque<std::string> Deque;
|
||||
|
||||
Server (Deque* pDeque, const int port);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
friend class Detail::Connection;
|
||||
typedef std::set<Detail::Connection*> ConnectionSet;
|
||||
|
||||
void removeConnection (Detail::Connection* ptr);
|
||||
void postMessage (const char* s);
|
||||
|
||||
void threadMain();
|
||||
|
||||
// Objects used to set up the listening server
|
||||
boost::asio::io_service mIOService;
|
||||
boost::asio::ip::tcp::acceptor mAcceptor;
|
||||
boost::thread* mpThread;
|
||||
bool mbStopping;
|
||||
|
||||
// Track active connections
|
||||
ConnectionSet mConnections;
|
||||
mutable boost::mutex mConnectionsMutex;
|
||||
|
||||
// Pointer to output queue in which to put received strings
|
||||
Deque* mpCommands;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif // CONSOLESERVER_H
|
Loading…
Add table
Add a link
Reference in a new issue