From 0c5139310d634d6d366f4120d88deef66c9266af Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Sat, 20 Sep 2014 17:17:50 -0400 Subject: dev: Refactor terminal<->UART interface to make it more generic The terminal currently assumes that the transport to the guest always inherits from the Uart class. This assumption breaks when implementing, for example, a VirtIO consoles. This patch removes this assumption by adding pointer to the from the terminal to the uart and replacing it with a more general callback interface. The Uart, or any other class using the terminal, class implements an instance of the callbacks class and registers it with the terminal. --- src/dev/terminal.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/dev/terminal.cc') diff --git a/src/dev/terminal.cc b/src/dev/terminal.cc index e70a8775f..895069774 100644 --- a/src/dev/terminal.cc +++ b/src/dev/terminal.cc @@ -99,8 +99,8 @@ Terminal::DataEvent::process(int revent) * Terminal code */ Terminal::Terminal(const Params *p) - : SimObject(p), listenEvent(NULL), dataEvent(NULL), number(p->number), - data_fd(-1), txbuf(16384), rxbuf(16384), outfile(NULL) + : SimObject(p), termDataAvail(NULL), listenEvent(NULL), dataEvent(NULL), + number(p->number), data_fd(-1), txbuf(16384), rxbuf(16384), outfile(NULL) #if TRACING_ON == 1 , linebuf(16384) #endif @@ -129,6 +129,17 @@ Terminal::~Terminal() delete dataEvent; } +void +Terminal::regDataAvailCallback(Callback *c) +{ + // This can happen if the user has connected multiple UARTs to the + // same terminal. In that case, each of them tries to register + // callbacks. + if (termDataAvail) + fatal("Terminal already has already been associated with a UART.\n"); + termDataAvail = c; +} + /////////////////////////////////////////////////////////////////////// // socket creation and terminal attach // @@ -215,7 +226,8 @@ Terminal::data() if (len) { rxbuf.write((char *)buf, len); // Inform the UART there is data available - uart->dataAvailable(); + assert(termDataAvail); + termDataAvail->process(); } } -- cgit v1.2.3