-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCGraphics.cpp
More file actions
69 lines (59 loc) · 1.43 KB
/
CGraphics.cpp
File metadata and controls
69 lines (59 loc) · 1.43 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 "CGraphics.h"
void CGraphics::Receive()
{
while (!queue->isSendingDone.load() || !queue->isEmpty())
{
if (queue->isFlushing.load())
continue;
ERQCommand cmd = queue->ReadCommand();
queue->isProcessingDone.store(false);
switch (cmd)
{
case ERQCommand::INVALID:
continue;
break;
case ERQCommand::PRINT_VALUE:
{
uint32_t value = queue->ReadValue();
Process(value);
}
break;
case ERQCommand::PRINT_STRING:
{
uint32_t size = queue->ReadValue();
const char* data{};
try
{
data = queue->ReadData(size);
}
catch (...)
{
// forced done
queue->isProcessingDone.store(true);
queue->isProcessingDone.notify_all();
continue;
}
Process(data, size);
}
break;
default:
continue;
}
}
std::cout << "All received\n";
}
void CGraphics::Process(uint32_t value)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "\t\t\t\t\t====> Processed value: " << value << "\n";
queue->isProcessingDone.store(true);
queue->isProcessingDone.notify_all();
}
void CGraphics::Process(const char* data, size_t size)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::string str(data);
std::cout << "\t\t\t\t\t====> Processed string: \"" << str << "\"\n";
queue->isProcessingDone.store(true);
queue->isProcessingDone.notify_all();
}