Yarilo v0.9.9
WPA2 Decrypter & Packet Analyzer
Loading...
Searching...
No Matches
log_queue.h
Go to the documentation of this file.
1#ifndef SNIFF_LOG_QUEUE
2#define SNIFF_LOG_QUEUE
3
4#include "proto/service.pb.h"
5#include <condition_variable>
6#include <mutex>
7#include <vector>
8
9namespace yarilo {
10
17class LogQueue {
18public:
23 LogQueue(uint64_t queueMaxSize) : queueMaxSize(queueMaxSize), stopped(false) {
24 queue.reserve(queueMaxSize);
25 }
26
35 bool insert(proto::LogEntry *item) {
36 {
37 std::unique_lock<std::mutex> lock(queueMutex);
38 if (stopped)
39 return false;
40
41 if (queue.size() >= queueMaxSize)
42 queue.back() = item;
43 else
44 queue.emplace_back(item);
45 }
46
47 return true;
48 }
49
56 bool fetch_all(std::vector<proto::LogEntry *> &refFetchedItems) {
57 {
58 std::unique_lock<std::mutex> lock(queueMutex);
59 if (stopped)
60 return false;
61
62 refFetchedItems = std::move(queue);
63 queue.clear();
64 }
65
66 cvInsert.notify_all();
67 return true;
68 }
69
74 void stop() {
75 {
76 std::unique_lock<std::mutex> lock(queueMutex);
77 stopped = true;
78 }
79
80 cvInsert.notify_all();
81 }
82
87 bool is_stopped() { return stopped; }
88
89private:
90 std::vector<proto::LogEntry *> queue;
91 uint64_t queueMaxSize;
92 std::mutex queueMutex;
93 std::condition_variable cvInsert;
94 bool stopped;
95};
96
97} // namespace yarilo
98
99#endif // SNIFF_LOG_QUEUE
A queue for storing log entries with thread-safe operations.
Definition log_queue.h:17
void stop()
Stops the queue. This will unblock all waiting threads and prevent further operations.
Definition log_queue.h:74
bool fetch_all(std::vector< proto::LogEntry * > &refFetchedItems)
Fetches all log entries from the queue.
Definition log_queue.h:56
bool is_stopped()
Checks if the queue has been stopped.
Definition log_queue.h:87
bool insert(proto::LogEntry *item)
Inserts a log entry into the queue. If the queue is full, it replaces the last item in the queue....
Definition log_queue.h:35
LogQueue(uint64_t queueMaxSize)
Definition log_queue.h:23
Definition access_point.cpp:22