Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
DetectorSubscription Class Reference

A registered subscriber. Unregisters when destroyed. More...

#include <detector_stream.h>

Public Member Functions

 ~DetectorSubscription ()
bool Wait (std::vector< DetectorEventRecord > &out, DWORD timeoutMs)
 Waits up to timeoutMs for events and moves the queued ones into out (which it clears first). Returns false once StopDetectorStreams has been called.
 DetectorSubscription (const DetectorSubscription &)=delete
DetectorSubscription & operator= (const DetectorSubscription &)=delete

Static Public Member Functions

static std::unique_ptr< DetectorSubscription > Open (const std::vector< std::string > &eventNames)
 Registers a subscriber. Returns nullptr when the service is stopping or too many subscribers are connected.

Detailed Description

A registered subscriber. Unregisters when destroyed.

Definition at line 38 of file detector_stream.h.

Constructor & Destructor Documentation

◆ ~DetectorSubscription()

DetectorSubscription::~DetectorSubscription ( )

Definition at line 52 of file detector_stream.cpp.

53{
54 std::lock_guard<std::mutex> guard(g_SubscribersLock);
55 g_Subscribers.erase(std::remove(g_Subscribers.begin(), g_Subscribers.end(), m_state), g_Subscribers.end());
56 g_SubscriberCount = g_Subscribers.size();
57}

◆ DetectorSubscription()

DetectorSubscription::DetectorSubscription ( const DetectorSubscription & )
delete

Member Function Documentation

◆ Open()

std::unique_ptr< DetectorSubscription > DetectorSubscription::Open ( const std::vector< std::string > & eventNames)
static

Registers a subscriber. Returns nullptr when the service is stopping or too many subscribers are connected.

Parameters
eventNamesOnly events whose "Event" is in this list are queued; empty means all

Definition at line 33 of file detector_stream.cpp.

34{
35 auto state = std::make_shared<DetectorSubscriberState>();
36 state->EventNames.insert(eventNames.begin(), eventNames.end());
37
38 std::lock_guard<std::mutex> guard(g_SubscribersLock);
39 if (g_Stopping || g_Subscribers.size() >= PANO_MAX_DETECTOR_SUBSCRIBERS) {
40 return nullptr;
41 }
42 g_Subscribers.push_back(state);
43 g_SubscriberCount = g_Subscribers.size();
44 return std::unique_ptr<DetectorSubscription>(new DetectorSubscription(state));
45}
DetectorSubscription(const DetectorSubscription &)=delete
#define PANO_MAX_DETECTOR_SUBSCRIBERS

References DetectorSubscription(), and PANO_MAX_DETECTOR_SUBSCRIBERS.

◆ operator=()

DetectorSubscription & DetectorSubscription::operator= ( const DetectorSubscription & )
delete

◆ Wait()

bool DetectorSubscription::Wait ( std::vector< DetectorEventRecord > & out,
DWORD timeoutMs )

Waits up to timeoutMs for events and moves the queued ones into out (which it clears first). Returns false once StopDetectorStreams has been called.

Definition at line 59 of file detector_stream.cpp.

60{
61 out.clear();
62 std::unique_lock<std::mutex> lock(m_state->Lock);
63 m_state->Wake.wait_for(lock, std::chrono::milliseconds(timeoutMs),
64 [this] { return !m_state->Queue.empty() || m_state->Stopping; });
65 if (m_state->Stopping) {
66 return false;
67 }
68 out.assign(std::make_move_iterator(m_state->Queue.begin()), std::make_move_iterator(m_state->Queue.end()));
69 m_state->Queue.clear();
70 return true;
71}

The documentation for this class was generated from the following files: