Renamed EventNotifer to EventFdNotifier and employed new NotifierInterface
This commit is contained in:
@@ -44,7 +44,8 @@ namespace Bloom::DebugServer
|
||||
[this] () -> std::unique_ptr<ServerInterface> {
|
||||
return std::make_unique<DebugServer::Gdb::AvrGdb::AvrGdbRsp>(
|
||||
this->debugServerConfig,
|
||||
*(this->eventListener.get())
|
||||
*(this->eventListener.get()),
|
||||
this->interruptEventNotifier
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "src/Helpers/Thread.hpp"
|
||||
#include "src/ProjectConfig.hpp"
|
||||
#include "src/Helpers/EventNotifier.hpp"
|
||||
#include "src/Helpers/EventFdNotifier.hpp"
|
||||
#include "src/EventManager/EventListener.hpp"
|
||||
#include "src/EventManager/Events/Events.hpp"
|
||||
|
||||
@@ -48,11 +48,11 @@ namespace Bloom::DebugServer
|
||||
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
|
||||
* 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.
|
||||
|
||||
@@ -13,9 +13,10 @@ namespace Bloom::DebugServer::Gdb::AvrGdb
|
||||
|
||||
AvrGdbRsp::AvrGdbRsp(
|
||||
const DebugServerConfig& debugServerConfig,
|
||||
EventListener& eventListener
|
||||
EventListener& eventListener,
|
||||
EventFdNotifier& eventNotifier
|
||||
)
|
||||
: GdbRspDebugServer(debugServerConfig, eventListener)
|
||||
: GdbRspDebugServer(debugServerConfig, eventListener, eventNotifier)
|
||||
{}
|
||||
|
||||
void AvrGdbRsp::init() {
|
||||
|
||||
@@ -28,7 +28,8 @@ namespace Bloom::DebugServer::Gdb::AvrGdb
|
||||
public:
|
||||
AvrGdbRsp(
|
||||
const DebugServerConfig& debugServerConfig,
|
||||
EventListener& eventListener
|
||||
EventListener& eventListener,
|
||||
EventFdNotifier& eventNotifier
|
||||
);
|
||||
|
||||
std::string getName() const override {
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Bloom::DebugServer::Gdb
|
||||
|
||||
using ResponsePackets::ResponsePacket;
|
||||
|
||||
Connection::Connection(int serverSocketFileDescriptor, EventNotifier& interruptEventNotifier)
|
||||
Connection::Connection(int serverSocketFileDescriptor, EventFdNotifier& interruptEventNotifier)
|
||||
: interruptEventNotifier(interruptEventNotifier)
|
||||
{
|
||||
this->accept(serverSocketFileDescriptor);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
|
||||
#include "src/Helpers/EventNotifier.hpp"
|
||||
#include "src/Helpers/EventFdNotifier.hpp"
|
||||
#include "src/Helpers/EpollInstance.hpp"
|
||||
|
||||
#include "src/DebugServer/Gdb/Packet.hpp"
|
||||
@@ -23,7 +23,7 @@ namespace Bloom::DebugServer::Gdb
|
||||
class Connection
|
||||
{
|
||||
public:
|
||||
explicit Connection(int serverSocketFileDescriptor, EventNotifier& interruptEventNotifier);
|
||||
explicit Connection(int serverSocketFileDescriptor, EventFdNotifier& interruptEventNotifier);
|
||||
|
||||
Connection() = delete;
|
||||
Connection(const Connection&) = delete;
|
||||
@@ -77,8 +77,8 @@ namespace Bloom::DebugServer::Gdb
|
||||
int maxPacketSize = 1024;
|
||||
|
||||
/**
|
||||
* The interruptEventNotifier (instance of EventNotifier) 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
|
||||
* The interruptEventNotifier (instance of EventFdNotifier) allows us to interrupt blocking I/O calls on this
|
||||
* connection's socket. Under the hood, the EventFdNotifier class is just an RAII wrapper for a Linux eventfd
|
||||
* object.
|
||||
*
|
||||
* 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
|
||||
* 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();
|
||||
|
||||
bool readInterruptEnabled = false;
|
||||
|
||||
@@ -39,14 +39,13 @@ namespace Bloom::DebugServer::Gdb
|
||||
|
||||
GdbRspDebugServer::GdbRspDebugServer(
|
||||
const DebugServerConfig& debugServerConfig,
|
||||
EventListener& eventListener
|
||||
EventListener& eventListener,
|
||||
EventFdNotifier& eventNotifier
|
||||
)
|
||||
: debugServerConfig(GdbDebugServerConfig(debugServerConfig))
|
||||
, eventListener(eventListener)
|
||||
, interruptEventNotifier(eventListener.getInterruptEventNotifier())
|
||||
{
|
||||
assert(this->interruptEventNotifier != nullptr);
|
||||
}
|
||||
, interruptEventNotifier(eventNotifier)
|
||||
{}
|
||||
|
||||
void GdbRspDebugServer::init() {
|
||||
this->socketAddress.sin_family = AF_INET;
|
||||
@@ -102,7 +101,7 @@ namespace Bloom::DebugServer::Gdb
|
||||
);
|
||||
|
||||
this->epollInstance.addEntry(
|
||||
this->interruptEventNotifier->getFileDescriptor(),
|
||||
this->interruptEventNotifier.getFileDescriptor(),
|
||||
static_cast<std::uint16_t>(EpollEvent::READ_READY)
|
||||
);
|
||||
|
||||
@@ -203,15 +202,15 @@ namespace Bloom::DebugServer::Gdb
|
||||
|
||||
if (
|
||||
!eventFileDescriptor.has_value()
|
||||
|| eventFileDescriptor.value() == this->interruptEventNotifier->getFileDescriptor()
|
||||
|| eventFileDescriptor.value() == this->interruptEventNotifier.getFileDescriptor()
|
||||
) {
|
||||
this->interruptEventNotifier->clear();
|
||||
this->interruptEventNotifier.clear();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return std::make_optional<Connection>(
|
||||
this->serverSocketFileDescriptor.value(),
|
||||
*(this->interruptEventNotifier)
|
||||
this->interruptEventNotifier
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "GdbDebugServerConfig.hpp"
|
||||
#include "src/EventManager/EventListener.hpp"
|
||||
#include "src/Helpers/EpollInstance.hpp"
|
||||
#include "src/Helpers/EventFdNotifier.hpp"
|
||||
#include "src/TargetController/TargetControllerConsole.hpp"
|
||||
|
||||
#include "Connection.hpp"
|
||||
@@ -41,7 +42,8 @@ namespace Bloom::DebugServer::Gdb
|
||||
public:
|
||||
explicit GdbRspDebugServer(
|
||||
const DebugServerConfig& debugServerConfig,
|
||||
EventListener& eventListener
|
||||
EventListener& eventListener,
|
||||
EventFdNotifier& eventNotifier
|
||||
);
|
||||
|
||||
GdbRspDebugServer() = delete;
|
||||
@@ -86,24 +88,24 @@ namespace Bloom::DebugServer::Gdb
|
||||
EventListener& eventListener;
|
||||
|
||||
/**
|
||||
* EventNotifier object for interrupting blocking I/O operations.
|
||||
* EventFdNotifier object for interrupting blocking I/O operations.
|
||||
*
|
||||
* Extracted from this->eventListener.
|
||||
*
|
||||
* 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,
|
||||
* 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.
|
||||
*
|
||||
* See GdbRspDebugServer::init()
|
||||
* See DebugServer::interruptEventNotifier
|
||||
* See EpollInstance
|
||||
* See EventNotifier
|
||||
* See EventFdNotifier
|
||||
*/
|
||||
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
|
||||
[`EventNotifier`](../Helpers/EventNotifier.hpp) and [`EpollInstance`](../Helpers/EpollInstance.hpp).
|
||||
[`EventFdNotifier`](../Helpers/EventFdNotifier.hpp) and [`EpollInstance`](../Helpers/EpollInstance.hpp).
|
||||
|
||||
Key points:
|
||||
- The `EventNotifier` 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
|
||||
object via a call to `EventNotifier::notify()`.
|
||||
- The [`EventListener`](../EventManager/EventListener.hpp) class can accept an `EventNotifier` object via
|
||||
`EventListener::setInterruptEventNotifier()`. If an `EventNotifier` has been set on an `EventListener`, the
|
||||
`EventListener` will call `EventNotifer::notify()` everytime an event is registered for that listener.
|
||||
- The `EventFdNotifier` class is an RAII wrapper for a Linux
|
||||
[eventfd object](https://man7.org/linux/man-pages/man2/eventfd.2.html). It implements the
|
||||
[`NotifierInterface`](../Helpers/NotifierInterface.hpp). An event can be recorded against the eventfd
|
||||
object via a call to `EventFdNotifier::notify()`.
|
||||
- The [`EventListener`](../EventManager/EventListener.hpp) class can accept an `NotifierInterface` object via
|
||||
`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
|
||||
[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()`
|
||||
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.
|
||||
|
||||
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
|
||||
the interruption of blocking I/O operations when an event is triggered. Specifically,
|
||||
[`GdbRspDebugServer::waitForConnection()`](./Gdb/GdbRspDebugServer.hpp) or
|
||||
|
||||
Reference in New Issue
Block a user