Skip to content

Commit 78dd799

Browse files
committed
DPL: add status endpoint to the driver
1 parent e2e7eb8 commit 78dd799

File tree

7 files changed

+482
-1
lines changed

7 files changed

+482
-1
lines changed

Framework/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ o2_add_library(Framework
158158
src/StepTHn.cxx
159159
src/Base64.cxx
160160
src/DPLWebSocket.cxx
161+
src/StatusWebSocketHandler.cxx
161162
src/TimerParamSpec.cxx
162163
test/TestClasses.cxx
163164
TARGETVARNAME targetName

Framework/Core/src/ControlWebSocketHandler.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "ControlWebSocketHandler.h"
1313
#include "DriverServerContext.h"
14+
#include "StatusWebSocketHandler.h"
1415
#include "Framework/DeviceMetricsHelper.h"
1516
#include "Framework/ServiceMetricsInfo.h"
1617
#include <regex>
@@ -83,6 +84,10 @@ void ControlWebSocketHandler::endChunk()
8384
for (auto& callback : *mContext.metricProcessingCallbacks) {
8485
callback(mContext.registry, ServiceMetricsInfo{*mContext.metrics, *mContext.specs, *mContext.infos, mContext.driver->metrics, *mContext.driver}, timestamp);
8586
}
87+
// Notify status clients before changed flags are reset so they can see what changed.
88+
for (auto* statusHandler : mContext.statusHandlers) {
89+
statusHandler->sendUpdate(mIndex);
90+
}
8691
for (auto& metricsInfo : *mContext.metrics) {
8792
std::fill(metricsInfo.changed.begin(), metricsInfo.changed.end(), false);
8893
}

Framework/Core/src/DPLWebSocket.cxx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "DriverServerContext.h"
1919
#include "DriverClientContext.h"
2020
#include "ControlWebSocketHandler.h"
21+
#include "StatusWebSocketHandler.h"
2122
#include "HTTPParser.h"
2223
#include <algorithm>
2324
#include <atomic>
@@ -193,9 +194,10 @@ void WSDPLHandler::method(std::string_view const& s)
193194

194195
void WSDPLHandler::target(std::string_view const& s)
195196
{
196-
if (s != "/") {
197+
if (s != "/" && s != "/status") {
197198
throw WSError{404, "Unknown"};
198199
}
200+
mTarget = s;
199201
}
200202

201203
void populateHeader(std::map<std::string, std::string>& headers, std::string_view const& k, std::string_view const& v)
@@ -294,6 +296,12 @@ void WSDPLHandler::endHeaders()
294296
break;
295297
}
296298
}
299+
} else if (mTarget == "/status" && mServerContext->isDriver) {
300+
LOGP(info, "Status client connected ({} total)", mServerContext->statusHandlers.size() + 1);
301+
auto* statusHandler = new StatusWebSocketHandler(*mServerContext, this);
302+
mServerContext->statusHandlers.push_back(statusHandler);
303+
mHandler = std::unique_ptr<WebSocketHandler>(statusHandler);
304+
mHandler->headers(mHeaders);
297305
} else {
298306
if ((mServerContext->isDriver && getenv("DPL_DRIVER_REMOTE_GUI")) || ((mServerContext->isDriver == false) && getenv("DPL_DEVICE_REMOTE_GUI"))) {
299307
LOG(info) << "Connection not bound to a PID";

Framework/Core/src/DPLWebSocket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct WSDPLHandler : public HTTPParser {
6262
bool mHandshaken = false;
6363
uv_stream_t* mStream = nullptr;
6464
std::map<std::string, std::string> mHeaders;
65+
std::string mTarget;
6566
DriverServerContext* mServerContext;
6667
};
6768

Framework/Core/src/DriverServerContext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace o2::framework
2929
struct DriverInfo;
3030
struct ServiceRegistry;
3131
struct GuiCallbackContext;
32+
struct StatusWebSocketHandler;
3233

3334
struct DriverServerContext {
3435
ServiceRegistryRef registry;
@@ -49,6 +50,10 @@ struct DriverServerContext {
4950
/// or something like that.
5051
bool isDriver = false;
5152

53+
/// Connected MCP/status clients. Updated by StatusWebSocketHandler
54+
/// on connect/disconnect; notified by ControlWebSocketHandler::endChunk().
55+
std::vector<StatusWebSocketHandler*> statusHandlers;
56+
5257
/// The handle to the server component of the
5358
/// driver.
5459
uv_tcp_t serverHandle;

0 commit comments

Comments
 (0)