| 1 | // |
| 2 | // DialogServer.h |
| 3 | // |
| 4 | // Definition of the DialogServer class. |
| 5 | // |
| 6 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
| 7 | // and Contributors. |
| 8 | // |
| 9 | // SPDX-License-Identifier: BSL-1.0 |
| 10 | // |
| 11 | |
| 12 | |
| 13 | #ifndef DialogServer_INCLUDED |
| 14 | #define DialogServer_INCLUDED |
| 15 | |
| 16 | |
| 17 | #include "Poco/Net/Net.h" |
| 18 | #include "Poco/Net/ServerSocket.h" |
| 19 | #include "Poco/Net/StreamSocket.h" |
| 20 | #include "Poco/Thread.h" |
| 21 | #include "Poco/Event.h" |
| 22 | #include "Poco/Mutex.h" |
| 23 | #include <vector> |
| 24 | |
| 25 | |
| 26 | class DialogServer: public Poco::Runnable |
| 27 | /// A server for testing FTPClientSession and friends. |
| 28 | { |
| 29 | public: |
| 30 | DialogServer(bool acceptCommands = true); |
| 31 | /// Creates the DialogServer. |
| 32 | |
| 33 | ~DialogServer(); |
| 34 | /// Destroys the DialogServer. |
| 35 | |
| 36 | Poco::UInt16 port() const; |
| 37 | /// Returns the port the echo server is |
| 38 | /// listening on. |
| 39 | |
| 40 | void run(); |
| 41 | /// Does the work. |
| 42 | |
| 43 | const std::string& lastCommand() const; |
| 44 | /// Returns the last command received by the server. |
| 45 | |
| 46 | std::string popCommand(); |
| 47 | /// Pops the next command from the list of received commands. |
| 48 | |
| 49 | std::string popCommandWait(); |
| 50 | /// Pops the next command from the list of received commands. |
| 51 | /// Waits until a command is available. |
| 52 | |
| 53 | const std::vector<std::string>& lastCommands() const; |
| 54 | /// Returns the last command received by the server. |
| 55 | |
| 56 | void addResponse(const std::string& response); |
| 57 | /// Sets the next response returned by the server. |
| 58 | |
| 59 | void clearCommands(); |
| 60 | /// Clears all commands. |
| 61 | |
| 62 | void clearResponses(); |
| 63 | /// Clears all responses. |
| 64 | |
| 65 | void log(bool flag); |
| 66 | /// Enables or disables logging to stdout. |
| 67 | |
| 68 | private: |
| 69 | Poco::Net::ServerSocket _socket; |
| 70 | Poco::Thread _thread; |
| 71 | Poco::Event _ready; |
| 72 | mutable Poco::FastMutex _mutex; |
| 73 | bool _stop; |
| 74 | std::vector<std::string> _nextResponses; |
| 75 | std::vector<std::string> _lastCommands; |
| 76 | bool _acceptCommands; |
| 77 | bool _log; |
| 78 | }; |
| 79 | |
| 80 | |
| 81 | #endif // DialogServer_INCLUDED |
| 82 | |