-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamPool.cpp
85 lines (77 loc) · 1.41 KB
/
StreamPool.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
#include "StreamPool.h"
#include <QThread>
StreamPool::StreamPool()
{
num.resize(STREAM_NUM);
}
StreamPool::~StreamPool()
{
for (auto s : data)
{
delete s;
}
data.clear();
}
QString StreamPool::generKey(StreamMsg* s)
{
QString key;
if (s->client_port < s->server_port)
{
key = s->proto + "_" + s->client_addr + "_" + QString::number(s->client_port)
+ "_" + s->server_addr + "_" + QString::number(s->server_port);
}
else {
key = s->proto + "_" + s->server_addr + "_" + QString::number(s->server_port)
+ "_" + s->client_addr + "_" + QString::number(s->client_port);
}
return key;
}
bool StreamPool::hasStream(StreamMsg* s)
{
QString key = generKey(s);
return data.contains(key);
}
int StreamPool::getStreamIndex(StreamMsg* s)
{
QString key = generKey(s);
if (hasStream(s))
{
return data[key]->index.back();
}
else {
return -1;
}
}
int StreamPool::addStream(StreamMsg* s)
{
QString key = generKey(s);
StreamType type = getStreamType(s->proto);
if (!hasStream(s))
{
data[key] = s;
s->index.push_back(num[type]);
} else {
data[key]->index.push_back(num[type]);
}
return num[type]++;
}
QString StreamPool::getStreamName(StreamType type)
{
QString STREAM_TYPE[STREAM_NUM] = {
"udp", "tcp"
};
return STREAM_TYPE[type];
}
StreamType StreamPool::getStreamType(QString name)
{
StreamType type;
if (name == "udp")
{
type = UDP;
}
else if (name == "tcp")
{
type = TCP;
}
return type;
}