2012-10-09 15:28:44 +00:00
|
|
|
/*
|
|
|
|
* \brief Buffer for storing decoded characters
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2011-06-06
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2019-02-08 00:26:21 +00:00
|
|
|
* Copyright (C) 2011-2019 Genode Labs GmbH
|
2012-10-09 15:28:44 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2012-10-09 15:28:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _TERMINAL__READ_BUFFER_H_
|
|
|
|
#define _TERMINAL__READ_BUFFER_H_
|
|
|
|
|
|
|
|
#include <os/ring_buffer.h>
|
2019-02-08 00:26:21 +00:00
|
|
|
#include <util/utf8.h>
|
2012-10-09 15:28:44 +00:00
|
|
|
#include <base/signal.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Terminal {
|
|
|
|
|
|
|
|
class Read_buffer;
|
|
|
|
|
|
|
|
enum { READ_BUFFER_SIZE = 4096 };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-14 08:51:53 +00:00
|
|
|
class Terminal::Read_buffer : public Genode::Ring_buffer<unsigned char, READ_BUFFER_SIZE>
|
2012-10-09 15:28:44 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2018-02-06 20:32:02 +00:00
|
|
|
Genode::Signal_context_capability _sigh_cap { };
|
2012-10-09 15:28:44 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register signal handler for read-avail signals
|
|
|
|
*/
|
2018-02-06 20:32:02 +00:00
|
|
|
void sigh(Genode::Signal_context_capability cap) { _sigh_cap = cap; }
|
2012-10-09 15:28:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add element into read buffer and emit signal
|
|
|
|
*/
|
|
|
|
void add(unsigned char c)
|
|
|
|
{
|
2015-04-14 08:51:53 +00:00
|
|
|
Genode::Ring_buffer<unsigned char, READ_BUFFER_SIZE>::add(c);
|
2012-10-09 15:28:44 +00:00
|
|
|
|
|
|
|
if (_sigh_cap.valid())
|
|
|
|
Genode::Signal_transmitter(_sigh_cap).submit();
|
|
|
|
}
|
|
|
|
|
2019-02-08 00:26:21 +00:00
|
|
|
void add(Codepoint code)
|
|
|
|
{
|
|
|
|
/* send Unicode in a burst of UTF-8 */
|
|
|
|
Genode::String<5> utf8(code);
|
|
|
|
char const *str = utf8.string();
|
|
|
|
|
|
|
|
while (*str)
|
|
|
|
Genode::Ring_buffer<unsigned char, READ_BUFFER_SIZE>::add(*str++);
|
|
|
|
|
|
|
|
if (_sigh_cap.valid())
|
|
|
|
Genode::Signal_transmitter(_sigh_cap).submit();
|
|
|
|
}
|
|
|
|
|
2012-10-09 15:28:44 +00:00
|
|
|
void add(char const *str)
|
|
|
|
{
|
|
|
|
while (*str)
|
|
|
|
add(*str++);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _TERMINAL__READ_BUFFER_H_ */
|