blob: 73a5bfdff7acfce5ee357398a5de534954df4488 [file] [log] [blame]
Artem Senicheve8837d52020-06-07 11:59:04 +03001// 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 */
12class 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
Nan Zhou042b5ba2021-06-18 09:32:45 -070022 virtual ~HostConsole();
Artem Senicheve8837d52020-06-07 11:59:04 +030023
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 */
Nan Zhou042b5ba2021-06-18 09:32:45 -070030 virtual void connect();
Artem Senicheve8837d52020-06-07 11:59:04 +030031
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 */
Nan Zhou042b5ba2021-06-18 09:32:45 -070042 virtual size_t read(char* buf, size_t sz) const;
Artem Senicheve8837d52020-06-07 11:59:04 +030043
44 /** @brief Get socket file descriptor, used for watching IO. */
Nan Zhou042b5ba2021-06-18 09:32:45 -070045 virtual operator int() const;
Artem Senicheve8837d52020-06-07 11:59:04 +030046
47 private:
48 /** @brief Socket Id. */
49 std::string socketId;
50 /** @brief File descriptor of the socket. */
51 int socketFd;
52};