Artem Senichev | e8837d5 | 2020-06-07 11:59:04 +0300 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2020 YADRO |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <string> |
| 7 | |
| 8 | /** |
| 9 | * @class HostConsole |
| 10 | * @brief Connection with host's console. |
| 11 | */ |
| 12 | class HostConsole |
| 13 | { |
| 14 | public: |
| 15 | /** |
| 16 | * @brief Constructor. |
| 17 | * |
| 18 | * @param[in] socketId socket ID used for construction path to the socket |
| 19 | */ |
| 20 | HostConsole(const std::string& socketId); |
| 21 | |
| 22 | ~HostConsole(); |
| 23 | |
| 24 | /** |
| 25 | * @brief Connect to the host's console via socket. |
| 26 | * |
| 27 | * @throw std::invalid_argument if socket ID is invalid |
| 28 | * @throw std::system_error in case of other errors |
| 29 | */ |
| 30 | void connect(); |
| 31 | |
| 32 | /** |
| 33 | * @brief Non-blocking read data from console's socket. |
| 34 | * |
| 35 | * @param[out] buf buffer to write the incoming data |
| 36 | * @param[in] sz size of the buffer |
| 37 | * |
| 38 | * @throw std::system_error in case of errors |
| 39 | * |
| 40 | * @return number of actually read bytes |
| 41 | */ |
| 42 | size_t read(char* buf, size_t sz) const; |
| 43 | |
| 44 | /** @brief Get socket file descriptor, used for watching IO. */ |
| 45 | operator int() const; |
| 46 | |
| 47 | private: |
| 48 | /** @brief Socket Id. */ |
| 49 | std::string socketId; |
| 50 | /** @brief File descriptor of the socket. */ |
| 51 | int socketFd; |
| 52 | }; |