-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringHandler.h
More file actions
48 lines (41 loc) · 895 Bytes
/
StringHandler.h
File metadata and controls
48 lines (41 loc) · 895 Bytes
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
#ifndef SH_H
#define SH_H
#include <string>
#include <list>
#include <functional>
#include <vector>
#include <mutex>
#include <thread>
struct ops {
std::string name;
std::vector<std::string> filters;
std::function<void(std::string packet)> f = NULL;
};
struct task {
std::string packet;
ops& o;
public:
task(std::string p, ops& op) : packet(p), o(op) {
}
};
class StringHandler
{
public:
StringHandler();
~StringHandler();
static void execute(StringHandler* i);
void search(std::string packet);
void add_filter(std::string name, std::string filter);
void on(std::string name, std::function<void(std::string packet)> callback);
private:
std::thread task_executer;
int task_count();
task get_task();
void add_task(std::string packet, ops& o);
void remove_task();
std::list<ops> filters;
std::list<task> tasks;
std::mutex task_mutex;
std::mutex thread_mutex;
};
#endif