-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
93 lines (68 loc) · 2.18 KB
/
main.cpp
File metadata and controls
93 lines (68 loc) · 2.18 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
#include <iostream>
#include <thread>
#include "api/task_queue/default_task_queue_factory.h"
#include "rtc_base/event.h"
#include "api/units/time_delta.h"
#include "rtc_base/thread.h"
#ifdef WEBRTC_WIN
#include "rtc_base/win32_socket_init.h"
#endif
#include "rtc_base/physical_socket_server.h"
#include "rtc_base/third_party/sigslot/sigslot2.h"
using namespace std;
class Controller {
public:
signals:
sigslot2::signal0<> _click;
};
class Worker : public sigslot2::HasSlots<>{
public slots:
void onClicked1() {
std::cout << "Worker::onClicked1(): " << std::this_thread::get_id() << std::endl;
}
void onClicked2() {
std::cout << "Worker::onClicked2(): " << std::this_thread::get_id() << std::endl;
}
};
int main()
{
cout << "Hello World!" << endl;
cout << "main thread: " << std::this_thread::get_id() << endl;
#ifdef WEBRTC_WIN
rtc::WinsockInitializer winsockInit;
rtc::PhysicalSocketServer pss;
rtc::AutoSocketServerThread mainThread(&pss);
#endif
//auto main = rtc::ThreadManager::Instance()->CurrentThread();
auto tqf = webrtc::CreateDefaultTaskQueueFactory();
auto tq = tqf->CreateTaskQueue("my-queue", webrtc::TaskQueueFactory::Priority::NORMAL);
rtc::Event event;
tq->PostTask([&event](){
cout << "call in queue thread: " << std::this_thread::get_id() << endl;
event.Set();
});
event.Wait(webrtc::TimeDelta::Seconds(10));
//main->PostTask([&main](){
// cout << "call in main thread: " << std::this_thread::get_id() << endl;
// main->Stop();
//});
//main->Run();
auto thread = rtc::Thread::Create();
thread->Start();
Controller ctrl;
Worker worker;
int ret = -1;
ret = ctrl._click.connect(&worker, &Worker::onClicked1, sigslot2::QueuedConnection, &mainThread);
std::cout << "ret1: " << ret << std::endl;
ret = ctrl._click.connect(&worker, &Worker::onClicked2, sigslot2::BlockingQueuedConnection, thread.get());
std::cout << "ret2: " << ret << std::endl;
//ctrl._click();
//ctrl._click();
ctrl._click();
std::cout << "done" << std::endl;
thread->Stop();
#ifdef WEBRTC_WIN
mainThread.Run();
#endif
return 0;
}