MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
MockWriter Struct Reference
Inheritance diagram for MockWriter:
Collaboration diagram for MockWriter:

Public Member Functions

virtual mxlStatus cancel () override
bool checkReadTimeUpdated ()
virtual mxlStatus commit (mxlGrainInfo const &) override
virtual::mxlFlowConfigInfo getFlowConfigInfo () const override
virtual FlowData const & getFlowData () const override
virtual FlowData & getFlowData () override
virtual::mxlFlowInfo getFlowInfo () const override
virtual::mxlFlowRuntimeInfo getFlowRuntimeInfo () const override
virtual mxlGrainInfo getGrainInfo (std::uint64_t) const override
virtual bool isExclusive () const override
virtual bool makeExclusive () override
 MockWriter (std::filesystem::path const &domain, uuids::uuid id, DomainWatcher::ptr const &watcher)
virtual mxlStatus openGrain (std::uint64_t, mxlGrainInfo *, std::uint8_t **) override
virtual ~MockWriter () override
Public Member Functions inherited from mxl::lib::FlowWriter
uuids::uuid const & getId () const
virtual ~FlowWriter ()

Public Attributes

Flow * _flowData
int _flowDataFd
uuids::uuid _id
mxlFlowInfo _info
std::uint64_t _lastReadTime
DomainWatcher::ptr _watcher

Additional Inherited Members

Protected Member Functions inherited from mxl::lib::DiscreteFlowWriter
 FlowWriter (uuids::uuid &&flowId, std::filesystem::path const &domain)
 FlowWriter (uuids::uuid const &flowId, std::filesystem::path const &domain)
Protected Member Functions inherited from mxl::lib::FlowWriter
bool checkPermissions () const
 FlowWriter (uuids::uuid &&flowId, std::filesystem::path const &domain)
 FlowWriter (uuids::uuid const &flowId, std::filesystem::path const &domain)

Detailed Description

Definition at line 103 of file test_domainwatcher.cpp.

Constructor & Destructor Documentation

◆ MockWriter()

MockWriter::MockWriter ( std::filesystem::path const & domain,
uuids::uuid id,
DomainWatcher::ptr const & watcher )
inline

Definition at line 105 of file test_domainwatcher.cpp.

106 : mxl::lib::DiscreteFlowWriter{id, domain}
107 , _info{}
108 , _id{id}
109 , _watcher{watcher}
110 {
111 _watcher->addFlow(this, _id);
112 _flowDataFd = ::open(makeFlowDataFilePath(domain, uuids::to_string(id)).c_str(), O_RDONLY | O_CLOEXEC, 0);
113 if (_flowDataFd < 0)
114 {
115 auto const error = errno;
116 throw std::system_error{error, std::system_category(), "Failed to open grain data file"};
117 }
118
119 _flowData = reinterpret_cast<Flow*>(::mmap(nullptr, sizeof(Flow), PROT_READ, MAP_SHARED, _flowDataFd, 0));
120 if (_flowData == MAP_FAILED)
121 {
122 auto const error = errno;
123 throw std::system_error{error, std::system_category(), "Failed to map grain data file"};
124 }
125 }
std::filesystem::path makeFlowDataFilePath(std::filesystem::path const &flowDirectory)
Definition PathUtils.cpp:17
DomainWatcher::ptr _watcher

◆ ~MockWriter()

virtual MockWriter::~MockWriter ( )
inlineoverridevirtual

Definition at line 127 of file test_domainwatcher.cpp.

128 {
129 _watcher->removeFlow(this, _id);
130 if ((_flowData != nullptr) && (_flowData != MAP_FAILED))
131 {
132 (void)::munmap(_flowData, sizeof(Flow));
133 }
134
135 if (_flowDataFd > -1)
136 {
137 (void)::close(_flowDataFd);
138 }
139 }

Member Function Documentation

◆ cancel()

virtual mxlStatus MockWriter::cancel ( )
inlineoverridevirtual

Implements mxl::lib::DiscreteFlowWriter.

Definition at line 200 of file test_domainwatcher.cpp.

201 {
202 return MXL_STATUS_OK;
203 }
@ MXL_STATUS_OK
Definition mxl.h:23

◆ checkReadTimeUpdated()

bool MockWriter::checkReadTimeUpdated ( )
inline

Definition at line 205 of file test_domainwatcher.cpp.

206 {
207 auto before = _lastReadTime;
208 _lastReadTime = _flowData->info.runtime.lastReadTime;
209 return before != _lastReadTime;
210 }
std::uint64_t _lastReadTime

◆ commit()

virtual mxlStatus MockWriter::commit ( mxlGrainInfo const & )
inlineoverridevirtual

