-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathnetheader.h
138 lines (116 loc) · 2.42 KB
/
netheader.h
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
#ifndef NETHEADER_H
#define NETHEADER_H
#include <QMetaType>
#include <QMutex>
#include <QQueue>
#include <QImage>
#include <QWaitCondition>
#define QUEUE_MAXSIZE 1500
#ifndef MB
#define MB 1024*1024
#endif
#ifndef KB
#define KB 1024
#endif
#ifndef WAITSECONDS
#define WAITSECONDS 2
#endif
#ifndef OPENVIDEO
#define OPENVIDEO "打开视频"
#endif
#ifndef CLOSEVIDEO
#define CLOSEVIDEO "关闭视频"
#endif
#ifndef OPENAUDIO
#define OPENAUDIO "打开音频"
#endif
#ifndef CLOSEAUDIO
#define CLOSEAUDIO "关闭音频"
#endif
#ifndef MSG_HEADER
#define MSG_HEADER 11
#endif
enum MSG_TYPE
{
IMG_SEND = 0,
IMG_RECV,
AUDIO_SEND,
AUDIO_RECV,
TEXT_SEND,
TEXT_RECV,
CREATE_MEETING,
EXIT_MEETING,
JOIN_MEETING,
CLOSE_CAMERA,
CREATE_MEETING_RESPONSE = 20,
PARTNER_EXIT = 21,
PARTNER_JOIN = 22,
JOIN_MEETING_RESPONSE = 23,
PARTNER_JOIN2 = 24,
RemoteHostClosedError = 40,
OtherNetError = 41
};
Q_DECLARE_METATYPE(MSG_TYPE);
struct MESG //消息结构体
{
MSG_TYPE msg_type;
uchar* data;
long len;
quint32 ip;
};
Q_DECLARE_METATYPE(MESG *);
//-------------------------------
template<class T>
struct QUEUE_DATA //消息队列
{
private:
QMutex send_queueLock;
QWaitCondition send_queueCond;
QQueue<T*> send_queue;
public:
void push_msg(T* msg)
{
send_queueLock.lock();
while(send_queue.size() > QUEUE_MAXSIZE)
{
send_queueCond.wait(&send_queueLock);
}
send_queue.push_back(msg);
send_queueLock.unlock();
send_queueCond.wakeOne();
}
T* pop_msg()
{
send_queueLock.lock();
while(send_queue.size() == 0)
{
bool f = send_queueCond.wait(&send_queueLock, WAITSECONDS * 1000);
if(f == false)
{
send_queueLock.unlock();
return NULL;
}
}
T* send = send_queue.front();
send_queue.pop_front();
send_queueLock.unlock();
send_queueCond.wakeOne();
return send;
}
void clear()
{
send_queueLock.lock();
send_queue.clear();
send_queueLock.unlock();
}
};
struct Log
{
char *ptr;
uint len;
};
void log_print(const char *, const char *, int, const char *, ...);
#define WRITE_LOG(LOGTEXT, ...) do{ \
log_print(__FILE__, __FUNCTION__, __LINE__, LOGTEXT, ##__VA_ARGS__);\
}while(0);
#endif // NETHEADER_H