Skip to content

Commit 50fa021

Browse files
committed
Delegates: Updated to even simpler delegate initialization some places
1 parent 0b7ff01 commit 50fa021

14 files changed

Lines changed: 34 additions & 45 deletions

File tree

api/hw/serial.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <hw/ioport.hpp>
2525
#include <cstdio>
2626

27-
namespace hw{
27+
namespace hw {
2828

2929
class Serial {
3030
public:
@@ -33,16 +33,14 @@ namespace hw{
3333
using on_data_handler = delegate<void(char c)>;
3434
using on_string_handler = delegate<void(const std::string& s)>;
3535

36-
using irq_delg = delegate<void()>;
37-
3836
template <uint16_t PORT>
3937
static Serial& port(){
4038
static Serial s{PORT};
4139
return s;
4240
}
4341

4442
OS::print_func get_print_handler() {
45-
return OS::print_func{this, &Serial::print_handler};
43+
return {this, &Serial::print_handler};
4644
}
4745

4846
void on_data(on_data_handler del);

api/kernel/vga.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ConsoleVGA {
4747
explicit ConsoleVGA() noexcept;
4848

4949
OS::print_func get_print_handler() {
50-
return OS::print_func{this, &ConsoleVGA::write};
50+
return {this, &ConsoleVGA::write};
5151
}
5252

5353
constexpr static uint8_t make_color(const vga_color fg, const vga_color bg) noexcept

api/net/ip4/arp.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ namespace net {
9797
// @TODO: Add HÅREK-mapping here
9898
switch (nm) {
9999
case HH_MAP:
100-
arp_resolver_ = Arp_resolver{*this, &Arp::hh_map};
100+
arp_resolver_ = {this, &Arp::hh_map};
101101
break;
102102
default:
103-
arp_resolver_ = Arp_resolver{*this, &Arp::arp_resolve};
103+
arp_resolver_ = {this, &Arp::arp_resolve};
104104
}
105105
}
106106

@@ -145,7 +145,7 @@ namespace net {
145145
void arp_resolve(Packet_ptr);
146146
void hh_map(Packet_ptr);
147147

148-
Arp_resolver arp_resolver_ = Arp_resolver{*this, &Arp::arp_resolve};
148+
Arp_resolver arp_resolver_ = {this, &Arp::arp_resolve};
149149

150150
PacketQueue waiting_packets_;
151151

api/net/tcp/connection.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ inline Connection& Connection::_on_cleanup(CleanupCallback cb) {
4444
}
4545

4646
inline void Connection::write(const void* buf, size_t n) {
47-
write(buf, n, WriteCallback{this, &Connection::default_on_write}, true);
47+
write(buf, n, {this, &Connection::default_on_write}, true);
4848
}
4949

5050
inline void Connection::write(const void* buf, size_t n, WriteCallback callback) {
5151
write(buf, n, callback, true);
5252
}
5353

5454
inline void Connection::write(buffer_t buffer, size_t n) {
55-
write({buffer, n, true}, WriteCallback{this, &Connection::default_on_write});
55+
write({buffer, n, true}, {this, &Connection::default_on_write});
5656
}
5757

5858
inline void Connection::write(buffer_t buffer, size_t n, WriteCallback callback) {

api/net/tcp/read_request.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct ReadRequest {
3232

3333
/*ReadRequest()
3434
: buffer(nullptr, 0),
35-
callback(ReadCallback{this, &ReadRequest::default_read_callback})
35+
callback({this, &ReadRequest::default_read_callback})
3636
{}*/
3737

3838
ReadRequest(ReadBuffer buf, ReadCallback cb)
@@ -42,7 +42,7 @@ struct ReadRequest {
4242

4343
ReadRequest(size_t n = 0)
4444
: buffer(buffer_t(new uint8_t[n], std::default_delete<uint8_t[]>()), n),
45-
callback(ReadCallback{this, &ReadRequest::default_read_callback})
45+
callback({this, &ReadRequest::default_read_callback})
4646
{}
4747

4848
void clean_up() {

src/drivers/virtionet.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ std::shared_ptr<Packet>
302302
VirtioNet::recv_packet(uint8_t* data, uint16_t size)
303303
{
304304
auto* ptr = (Packet*) (data + sizeof(VirtioNet::virtio_net_hdr) - sizeof(Packet));
305-
new (ptr) Packet(bufsize(), size,
306-
delegate<void(void*)>{&bufstore(), &BufferStore::release});
305+
new (ptr) Packet(bufsize(), size, {&bufstore(), &BufferStore::release});
307306

308307
return std::shared_ptr<Packet> (ptr);
309308
}

src/drivers/virtionet.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ class VirtioNet : Virtio, public hw::Nic {
128128
{ return 1500; }
129129

130130
net::downstream get_physical_out() override {
131-
using downstream = net::downstream;
132-
return downstream{this, &VirtioNet::transmit};
131+
return {this, &VirtioNet::transmit};
133132
}
134133

135134
/** Linklayer input. Hooks into IP-stack bottom, w.DOWNSTREAM data.*/

src/hw/serial.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ void Serial::print_handler(const char* str, size_t len) {
5353

5454
void Serial::on_data(on_data_handler del) {
5555
enable_interrupt();
56-
on_data_=del;
56+
on_data_ = del;
5757
INFO("Serial", "Subscribing to data on IRQ %i",irq_);
58-
IRQ_manager::get().subscribe(irq_, irq_delg{this, &Serial::irq_handler_});
58+
IRQ_manager::get().subscribe(irq_, {this, &Serial::irq_handler_});
5959
IRQ_manager::get().enable_irq(irq_);
6060
}
6161

6262
void Serial::on_readline(on_string_handler del, char delim) {
6363
newline = delim;
6464
on_readline_ = del;
65-
on_data(on_data_handler{this, &Serial::readline_handler_});
65+
on_data({this, &Serial::readline_handler_});
6666
debug("<Serial::on_readline> Subscribing to data %i \n", irq_);
6767
}
6868

src/net/inet4.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ Inet4::Inet4(hw::Nic& nic)
2828

2929
/** Upstream wiring */
3030
// Packets available
31-
nic.on_transmit_queue_available(
32-
transmit_avail_delg{*this, &Inet4::process_sendq});
31+
nic.on_transmit_queue_available({this, &Inet4::process_sendq});
3332

3433
// Phys -> Eth (Later, this will be passed through router)
3534
nic.set_linklayer_out(eth_bottom);

src/net/ip4/udp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ namespace net {
3030
: stack_(inet)
3131
{
3232
network_layer_out_ = [] (net::Packet_ptr) {};
33-
inet.on_transmit_queue_available(
34-
transmit_avail_delg{this, &UDP::process_sendq});
33+
inet.on_transmit_queue_available({this, &UDP::process_sendq});
3534
}
3635

3736
void UDP::bottom(net::Packet_ptr pckt)

0 commit comments

Comments
 (0)