Renamed EventNotifer to EventFdNotifier and employed new NotifierInterface
This commit is contained in:
@@ -8,7 +8,7 @@ target_sources(
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/Logger/Logger.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Logger/Logger.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/Paths.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/Paths.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/EpollInstance.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/EpollInstance.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/EventNotifier.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Helpers/EventFdNotifier.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/VersionNumber.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/VersionNumber.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Generated/resources.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/Generated/resources.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ namespace Bloom::DebugServer
|
|||||||
[this] () -> std::unique_ptr<ServerInterface> {
|
[this] () -> std::unique_ptr<ServerInterface> {
|
||||||
return std::make_unique<DebugServer::Gdb::AvrGdb::AvrGdbRsp>(
|
return std::make_unique<DebugServer::Gdb::AvrGdb::AvrGdbRsp>(
|
||||||
this->debugServerConfig,
|
this->debugServerConfig,
|
||||||
*(this->eventListener.get())
|
*(this->eventListener.get()),
|
||||||
|
this->interruptEventNotifier
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "src/Helpers/Thread.hpp"
|
#include "src/Helpers/Thread.hpp"
|
||||||
#include "src/ProjectConfig.hpp"
|
#include "src/ProjectConfig.hpp"
|
||||||
#include "src/Helpers/EventNotifier.hpp"
|
#include "src/Helpers/EventFdNotifier.hpp"
|
||||||
#include "src/EventManager/EventListener.hpp"
|
#include "src/EventManager/EventListener.hpp"
|
||||||
#include "src/EventManager/Events/Events.hpp"
|
#include "src/EventManager/Events/Events.hpp"
|
||||||
|
|
||||||
@@ -48,11 +48,11 @@ namespace Bloom::DebugServer
|
|||||||
DebugServerConfig debugServerConfig;
|
DebugServerConfig debugServerConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This EventNotifier is injected into this->eventListener. It can be used by server implementations to
|
* This EventFdNotifier is injected into this->eventListener. It can be used by server implementations to
|
||||||
* interrupt blocking I/O calls upon an event being triggered. For more, see the "Servicing events" section in
|
* interrupt blocking I/O calls upon an event being triggered. For more, see the "Servicing events" section in
|
||||||
* the DebugServer documentation (src/DebugServer/README.md).
|
* the DebugServer documentation (src/DebugServer/README.md).
|
||||||
*/
|
*/
|
||||||
EventNotifier interruptEventNotifier = EventNotifier();
|
EventFdNotifier interruptEventNotifier = EventFdNotifier();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An instance to the selected server implementation. See DebugServerComponent::startup() for more.
|
* An instance to the selected server implementation. See DebugServerComponent::startup() for more.
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ namespace Bloom::DebugServer::Gdb::AvrGdb
|
|||||||
|
|
||||||
AvrGdbRsp::AvrGdbRsp(
|
AvrGdbRsp::AvrGdbRsp(
|
||||||
const DebugServerConfig& debugServerConfig,
|
const DebugServerConfig& debugServerConfig,
|
||||||
EventListener& eventListener
|
EventListener& eventListener,
|
||||||
|
EventFdNotifier& eventNotifier
|
||||||
)
|
)
|
||||||
: GdbRspDebugServer(debugServerConfig, eventListener)
|
: GdbRspDebugServer(debugServerConfig, eventListener, eventNotifier)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void AvrGdbRsp::init() {
|
void AvrGdbRsp::init() {
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ namespace Bloom::DebugServer::Gdb::AvrGdb
|
|||||||
public:
|
public:
|
||||||
AvrGdbRsp(
|
AvrGdbRsp(
|
||||||
const DebugServerConfig& debugServerConfig,
|
const DebugServerConfig& debugServerConfig,
|
||||||
EventListener& eventListener
|
EventListener& eventListener,
|
||||||
|
EventFdNotifier& eventNotifier
|
||||||
);
|
);
|
||||||
|
|
||||||
std::string getName() const override {
|
std::string getName() const override {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
|
|
||||||
using ResponsePackets::ResponsePacket;
|
using ResponsePackets::ResponsePacket;
|
||||||
|
|
||||||
Connection::Connection(int serverSocketFileDescriptor, EventNotifier& interruptEventNotifier)
|
Connection::Connection(int serverSocketFileDescriptor, EventFdNotifier& interruptEventNotifier)
|
||||||
: interruptEventNotifier(interruptEventNotifier)
|
: interruptEventNotifier(interruptEventNotifier)
|
||||||
{
|
{
|
||||||
this->accept(serverSocketFileDescriptor);
|
this->accept(serverSocketFileDescriptor);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
#include "src/Helpers/EventNotifier.hpp"
|
#include "src/Helpers/EventFdNotifier.hpp"
|
||||||
#include "src/Helpers/EpollInstance.hpp"
|
#include "src/Helpers/EpollInstance.hpp"
|
||||||
|
|
||||||
#include "src/DebugServer/Gdb/Packet.hpp"
|
#include "src/DebugServer/Gdb/Packet.hpp"
|
||||||
@@ -23,7 +23,7 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
class Connection
|
class Connection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Connection(int serverSocketFileDescriptor, EventNotifier& interruptEventNotifier);
|
explicit Connection(int serverSocketFileDescriptor, EventFdNotifier& interruptEventNotifier);
|
||||||
|
|
||||||
Connection() = delete;
|
Connection() = delete;
|
||||||
Connection(const Connection&) = delete;
|
Connection(const Connection&) = delete;
|
||||||
@@ -77,8 +77,8 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
int maxPacketSize = 1024;
|
int maxPacketSize = 1024;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interruptEventNotifier (instance of EventNotifier) allows us to interrupt blocking I/O calls on this
|
* The interruptEventNotifier (instance of EventFdNotifier) allows us to interrupt blocking I/O calls on this
|
||||||
* connection's socket. Under the hood, the EventNotifier class is just an RAII wrapper for a Linux eventfd
|
* connection's socket. Under the hood, the EventFdNotifier class is just an RAII wrapper for a Linux eventfd
|
||||||
* object.
|
* object.
|
||||||
*
|
*
|
||||||
* The file descriptors of the eventfd object and the socket are both added to an EpollInstance (which is just
|
* The file descriptors of the eventfd object and the socket are both added to an EpollInstance (which is just
|
||||||
@@ -86,9 +86,9 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
* either of the two file descriptors. See any of the Connection I/O functions (e.g Connection::read()) for
|
* either of the two file descriptors. See any of the Connection I/O functions (e.g Connection::read()) for
|
||||||
* more on this.
|
* more on this.
|
||||||
*
|
*
|
||||||
* See the EventNotifier and EpollInstance classes for more.
|
* See the EventFdNotifier and EpollInstance classes for more.
|
||||||
*/
|
*/
|
||||||
EventNotifier& interruptEventNotifier;
|
EventFdNotifier& interruptEventNotifier;
|
||||||
EpollInstance epollInstance = EpollInstance();
|
EpollInstance epollInstance = EpollInstance();
|
||||||
|
|
||||||
bool readInterruptEnabled = false;
|
bool readInterruptEnabled = false;
|
||||||
|
|||||||
@@ -39,14 +39,13 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
|
|
||||||
GdbRspDebugServer::GdbRspDebugServer(
|
GdbRspDebugServer::GdbRspDebugServer(
|
||||||
const DebugServerConfig& debugServerConfig,
|
const DebugServerConfig& debugServerConfig,
|
||||||
EventListener& eventListener
|
EventListener& eventListener,
|
||||||
|
EventFdNotifier& eventNotifier
|
||||||
)
|
)
|
||||||
: debugServerConfig(GdbDebugServerConfig(debugServerConfig))
|
: debugServerConfig(GdbDebugServerConfig(debugServerConfig))
|
||||||
, eventListener(eventListener)
|
, eventListener(eventListener)
|
||||||
, interruptEventNotifier(eventListener.getInterruptEventNotifier())
|
, interruptEventNotifier(eventNotifier)
|
||||||
{
|
{}
|
||||||
assert(this->interruptEventNotifier != nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GdbRspDebugServer::init() {
|
void GdbRspDebugServer::init() {
|
||||||
this->socketAddress.sin_family = AF_INET;
|
this->socketAddress.sin_family = AF_INET;
|
||||||
@@ -102,7 +101,7 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
);
|
);
|
||||||
|
|
||||||
this->epollInstance.addEntry(
|
this->epollInstance.addEntry(
|
||||||
this->interruptEventNotifier->getFileDescriptor(),
|
this->interruptEventNotifier.getFileDescriptor(),
|
||||||
static_cast<std::uint16_t>(EpollEvent::READ_READY)
|
static_cast<std::uint16_t>(EpollEvent::READ_READY)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -203,15 +202,15 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
!eventFileDescriptor.has_value()
|
!eventFileDescriptor.has_value()
|
||||||
|| eventFileDescriptor.value() == this->interruptEventNotifier->getFileDescriptor()
|
|| eventFileDescriptor.value() == this->interruptEventNotifier.getFileDescriptor()
|
||||||
) {
|
) {
|
||||||
this->interruptEventNotifier->clear();
|
this->interruptEventNotifier.clear();
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_optional<Connection>(
|
return std::make_optional<Connection>(
|
||||||
this->serverSocketFileDescriptor.value(),
|
this->serverSocketFileDescriptor.value(),
|
||||||
*(this->interruptEventNotifier)
|
this->interruptEventNotifier
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "GdbDebugServerConfig.hpp"
|
#include "GdbDebugServerConfig.hpp"
|
||||||
#include "src/EventManager/EventListener.hpp"
|
#include "src/EventManager/EventListener.hpp"
|
||||||
#include "src/Helpers/EpollInstance.hpp"
|
#include "src/Helpers/EpollInstance.hpp"
|
||||||
|
#include "src/Helpers/EventFdNotifier.hpp"
|
||||||
#include "src/TargetController/TargetControllerConsole.hpp"
|
#include "src/TargetController/TargetControllerConsole.hpp"
|
||||||
|
|
||||||
#include "Connection.hpp"
|
#include "Connection.hpp"
|
||||||
@@ -41,7 +42,8 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
public:
|
public:
|
||||||
explicit GdbRspDebugServer(
|
explicit GdbRspDebugServer(
|
||||||
const DebugServerConfig& debugServerConfig,
|
const DebugServerConfig& debugServerConfig,
|
||||||
EventListener& eventListener
|
EventListener& eventListener,
|
||||||
|
EventFdNotifier& eventNotifier
|
||||||
);
|
);
|
||||||
|
|
||||||
GdbRspDebugServer() = delete;
|
GdbRspDebugServer() = delete;
|
||||||
@@ -86,24 +88,24 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
EventListener& eventListener;
|
EventListener& eventListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EventNotifier object for interrupting blocking I/O operations.
|
* EventFdNotifier object for interrupting blocking I/O operations.
|
||||||
*
|
*
|
||||||
* Extracted from this->eventListener.
|
* Extracted from this->eventListener.
|
||||||
*
|
*
|
||||||
* See documentation in src/DebugServer/README.md for more.
|
* See documentation in src/DebugServer/README.md for more.
|
||||||
*/
|
*/
|
||||||
EventNotifier* interruptEventNotifier = nullptr;
|
EventFdNotifier& interruptEventNotifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When waiting for a connection, we don't listen on the this->serverSocketFileDescriptor directly. Instead,
|
* When waiting for a connection, we don't listen on the this->serverSocketFileDescriptor directly. Instead,
|
||||||
* we use an EpollInstance to monitor both this->serverSocketFileDescriptor and this->interruptEventNotifier.
|
* we use an EpollInstance to monitor both this->serverSocketFileDescriptor and this->interruptEventNotifier.
|
||||||
* This allows us to interrupt any blocking socket IO calls when EventNotifier::notify() is called on
|
* This allows us to interrupt any blocking socket IO calls when EventFdNotifier::notify() is called on
|
||||||
* this->interruptEventNotifier.
|
* this->interruptEventNotifier.
|
||||||
*
|
*
|
||||||
* See GdbRspDebugServer::init()
|
* See GdbRspDebugServer::init()
|
||||||
* See DebugServer::interruptEventNotifier
|
* See DebugServer::interruptEventNotifier
|
||||||
* See EpollInstance
|
* See EpollInstance
|
||||||
* See EventNotifier
|
* See EventFdNotifier
|
||||||
*/
|
*/
|
||||||
EpollInstance epollInstance = EpollInstance();
|
EpollInstance epollInstance = EpollInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -35,22 +35,23 @@ method to ensure that events are processed ASAP. See the relevant documentation
|
|||||||
---
|
---
|
||||||
|
|
||||||
Any blocking I/O employed by a server implementation can support event interrupts using an
|
Any blocking I/O employed by a server implementation can support event interrupts using an
|
||||||
[`EventNotifier`](../Helpers/EventNotifier.hpp) and [`EpollInstance`](../Helpers/EpollInstance.hpp).
|
[`EventFdNotifier`](../Helpers/EventFdNotifier.hpp) and [`EpollInstance`](../Helpers/EpollInstance.hpp).
|
||||||
|
|
||||||
Key points:
|
Key points:
|
||||||
- The `EventNotifier` class is an RAII wrapper for a Linux
|
- The `EventFdNotifier` class is an RAII wrapper for a Linux
|
||||||
[eventfd object](https://man7.org/linux/man-pages/man2/eventfd.2.html). An event can be recorded against the eventfd
|
[eventfd object](https://man7.org/linux/man-pages/man2/eventfd.2.html). It implements the
|
||||||
object via a call to `EventNotifier::notify()`.
|
[`NotifierInterface`](../Helpers/NotifierInterface.hpp). An event can be recorded against the eventfd
|
||||||
- The [`EventListener`](../EventManager/EventListener.hpp) class can accept an `EventNotifier` object via
|
object via a call to `EventFdNotifier::notify()`.
|
||||||
`EventListener::setInterruptEventNotifier()`. If an `EventNotifier` has been set on an `EventListener`, the
|
- The [`EventListener`](../EventManager/EventListener.hpp) class can accept an `NotifierInterface` object via
|
||||||
`EventListener` will call `EventNotifer::notify()` everytime an event is registered for that listener.
|
`EventListener::setInterruptEventNotifier()`. If a `NotifierInterface` has been set on an `EventListener`, the
|
||||||
|
`EventListener` will call `NotifierInterface::notify()` everytime an event is registered for that listener.
|
||||||
- The `EpollInstance` class is an RAII wrapper for a Linux
|
- The `EpollInstance` class is an RAII wrapper for a Linux
|
||||||
[epoll instance](https://man7.org/linux/man-pages/man7/epoll.7.html). It allows us to wait for any activity on a set
|
[epoll instance](https://man7.org/linux/man-pages/man7/epoll.7.html). It allows us to wait for any activity on a set
|
||||||
of file descriptors. File descriptors can be added and removed from the epoll instance via `EpollInstance::addEntry()`
|
of file descriptors. File descriptors can be added and removed from the epoll instance via `EpollInstance::addEntry()`
|
||||||
and `EpollInstance::removeEntry()`. Calling `EpollInstance::waitForEvent()` will block until there is activity on at
|
and `EpollInstance::removeEntry()`. Calling `EpollInstance::waitForEvent()` will block until there is activity on at
|
||||||
least one of the file descriptors, or a timeout has been reached.
|
least one of the file descriptors, or a timeout has been reached.
|
||||||
|
|
||||||
With an `EventNotifer` and `EpollInstance`, one can perform a blocking I/O operation which can be interrupted by an
|
With an `EventFdNotifier` and `EpollInstance`, one can perform a blocking I/O operation which can be interrupted by an
|
||||||
event. For an example of this, see the AVR GDB server implementation - it employs the method described above to allow
|
event. For an example of this, see the AVR GDB server implementation - it employs the method described above to allow
|
||||||
the interruption of blocking I/O operations when an event is triggered. Specifically,
|
the interruption of blocking I/O operations when an event is triggered. Specifically,
|
||||||
[`GdbRspDebugServer::waitForConnection()`](./Gdb/GdbRspDebugServer.hpp) or
|
[`GdbRspDebugServer::waitForConnection()`](./Gdb/GdbRspDebugServer.hpp) or
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include "src/EventManager/Events/Events.hpp"
|
#include "src/EventManager/Events/Events.hpp"
|
||||||
#include "src/Helpers/SyncSafe.hpp"
|
#include "src/Helpers/SyncSafe.hpp"
|
||||||
#include "src/Helpers/EventNotifier.hpp"
|
#include "src/Helpers/NotifierInterface.hpp"
|
||||||
|
|
||||||
namespace Bloom
|
namespace Bloom
|
||||||
{
|
{
|
||||||
@@ -92,11 +92,11 @@ namespace Bloom
|
|||||||
*/
|
*/
|
||||||
void registerEvent(Events::SharedGenericEventPointer event);
|
void registerEvent(Events::SharedGenericEventPointer event);
|
||||||
|
|
||||||
void setInterruptEventNotifier(EventNotifier* interruptEventNotifier) {
|
void setInterruptEventNotifier(NotifierInterface* interruptEventNotifier) {
|
||||||
this->interruptEventNotifier = interruptEventNotifier;
|
this->interruptEventNotifier = interruptEventNotifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] EventNotifier* getInterruptEventNotifier() {
|
[[nodiscard]] NotifierInterface* getInterruptEventNotifier() {
|
||||||
return this->interruptEventNotifier;
|
return this->interruptEventNotifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,7 +370,7 @@ namespace Bloom
|
|||||||
SyncSafe<std::map<Events::EventType, std::vector<std::function<void(const Events::Event&)>>>> eventTypeToCallbacksMapping;
|
SyncSafe<std::map<Events::EventType, std::vector<std::function<void(const Events::Event&)>>>> eventTypeToCallbacksMapping;
|
||||||
SyncSafe<std::set<Events::EventType>> registeredEventTypes;
|
SyncSafe<std::set<Events::EventType>> registeredEventTypes;
|
||||||
|
|
||||||
EventNotifier* interruptEventNotifier = nullptr;
|
NotifierInterface* interruptEventNotifier = nullptr;
|
||||||
|
|
||||||
std::vector<Events::SharedGenericEventPointer> getEvents();
|
std::vector<Events::SharedGenericEventPointer> getEvents();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "EventNotifier.hpp"
|
#include "EventFdNotifier.hpp"
|
||||||
|
|
||||||
#include <sys/eventfd.h>
|
#include <sys/eventfd.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -11,7 +11,7 @@ namespace Bloom
|
|||||||
{
|
{
|
||||||
using Exceptions::Exception;
|
using Exceptions::Exception;
|
||||||
|
|
||||||
EventNotifier::EventNotifier() {
|
EventFdNotifier::EventFdNotifier() {
|
||||||
this->fileDescriptor = ::eventfd(0, EFD_NONBLOCK);
|
this->fileDescriptor = ::eventfd(0, EFD_NONBLOCK);
|
||||||
|
|
||||||
if (this->fileDescriptor < 0) {
|
if (this->fileDescriptor < 0) {
|
||||||
@@ -22,32 +22,32 @@ namespace Bloom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventNotifier::EventNotifier(EventNotifier&& other) noexcept
|
EventFdNotifier::EventFdNotifier(EventFdNotifier&& other) noexcept
|
||||||
: fileDescriptor(other.fileDescriptor)
|
: fileDescriptor(other.fileDescriptor)
|
||||||
{
|
{
|
||||||
other.fileDescriptor = std::nullopt;
|
other.fileDescriptor = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventNotifier::~EventNotifier() noexcept {
|
EventFdNotifier::~EventFdNotifier() noexcept {
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventNotifier::notify() {
|
void EventFdNotifier::notify() {
|
||||||
if (::eventfd_write(this->fileDescriptor.value(), 1) < 0) {
|
if (::eventfd_write(this->fileDescriptor.value(), 1) < 0) {
|
||||||
throw Exceptions::Exception("Failed to increment eventfd counter - error number: "
|
throw Exceptions::Exception("Failed to increment eventfd counter - error number: "
|
||||||
+ std::to_string(errno));
|
+ std::to_string(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventNotifier::clear() {
|
void EventFdNotifier::clear() {
|
||||||
eventfd_t counter = {};
|
eventfd_t counter = {};
|
||||||
if (::eventfd_read(this->fileDescriptor.value(), &counter) < 0 && errno != EAGAIN) {
|
if (::eventfd_read(this->fileDescriptor.value(), &counter) < 0 && errno != EAGAIN) {
|
||||||
throw Exceptions::Exception("Failed to clear EventNotifier object - eventfd_read failed - "
|
throw Exceptions::Exception("Failed to clear EventFdNotifier object - eventfd_read failed - "
|
||||||
"error number: " + std::to_string(errno));
|
"error number: " + std::to_string(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventNotifier::close() {
|
void EventFdNotifier::close() {
|
||||||
if (this->fileDescriptor.value_or(-1) >= 0) {
|
if (this->fileDescriptor.value_or(-1) >= 0) {
|
||||||
::close(this->fileDescriptor.value());
|
::close(this->fileDescriptor.value());
|
||||||
}
|
}
|
||||||
46
src/Helpers/EventFdNotifier.hpp
Normal file
46
src/Helpers/EventFdNotifier.hpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include "NotifierInterface.hpp"
|
||||||
|
|
||||||
|
namespace Bloom
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The EventFdNotifier class is an RAII wrapper for a Linux eventfd object.
|
||||||
|
*
|
||||||
|
* It uses an eventfd object to implement the NotifierInterface.
|
||||||
|
*/
|
||||||
|
class EventFdNotifier: public NotifierInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EventFdNotifier();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* EventNotifier objects should not be copied.
|
||||||
|
*/
|
||||||
|
EventFdNotifier(EventFdNotifier& other) = delete;
|
||||||
|
EventFdNotifier& operator = (EventFdNotifier& other) = delete;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: Implement this. For now, use the move constructor.
|
||||||
|
*/
|
||||||
|
EventFdNotifier& operator = (EventFdNotifier&& other) = delete;
|
||||||
|
|
||||||
|
EventFdNotifier(EventFdNotifier&& other) noexcept;
|
||||||
|
~EventFdNotifier() noexcept override;
|
||||||
|
|
||||||
|
[[nodiscard]] int getFileDescriptor() const {
|
||||||
|
return this->fileDescriptor.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
void notify() override;
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::optional<int> fileDescriptor;
|
||||||
|
|
||||||
|
void close();
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
namespace Bloom
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The EventNotifier class is an RAII wrapper for a Linux eventfd object.
|
|
||||||
*
|
|
||||||
* The EventListener can hold an instance to EventNotifier, where it will invoke EventNotifier::notify() everytime
|
|
||||||
* a new event is registered on the listener.
|
|
||||||
*/
|
|
||||||
class EventNotifier
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
EventNotifier();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* EpollInstance objects should not be copied.
|
|
||||||
*/
|
|
||||||
EventNotifier(EventNotifier& other) = delete;
|
|
||||||
EventNotifier& operator = (EventNotifier& other) = delete;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO: Implement this. For now, use the move constructor.
|
|
||||||
*/
|
|
||||||
EventNotifier& operator = (EventNotifier&& other) = delete;
|
|
||||||
|
|
||||||
EventNotifier(EventNotifier&& other) noexcept;
|
|
||||||
~EventNotifier() noexcept;
|
|
||||||
|
|
||||||
[[nodiscard]] int getFileDescriptor() const {
|
|
||||||
return this->fileDescriptor.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify();
|
|
||||||
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::optional<int> fileDescriptor;
|
|
||||||
|
|
||||||
void close();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user