Implements mxl::lib::DiscreteFlowWriter.

Definition at line 195 of file test_domainwatcher.cpp.

196 {
197 return MXL_STATUS_OK;
198 }

◆ getFlowConfigInfo()

virtual::mxlFlowConfigInfo MockWriter::getFlowConfigInfo ( ) const
inlineoverridevirtual

Accessor for the immutable metadata that describes the currently opened flow. The reader must be properly attached to the flow before invoking this method.

Returns
A copy of the mxlFlowConfigInfo of the currently opened flow.

Implements mxl::lib::FlowWriter.

Definition at line 160 of file test_domainwatcher.cpp.

161 {
162 return _info.config;
163 }

◆ getFlowData() [1/2]

virtual FlowData const & MockWriter::getFlowData ( ) const
inlineoverridevirtual

Accessor for the underlying flow data. The flow writer must first open the flow before invoking this method.

Implements mxl::lib::FlowWriter.

Definition at line 149 of file test_domainwatcher.cpp.

150 {
151 // Implementation is not provided
152 std::terminate();
153 }

◆ getFlowData() [2/2]

virtual FlowData & MockWriter::getFlowData ( )
inlineoverridevirtual

Accessor for the underlying flow data. The flow writer must first open the flow before invoking this method.

Implements mxl::lib::FlowWriter.

Definition at line 142 of file test_domainwatcher.cpp.

143 {
144 // Implementation is not provided
145 std::terminate();
146 }

◆ getFlowInfo()

virtual::mxlFlowInfo MockWriter::getFlowInfo ( ) const
inlineoverridevirtual

Accessor for the current mxlFlowInfo. A copy of the current structure is returned. The flow writer must first open the flow before invoking this method.

Returns
A copy of the mxlFlowInfo

Implements mxl::lib::FlowWriter.

Definition at line 155 of file test_domainwatcher.cpp.

156 {
157 return _info;
158 }

◆ getFlowRuntimeInfo()

virtual::mxlFlowRuntimeInfo MockWriter::getFlowRuntimeInfo ( ) const
inlineoverridevirtual

Accessor for the current metadata that describes the current runtime state of the currently opened flow. The reader must be properly attached to the flow before invoking this method.

Returns
A copy of the current mxlFlowRuntimeInfo of the currently opened flow.

Implements mxl::lib::FlowWriter.

Definition at line 165 of file test_domainwatcher.cpp.

166 {
167 return _info.runtime;
168 }

◆ getGrainInfo()

virtual mxlGrainInfo MockWriter::getGrainInfo ( std::uint64_t ) const
inlineoverridevirtual

Get the grain info for a specific grain index without opening the grain for mutation.

Implements mxl::lib::DiscreteFlowWriter.

Definition at line 184 of file test_domainwatcher.cpp.

185 {
186 // Implementation is not provided
187 std::terminate();
188 };

◆ isExclusive()

virtual bool MockWriter::isExclusive ( ) const
inlineoverridevirtual

Check if this is the only writer for this flow.

Implements mxl::lib::FlowWriter.

Definition at line 170 of file test_domainwatcher.cpp.

171 {
172 return false;
173 }

◆ makeExclusive()

virtual bool MockWriter::makeExclusive ( )
inlineoverridevirtual

Try to turn this into a exclusive writer.

Returns
true if the operation was successful and this is the only writer, false if the operation was not successful because there are other active writers for this flow.

Implements mxl::lib::FlowWriter.

Definition at line 175 of file test_domainwatcher.cpp.

176 {
177 return false;
178 }

◆ openGrain()

virtual mxlStatus MockWriter::openGrain ( std::uint64_t ,
mxlGrainInfo * ,
std::uint8_t **  )
inlineoverridevirtual

Implements mxl::lib::DiscreteFlowWriter.

Definition at line 190 of file test_domainwatcher.cpp.

191 {
192 return MXL_STATUS_OK;
193 }

Member Data Documentation

◆ _flowData

Flow* MockWriter::_flowData

Definition at line 218 of file test_domainwatcher.cpp.

◆ _flowDataFd

int MockWriter::_flowDataFd

Definition at line 217 of file test_domainwatcher.cpp.

◆ _id

uuids::uuid MockWriter::_id

Definition at line 213 of file test_domainwatcher.cpp.

◆ _info

mxlFlowInfo MockWriter::_info

Definition at line 212 of file test_domainwatcher.cpp.

◆ _lastReadTime

std::uint64_t MockWriter::_lastReadTime

Definition at line 216 of file test_domainwatcher.cpp.

◆ _watcher

DomainWatcher::ptr MockWriter::_watcher

Definition at line 214 of file test_domainwatcher.cpp.


The documentation for this struct was generated from the following file: