-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathqeventloop_wrapper.h
More file actions
144 lines (131 loc) · 5.13 KB
/
Copy pathqeventloop_wrapper.h
File metadata and controls
144 lines (131 loc) · 5.13 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once
#include "framework.h"
#include <QEventLoop>
#include "qobject_wrapper.h"
namespace shelllet {
namespace core {
template<typename T, bool> class QEventLoopPrivate;
template<typename T, typename U, bool C>
class QEventLoopWrapper : public QObjectWrapper<T, U, C>
{
public:
template<bool M>
QEventLoopWrapper(QEventLoopPrivate<T, M>& d, const v8::FunctionCallbackInfo<v8::Value>& args)
: QObjectWrapper(d, args) {
}
QEventLoopWrapper(v8::Isolate* isolate, const v8::Local<v8::FunctionTemplate>& tpl) : QObjectWrapper(isolate, tpl) {}
QEventLoopWrapper(v8::Isolate* isolate, const v8::Local<v8::ObjectTemplate>& proto) : QObjectWrapper(isolate, proto) {
tpl->PrototypeTemplate()->Set(isolate, "isRunning", v8::FunctionTemplate::New(isolate, IsRunning));
tpl->PrototypeTemplate()->Set(isolate, "processEvents", v8::FunctionTemplate::New(isolate, ProcessEvents));
tpl->PrototypeTemplate()->Set(isolate, "exec", v8::FunctionTemplate::New(isolate, Exec));
tpl->PrototypeTemplate()->Set(isolate, "exit", v8::FunctionTemplate::New(isolate, Exit));
tpl->PrototypeTemplate()->Set(isolate, "quit", v8::FunctionTemplate::New(isolate, Quit));
{
v8::Local<v8::ObjectTemplate> process_events_flag = v8::ObjectTemplate::New(isolate);
V8_CREATE_ENUM_SYMBOL(process_events_flag, isolate, QEventLoop, ProcessEventsFlag, AllEvents);
V8_CREATE_ENUM_SYMBOL(process_events_flag, isolate, QEventLoop, ProcessEventsFlag, ExcludeUserInputEvents);
V8_CREATE_ENUM_SYMBOL(process_events_flag, isolate, QEventLoop, ProcessEventsFlag, ExcludeSocketNotifiers);
V8_CREATE_ENUM_SYMBOL(process_events_flag, isolate, QEventLoop, ProcessEventsFlag, WaitForMoreEvents);
V8_CREATE_ENUM_SYMBOL(process_events_flag, isolate, QEventLoop, ProcessEventsFlag, X11ExcludeTimers);
V8_CREATE_ENUM_SYMBOL(process_events_flag, isolate, QEventLoop, ProcessEventsFlag, EventLoopExec);
V8_CREATE_ENUM_SYMBOL(process_events_flag, isolate, QEventLoop, ProcessEventsFlag, DialogExec);
tpl->Set(isolate, "ProcessEventsFlag", process_events_flag);
}
}
protected:
static void Exec(const v8::FunctionCallbackInfo<v8::Value>& args)
{
V8_CREATE_LOCAL_CONTEXT_WITHOUT_LOCKER_BY_CALLBACK_INFO(args)
{
auto* p = convert::Object::UnWrap<QEventLoopWrapper<T, U, C>>(args.This());
QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents;
if (p)
{
if (args.Length() > 0 && args[0]->IsNumber()) {
flags = static_cast<QEventLoop::ProcessEventsFlags>(args[0]->Int32Value(context).FromJust());
}
v8::Unlocker unlocker(isolate);
p->d_func()->exec(flags);
}
}
V8_CREATE_LOCAL_CONTEXT_END
}
static void Exit(const v8::FunctionCallbackInfo<v8::Value>& args)
{
V8_CREATE_LOCAL_CONTEXT_WITHOUT_LOCKER_BY_CALLBACK_INFO(args)
{
auto* p = convert::Object::UnWrap<QEventLoopWrapper<T, U, C>>(args.This());
int return_code = 0;
if (p)
{
if (args.Length() > 0 && args[0]->IsNumber()) {
return_code = args[0]->Int32Value(context).FromJust();
}
p->d_func()->exit(return_code);
}
}
V8_CREATE_LOCAL_CONTEXT_END
}
static void IsRunning(const v8::FunctionCallbackInfo<v8::Value>& args)
{
V8_CREATE_LOCAL_CONTEXT_WITHOUT_LOCKER_BY_CALLBACK_INFO(args)
{
auto* p = convert::Object::UnWrap<QEventLoopWrapper<T, U, C>>(args.This());
if (p)
{
args.GetReturnValue().Set(p->d_func()->isRunning());
}
}
V8_CREATE_LOCAL_CONTEXT_END
}
static void ProcessEvents(const v8::FunctionCallbackInfo<v8::Value>& args)
{
V8_CREATE_LOCAL_CONTEXT_WITHOUT_LOCKER_BY_CALLBACK_INFO(args)
{
auto* p = convert::Object::UnWrap<QEventLoopWrapper<T, U, C>>(args.This());
QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents;
if (p)
{
if (args.Length() > 0 && args[0]->IsNumber()) {
flags = static_cast<QEventLoop::ProcessEventsFlags>(args[0]->Int32Value(context).FromJust());
//p->loop_->processEvents(flags);
}
else if (args.Length() > 2 && args[0]->IsNumber() && args[1]->IsNumber()) {
QEventLoop::ProcessEventsFlags flags = static_cast<QEventLoop::ProcessEventsFlags>(args[0]->Int32Value(context).FromJust());
int max_time = static_cast<QEventLoop::ProcessEventsFlags>(args[1]->Int32Value(context).FromJust());
p->d_func()->processEvents(flags, max_time);
}
else {
p->d_func()->processEvents(flags);
}
}
}
V8_CREATE_LOCAL_CONTEXT_END
}
static void WakeUp(const v8::FunctionCallbackInfo<v8::Value>& args)
{
V8_CREATE_LOCAL_CONTEXT_WITHOUT_LOCKER_BY_CALLBACK_INFO(args)
{
auto* p = convert::Object::UnWrap<QEventLoopWrapper<T, U, C>>(args.This());
if (p)
{
p->d_func()->wakeUp();
}
}
V8_CREATE_LOCAL_CONTEXT_END
}
static void Quit(const v8::FunctionCallbackInfo<v8::Value>& args)
{
V8_CREATE_LOCAL_CONTEXT_WITHOUT_LOCKER_BY_CALLBACK_INFO(args)
{
auto* p = convert::Object::UnWrap<QEventLoopWrapper<T, U, C>>(args.This());
if (p)
{
p->d_func()->quit();
}
}
V8_CREATE_LOCAL_CONTEXT_END
}
};
}
}