47#if defined(__FreeBSD__)
51#include <sys/termios.h>
71#include "debug/Terminal.hh"
72#include "debug/TerminalVerbose.hh"
115 else if (revent & POLLNVAL)
153 case TerminalDump::none:
155 case TerminalDump::stdoutput:
157 case TerminalDump::stderror:
159 case TerminalDump::file:
162 panic(
"Invalid option\n");
174 warn_once(
"Sockets disabled, not accepting terminal connections");
188 panic(
"%s: cannot accept a connection if not listening!",
name());
192 char message[] =
"terminal already attached!\n";
202 std::stringstream stream;
209 write((
const uint8_t *)stream.str().c_str(), stream.str().size());
213 for (
size_t i = 0;
i <
txbuf.
size();
i +=
sizeof(buf)) {
214 const size_t chunk_len(std::min(
txbuf.
size() -
i,
sizeof(buf)));
216 write((
const uint8_t *)buf, chunk_len);
252 panic(
"Terminal not properly attached.\n");
257 }
while (ret == -1 && errno == EINTR);
276 panic(
"Terminal not properly attached.\n");
285#define MORE_PENDING (1ULL << 61)
286#define RECEIVE_SUCCESS (0ULL << 62)
287#define RECEIVE_NONE (2ULL << 62)
288#define RECEIVE_ERROR (3ULL << 62)
298 DPRINTF(TerminalVerbose,
"in: \'%c\' %#02x more: %d\n",
317 DPRINTF(TerminalVerbose,
"console_in: return: %#x\n", value);
326 if (debug::Terminal) {
327 static char last =
'\0';
329 if ((
c !=
'\n' &&
c !=
'\r') || (last !=
'\n' && last !=
'\r')) {
330 if (
c ==
'\n' ||
c ==
'\r') {
331 int size = linebuf.size();
332 char *buffer =
new char[size + 1];
333 linebuf.read(buffer, size);
338 linebuf.write(&
c, 1);
354 DPRINTF(TerminalVerbose,
"out: \'%c\' %#02x\n",
355 isprint(
c) ?
c :
' ', (int)
c);
void read(OutputIterator out, size_t len)
Copy buffer contents and advance the read pointer.
void write(InputIterator in, size_t len)
Add elements to the end of the ring buffers and advance.
void peek(OutputIterator out, size_t len) const
Copy buffer contents without advancing the read pointer.
static bool allDisabled()
virtual std::string name() const
OutputStream * findOrCreate(const std::string &name, bool binary=false)
std::ostream * stream() const
Get the output underlying output stream.
Base class for serial devices such as terminals.
void notifyInterface()
Notify the host interface of pending data.
DataEvent(Terminal *t, int fd, int e)
ListenEvent(Terminal *t, int fd, int e)
OutputStream * terminalDump(const TerminalParams &p)
uint8_t readData() override
Read a character from the device.
Terminal(const Params &p)
void writeData(uint8_t c) override
Transmit a character from the host interface to the device.
ListenEvent * listenEvent
bool dataAvailable() const override
Check if there is pending data from the serial device.
#define panic(...)
This implements a cprintf based panic() function.
void remove(PollEvent *event)
void schedule(PollEvent *event)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
ssize_t atomic_write(int fd, const void *s, size_t n)
void ccprintf(cp::Print &print)