-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.cpp
More file actions
69 lines (62 loc) · 1.34 KB
/
task.cpp
File metadata and controls
69 lines (62 loc) · 1.34 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
61
62
63
64
65
66
67
68
69
#include <debug.h>
#include "task.h"
#include "common.h"
void Task::start()
{
common_panic_assert(m_actived == false);
m_impl->on_start();
m_actived = true;
}
void Task::stop()
{
common_panic_assert(m_actived == true);
m_impl->on_stop();
m_actived = false;
}
void Task::loop()
{
if (m_actived)
m_impl->on_loop();
}
const char* Task::get_name() const
{
return m_impl->get_name();
}
LogPrint TaskImpl::get_logger(unsigned int log_level)
{
char ptrbuf[24];
static const char *chrtable = "VDIWE";
if (log_level < m_log_level)
return LogPrint();
Print& pt = get_debug_stream();
sprintf(ptrbuf, "%p", reinterpret_cast<void*>(this));
const char *ptr_print = ptrbuf;
if (ptr_print[0] == '0' && ptr_print[1] == 'x')
ptr_print += 2;
pt << "[" << get_name() << "@" << ptr_print << "/" << chrtable[log_level] << "] ";
return LogPrint(&pt, "\n", log_level >= LOG_WARNING);
}
void Task::set_log_level(unsigned int log_level)
{
m_impl->m_log_level = log_level;
}
LogPrint TaskImpl::logv()
{
return get_logger(LOG_VERBOSE);
}
LogPrint TaskImpl::logd()
{
return get_logger(LOG_DEBUG);
}
LogPrint TaskImpl::logi()
{
return get_logger(LOG_INFO);
}
LogPrint TaskImpl::logw()
{
return get_logger(LOG_WARNING);
}
LogPrint TaskImpl::loge()
{
return get_logger(LOG_ERROR);
}