From cfd013a01afddec1cf10fd7e48a66a2ebff8fc34 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 22 May 2024 17:22:53 +0200 Subject: [PATCH] os/include: use C++20 function template syntax Issue #5227 --- repos/os/include/block/request_stream.h | 15 +-- repos/os/include/block_session/connection.h | 18 ++-- .../include/capture_session/capture_session.h | 3 +- repos/os/include/capture_session/connection.h | 6 +- repos/os/include/decorator/window_stack.h | 11 +-- repos/os/include/event_session/client.h | 3 +- .../include/file_system_session/connection.h | 5 +- .../file_system_session/file_system_session.h | 3 +- repos/os/include/gui_session/client.h | 7 +- repos/os/include/i2c_session/i2c_session.h | 3 +- repos/os/include/input/event.h | 30 ++---- repos/os/include/input_session/client.h | 7 +- repos/os/include/monitor/output.h | 3 +- repos/os/include/net/dhcp.h | 24 ++--- repos/os/include/os/buffered_xml.h | 12 +-- repos/os/include/os/reporter.h | 8 +- repos/os/include/os/session_policy.h | 14 +-- repos/os/include/os/vfs.h | 30 ++---- repos/os/include/pci/config.h | 7 +- .../os/include/platform_session/connection.h | 6 +- repos/os/include/smbios/smbios.h | 84 +++++++---------- repos/os/include/terminal/print.h | 4 +- repos/os/include/trace/trace_buffer.h | 5 +- repos/os/include/usb_session/connection.h | 6 +- repos/os/include/usb_session/device.h | 93 +++++++------------ repos/os/include/util/bezier.h | 22 ++--- repos/os/include/util/dirty_rect.h | 3 +- repos/os/include/util/formatted_output.h | 3 +- repos/os/include/vfs/dir_file_system.h | 4 +- repos/os/include/vfs/vfs_handle.h | 5 +- repos/os/include/virtio/pci_device.h | 3 +- repos/os/include/virtio/queue.h | 29 +++--- 32 files changed, 183 insertions(+), 293 deletions(-) diff --git a/repos/os/include/block/request_stream.h b/repos/os/include/block/request_stream.h index 57aadf6a02..af02dbae8b 100644 --- a/repos/os/include/block/request_stream.h +++ b/repos/os/include/block/request_stream.h @@ -98,8 +98,7 @@ class Block::Request_stream : Genode::Noncopyable * If the request does not carry any payload, 'fn' is not * called. */ - template - void with_content(Block::Request request, FN const &fn) const + void with_content(Block::Request request, auto const &fn) const { if (_valid_range_and_alignment(request)) fn(_request_ptr(request), _request_size(request)); @@ -148,8 +147,7 @@ class Block::Request_stream : Genode::Noncopyable * The 'Payload' interface allows the functor to access the content * of a request by calling 'Payload::with_content'. */ - template - void with_payload(FN const &fn) const { fn(_payload); } + void with_payload(auto const &fn) const { fn(_payload); } /** * Call functor 'fn' with the pointer and size to the 'request' content @@ -158,8 +156,7 @@ class Block::Request_stream : Genode::Noncopyable * in situations where the 'Payload' interface does not need to be * propagated as argument. */ - template - void with_content(Request const &request, FN const &fn) const + void with_content(Request const &request, auto const &fn) const { _payload.with_content(request, fn); } @@ -174,8 +171,7 @@ class Block::Request_stream : Genode::Noncopyable * packet stream. If the request could not be accepted, the iteration * aborts and the request packet stays in the packet stream. */ - template - void with_requests(FN const &fn) + void with_requests(auto const &fn) { Tx_sink &tx_sink = *_tx.sink(); @@ -287,8 +283,7 @@ class Block::Request_stream : Genode::Noncopyable * iteration stops when the acknowledgement queue is fully populated or if * the functor does not call 'Ack::submit'. */ - template - void try_acknowledge(FN const &fn) + void try_acknowledge(auto const &fn) { Tx_sink &tx_sink = *_tx.sink(); diff --git a/repos/os/include/block_session/connection.h b/repos/os/include/block_session/connection.h index d4478892d8..4c4e9f6574 100644 --- a/repos/os/include/block_session/connection.h +++ b/repos/os/include/block_session/connection.h @@ -118,8 +118,7 @@ struct Block::Connection : Genode::Connection, Session_client _operation.count - _position) }; } - template - static void _with_offset_and_length(Job &job, FN const &fn) + static void _with_offset_and_length(Job &job, auto const &fn) { if (!Operation::has_payload(job._operation.type)) return; @@ -131,8 +130,7 @@ struct Block::Connection : Genode::Connection, Session_client Genode::min(job._payload.bytes, operation.count * block_size)); } - template - void _submit(POLICY &policy, _JOB &job, Tx::Source &tx) + void _submit(auto &policy, _JOB &job, Tx::Source &tx) { if (!_tag.constructed()) return; @@ -210,16 +208,14 @@ struct Block::Connection : Genode::Connection, Session_client * * \return true if progress was made */ - template - bool _try_process_ack(POLICY &, Tx::Source &); + bool _try_process_ack(auto &, Tx::Source &); /** * Submit next pending job to server, if possible * * \return true if a job was successfully submitted */ - template - bool _try_submit_pending_job(POLICY &, Tx::Source &); + bool _try_submit_pending_job(auto &, Tx::Source &); public: @@ -260,8 +256,7 @@ struct Block::Connection : Genode::Connection, Session_client * * \return true if progress was made */ - template - bool update_jobs(POLICY &policy) + bool update_jobs(auto &policy) { Tx::Source &tx = *_tx.source(); @@ -330,8 +325,7 @@ struct Block::Connection : Genode::Connection, Session_client * This method is intended for the destruction of the jobs associated * with the connection before destructing the 'Connection' object. */ - template - void dissolve_all_jobs(FN const &fn) + void dissolve_all_jobs(auto const &fn) { _pending.dequeue_all([&] (Genode::Fifo_element<_JOB> &elem) { fn(elem.object()); }); diff --git a/repos/os/include/capture_session/capture_session.h b/repos/os/include/capture_session/capture_session.h index 977d6188e4..dc1fe698ea 100644 --- a/repos/os/include/capture_session/capture_session.h +++ b/repos/os/include/capture_session/capture_session.h @@ -98,8 +98,7 @@ struct Capture::Session : Genode::Session Rect rects[NUM_RECTS]; - template - void for_each_rect(FN const &fn) const + void for_each_rect(auto const &fn) const { for (unsigned i = 0; i < NUM_RECTS; i++) if (rects[i].valid()) diff --git a/repos/os/include/capture_session/connection.h b/repos/os/include/capture_session/connection.h index 975cc9e9bc..35393a7737 100644 --- a/repos/os/include/capture_session/connection.h +++ b/repos/os/include/capture_session/connection.h @@ -83,11 +83,7 @@ class Capture::Connection::Screen size(size), _connection(connection), _ds(rm, _connection.dataspace()) { } - template - void with_texture(FN const &fn) const - { - fn(_texture); - } + void with_texture(auto const &fn) const { fn(_texture); } void apply_to_surface(Surface &surface) { diff --git a/repos/os/include/decorator/window_stack.h b/repos/os/include/decorator/window_stack.h index 9cd28a5ef3..9d3db1ab63 100644 --- a/repos/os/include/decorator/window_stack.h +++ b/repos/os/include/decorator/window_stack.h @@ -85,8 +85,7 @@ class Decorator::Window_stack : public Window_base::Draw_behind_fn return result; } - template - inline void update_model(Xml_node root_node, FN const &flush); + inline void update_model(Xml_node root_node, auto const &flush_fn); bool schedule_animated_windows() { @@ -107,8 +106,7 @@ class Decorator::Window_stack : public Window_base::Draw_behind_fn * * The functor is called with 'Window_base &' as argument. */ - template - void for_each_window(FUNC const &func) { _windows.for_each(func); } + void for_each_window(auto const &fn) { _windows.for_each(fn); } void update_gui_views() { @@ -186,9 +184,8 @@ void Decorator::Window_stack::_draw_rec(Decorator::Canvas_base &canvas, } -template void Decorator::Window_stack::update_model(Genode::Xml_node root_node, - FN const &flush_window_stack_changes) + auto const &flush_window_stack_changes_fn) { Abandoned_windows _abandoned_windows { }; @@ -280,7 +277,7 @@ void Decorator::Window_stack::update_model(Genode::Xml_node root_node, * Apply window-creation operations before destroying windows to prevent * flickering. */ - flush_window_stack_changes(); + flush_window_stack_changes_fn(); /* * Destroy abandoned window objects diff --git a/repos/os/include/event_session/client.h b/repos/os/include/event_session/client.h index 35f8467178..4b0e4b687d 100644 --- a/repos/os/include/event_session/client.h +++ b/repos/os/include/event_session/client.h @@ -90,8 +90,7 @@ class Event::Session_client : public Genode::Rpc_client _ds(local_rm, call()) { } - template - void with_batch(FN const &fn) + void with_batch(auto const &fn) { Batch_impl batch { *this }; diff --git a/repos/os/include/file_system_session/connection.h b/repos/os/include/file_system_session/connection.h index 6ddf61d816..defb0b16ef 100644 --- a/repos/os/include/file_system_session/connection.h +++ b/repos/os/include/file_system_session/connection.h @@ -39,14 +39,13 @@ struct File_system::Connection : Genode::Connection, Session_client * * \noapi */ - template - auto _retry(FUNC func) -> decltype(func()) + auto _retry(auto const &fn) -> decltype(fn()) { enum { UPGRADE_ATTEMPTS = ~0U }; return Genode::retry( [&] () { return Genode::retry( - [&] () { return func(); }, + [&] () { return fn(); }, [&] () { File_system::Connection::upgrade_caps(2); }, UPGRADE_ATTEMPTS); }, diff --git a/repos/os/include/file_system_session/file_system_session.h b/repos/os/include/file_system_session/file_system_session.h index d48acf0505..0316539b34 100644 --- a/repos/os/include/file_system_session/file_system_session.h +++ b/repos/os/include/file_system_session/file_system_session.h @@ -248,8 +248,7 @@ class File_system::Packet_descriptor : public Genode::Packet_descriptor size_t length() const { return _op != Opcode::WRITE_TIMESTAMP ? _length : 0; } bool succeeded() const { return _success; } - template - void with_timestamp(FN const &fn) const + void with_timestamp(auto const &fn) const { if (_op == Opcode::WRITE_TIMESTAMP) fn(_modification_time); diff --git a/repos/os/include/gui_session/client.h b/repos/os/include/gui_session/client.h index 1cc8e79c37..d1f26c382c 100644 --- a/repos/os/include/gui_session/client.h +++ b/repos/os/include/gui_session/client.h @@ -97,11 +97,8 @@ class Gui::Session_client : public Genode::Rpc_client * Only in the corner case when there is not space left in the command * buffer, the 'execute' is called to make room in the buffer. */ - template - void enqueue(ARGS... args) - { - enqueue(Command( CMD { args... } )); - } + template + void enqueue(auto &&... args) { enqueue(Command( CMD { args... } )); } void enqueue(Command const &command) { diff --git a/repos/os/include/i2c_session/i2c_session.h b/repos/os/include/i2c_session/i2c_session.h index ae60f28858..d3fead3497 100644 --- a/repos/os/include/i2c_session/i2c_session.h +++ b/repos/os/include/i2c_session/i2c_session.h @@ -55,8 +55,7 @@ struct I2c::Session : public Genode::Session Message() {} - template - Message(Type type, ARGS ... args) + Message(Type type, auto ... args) : Byte_array(args...), type(type) {} }; diff --git a/repos/os/include/input/event.h b/repos/os/include/input/event.h index e9f84c71e1..9893017317 100644 --- a/repos/os/include/input/event.h +++ b/repos/os/include/input/event.h @@ -146,71 +146,61 @@ class Input::Event return release() && _attr.release.key == key; } - template - void handle_press(FN const &fn) const + void handle_press(auto const &fn) const { if (press() && _valid(_attr.press.key)) fn(_attr.press.key, _attr.press.codepoint); } - template - void handle_repeat(FN const &fn) const + void handle_repeat(auto const &fn) const { if (key_press(KEY_UNKNOWN) && _attr.press.codepoint.valid()) fn(_attr.press.codepoint); } - template - void handle_release(FN const &fn) const + void handle_release(auto const &fn) const { if (release() && _valid(_attr.release.key)) fn(_attr.release.key); } - template - void handle_relative_motion(FN const &fn) const + void handle_relative_motion(auto const &fn) const { if (relative_motion()) fn(_attr.rel_motion.x, _attr.rel_motion.y); } - template - void handle_absolute_motion(FN const &fn) const + void handle_absolute_motion(auto const &fn) const { if (absolute_motion()) fn(_attr.abs_motion.x, _attr.abs_motion.y); } - template - void handle_wheel(FN const &fn) const + void handle_wheel(auto const &fn) const { if (wheel()) fn(_attr.wheel.x, _attr.wheel.y); } - template - void handle_touch(FN const &fn) const + void handle_touch(auto const &fn) const { if (touch()) fn(_attr.touch.id, _attr.touch.x, _attr.touch.y); } - template - void handle_touch_release(FN const &fn) const + void handle_touch_release(auto const &fn) const { if (touch_release()) fn(_attr.touch_release.id); } - template - void handle_seq_number(FN const &fn) const + void handle_seq_number(auto const &fn) const { if (seq_number()) fn(_attr.seq_number); } - template - void handle_axis(FN const &fn) const + void handle_axis(auto const &fn) const { if (axis()) fn(_attr.axis.id, _attr.axis.value); diff --git a/repos/os/include/input_session/client.h b/repos/os/include/input_session/client.h index dd29a1e4f7..633bc98d3d 100644 --- a/repos/os/include/input_session/client.h +++ b/repos/os/include/input_session/client.h @@ -56,17 +56,16 @@ class Input::Session_client : public Genode::Rpc_client /** * Flush and apply functor to pending events * - * \param func functor in the form of f(Event const &e) + * \param fn functor in the form of f(Event const &e) * \return number of events processed */ - template - void for_each_event(FUNC const &func) + void for_each_event(auto const &fn) { Genode::size_t const n = Genode::min((Genode::size_t)call(), _max_events); Event const *ev_buf = _event_ds.local_addr(); for (Genode::size_t i = 0; i < n; ++i) - func(ev_buf[i]); + fn(ev_buf[i]); } }; diff --git a/repos/os/include/monitor/output.h b/repos/os/include/monitor/output.h index f16853d2fa..db9364ccc6 100644 --- a/repos/os/include/monitor/output.h +++ b/repos/os/include/monitor/output.h @@ -25,8 +25,7 @@ namespace Genode { struct Genode::Gdb_hex : Hex { - template - explicit Gdb_hex(T value) : Hex(value, OMIT_PREFIX, PAD) { } + explicit Gdb_hex(auto value) : Hex(value, OMIT_PREFIX, PAD) { } }; diff --git a/repos/os/include/net/dhcp.h b/repos/os/include/net/dhcp.h index 7dcef7a6e6..f53a30a09b 100644 --- a/repos/os/include/net/dhcp.h +++ b/repos/os/include/net/dhcp.h @@ -217,13 +217,12 @@ class Net::Dhcp_packet Dns_server(Genode::size_t len) : Option(CODE, (Genode::uint8_t)len) { } - template - void for_each_address(FUNC && func) const + void for_each_address(auto const &fn) const { for (unsigned idx = 0; idx < len() / sizeof(_dns_servers[0]); idx++) { - func(_dns_servers[idx]); + fn(_dns_servers[idx]); } } }; @@ -243,10 +242,9 @@ class Net::Dhcp_packet Domain_name (Genode::size_t len) : Option(CODE, (Genode::uint8_t)len) { } - template - void with_string(FUNC && func) const + void with_string(auto const &fn) const { - func(_name, Option::len()); + fn(_name, Option::len()); } }; @@ -427,12 +425,11 @@ class Net::Dhcp_packet _size_guard(size_guard) { } - template - void append_option(ARGS &&... args) + template + void append_option(auto &&... args) { _size_guard.consume_head(sizeof(OPTION)); - Genode::construct_at