mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-01 23:20:55 +00:00
parent
dbb641d44a
commit
1e2fb9432f
@ -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
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
* under the terms of the GNU General Public License version 2.
|
* under the terms of the GNU General Public License version 2.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Genode includes */
|
/* Genode includes */
|
||||||
#include <cap_session/connection.h>
|
#include <base/component.h>
|
||||||
#include <base/printf.h>
|
#include <base/heap.h>
|
||||||
#include <base/rpc_server.h>
|
|
||||||
#include <base/sleep.h>
|
|
||||||
|
|
||||||
/* local includes */
|
/* local includes */
|
||||||
#include "terminal_root.h"
|
#include "terminal_root.h"
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
namespace Terminal_crosslink {
|
||||||
{
|
|
||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
|
|
||||||
static Cap_connection cap;
|
struct Main;
|
||||||
static Rpc_entrypoint ep(&cap, Terminal::STACK_SIZE, "terminal_ep");
|
}
|
||||||
|
|
||||||
static Terminal::Root terminal_root(&ep, env()->heap(), cap);
|
struct Terminal_crosslink::Main
|
||||||
env()->parent()->announce(ep.manage(&terminal_root));
|
{
|
||||||
|
Env &_env;
|
||||||
sleep_forever();
|
Heap _heap { _env.ram(), _env.rm() };
|
||||||
return 0;
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
@ -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
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
* under the terms of the GNU General Public License version 2.
|
* under the terms of the GNU General Public License version 2.
|
||||||
@ -22,11 +22,11 @@
|
|||||||
#include "terminal_session_component.h"
|
#include "terminal_session_component.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Terminal {
|
namespace Terminal_crosslink {
|
||||||
|
|
||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
|
|
||||||
class Root : public Rpc_object<Typed_root<Session> >
|
class Root : public Root_component<Session_component>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -68,10 +68,10 @@ namespace Terminal {
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
Root(Rpc_entrypoint *ep, Allocator *md_alloc,
|
Root(Env &env, Allocator &alloc)
|
||||||
Cap_session &cap_session)
|
: Root_component(&env.ep().rpc_ep(), &alloc),
|
||||||
: _session_component1(_session_component2, cap_session, "terminal_ep1"),
|
_session_component1(env, _session_component2),
|
||||||
_session_component2(_session_component1, cap_session, "terminal_ep2"),
|
_session_component2(env, _session_component1),
|
||||||
_session_state(0)
|
_session_state(0)
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
@ -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
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
* under the terms of the GNU General Public License version 2.
|
* under the terms of the GNU General Public License version 2.
|
||||||
@ -24,38 +24,38 @@
|
|||||||
|
|
||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
|
|
||||||
namespace Terminal {
|
Terminal_crosslink::Session_component::Session_component(Env &env,
|
||||||
|
Session_component &partner)
|
||||||
Session_component::Session_component(Session_component &partner, Cap_session &cap_session, const char *ep_name)
|
: _env(env),
|
||||||
: _partner(partner),
|
_partner(partner),
|
||||||
_ep(&cap_session, STACK_SIZE, ep_name),
|
_session_cap(_env.ep().rpc_ep().manage(this)),
|
||||||
_session_cap(_ep.manage(this)),
|
_io_buffer(env.ram(), env.rm(), BUFFER_SIZE),
|
||||||
_io_buffer(Genode::env()->ram_session(), BUFFER_SIZE),
|
|
||||||
_cross_num_bytes_avail(0)
|
_cross_num_bytes_avail(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Genode::Session_capability Session_component::cap()
|
Session_capability Terminal_crosslink::Session_component::cap()
|
||||||
{
|
{
|
||||||
return _session_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; });
|
return session == this; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Session_component::cross_avail()
|
bool Terminal_crosslink::Session_component::cross_avail()
|
||||||
{
|
{
|
||||||
return (_cross_num_bytes_avail > 0);
|
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;
|
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;
|
_cross_num_bytes_avail -= num_bytes_read;
|
||||||
|
|
||||||
_write_avail_lock.unlock();
|
|
||||||
|
|
||||||
return num_bytes_read;
|
return num_bytes_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session_component::cross_write()
|
void Terminal_crosslink::Session_component::cross_write()
|
||||||
{
|
{
|
||||||
Signal_transmitter(_read_avail_sigh).submit();
|
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();
|
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);
|
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>();
|
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 num_bytes_written = 0;
|
||||||
size_t src_index = 0;
|
|
||||||
while (num_bytes_written < num_bytes)
|
while (num_bytes_written < num_bytes)
|
||||||
try {
|
try {
|
||||||
_buffer.add(src[src_index]);
|
_buffer.add(src[num_bytes_written]);
|
||||||
++src_index;
|
|
||||||
++num_bytes_written;
|
++num_bytes_written;
|
||||||
} catch(Local_buffer::Overflow) {
|
} catch(Local_buffer::Overflow) {
|
||||||
_cross_num_bytes_avail += num_bytes_written;
|
break;
|
||||||
|
|
||||||
/* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_cross_num_bytes_avail += num_bytes_written;
|
_cross_num_bytes_avail += num_bytes_written;
|
||||||
_partner.cross_write();
|
_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
|
* 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;
|
_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; }
|
||||||
}
|
|
||||||
|
@ -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
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
* under the terms of the GNU General Public License version 2.
|
* under the terms of the GNU General Public License version 2.
|
||||||
@ -20,7 +20,7 @@
|
|||||||
#include <os/ring_buffer.h>
|
#include <os/ring_buffer.h>
|
||||||
#include <terminal_session/terminal_session.h>
|
#include <terminal_session/terminal_session.h>
|
||||||
|
|
||||||
namespace Terminal {
|
namespace Terminal_crosslink {
|
||||||
|
|
||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
|
|
||||||
@ -32,25 +32,25 @@ namespace Terminal {
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Env &_env;
|
||||||
|
|
||||||
Session_component &_partner;
|
Session_component &_partner;
|
||||||
Rpc_entrypoint _ep;
|
|
||||||
Genode::Session_capability _session_cap;
|
Genode::Session_capability _session_cap;
|
||||||
|
|
||||||
Attached_ram_dataspace _io_buffer;
|
Attached_ram_dataspace _io_buffer;
|
||||||
|
|
||||||
typedef Genode::Ring_buffer<unsigned char, BUFFER_SIZE+1> Local_buffer;
|
typedef Genode::Ring_buffer<unsigned char, BUFFER_SIZE+1> Local_buffer;
|
||||||
|
|
||||||
Local_buffer _buffer;
|
Local_buffer _buffer;
|
||||||
size_t _cross_num_bytes_avail;
|
size_t _cross_num_bytes_avail;
|
||||||
Lock _write_avail_lock;
|
Signal_context_capability _read_avail_sigh;
|
||||||
Signal_context_capability _read_avail_sigh;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
Session_component(Session_component &partner, Cap_session &cap_session, const char *ep_name);
|
Session_component(Env &env, Session_component &partner);
|
||||||
|
|
||||||
Session_capability cap();
|
Session_capability cap();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user