terminal_crosslink: API transition

Fixes #2241
This commit is contained in:
Christian Prochaska 2017-01-17 14:55:49 +01:00 committed by Norman Feske
parent dbb641d44a
commit 1e2fb9432f
4 changed files with 70 additions and 85 deletions

View File

@ -5,31 +5,40 @@
*/
/*
* Copyright (C) 2012-2013 Genode Labs GmbH
* Copyright (C) 2012-2017 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.
*/
/* Genode includes */
#include <cap_session/connection.h>
#include <base/printf.h>
#include <base/rpc_server.h>
#include <base/sleep.h>
#include <base/component.h>
#include <base/heap.h>
/* local includes */
#include "terminal_root.h"
int main(int argc, char **argv)
{
namespace Terminal_crosslink {
using namespace Genode;
static Cap_connection cap;
static Rpc_entrypoint ep(&cap, Terminal::STACK_SIZE, "terminal_ep");
static Terminal::Root terminal_root(&ep, env()->heap(), cap);
env()->parent()->announce(ep.manage(&terminal_root));
sleep_forever();
return 0;
struct Main;
}
struct Terminal_crosslink::Main
{
Env &_env;
Heap _heap { _env.ram(), _env.rm() };
Root _terminal_root { _env, _heap };
Main(Env &env) : _env(env)
{
env.parent().announce(env.ep().manage(_terminal_root));
}
};
void Component::construct(Genode::Env &env)
{
static Terminal_crosslink::Main main(env);
}

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (C) 2012-2013 Genode Labs GmbH
* Copyright (C) 2012-2017 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.
@ -22,11 +22,11 @@
#include "terminal_session_component.h"
namespace Terminal {
namespace Terminal_crosslink {
using namespace Genode;
class Root : public Rpc_object<Typed_root<Session> >
class Root : public Root_component<Session_component>
{
private:
@ -68,10 +68,10 @@ namespace Terminal {
/**
* Constructor
*/
Root(Rpc_entrypoint *ep, Allocator *md_alloc,
Cap_session &cap_session)
: _session_component1(_session_component2, cap_session, "terminal_ep1"),
_session_component2(_session_component1, cap_session, "terminal_ep2"),
Root(Env &env, Allocator &alloc)
: Root_component(&env.ep().rpc_ep(), &alloc),
_session_component1(env, _session_component2),
_session_component2(env, _session_component1),
_session_state(0)
{ }
};

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (C) 2012-2013 Genode Labs GmbH
* Copyright (C) 2012-2017 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.
@ -24,38 +24,38 @@
using namespace Genode;
namespace Terminal {
Session_component::Session_component(Session_component &partner, Cap_session &cap_session, const char *ep_name)
: _partner(partner),
_ep(&cap_session, STACK_SIZE, ep_name),
_session_cap(_ep.manage(this)),
_io_buffer(Genode::env()->ram_session(), BUFFER_SIZE),
Terminal_crosslink::Session_component::Session_component(Env &env,
Session_component &partner)
: _env(env),
_partner(partner),
_session_cap(_env.ep().rpc_ep().manage(this)),
_io_buffer(env.ram(), env.rm(), BUFFER_SIZE),
_cross_num_bytes_avail(0)
{
}
Genode::Session_capability Session_component::cap()
Session_capability Terminal_crosslink::Session_component::cap()
{
return _session_cap;
}
bool Session_component::belongs_to(Genode::Session_capability cap)
bool Terminal_crosslink::Session_component::belongs_to(Session_capability cap)
{
return _ep.apply(cap, [this] (Session_component *session) {
return _env.ep().rpc_ep().apply(cap, [this] (Session_component *session) {
return session == this; });
}
bool Session_component::cross_avail()
bool Terminal_crosslink::Session_component::cross_avail()
{
return (_cross_num_bytes_avail > 0);
}
size_t Session_component::cross_read(unsigned char *buf, size_t dst_len)
size_t Terminal_crosslink::Session_component::cross_read(unsigned char *buf,
size_t dst_len)
{
size_t num_bytes_read;
@ -66,80 +66,56 @@ size_t Session_component::cross_read(unsigned char *buf, size_t dst_len)
_cross_num_bytes_avail -= num_bytes_read;
_write_avail_lock.unlock();
return num_bytes_read;
}
void Session_component::cross_write()
void Terminal_crosslink::Session_component::cross_write()
{
Signal_transmitter(_read_avail_sigh).submit();
}
Session::Size Session_component::size() { return Size(0, 0); }
Terminal::Session::Size Terminal_crosslink::Session_component::size()
{ return Terminal::Session::Size(0, 0); }
bool Session_component::avail()
bool Terminal_crosslink::Session_component::avail()
{
return _partner.cross_avail();
}
Genode::size_t Session_component::_read(Genode::size_t dst_len)
size_t Terminal_crosslink::Session_component::_read(size_t dst_len)
{
return _partner.cross_read(_io_buffer.local_addr<unsigned char>(), dst_len);
}
Genode::size_t Session_component::_write(Genode::size_t num_bytes)
size_t Terminal_crosslink::Session_component::_write(size_t num_bytes)
{
unsigned char *src = _io_buffer.local_addr<unsigned char>();
size_t const num_bytes_total = num_bytes;
size_t num_bytes_written = 0;
size_t src_index = 0;
while (num_bytes_written < num_bytes)
try {
_buffer.add(src[src_index]);
++src_index;
_buffer.add(src[num_bytes_written]);
++num_bytes_written;
} catch(Local_buffer::Overflow) {
_cross_num_bytes_avail += num_bytes_written;
/* Lock the lock (always succeeds) */
_write_avail_lock.lock();
_partner.cross_write();
/*
* This lock operation blocks or not, depending on whether the
* partner already has called 'cross_read()' in the meantime
*/
_write_avail_lock.lock();
/*
* Unlock the lock, so it is unlocked the next time the exception
* triggers
*/
_write_avail_lock.unlock();
num_bytes -= num_bytes_written;
num_bytes_written = 0;
break;
}
_cross_num_bytes_avail += num_bytes_written;
_partner.cross_write();
return num_bytes_total;
return num_bytes_written;
}
Genode::Dataspace_capability Session_component::_dataspace() { return _io_buffer.cap(); }
Dataspace_capability Terminal_crosslink::Session_component::_dataspace()
{ return _io_buffer.cap(); }
void Session_component::connected_sigh(Genode::Signal_context_capability sigh)
void Terminal_crosslink::Session_component::connected_sigh(Signal_context_capability sigh)
{
/*
* Immediately reflect connection-established signal to the
@ -150,15 +126,15 @@ void Session_component::connected_sigh(Genode::Signal_context_capability sigh)
}
void Session_component::read_avail_sigh(Genode::Signal_context_capability sigh)
void Terminal_crosslink::Session_component::read_avail_sigh(Signal_context_capability sigh)
{
_read_avail_sigh = sigh;
}
Genode::size_t Session_component::read(void *, Genode::size_t) { return 0; }
size_t Terminal_crosslink::Session_component::read(void *, size_t)
{ return 0; }
Genode::size_t Session_component::write(void const *, Genode::size_t) { return 0; }
}
size_t Terminal_crosslink::Session_component::write(void const *, size_t)
{ return 0; }

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (C) 2012-2013 Genode Labs GmbH
* Copyright (C) 2012-2017 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.
@ -20,7 +20,7 @@
#include <os/ring_buffer.h>
#include <terminal_session/terminal_session.h>
namespace Terminal {
namespace Terminal_crosslink {
using namespace Genode;
@ -32,8 +32,9 @@ namespace Terminal {
{
private:
Env &_env;
Session_component &_partner;
Rpc_entrypoint _ep;
Genode::Session_capability _session_cap;
Attached_ram_dataspace _io_buffer;
@ -42,7 +43,6 @@ namespace Terminal {
Local_buffer _buffer;
size_t _cross_num_bytes_avail;
Lock _write_avail_lock;
Signal_context_capability _read_avail_sigh;
public:
@ -50,7 +50,7 @@ namespace Terminal {
/**
* Constructor
*/
Session_component(Session_component &partner, Cap_session &cap_session, const char *ep_name);
Session_component(Env &env, Session_component &partner);
Session_capability cap();