ServerCore/TCPServerSocket.h
2019-02-07 13:28:21 -08:00

105 lines
3.2 KiB
C++

#ifndef __TCPServerSocket_h__
#define __TCPServerSocket_h__
#include "Socket.h"
#include "TCPSocket.h"
#include "Command.h"
#include "CommandList.h"
namespace core {
///
/// TCPServerSocket
///
/// Manage a socket connection as a TCP server type. Connections to the socket are processed through
/// the accept functionality.
///
/// A list of connections is maintained in a vector object.
///
/// This object extends the BMACommand object as well so it can be added to a Console object and
/// process commands to display status information.
///
class TCPServerSocket : public TCPSocket, public Command {
public:
///
/// The constructor for the BMATCPSocket object.
///
/// @param ePoll the EPoll instance that manages the socket.
/// @param url the IP address for the socket to receive connection requests.
/// @param port the port number that the socket will listen on.
/// @param commandName the name of the command used to invoke the status display for this object.
/// @return the instance of the BMATCPServerSocket.
TCPServerSocket(EPoll &ePoll, std::string url, short int port);
///
/// The destructor for this object.
///
~TCPServerSocket();
void removeFromSessionList(Session *session);
///
/// The list of sessions that are currently open and being maintained by this object.
///
std::vector<Session *> sessions;
///
/// The commands object is a CommandList and is used to store Command objects to be
/// parsed and run as data comes into the session.
///
CommandList commands;
virtual void sessionErrorHandler(std::string errorString, Session *session);
protected:
virtual void init();
///
/// getSocketAccept is designed to allow a polymorphic extension of this object to
/// return a type of object that extends the definition of the server socket.
/// Returning the appropriate session object that extends from BMASession provides
/// the mechanism where the server can select the protocol dialog for the desired
/// service.
///
virtual Session * getSocketAccept();
///
/// Override the virtual dataReceived since for the server these
/// are requests to accept the new connection socket.
/// No data is to be read or written when this method is called. It is the response to
/// the fact that a new connection is coming into the system
///
/// @param data the pointer to the buffer containing the received data.
/// @param length the length of the associated data buffer.
///
void onDataReceived(std::string data) override;
///
/// This method is called when the Command associated with this object is requested
/// because a user has typed in the associated command name on a command entry line.
///
/// @param the session object to write the output to.
///
int processCommand(std::string command, Session *session) override;
private:
Session * accept();
};
}
#endif