-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDebugItem.cpp
87 lines (79 loc) · 1.91 KB
/
DebugItem.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "DebugItem.h"
DebugItem::DebugItem(const ttstr& name) :itemname(name + L":") {
//nmsgs.resize(20);
#ifdef THROW_GLOBAL_EXCEPTION
exeptmsgs.resize(20);
#endif
erritemname = L"[Error]" + itemname;
kr = new KRunnable([this] {depletmsgs(); });
kr->is_timer = true;
}
DebugItem::~DebugItem()
{
delete kr;
}
void DebugItem::ExceptionPrint(const tjs_char* msg) {
if (!msg)
return;
std::lock_guard<std::mutex> lck(lock);
#ifdef THROW_GLOBAL_EXCEPTION
exeptmsgs.push_back(erritemname + msg);
#else
nmsgs.push_back(erritemname + msg);
#endif
kr->runTask();
}
void DebugItem::Print(const tjs_char* msg) {
if (!msg)
return;
std::lock_guard<std::mutex> lck(lock);
nmsgs.push_back(itemname + msg);
kr->runTask();
}
void DebugItem::depletmsgs() {
ttstr msg;
//msg.AppendBuffer(10);
#ifdef THROW_GLOBAL_EXCEPTION
while (!exeptmsgs.empty()) {
msg = exeptmsgs.front();
exeptmsgs.pop_front();
TVPThrowExceptionMessage(msg);
}
#endif
std::lock_guard<std::mutex> lck(lock);
while (!nmsgs.empty()) {
msg = nmsgs.front();
nmsgs.pop_front();
TVPAddLog(msg);
}
};
DebugObject::DebugObject(DebugItem* di) :item(di) {
putFunc(L"message", [this]TJSNATIVEARG{
for (int i = 0; i < n; i++)
item->Print(ttstr(*p[i]).c_str());
return TJS_S_OK;
});
putFunc(L"notice", [this]TJSNATIVEARG{
item->Print((const tjs_char*)(p[0]->AsStringNoAddRef()));
return TJS_S_OK;
});
putFunc(L"getLastLog", [this]TJSNATIVEARG{
TJS::iTJSDispatch2 * array = TJS::TJSCreateArrayObject();
std::lock_guard<std::mutex> lck(item->lock);
ttstr msg;
tjs_int i = 0;
while (!item->nmsgs.empty()) {
msg = item->nmsgs.front();
item->nmsgs.pop_front();
PutToObject(i++, msg, (iTJSDispatch2*)array);
}
*r = tTJSVariant((iTJSDispatch2*)array, (iTJSDispatch2*)array);
return TJS_S_OK;
});
putFunc(L"startLogToFile", []TJSNATIVEARG{
return TJS_E_NOTIMPL;
});
putFunc(L"logAsError", []TJSNATIVEARG{
return TJS_S_OK;
});
}