-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.cpp
More file actions
60 lines (48 loc) · 1.04 KB
/
context.cpp
File metadata and controls
60 lines (48 loc) · 1.04 KB
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
54
55
56
57
58
59
60
//
// Created by amoncusir on 05/10/23.
//
#include "context.h"
#include <stdexcept>
#include <cstdio>
namespace Logtrigger
{
Context* Context::s_singleton = nullptr;
Context::~Context()
{
delete m_handler;
}
TriggerHandler& Context::handler()
{
return *m_handler;
}
void Context::process_event(ubus_log_event* event) const
{
try
{
m_handler->process(*event);
}
catch (...)
{
fprintf(stderr, "Error on handler process\n");
}
}
Context& Context::init_instance()
{
if (s_singleton != nullptr)
{
throw std::runtime_error("Initialized Context");
}
s_singleton = new Context();
return *s_singleton;
}
const Context& Context::get_instance()
{
#ifdef DEBUG
if (s_singleton == nullptr)
{
throw std::runtime_error("Uninitialized Context. First call Context::init_instance");
}
#endif
return *s_singleton;
}
}