mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-19 03:06:39 +00:00
parent
602def9bdd
commit
443d3c98dd
94
repos/os/include/event_session/client.h
Normal file
94
repos/os/include/event_session/client.h
Normal 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_ */
|
39
repos/os/include/event_session/connection.h
Normal file
39
repos/os/include/event_session/connection.h
Normal 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_ */
|
49
repos/os/include/event_session/event_session.h
Normal file
49
repos/os/include/event_session/event_session.h
Normal 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_ */
|
2
repos/os/recipes/api/event_session/content.mk
Normal file
2
repos/os/recipes/api/event_session/content.mk
Normal file
@ -0,0 +1,2 @@
|
||||
MIRRORED_FROM_REP_DIR := include/event_session include/input
|
||||
include $(REP_DIR)/recipes/api/session.inc
|
1
repos/os/recipes/api/event_session/hash
Normal file
1
repos/os/recipes/api/event_session/hash
Normal file
@ -0,0 +1 @@
|
||||
2020-07-02 5bc20ba1099e392f36b8c8b073746317a0ad8fbd
|
Loading…
Reference in New Issue
Block a user