blob: 4ad29a6707e30fbe33c59cadd75ab78b2fd22ebd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#pragma once
#include <app.hpp>
#include <event_service_manager.hpp>
namespace redfish
{
inline void createSubscription(crow::sse_socket::Connection& conn)
{
EventServiceManager& manager =
EventServiceManager::getInstance(&conn.getIoContext());
if ((manager.getNumberOfSubscriptions() >= maxNoOfSubscriptions) ||
manager.getNumberOfSSESubscriptions() >= maxNoOfSSESubscriptions)
{
BMCWEB_LOG_WARNING("Max SSE subscriptions reached");
conn.close("Max SSE subscriptions reached");
return;
}
std::shared_ptr<redfish::Subscription> subValue =
std::make_shared<redfish::Subscription>(conn);
// GET on this URI means, Its SSE subscriptionType.
subValue->subscriptionType = redfish::subscriptionTypeSSE;
subValue->protocol = "Redfish";
subValue->retryPolicy = "TerminateAfterRetries";
subValue->eventFormatType = "Event";
std::string id = manager.addSubscription(subValue, false);
if (id.empty())
{
conn.close("Internal Error");
}
}
inline void deleteSubscription(crow::sse_socket::Connection& conn)
{
redfish::EventServiceManager::getInstance(&conn.getIoContext())
.deleteSseSubscription(conn);
}
inline void requestRoutesEventServiceSse(App& app)
{
// Note, this endpoint is given the same privilege level as creating a
// subscription, because functionally, that's the operation being done
BMCWEB_ROUTE(app, "/redfish/v1/EventService/SSE")
.privileges(redfish::privileges::postEventDestinationCollection)
.serverSentEvent()
.onopen(createSubscription)
.onclose(deleteSubscription);
}
} // namespace redfish
|