Skip to content

Commit 0c9d09b

Browse files
authored
Merge pull request #849 from AnnikaH/dev
Delegates: Updated to new delegate initialization
2 parents b0fe03b + 50fa021 commit 0c9d09b

20 files changed

Lines changed: 82 additions & 106 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::from(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::from(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::from<Arp, &Arp::hh_map>(*this);
100+
arp_resolver_ = {this, &Arp::hh_map};
101101
break;
102102
default:
103-
arp_resolver_ = Arp_resolver::from<Arp, &Arp::arp_resolve>(*this);
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::from<Arp, &Arp::arp_resolve>(*this);
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::from<Connection,&Connection::default_on_write>(this), 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::from<Connection,&Connection::default_on_write>(this));
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: 3 additions & 3 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::from<ReadRequest, &ReadRequest::default_read_callback>(this))
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::from<ReadRequest, &ReadRequest::default_read_callback>(this))
45+
callback({this, &ReadRequest::default_read_callback})
4646
{}
4747

4848
void clean_up() {
@@ -55,4 +55,4 @@ struct ReadRequest {
5555
} // < namespace tcp
5656
} // < namespace net
5757

58-
#endif // < NET_TCP_READ_REQUEST_HPP
58+
#endif // < NET_TCP_READ_REQUEST_HPP

src/drivers/virtioblk.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void null_deleter(uint8_t*) {};
3434
#include <statman>
3535

3636
VirtioBlk::VirtioBlk(hw::PCI_Device& d)
37-
: Virtio(d), hw::Drive(), req(queue_size(0), 0, iobase())
37+
: Virtio(d), hw::Drive(), req(queue_size(0), 0, iobase()), inflight(0)
3838
{
3939
INFO("VirtioBlk", "Driver initializing");
4040
{
@@ -93,16 +93,16 @@ VirtioBlk::VirtioBlk(hw::PCI_Device& d)
9393
// Hook up IRQ handler (inherited from Virtio)
9494
if (is_msix())
9595
{
96-
auto conf_del(delegate<void()>::from<VirtioBlk, &VirtioBlk::msix_conf_handler>(this));
97-
auto req_del(delegate<void()>::from<VirtioBlk, &VirtioBlk::service_RX>(this));
96+
auto conf_del(delegate<void()>{this, &VirtioBlk::msix_conf_handler});
97+
auto req_del(delegate<void()>{this, &VirtioBlk::service_RX});
9898
// update IRQ subscriptions
9999
IRQ_manager::get().subscribe(irq() + 0, req_del);
100100
IRQ_manager::get().subscribe(irq() + 1, conf_del);
101101
}
102102
else
103103
{
104-
auto del(delegate<void()>::from<VirtioBlk, &VirtioBlk::irq_handler>(this));
105-
IRQ_manager::get().subscribe(irq(),del);
104+
auto del(delegate<void()>{this, &VirtioBlk::irq_handler});
105+
IRQ_manager::get().subscribe(irq(), del);
106106
}
107107

108108
// Done

src/drivers/virtionet.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ VirtioNet::VirtioNet(hw::PCI_Device& d)
152152
if (is_msix())
153153
{
154154
// for now use service queues, otherwise stress test fails
155-
auto recv_del(delegate<void()>::from<VirtioNet,&VirtioNet::msix_recv_handler>(this));
156-
auto xmit_del(delegate<void()>::from<VirtioNet,&VirtioNet::msix_xmit_handler>(this));
157-
auto conf_del(delegate<void()>::from<VirtioNet,&VirtioNet::msix_conf_handler>(this));
155+
auto recv_del(delegate<void()>{this, &VirtioNet::msix_recv_handler});
156+
auto xmit_del(delegate<void()>{this, &VirtioNet::msix_xmit_handler});
157+
auto conf_del(delegate<void()>{this, &VirtioNet::msix_conf_handler});
158+
158159
// update BSP IDT
159160
IRQ_manager::get().subscribe(irq() + 0, recv_del);
160161
IRQ_manager::get().subscribe(irq() + 1, xmit_del);
@@ -163,7 +164,7 @@ VirtioNet::VirtioNet(hw::PCI_Device& d)
163164
else
164165
{
165166
// legacy PCI interrupt
166-
auto del(delegate<void()>::from<VirtioNet,&VirtioNet::irq_handler>(this));
167+
auto del(delegate<void()>{this, &VirtioNet::irq_handler});
167168
IRQ_manager::get().subscribe(irq(),del);
168169
}
169170

@@ -301,8 +302,7 @@ std::shared_ptr<Packet>
301302
VirtioNet::recv_packet(uint8_t* data, uint16_t size)
302303
{
303304
auto* ptr = (Packet*) (data + sizeof(VirtioNet::virtio_net_hdr) - sizeof(Packet));
304-
new (ptr) Packet(bufsize(), size,
305-
delegate<void(void*)>::from<BufferStore, &BufferStore::release> (&bufstore()));
305+
new (ptr) Packet(bufsize(), size, {&bufstore(), &BufferStore::release});
306306

307307
return std::shared_ptr<Packet> (ptr);
308308
}
@@ -367,7 +367,7 @@ void VirtioNet::service_queues(){
367367
auto buf = transmit_queue_;
368368
transmit_queue_ = 0;
369369
transmit(buf);
370-
}else{
370+
} else {
371371
debug("<VirtioNet> Transmit queue is empty \n");
372372
}
373373

@@ -400,7 +400,7 @@ void VirtioNet::add_to_tx_buffer(net::Packet_ptr pckt){
400400
debug("Buffering, %i packets chained \n", chain_length);
401401
}
402402
#include <cstdlib>
403-
void VirtioNet::transmit(net::Packet_ptr pckt){
403+
void VirtioNet::transmit(net::Packet_ptr pckt) {
404404
/** @note We have to send a virtio header first, then the packet.
405405
406406
From Virtio std. §5.1.6.6:

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::from<VirtioNet, &VirtioNet::transmit>(this);
131+
return {this, &VirtioNet::transmit};
133132
}
134133

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

src/hw/ide.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ namespace hw {
272272
}
273273

274274
void IDE::enable_irq_handler() {
275-
auto del(delegate<void()>::from<IDE, &IDE::callback_wrapper>(this));
275+
auto del(delegate<void()>{this, &IDE::callback_wrapper});
276276
IRQ_manager::get().subscribe(IDE_IRQN, del);
277277
//IRQ_manager::cpu(0).set_irq_handler(IDE_IRQN + 32, ide_irq_entry);
278278
}

src/hw/pit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ namespace hw {
284284
// must be done to program IOAPIC to redirect to BSP LAPIC
285285
IRQ_manager::get().enable_irq(0);
286286
// register irq handler
287-
auto handler(IRQ_manager::irq_delegate::from<PIT,&PIT::irq_handler>(&instance()));
287+
auto handler(IRQ_manager::irq_delegate{&instance(), &PIT::irq_handler});
288288
IRQ_manager::get().subscribe(0, handler);
289289
}
290290

0 commit comments

Comments
 (0)