diff --git a/repos/os/include/event_session/client.h b/repos/os/include/event_session/client.h new file mode 100644 index 0000000000..0696684e0b --- /dev/null +++ b/repos/os/include/event_session/client.h @@ -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 +#include +#include +#include +#include + +namespace Event { struct Session_client; } + + +class Event::Session_client : public Genode::Rpc_client +{ + private: + + Genode::Attached_dataspace _ds; + + public: + + Session_client(Genode::Region_map &local_rm, + Genode::Capability session) + : + Genode::Rpc_client(session), + _ds(local_rm, call()) + { } + + 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(_count); + + _count = 0; + } + + Batch(Session_client &session) + : + _session(session), + _buffer({ .events = session._ds.local_addr(), + .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 + void with_batch(FN const &fn) + { + Batch batch { *this }; + + fn(batch); + } +}; + +#endif /* _INCLUDE__EVENT_SESSION__CLIENT_H_ */ diff --git a/repos/os/include/event_session/connection.h b/repos/os/include/event_session/connection.h new file mode 100644 index 0000000000..664185f69a --- /dev/null +++ b/repos/os/include/event_session/connection.h @@ -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 +#include + +namespace Event { struct Connection; } + +struct Event::Connection : Genode::Connection, Session_client +{ + enum { RAM_QUOTA = 18*1024UL }; + + /** + * Constructor + */ + Connection(Genode::Env &env, char const *label = "") + : + Genode::Connection(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_ */ diff --git a/repos/os/include/event_session/event_session.h b/repos/os/include/event_session/event_session.h new file mode 100644 index 0000000000..b8e70fe243 --- /dev/null +++ b/repos/os/include/event_session/event_session.h @@ -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 +#include +#include + +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_ */ diff --git a/repos/os/recipes/api/event_session/content.mk b/repos/os/recipes/api/event_session/content.mk new file mode 100644 index 0000000000..7eb9c39605 --- /dev/null +++ b/repos/os/recipes/api/event_session/content.mk @@ -0,0 +1,2 @@ +MIRRORED_FROM_REP_DIR := include/event_session include/input +include $(REP_DIR)/recipes/api/session.inc diff --git a/repos/os/recipes/api/event_session/hash b/repos/os/recipes/api/event_session/hash new file mode 100644 index 0000000000..54abc27420 --- /dev/null +++ b/repos/os/recipes/api/event_session/hash @@ -0,0 +1 @@ +2020-07-02 5bc20ba1099e392f36b8c8b073746317a0ad8fbd