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
8#include <utility>
9
10namespace ringbuffer
11{
13 {
14 private:
15 WriterPtr underlying_writer;
16 ccf::ds::WorkBeaconPtr work_beacon;
17
18 public:
20 underlying_writer(std::move(writer)),
21 work_beacon(std::move(wb))
22 {}
23
24 // After the underlying writer finishes writing a message, notify any
25 // waiting receivers
26 void finish(const WriteMarker& marker) override
27 {
28 underlying_writer->finish(marker);
29 work_beacon->notify_work_available();
30 }
31
32 // For all other overrides, defer directly to the underlying writer
34 Message m,
35 size_t size,
36 bool wait = true,
37 size_t* identifier = nullptr) override
38 {
39 return underlying_writer->prepare(m, size, wait, identifier);
40 }
41
43 const WriteMarker& marker, const uint8_t* bytes, size_t size) override
44 {
45 return underlying_writer->write_bytes(marker, bytes, size);
46 }
47
48 size_t get_max_message_size() override
49 {
50 return underlying_writer->get_max_message_size();
51 }
52 };
53
55 {
56 private:
57 AbstractWriterFactory& factory_impl;
58
59 ccf::ds::WorkBeaconPtr outbound_work_beacon;
60 ccf::ds::WorkBeaconPtr inbound_work_beacon;
61
62 public:
64 factory_impl(impl),
65 outbound_work_beacon(std::make_shared<ccf::ds::WorkBeacon>()),
66 inbound_work_beacon(std::make_shared<ccf::ds::WorkBeacon>())
67 {}
68
70 {
71 return outbound_work_beacon;
72 }
73
75 {
76 return inbound_work_beacon;
77 }
78
79 std::shared_ptr<NotifyingWriter> create_notifying_writer_to_outside()
80 {
81 return std::make_shared<NotifyingWriter>(
82 factory_impl.create_writer_to_outside(), outbound_work_beacon);
83 }
84
85 std::shared_ptr<NotifyingWriter> create_notifying_writer_to_inside()
86 {
87 return std::make_shared<NotifyingWriter>(
88 factory_impl.create_writer_to_inside(), inbound_work_beacon);
89 }
90
91 std::shared_ptr<ringbuffer::AbstractWriter> create_writer_to_outside()
92 override
93 {
95 }
96
97 std::shared_ptr<ringbuffer::AbstractWriter> create_writer_to_inside()
98 override
99 {
101 }
102 };
103}
Definition ring_buffer_types.h:157
virtual WriterPtr create_writer_to_inside()=0
virtual WriterPtr create_writer_to_outside()=0
Definition ring_buffer_types.h:63
std::optional< size_t > WriteMarker
Definition ring_buffer_types.h:100
Definition notifying.h:55
std::shared_ptr< NotifyingWriter > create_notifying_writer_to_outside()
Definition notifying.h:79
std::shared_ptr< ringbuffer::AbstractWriter > create_writer_to_outside() override
Definition notifying.h:91
std::shared_ptr< NotifyingWriter > create_notifying_writer_to_inside()
Definition notifying.h:85
std::shared_ptr< ringbuffer::AbstractWriter > create_writer_to_inside() override
Definition notifying.h:97
ccf::ds::WorkBeaconPtr get_inbound_work_beacon()
Definition notifying.h:74
ccf::ds::WorkBeaconPtr get_outbound_work_beacon()
Definition notifying.h:69
NotifyingWriterFactory(AbstractWriterFactory &impl)
Definition notifying.h:63
Definition notifying.h:13
NotifyingWriter(WriterPtr writer, ccf::ds::WorkBeaconPtr wb)
Definition notifying.h:19
WriteMarker write_bytes(const WriteMarker &marker, const uint8_t *bytes, size_t size) override
Definition notifying.h:42
size_t get_max_message_size() override
Definition notifying.h:48
WriteMarker prepare(Message m, size_t size, bool wait=true, size_t *identifier=nullptr) override
Definition notifying.h:33
void finish(const WriteMarker &marker) override
Definition notifying.h:26
std::shared_ptr< WorkBeacon > WorkBeaconPtr
Definition work_beacon.h:60
Definition app_interface.h:14
Definition dl_list.h:9
Definition non_blocking.h:15
std::shared_ptr< AbstractWriter > WriterPtr
Definition ring_buffer_types.h:154
uint32_t Message
Definition ring_buffer_types.h:19
STL namespace.