Event session interface

Issue #3812
This commit is contained in:
Norman Feske 2020-07-02 19:21:22 +02:00
parent 602def9bdd
commit 443d3c98dd
5 changed files with 185 additions and 0 deletions

View File

@ -0,0 +1,94 @@
/*
* \brief Client-side event session interface
* \author Norman Feske
* \date 2020-07-02
*/
/*
* Copyright (C) 2020 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__EVENT_SESSION__CLIENT_H_
#define _INCLUDE__EVENT_SESSION__CLIENT_H_
#include <util/noncopyable.h>
#include <event_session/event_session.h>
#include <base/attached_dataspace.h>
#include <base/rpc_client.h>
#include <input/event.h>
namespace Event { struct Session_client; }
class Event::Session_client : public Genode::Rpc_client<Session>
{
private:
Genode::Attached_dataspace _ds;
public:
Session_client(Genode::Region_map &local_rm,
Genode::Capability<Session> session)
:
Genode::Rpc_client<Session>(session),
_ds(local_rm, call<Rpc_dataspace>())
{ }
class Batch : Genode::Noncopyable
{
private:
friend class Session_client;
Session_client &_session;
struct {
Input::Event * const events;
Genode::size_t const max;
} _buffer;
unsigned _count = 0;
void _submit()
{
if (_count)
_session.call<Rpc_submit_batch>(_count);
_count = 0;
}
Batch(Session_client &session)
:
_session(session),
_buffer({ .events = session._ds.local_addr<Input::Event>(),
.max = session._ds.size() / sizeof(Input::Event) })
{ }
~Batch() { _submit(); }
public:
void submit(Input::Event const &event)
{
if (_count == _buffer.max)
_submit();
if (_count < _buffer.max)
_buffer.events[_count++] = event;
}
};
template <typename FN>
void with_batch(FN const &fn)
{
Batch batch { *this };
fn(batch);
}
};
#endif /* _INCLUDE__EVENT_SESSION__CLIENT_H_ */

View File

@ -0,0 +1,39 @@
/*
* \brief Connection to event service
* \author Norman Feske
* \date 2020-07-02
*/
/*
* Copyright (C) 2020 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__EVENT_SESSION__CONNECTION_H_
#define _INCLUDE__EVENT_SESSION__CONNECTION_H_
#include <event_session/client.h>
#include <base/connection.h>
namespace Event { struct Connection; }
struct Event::Connection : Genode::Connection<Session>, Session_client
{
enum { RAM_QUOTA = 18*1024UL };
/**
* Constructor
*/
Connection(Genode::Env &env, char const *label = "")
:
Genode::Connection<Event::Session>(env,
session(env.parent(),
"ram_quota=%u, cap_quota=%u, label=\"%s\"",
RAM_QUOTA, CAP_QUOTA, label)),
Session_client(env.rm(), cap())
{ }
};
#endif /* _INCLUDE__EVENT_SESSION__CONNECTION_H_ */

View File

@ -0,0 +1,49 @@
/*
* \brief Event session interface
* \author Norman Feske
* \date 2020-07-02
*/
/*
* Copyright (C) 2020 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__EVENT_SESSION__EVENT_SESSION_H_
#define _INCLUDE__EVENT_SESSION__EVENT_SESSION_H_
#include <dataspace/capability.h>
#include <base/rpc_server.h>
#include <session/session.h>
namespace Event { struct Session; }
struct Event::Session : Genode::Session
{
/**
* \noapi
*/
static const char *service_name() { return "Event"; }
/*
* An event session consumes a dataspace capability for the server's
* session-object allocation, a dataspace capability for the event
* buffer, and its session capability.
*/
enum { CAP_QUOTA = 3 };
/*********************
** RPC declaration **
*********************/
GENODE_RPC(Rpc_dataspace, Genode::Dataspace_capability, dataspace);
GENODE_RPC(Rpc_submit_batch, void, submit_batch, unsigned);
GENODE_RPC_INTERFACE(Rpc_dataspace, Rpc_submit_batch);
};
#endif /* _INCLUDE__EVENT_SESSION__EVENT_SESSION_H_ */

View File

@ -0,0 +1,2 @@
MIRRORED_FROM_REP_DIR := include/event_session include/input
include $(REP_DIR)/recipes/api/session.inc

View File

@ -0,0 +1 @@
2020-07-02 5bc20ba1099e392f36b8c8b073746317a0ad8fbd