base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
/*
|
2014-11-13 14:44:15 +00:00
|
|
|
* \brief Packet stream helper
|
|
|
|
* \author Sebastian Sumpf
|
|
|
|
* \date 2014-12-08
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2014-11-13 14:44:15 +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.
|
2014-11-13 14:44:15 +00:00
|
|
|
*/
|
|
|
|
#ifndef _INCLUDE__USB__PACKET_HANDLER_
|
|
|
|
#define _INCLUDE__USB__PACKET_HANDLER_
|
|
|
|
|
|
|
|
#include <base/lock.h>
|
|
|
|
#include <usb_session/connection.h>
|
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
namespace Usb { class Packet_handler; }
|
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
|
|
|
|
class Usb::Packet_handler
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Usb::Connection &_connection;
|
2016-06-21 10:59:11 +00:00
|
|
|
Genode::Entrypoint &_ep;
|
|
|
|
|
2016-08-12 13:10:50 +00:00
|
|
|
Signal_handler<Packet_handler> _rpc_ack_avail =
|
2016-06-21 10:59:11 +00:00
|
|
|
{_ep, *this, &Packet_handler::_packet_handler };
|
|
|
|
|
2016-08-12 13:10:50 +00:00
|
|
|
Signal_handler<Packet_handler> _rpc_ready_submit =
|
2016-06-21 10:59:11 +00:00
|
|
|
{ _ep, *this, &Packet_handler::_ready_handler };
|
2014-11-13 14:44:15 +00:00
|
|
|
|
|
|
|
bool _ready_submit = true;
|
|
|
|
|
2016-08-12 13:10:50 +00:00
|
|
|
void _packet_handler()
|
2014-11-13 14:44:15 +00:00
|
|
|
{
|
|
|
|
if (!_ready_submit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (packet_avail()) {
|
|
|
|
Packet_descriptor p = _connection.source()->get_acked_packet();
|
|
|
|
|
|
|
|
if (p.completion)
|
|
|
|
p.completion->complete(p);
|
|
|
|
else
|
|
|
|
release(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 13:10:50 +00:00
|
|
|
void _ready_handler()
|
2014-11-13 14:44:15 +00:00
|
|
|
{
|
|
|
|
_ready_submit = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-06-21 10:59:11 +00:00
|
|
|
Packet_handler(Connection &connection, Genode::Entrypoint &ep)
|
|
|
|
: _connection(connection), _ep(ep)
|
2014-11-13 14:44:15 +00:00
|
|
|
{
|
|
|
|
/* connect 'ack_avail' to our rpc member */
|
|
|
|
_connection.tx_channel()->sigh_ack_avail(_rpc_ack_avail);
|
|
|
|
_connection.tx_channel()->sigh_ready_to_submit(_rpc_ready_submit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************
|
|
|
|
** Packet stream wrapper **
|
|
|
|
***************************/
|
|
|
|
|
|
|
|
bool packet_avail() const
|
|
|
|
{
|
|
|
|
return _connection.source()->ack_avail();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wait_for_packet()
|
|
|
|
{
|
2016-08-12 13:10:50 +00:00
|
|
|
packet_avail() ? _packet_handler() : _ep.wait_and_dispatch_one_signal();
|
2014-11-13 14:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Packet_descriptor alloc(size_t size)
|
|
|
|
{
|
|
|
|
/* is size larger than packet stream */
|
|
|
|
if (size > _connection.source()->bulk_buffer_size()) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::error("packet allocation of (", size, " bytes) too large, "
|
|
|
|
"buffer has ", _connection.source()->bulk_buffer_size(),
|
|
|
|
" bytes");
|
2014-11-13 14:44:15 +00:00
|
|
|
throw Usb::Session::Tx::Source::Packet_alloc_failed();
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
Packet_descriptor p = _connection.source()->alloc_packet(size);
|
|
|
|
return p;
|
|
|
|
} catch (Usb::Session::Tx::Source::Packet_alloc_failed) {
|
|
|
|
/* block until some packets are freed */
|
|
|
|
wait_for_packet();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void submit(Packet_descriptor &p)
|
|
|
|
{
|
|
|
|
/* check if submit queue is full */
|
|
|
|
if (!_connection.source()->ready_to_submit()) {
|
|
|
|
_ready_submit = false;
|
|
|
|
|
|
|
|
/* wait for ready_to_submit signal */
|
|
|
|
while (!_ready_submit)
|
2016-06-21 10:59:11 +00:00
|
|
|
_ep.wait_and_dispatch_one_signal();
|
2014-11-13 14:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_connection.source()->submit_packet(p);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If an acknowledgement available signal occurred in the meantime,
|
|
|
|
* retrieve packets.
|
|
|
|
*/
|
|
|
|
if (packet_avail())
|
2016-08-12 13:10:50 +00:00
|
|
|
_packet_handler();
|
2014-11-13 14:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *content(Packet_descriptor &p)
|
|
|
|
{
|
|
|
|
return _connection.source()->packet_content(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void release(Packet_descriptor &p)
|
|
|
|
{
|
|
|
|
_connection.source()->release_packet(p);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__USB__PACKET_HANDLER_ */
|