1 #ifndef _CLASS_SOCKET_H_
2 #define _CLASS_SOCKET_H_
3 //=============================================================================
4 //
5 //   File : KvsObject_socket.h
6 //   Creation date : Sun Nov 11 03:13:46 2001 GMT by Szymon Stefanek
7 //
8 //   This file is part of the KVIrc IRC client distribution
9 //   Copyright (C) 2001 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 //   This program is FREE software. You can redistribute it and/or
12 //   modify it under the terms of the GNU General Public License
13 //   as published by the Free Software Foundation; either version 2
14 //   of the License, or (at your option) any later version.
15 //
16 //   This program is distributed in the HOPE that it will be USEFUL,
17 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
18 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 //   See the GNU General Public License for more details.
20 //
21 //   You should have received a copy of the GNU General Public License
22 //   along with this program. If not, write to the Free Software Foundation,
23 //   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 #include <QAbstractSocket>
28 #include <QTcpServer>
29 
30 #include "object_macros.h"
31 
32 class KvsObject_socket : public KviKvsObject
33 {
34 	Q_OBJECT
35 public:
36 	KVSO_DECLARE_OBJECT(KvsObject_socket)
37 protected:
38 	QAbstractSocket * m_pSocket = nullptr;
39 	QTcpServer * m_pServer = nullptr;
40 	KviKvsRunTimeContext * m_pContext = nullptr;
41 	bool bIsSetFromExternal = false;
42 
43 protected:
44 	bool init(KviKvsRunTimeContext * pContext, KviKvsVariantList * pParams) override;
45 	const char * getStateString(QAbstractSocket::SocketState);
46 
setInternalSocket(QAbstractSocket * pSocket)47 	void setInternalSocket(QAbstractSocket * pSocket)
48 	{
49 		delete m_pSocket;
50 		m_pSocket = pSocket;
51 		bIsSetFromExternal = true;
52 		makeConnections();
53 	}
54 
55 	bool status(KviKvsObjectFunctionCall * c);
56 	bool remotePort(KviKvsObjectFunctionCall * c);
57 	bool remoteIp(KviKvsObjectFunctionCall * c);
58 	bool localPort(KviKvsObjectFunctionCall * c);
59 	bool localIp(KviKvsObjectFunctionCall * c);
60 	bool functionConnect(KviKvsObjectFunctionCall * c);
61 	bool close(KviKvsObjectFunctionCall * c);
62 	bool read(KviKvsObjectFunctionCall * c);
63 	bool write(KviKvsObjectFunctionCall * c);
64 	bool bytesAvailable(KviKvsObjectFunctionCall * c);
65 	bool setProtocol(KviKvsObjectFunctionCall * c);
66 	//bool setReadBufferSize(KviKvsObjectFunctionCall *c);
67 	bool listen(KviKvsObjectFunctionCall * c);
68 	bool dataAvailableEvent(KviKvsObjectFunctionCall * c);
69 	bool incomingConnectionEvent(KviKvsObjectFunctionCall * c);
70 	bool connectedEvent(KviKvsObjectFunctionCall * c);
71 	bool disconnectedEvent(KviKvsObjectFunctionCall * c);
72 	bool errorEvent(KviKvsObjectFunctionCall * c);
73 	bool hostFoundEvent(KviKvsObjectFunctionCall * c);
74 	bool stateChangedEvent(KviKvsObjectFunctionCall * c);
75 
76 	void makeConnections();
77 protected slots:
78 	void slotReadyRead();
79 	void slotNewConnection();
80 	void slotConnected();
81 	void slotDisconnected();
82 	void slotError(QAbstractSocket::SocketError socketError);
83 	void slotHostFound();
84 	void slotStateChanged(QAbstractSocket::SocketState socketState);
85 };
86 #endif //_CLASS_SOCKET_H_
87