2006-12-18 15:39:33 +01:00
|
|
|
/******************************************************************************\
|
2011-02-22 19:56:52 +01:00
|
|
|
* Copyright (c) 2004-2011
|
2006-12-18 15:39:33 +01:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* 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; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#if !defined ( SOCKET_HOIHGE76GEKJH98_3_4344_BB23945IUHF1912__INCLUDED_ )
|
2006-12-18 15:39:33 +01:00
|
|
|
#define SOCKET_HOIHGE76GEKJH98_3_4344_BB23945IUHF1912__INCLUDED_
|
|
|
|
|
2008-01-20 19:07:13 +01:00
|
|
|
#include <qobject.h>
|
|
|
|
#include <qmessagebox.h>
|
|
|
|
#include <qudpsocket.h>
|
|
|
|
#include <qsocketnotifier.h>
|
2011-04-04 20:57:49 +02:00
|
|
|
#include <qmutex.h>
|
2006-12-18 15:39:33 +01:00
|
|
|
#include <vector>
|
|
|
|
#include "global.h"
|
|
|
|
#include "channel.h"
|
2011-04-06 21:01:39 +02:00
|
|
|
#include "protocol.h"
|
2006-12-18 15:39:33 +01:00
|
|
|
#include "util.h"
|
|
|
|
|
2009-07-30 20:36:37 +02:00
|
|
|
// The header file server.h requires to include this header file so we get a
|
|
|
|
// cyclic dependency. To solve this issue, a prototype of the server class is
|
|
|
|
// defined here.
|
|
|
|
class CServer; // forward declaration of CServer
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2011-04-07 20:26:54 +02:00
|
|
|
/* Definitions ****************************************************************/
|
|
|
|
// number of ports we try to bind until we give up
|
|
|
|
#define NUM_SOCKET_PORTS_TO_TRY 50
|
|
|
|
|
|
|
|
|
2006-12-18 15:39:33 +01:00
|
|
|
/* Classes ********************************************************************/
|
|
|
|
class CSocket : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2011-04-06 21:01:39 +02:00
|
|
|
CSocket ( CChannel* pNewChannel,
|
|
|
|
CProtocol* pNewCLProtocol,
|
2011-03-30 09:55:43 +02:00
|
|
|
const quint16 iPortNumber )
|
2011-04-06 21:01:39 +02:00
|
|
|
: pChannel( pNewChannel ), pConnLessProtocol ( pNewCLProtocol ),
|
2011-03-30 09:55:43 +02:00
|
|
|
bIsClient ( true ) { Init ( iPortNumber ); }
|
|
|
|
|
2011-04-14 08:46:21 +02:00
|
|
|
CSocket ( CServer* pNServP,
|
2011-03-30 09:55:43 +02:00
|
|
|
const quint16 iPortNumber )
|
|
|
|
: pServer ( pNServP ), bIsClient ( false ) { Init ( iPortNumber ); }
|
|
|
|
|
2009-03-28 21:02:21 +01:00
|
|
|
void SendPacket ( const CVector<uint8_t>& vecbySendBuf,
|
2011-04-07 20:26:54 +02:00
|
|
|
const CHostAddress& HostAddr );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
protected:
|
2009-03-10 18:35:39 +01:00
|
|
|
void Init ( const quint16 iPortNumber = LLCON_DEFAULT_PORT_NUMBER );
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2011-04-06 21:01:39 +02:00
|
|
|
QUdpSocket SocketDevice;
|
|
|
|
QMutex Mutex;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2011-04-06 21:01:39 +02:00
|
|
|
CVector<uint8_t> vecbyRecBuf;
|
|
|
|
CHostAddress RecHostAddr;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
2011-04-06 21:01:39 +02:00
|
|
|
CChannel* pChannel; // for client
|
|
|
|
CProtocol* pConnLessProtocol; // for client
|
|
|
|
CServer* pServer; // for server
|
2006-02-26 11:50:47 +01:00
|
|
|
|
2011-04-06 21:01:39 +02:00
|
|
|
bool bIsClient;
|
2006-12-18 15:39:33 +01:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void OnDataReceived();
|
|
|
|
};
|
|
|
|
|
2007-09-08 12:45:14 +02:00
|
|
|
#endif /* !defined ( SOCKET_HOIHGE76GEKJH98_3_4344_BB23945IUHF1912__INCLUDED_ ) */
|