CCF
Loading...
Searching...
No Matches
notifying.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ring_buffer.h"
6#include "work_beacon.h"
7
8namespace ringbuffer
9{
11 {
12 private:
13 WriterPtr underlying_writer;
14 ccf::ds::WorkBeaconPtr work_beacon;
15
16 public:
18 underlying_writer(writer),
19 work_beacon(wb)
20 {}
21
22 // After the underlying writer finishes writing a message, notify any
23 // waiting receivers
24 void finish(const WriteMarker& marker) override
25 {
26 underlying_writer->finish(marker);
27 work_beacon->notify_work_available();
28 }
29
30 // For all other overrides, defer directly to the underlying writer
32 Message m,
33 size_t size,
34 bool wait = true,
35 size_t* identifier = nullptr) override
36 {
37 return underlying_writer->prepare(m, size, wait, identifier);
38 }
39
41 const WriteMarker& marker, const uint8_t* bytes, size_t size) override
42 {
43 return underlying_writer->write_bytes(marker, bytes, size);
44 }
45
46 size_t get_max_message_size() override
47 {
48 return underlying_writer->get_max_message_size();
49 }
50 };
51
53 {
54 private:
55 AbstractWriterFactory& factory_impl;
56
57 ccf::ds::WorkBeaconPtr outbound_work_beacon;
58 ccf::ds::WorkBeaconPtr inbound_work_beacon;
59
60 public:
62 factory_impl(impl),
63 outbound_work_beacon(std::make_shared<ccf::ds::WorkBeacon>()),
64 inbound_work_beacon(std::make_shared<ccf::ds::WorkBeacon>())
65 {}
66
68 {
69 return outbound_work_beacon;
70 }
71
73 {
74 return inbound_work_beacon;
75 }
76
77 std::shared_ptr<NotifyingWriter> create_notifying_writer_to_outside()
78 {
79 return std::make_shared<NotifyingWriter>(
80 factory_impl.create_writer_to_outside(), outbound_work_beacon);
81 }
82
83 std::shared_ptr<NotifyingWriter> create_notifying_writer_to_inside()
84 {
85 return std::make_shared<NotifyingWriter>(
86 factory_impl.create_writer_to_inside(), inbound_work_beacon);
87 }
88
89 std::shared_ptr<ringbuffer::AbstractWriter> create_writer_to_outside()
90 override
91 {
93 }
94
95 std::shared_ptr<ringbuffer::AbstractWriter> create_writer_to_inside()
96 override
97 {
99 }
100 };
101}
Definition ring_buffer_types.h:153
virtual WriterPtr create_writer_to_inside()=0
virtual WriterPtr create_writer_to_outside()=0
Definition ring_buffer_types.h:61
std::optional< size_t > WriteMarker
Definition ring_buffer_types.h:98
Definition notifying.h:53
std::shared_ptr< NotifyingWriter > create_notifying_writer_to_outside()
Definition notifying.h:77
std::shared_ptr< ringbuffer::AbstractWriter > create_writer_to_outside() override
Definition notifying.h:89
std::shared_ptr< NotifyingWriter > create_notifying_writer_to_inside()
Definition notifying.h:83
std::shared_ptr< ringbuffer::AbstractWriter > create_writer_to_inside() override
Definition notifying.h:95
ccf::ds::WorkBeaconPtr get_inbound_work_beacon()
Definition notifying.h:72
ccf::ds::WorkBeaconPtr get_outbound_work_beacon()
Definition notifying.h:67
NotifyingWriterFactory(AbstractWriterFactory &impl)
Definition notifying.h:61
Definition notifying.h:11
NotifyingWriter(const WriterPtr &writer, const ccf::ds::WorkBeaconPtr &wb)
Definition notifying.h:17
WriteMarker write_bytes(const WriteMarker &marker, const uint8_t *bytes, size_t size) override
Definition notifying.h:40
size_t get_max_message_size() override
Definition notifying.h:46
WriteMarker prepare(Message m, size_t size, bool wait=true, size_t *identifier=nullptr) override
Definition notifying.h:31
void finish(const WriteMarker &marker) override
Definition notifying.h:24
std::shared_ptr< WorkBeacon > WorkBeaconPtr
Definition work_beacon.h:60
Definition app_interface.h:14
Definition dl_list.h:9
Definition non_blocking.h:14
std::shared_ptr< AbstractWriter > WriterPtr
Definition ring_buffer_types.h:150
uint32_t Message
Definition ring_buffer_types.h:19
STL namespace.