From 310a2c101b32a5e71a616027b6a1b788a341bc02 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 5 Mar 2013 17:39:48 +0100 Subject: initial GPLv2 release --- tsconnectionthread.h | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 tsconnectionthread.h (limited to 'tsconnectionthread.h') diff --git a/tsconnectionthread.h b/tsconnectionthread.h new file mode 100644 index 0000000..2d67be6 --- /dev/null +++ b/tsconnectionthread.h @@ -0,0 +1,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 +#include +#include +#include +#include +#include + +#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 -- cgit v1.2.3