Noux: use Terminal::Connection as singleton

We will reuse the terminal connection in the stdio filesystem
to implement /dev/tty. Therefor we need to access the terminal
from different locations which is simplified if it is provided
by a singleton.
This commit is contained in:
Josef Söntgen 2012-10-04 12:52:27 +02:00 committed by Norman Feske
parent 82eb0e9f9a
commit ebfe49ca84
2 changed files with 44 additions and 5 deletions

View File

@ -807,6 +807,13 @@ Noux::Io_receptor_registry * Noux::io_receptor_registry()
}
Terminal::Connection *Noux::terminal()
{
static Terminal::Connection _inst;
return &_inst;
}
void *operator new (Genode::size_t size) {
return Genode::env()->heap()->alloc(size); }
@ -869,17 +876,15 @@ int main(int argc, char **argv)
resources_ep,
false);
static Terminal::Connection terminal;
/*
* I/O channels must be dynamically allocated to handle cases where the
* init program closes one of these.
*/
typedef Terminal_io_channel Tio; /* just a local abbreviation */
Shared_pointer<Io_channel>
channel_0(new Tio(terminal, Tio::STDIN, sig_rec), Genode::env()->heap()),
channel_1(new Tio(terminal, Tio::STDOUT, sig_rec), Genode::env()->heap()),
channel_2(new Tio(terminal, Tio::STDERR, sig_rec), Genode::env()->heap());
channel_0(new Tio(*Noux::terminal(), Tio::STDIN, sig_rec), Genode::env()->heap()),
channel_1(new Tio(*Noux::terminal(), Tio::STDOUT, sig_rec), Genode::env()->heap()),
channel_2(new Tio(*Noux::terminal(), Tio::STDERR, sig_rec), Genode::env()->heap());
init_child->add_io_channel(channel_0, 0);
init_child->add_io_channel(channel_1, 1);

View File

@ -0,0 +1,34 @@
/*
* \brief Terminal connection
* \author Josef Soentgen
* \date 2012-08-02
*/
/*
* Copyright (C) 2012 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _NOUX__TERMINAL_CONNECTION_H_
#define _NOUX__TERMINAL_CONNECTION_H_
/* Genode includes */
#include <base/printf.h>
#include <base/lock.h>
#include <terminal_session/connection.h>
#include <util/string.h>
/* Noux includes */
#include <noux_session/sysio.h>
#include "file_system.h"
namespace Noux {
Terminal::Connection *terminal();
}
#endif /* _NOUX__TERMINAL_CONNECTION_H_ */