summaryrefslogtreecommitdiffstats
path: root/tsconnectionthread.h
diff options
context:
space:
mode:
Diffstat (limited to 'tsconnectionthread.h')
-rw-r--r--tsconnectionthread.h176
1 files changed, 176 insertions, 0 deletions
diff --git a/tsconnectionthread.h b/tsconnectionthread.h
new file mode 100644
index 0000000..2d67be6
--- /dev/null
+++ b/tsconnectionthread.h
@@ -0,0 +1,176 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; version 2 of the License.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14 *
15 * Authors: Manuel Mausz (manuel@mausz.at)
16 * Christian Raschko (c.raschko@netcore.at)
17 */
18
19#ifndef TSCONNECTION_H
20#define TSCONNECTION_H
21
22// Libraries
23#include <wx/wx.h>
24#include <wx/socket.h>
25#include <wx/stream.h>
26#include <wx/thread.h>
27#include <wx/list.h>
28#include <wx/stopwatch.h>
29
30#include "tsheaders.h"
31
32//WX_DECLARE_LIST
33WX_DECLARE_LIST_PTR(TSCmd, TSQueue);
34
35//! Repeat ping command after ...milliseconds
36#define PING_INTERMITTENT 1000
37//! Socket timeout ...seconds
38#define SOCKET_TIMEOUT 5
39//! Number of packets t loos for disconnect
40#define MAX_RETRIES 3
41//! Command timeout in milliseconds
42#define CMD_TIMEOUT 5000
43
44
45//! Ignore unknown commands
46#define IGNORE_UNKNOWN_COMMANDS
47
48//! TeamSpeak connection thread.
49/*! TSConnectionThread is used to communicate with the server.
50 * without bocking the main thread.
51 */
52class TSConnectionThread : public wxThread
53{
54 friend class TSClient;
55
56 DECLARE_CLASS(TSConnectionThread)
57
58 public:
59 /*! thread execution starts here
60 * \return Returns ExitCode.
61 */
62 virtual ExitCode Entry();
63
64 /*! and stops here
65 */
66 virtual void OnExit();
67
68 /*! Default CTor, Initializes the object.
69 */
70 TSConnectionThread(TSClient *client, wxMutex *mutex);
71
72 /*! Default DTor.
73 */
74 ~TSConnectionThread();
75
76 /*! Register a command, the class takes care of this pointer.
77 * \param cmd Command.
78 */
79 void RegisterCommand(TSCommand *cmd);
80
81 /*! Start main loop.
82 * \return Returns false if fails, check GetLastError for details.
83 * \sa GetLastError()
84 */
85 bool MainLoop();
86
87 /*! Executes a command.
88 * \param cmd Command.
89 * \return Returns false if fails, check GetLastError for details.
90 * \sa GetLastError()
91 */
92 bool ExecuteCommand(wxInputStream &istrm, wxOutputStream &ostrm,
93 TSCmd *cmd);
94
95 /*! Sync with TSClient and send command.
96 * \return Returns false if fails, check GetLastError for details.
97 * \sa GetLastError()
98 */
99 bool SyncSendCmd();
100
101 /*! Add command.
102 * \param cmd Command.
103 * \return Returns false if fails, check GetLastError for details.
104 * \sa GetLastError()
105 */
106 bool SendOutputCommand(TSCmd *cmd);
107
108 /*! Add command.
109 * \return Returns false if fails, check GetLastError for details.
110 * \sa GetLastError()
111 */
112 bool SendQueuedCommand();
113
114 /*! Add command.
115 * \param cmd Command.
116 * \return Returns false if fails, check GetLastError for details.
117 * \sa GetLastError()
118 */
119 void AddInputCommand(TSCmd *cmd);
120
121 void AddOutputCommand(TSCmd *cmd);
122
123 bool RecvCommand();
124
125 bool CheckInputQueue(TSCmd *cmd);
126
127 /*! Gets the LastError message, call this method
128 * to get more information for an error.
129 * \return LastError message.
130 */
131 wxString const &GetLastError() const
132 {
133 return m_LastError;
134 }
135
136 /*! Dumps object.
137 * \param ostrm Stream to write.
138 */
139 void Dump(wxOutputStream &ostrm) const;
140
141 private:
142 //Sets the LastError message.
143 void SetLastError(wxString const &str)
144 {
145 m_LastError = str;
146 }
147
148 // Send command
149 bool SendCommand(TSCmd *cmd);
150
151 // Send command to socket
152 bool SendCommandToSocket(TSCmd *cmd);
153
154 // SyncSendCmdError
155 bool SyncSendCmdLastError();
156
157 wxString m_LastError;
158 wxDatagramSocket *m_pMySock;
159 TSpCommandArray *m_ppCommands;
160 wxIPV4address m_ClientAddr;
161 wxIPV4address m_ServerAddr;
162 TSQueue *m_InQueue;
163 TSQueue *m_OutQueue;
164 TSClient *m_pClient;
165 bool m_Exit;
166 bool m_Error;
167 bool m_LocalCmd;
168 bool m_Timer;
169 bool m_Connected;
170 int m_Retries;
171 wxMutex *m_pMutex;
172 TSCmd *m_pCurCmd;
173 wxStopWatch m_SWTimeout;
174};
175
176#endif