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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Manuel Mausz (manuel@mausz.at)
* Christian Raschko (c.raschko@netcore.at)
*/
#ifndef TSCONNECTION_H
#define TSCONNECTION_H
// Libraries
#include <wx/wx.h>
#include <wx/socket.h>
#include <wx/stream.h>
#include <wx/thread.h>
#include <wx/list.h>
#include <wx/stopwatch.h>
#include "tsheaders.h"
//WX_DECLARE_LIST
WX_DECLARE_LIST_PTR(TSCmd, TSQueue);
//! Repeat ping command after ...milliseconds
#define PING_INTERMITTENT 1000
//! Socket timeout ...seconds
#define SOCKET_TIMEOUT 5
//! Number of packets t loos for disconnect
#define MAX_RETRIES 3
//! Command timeout in milliseconds
#define CMD_TIMEOUT 5000
//! Ignore unknown commands
#define IGNORE_UNKNOWN_COMMANDS
//! TeamSpeak connection thread.
/*! TSConnectionThread is used to communicate with the server.
* without bocking the main thread.
*/
class TSConnectionThread : public wxThread
{
friend class TSClient;
DECLARE_CLASS(TSConnectionThread)
public:
/*! thread execution starts here
* \return Returns ExitCode.
*/
virtual ExitCode Entry();
/*! and stops here
*/
virtual void OnExit();
/*! Default CTor, Initializes the object.
*/
TSConnectionThread(TSClient *client, wxMutex *mutex);
/*! Default DTor.
*/
~TSConnectionThread();
/*! Register a command, the class takes care of this pointer.
* \param cmd Command.
*/
void RegisterCommand(TSCommand *cmd);
/*! Start main loop.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool MainLoop();
/*! Executes a command.
* \param cmd Command.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool ExecuteCommand(wxInputStream &istrm, wxOutputStream &ostrm,
TSCmd *cmd);
/*! Sync with TSClient and send command.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool SyncSendCmd();
/*! Add command.
* \param cmd Command.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool SendOutputCommand(TSCmd *cmd);
/*! Add command.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
bool SendQueuedCommand();
/*! Add command.
* \param cmd Command.
* \return Returns false if fails, check GetLastError for details.
* \sa GetLastError()
*/
void AddInputCommand(TSCmd *cmd);
void AddOutputCommand(TSCmd *cmd);
bool RecvCommand();
bool CheckInputQueue(TSCmd *cmd);
/*! Gets the LastError message, call this method
* to get more information for an error.
* \return LastError message.
*/
wxString const &GetLastError() const
{
return m_LastError;
}
/*! Dumps object.
* \param ostrm Stream to write.
*/
void Dump(wxOutputStream &ostrm) const;
private:
//Sets the LastError message.
void SetLastError(wxString const &str)
{
m_LastError = str;
}
// Send command
bool SendCommand(TSCmd *cmd);
// Send command to socket
bool SendCommandToSocket(TSCmd *cmd);
// SyncSendCmdError
bool SyncSendCmdLastError();
wxString m_LastError;
wxDatagramSocket *m_pMySock;
TSpCommandArray *m_ppCommands;
wxIPV4address m_ClientAddr;
wxIPV4address m_ServerAddr;
TSQueue *m_InQueue;
TSQueue *m_OutQueue;
TSClient *m_pClient;
bool m_Exit;
bool m_Error;
bool m_LocalCmd;
bool m_Timer;
bool m_Connected;
int m_Retries;
wxMutex *m_pMutex;
TSCmd *m_pCurCmd;
wxStopWatch m_SWTimeout;
};
#endif
|