| 1 | /************************************************************************* |
| 2 | * libjson-rpc-cpp |
| 3 | ************************************************************************* |
| 4 | * @file tcpsocketserver.h |
| 5 | * @date 17.07.2015 |
| 6 | * @author Alexandre Poirot <alexandre.poirot@legrand.fr> |
| 7 | * @license See attached LICENSE.txt |
| 8 | ************************************************************************/ |
| 9 | |
| 10 | #ifndef JSONRPC_CPP_TCPSOCKETSERVERCONNECTOR_H_ |
| 11 | #define JSONRPC_CPP_TCPSOCKETSERVERCONNECTOR_H_ |
| 12 | |
| 13 | #include "../abstractserverconnector.h" |
| 14 | |
| 15 | namespace jsonrpc { |
| 16 | /** |
| 17 | * This class provides an embedded TCP Socket Server that handle incoming |
| 18 | * Requests and send result over same socket. |
| 19 | * It uses the delimiter character to distinct a full RPC Message over the |
| 20 | * tcp flow. This character is parametered on |
| 21 | * compilation time in implementation files. The default value for this |
| 22 | * delimiter is 0x0A a.k.a. "new line". |
| 23 | * This class hides OS specific features in real implementation of this |
| 24 | * server. Currently it has implementation for |
| 25 | * both Linux and Windows. |
| 26 | */ |
| 27 | class TcpSocketServer : public AbstractServerConnector { |
| 28 | public: |
| 29 | /** |
| 30 | * @brief TcpSocketServer, constructor for the included |
| 31 | * TcpSocketServer |
| 32 | * |
| 33 | * Instanciates the real implementation of TcpSocketServerPrivate |
| 34 | * depending on running OS. |
| 35 | * |
| 36 | * @param ipToBind The ipv4 address on which the server should |
| 37 | * bind and listen |
| 38 | * @param port The port on which the server should bind and listen |
| 39 | */ |
| 40 | TcpSocketServer(const std::string &ipToBind, const unsigned int &port); |
| 41 | |
| 42 | ~TcpSocketServer(); |
| 43 | /** |
| 44 | * @brief The AbstractServerConnector::StartListening method overload. |
| 45 | * |
| 46 | * This method launches the listening loop that will handle client |
| 47 | * connections. |
| 48 | * The return value depends on the current listening states : |
| 49 | * - not listening and no error come up while bind and listen returns true |
| 50 | * - not listening but error happen on bind or listen returns false |
| 51 | * - is called while listening returns false |
| 52 | * |
| 53 | * @return A boolean that indicates the success or the failure of the |
| 54 | * operation. |
| 55 | */ |
| 56 | bool StartListening(); |
| 57 | /** |
| 58 | * @brief The AbstractServerConnector::StopListening method overload. |
| 59 | * |
| 60 | * This method stops the listening loop that will handle client connections. |
| 61 | * The return value depends on the current listening states : |
| 62 | * - listening and successfully stops the listen loop returns true |
| 63 | * - is called while not listening returns false |
| 64 | * |
| 65 | * @return A boolean that indicates the success or the failure of the |
| 66 | * operation. |
| 67 | */ |
| 68 | bool StopListening(); |
| 69 | |
| 70 | protected: |
| 71 | AbstractServerConnector *realSocket; |
| 72 | }; |
| 73 | |
| 74 | } /* namespace jsonrpc */ |
| 75 | #endif /* JSONRPC_CPP_TCPSOCKETSERVERCONNECTOR_H_ */ |
| 76 | |