Browse Source

broadcast beta

master
Robin Thoni 11 years ago
parent
commit
4cbd98321a
11 changed files with 269 additions and 47 deletions
  1. 5
    5
      Makefile
  2. 1
    1
      commons.pri
  3. 36
    17
      ptsocket/Makefile
  4. 103
    0
      ptsocket/broadcast.cpp
  5. 43
    0
      ptsocket/broadcast.h
  6. 4
    0
      ptsocket/ptsocket.cpp
  7. 4
    2
      ptsocket/ptsocket.pro
  8. 30
    9
      tests/Makefile
  9. 41
    4
      tests/main.cpp
  10. 0
    6
      tests/test.cpp
  11. 2
    3
      tests/tests.pro

+ 5
- 5
Makefile View File

1
 #############################################################################
1
 #############################################################################
2
 # Makefile for building: libptsocket
2
 # Makefile for building: libptsocket
3
-# Generated by qmake (2.01a) (Qt 4.8.2) on: mer. janv. 1 15:51:32 2014
3
+# Generated by qmake (2.01a) (Qt 4.8.2) on: jeu. janv. 2 15:45:44 2014
4
 # Project:  libptsocket.pro
4
 # Project:  libptsocket.pro
5
 # Template: subdirs
5
 # Template: subdirs
6
 # Command: /usr/bin/qmake -o Makefile libptsocket.pro
6
 # Command: /usr/bin/qmake -o Makefile libptsocket.pro
30
 
30
 
31
 ptsocket//$(MAKEFILE): 
31
 ptsocket//$(MAKEFILE): 
32
 	@$(CHK_DIR_EXISTS) ptsocket/ || $(MKDIR) ptsocket/ 
32
 	@$(CHK_DIR_EXISTS) ptsocket/ || $(MKDIR) ptsocket/ 
33
-	cd ptsocket/ && $(QMAKE) /pxeroot/root/share/libptsocket/ptsocket/ptsocket.pro -o $(MAKEFILE)
33
+	cd ptsocket/ && $(QMAKE) /home/robin/libptsocket/ptsocket/ptsocket.pro -o $(MAKEFILE)
34
 sub-ptsocket-qmake_all:  FORCE
34
 sub-ptsocket-qmake_all:  FORCE
35
 	@$(CHK_DIR_EXISTS) ptsocket/ || $(MKDIR) ptsocket/ 
35
 	@$(CHK_DIR_EXISTS) ptsocket/ || $(MKDIR) ptsocket/ 
36
-	cd ptsocket/ && $(QMAKE) /pxeroot/root/share/libptsocket/ptsocket/ptsocket.pro -o $(MAKEFILE)
36
+	cd ptsocket/ && $(QMAKE) /home/robin/libptsocket/ptsocket/ptsocket.pro -o $(MAKEFILE)
37
 sub-ptsocket: ptsocket//$(MAKEFILE) FORCE
37
 sub-ptsocket: ptsocket//$(MAKEFILE) FORCE
38
 	cd ptsocket/ && $(MAKE) -f $(MAKEFILE)
38
 	cd ptsocket/ && $(MAKE) -f $(MAKEFILE)
39
 sub-ptsocket-make_default: ptsocket//$(MAKEFILE) FORCE
39
 sub-ptsocket-make_default: ptsocket//$(MAKEFILE) FORCE
52
 	cd ptsocket/ && $(MAKE) -f $(MAKEFILE) uninstall
52
 	cd ptsocket/ && $(MAKE) -f $(MAKEFILE) uninstall
53
 tests//$(MAKEFILE): 
53
 tests//$(MAKEFILE): 
54
 	@$(CHK_DIR_EXISTS) tests/ || $(MKDIR) tests/ 
54
 	@$(CHK_DIR_EXISTS) tests/ || $(MKDIR) tests/ 
55
-	cd tests/ && $(QMAKE) /pxeroot/root/share/libptsocket/tests/tests.pro -o $(MAKEFILE)
55
+	cd tests/ && $(QMAKE) /home/robin/libptsocket/tests/tests.pro -o $(MAKEFILE)
56
 sub-tests-qmake_all:  FORCE
56
 sub-tests-qmake_all:  FORCE
57
 	@$(CHK_DIR_EXISTS) tests/ || $(MKDIR) tests/ 
57
 	@$(CHK_DIR_EXISTS) tests/ || $(MKDIR) tests/ 
58
-	cd tests/ && $(QMAKE) /pxeroot/root/share/libptsocket/tests/tests.pro -o $(MAKEFILE)
58
+	cd tests/ && $(QMAKE) /home/robin/libptsocket/tests/tests.pro -o $(MAKEFILE)
59
 sub-tests: tests//$(MAKEFILE) FORCE
59
 sub-tests: tests//$(MAKEFILE) FORCE
60
 	cd tests/ && $(MAKE) -f $(MAKEFILE)
60
 	cd tests/ && $(MAKE) -f $(MAKEFILE)
61
 sub-tests-make_default: tests//$(MAKEFILE) FORCE
61
 sub-tests-make_default: tests//$(MAKEFILE) FORCE

+ 1
- 1
commons.pri View File

1
-#DEFINES += PT_DEBUG
1
+DEFINES += PT_DEBUG

+ 36
- 17
ptsocket/Makefile View File

1
 #############################################################################
1
 #############################################################################
2
-# Makefile for building: libptsocket.so.1.0.0
3
-# Generated by qmake (2.01a) (Qt 4.8.2) on: mer. janv. 1 15:51:37 2014
2
+# Makefile for building: libptsocket.so.1.5.0
3
+# Generated by qmake (2.01a) (Qt 4.8.2) on: jeu. janv. 2 15:46:29 2014
4
 # Project:  ptsocket.pro
4
 # Project:  ptsocket.pro
5
 # Template: lib
5
 # Template: lib
6
 # Command: /usr/bin/qmake -o Makefile ptsocket.pro
6
 # Command: /usr/bin/qmake -o Makefile ptsocket.pro
10
 
10
 
11
 CC            = gcc
11
 CC            = gcc
12
 CXX           = g++
12
 CXX           = g++
13
-DEFINES       = -DQT_WEBKIT -DLIBPTSOCKET_LIBRARY -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
13
+DEFINES       = -DQT_WEBKIT -DPT_DEBUG -DLIBPTSOCKET_LIBRARY -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
14
 CFLAGS        = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
14
 CFLAGS        = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
15
 CXXFLAGS      = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
15
 CXXFLAGS      = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
16
 INCPATH       = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4 -I.
16
 INCPATH       = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4 -I.
44
 ####### Files
44
 ####### Files
45
 
45
 
46
 SOURCES       = ptsocket.cpp \
46
 SOURCES       = ptsocket.cpp \
47
-		ptserver.cpp moc_ptsocket.cpp \
48
-		moc_ptserver.cpp
47
+		ptserver.cpp \
48
+		broadcast.cpp moc_ptsocket.cpp \
49
+		moc_ptserver.cpp \
50
+		moc_broadcast.cpp
49
 OBJECTS       = ptsocket.o \
51
 OBJECTS       = ptsocket.o \
50
 		ptserver.o \
52
 		ptserver.o \
53
+		broadcast.o \
51
 		moc_ptsocket.o \
54
 		moc_ptsocket.o \
52
-		moc_ptserver.o
55
+		moc_ptserver.o \
56
+		moc_broadcast.o
53
 DIST          = /usr/share/qt4/mkspecs/common/unix.conf \
57
 DIST          = /usr/share/qt4/mkspecs/common/unix.conf \
54
 		/usr/share/qt4/mkspecs/common/linux.conf \
58
 		/usr/share/qt4/mkspecs/common/linux.conf \
55
 		/usr/share/qt4/mkspecs/common/gcc-base.conf \
59
 		/usr/share/qt4/mkspecs/common/gcc-base.conf \
79
 		ptsocket.pro
83
 		ptsocket.pro
80
 QMAKE_TARGET  = ptsocket
84
 QMAKE_TARGET  = ptsocket
81
 DESTDIR       = 
85
 DESTDIR       = 
82
-TARGET        = libptsocket.so.1.0.0
86
+TARGET        = libptsocket.so.1.5.0
83
 TARGETA       = libptsocket.a
87
 TARGETA       = libptsocket.a
84
-TARGETD       = libptsocket.so.1.0.0
88
+TARGETD       = libptsocket.so.1.5.0
85
 TARGET0       = libptsocket.so
89
 TARGET0       = libptsocket.so
86
 TARGET1       = libptsocket.so.1
90
 TARGET1       = libptsocket.so.1
87
-TARGET2       = libptsocket.so.1.0
91
+TARGET2       = libptsocket.so.1.5
88
 
92
 
89
 first: all
93
 first: all
90
 ####### Implicit rules
94
 ####### Implicit rules
186
 	@$(QMAKE) -o Makefile ptsocket.pro
190
 	@$(QMAKE) -o Makefile ptsocket.pro
187
 
191
 
188
 dist: 
192
 dist: 
189
-	@$(CHK_DIR_EXISTS) .tmp/ptsocket1.0.0 || $(MKDIR) .tmp/ptsocket1.0.0 
190
-	$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/ptsocket1.0.0/ && $(COPY_FILE) --parents ptsocket.h libptsocket_global.h ptserver.h .tmp/ptsocket1.0.0/ && $(COPY_FILE) --parents ptsocket.cpp ptserver.cpp .tmp/ptsocket1.0.0/ && (cd `dirname .tmp/ptsocket1.0.0` && $(TAR) ptsocket1.0.0.tar ptsocket1.0.0 && $(COMPRESS) ptsocket1.0.0.tar) && $(MOVE) `dirname .tmp/ptsocket1.0.0`/ptsocket1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/ptsocket1.0.0
193
+	@$(CHK_DIR_EXISTS) .tmp/ptsocket1.5.0 || $(MKDIR) .tmp/ptsocket1.5.0 
194
+	$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/ptsocket1.5.0/ && $(COPY_FILE) --parents ptsocket.h libptsocket_global.h ptserver.h broadcast.h .tmp/ptsocket1.5.0/ && $(COPY_FILE) --parents ptsocket.cpp ptserver.cpp broadcast.cpp .tmp/ptsocket1.5.0/ && (cd `dirname .tmp/ptsocket1.5.0` && $(TAR) ptsocket1.5.0.tar ptsocket1.5.0 && $(COMPRESS) ptsocket1.5.0.tar) && $(MOVE) `dirname .tmp/ptsocket1.5.0`/ptsocket1.5.0.tar.gz . && $(DEL_FILE) -r .tmp/ptsocket1.5.0
191
 
195
 
192
 
196
 
193
 clean:compiler_clean 
197
 clean:compiler_clean 
209
 
213
 
210
 mocables: compiler_moc_header_make_all compiler_moc_source_make_all
214
 mocables: compiler_moc_header_make_all compiler_moc_source_make_all
211
 
215
 
212
-compiler_moc_header_make_all: moc_ptsocket.cpp moc_ptserver.cpp
216
+compiler_moc_header_make_all: moc_ptsocket.cpp moc_ptserver.cpp moc_broadcast.cpp
213
 compiler_moc_header_clean:
217
 compiler_moc_header_clean:
214
-	-$(DEL_FILE) moc_ptsocket.cpp moc_ptserver.cpp
218
+	-$(DEL_FILE) moc_ptsocket.cpp moc_ptserver.cpp moc_broadcast.cpp
215
 moc_ptsocket.cpp: libptsocket_global.h \
219
 moc_ptsocket.cpp: libptsocket_global.h \
216
 		ptsocket.h
220
 		ptsocket.h
217
 	/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) ptsocket.h -o moc_ptsocket.cpp
221
 	/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) ptsocket.h -o moc_ptsocket.cpp
221
 		ptserver.h
225
 		ptserver.h
222
 	/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) ptserver.h -o moc_ptserver.cpp
226
 	/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) ptserver.h -o moc_ptserver.cpp
223
 
227
 
228
+moc_broadcast.cpp: ptsocket.h \
229
+		libptsocket_global.h \
230
+		broadcast.h
231
+	/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) broadcast.h -o moc_broadcast.cpp
232
+
224
 compiler_rcc_make_all:
233
 compiler_rcc_make_all:
225
 compiler_rcc_clean:
234
 compiler_rcc_clean:
226
 compiler_image_collection_make_all: qmake_image_collection.cpp
235
 compiler_image_collection_make_all: qmake_image_collection.cpp
249
 		ptsocket.h
258
 		ptsocket.h
250
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o ptserver.o ptserver.cpp
259
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o ptserver.o ptserver.cpp
251
 
260
 
261
+broadcast.o: broadcast.cpp broadcast.h \
262
+		ptsocket.h \
263
+		libptsocket_global.h
264
+	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o broadcast.o broadcast.cpp
265
+
252
 moc_ptsocket.o: moc_ptsocket.cpp 
266
 moc_ptsocket.o: moc_ptsocket.cpp 
253
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_ptsocket.o moc_ptsocket.cpp
267
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_ptsocket.o moc_ptsocket.cpp
254
 
268
 
255
 moc_ptserver.o: moc_ptserver.cpp 
269
 moc_ptserver.o: moc_ptserver.cpp 
256
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_ptserver.o moc_ptserver.cpp
270
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_ptserver.o moc_ptserver.cpp
257
 
271
 
272
+moc_broadcast.o: moc_broadcast.cpp 
273
+	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_broadcast.o moc_broadcast.cpp
274
+
258
 ####### Install
275
 ####### Install
259
 
276
 
260
 install_headers: first FORCE
277
 install_headers: first FORCE
261
 	@$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/usr/include/ptsocket/ || $(MKDIR) $(INSTALL_ROOT)/usr/include/ptsocket/ 
278
 	@$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/usr/include/ptsocket/ || $(MKDIR) $(INSTALL_ROOT)/usr/include/ptsocket/ 
262
-	-$(INSTALL_FILE) /pxeroot/root/share/libptsocket/ptsocket/ptsocket.h $(INSTALL_ROOT)/usr/include/ptsocket/
263
-	-$(INSTALL_FILE) /pxeroot/root/share/libptsocket/ptsocket/libptsocket_global.h $(INSTALL_ROOT)/usr/include/ptsocket/
264
-	-$(INSTALL_FILE) /pxeroot/root/share/libptsocket/ptsocket/ptserver.h $(INSTALL_ROOT)/usr/include/ptsocket/
279
+	-$(INSTALL_FILE) /home/robin/libptsocket/ptsocket/ptsocket.h $(INSTALL_ROOT)/usr/include/ptsocket/
280
+	-$(INSTALL_FILE) /home/robin/libptsocket/ptsocket/libptsocket_global.h $(INSTALL_ROOT)/usr/include/ptsocket/
281
+	-$(INSTALL_FILE) /home/robin/libptsocket/ptsocket/ptserver.h $(INSTALL_ROOT)/usr/include/ptsocket/
282
+	-$(INSTALL_FILE) /home/robin/libptsocket/ptsocket/broadcast.h $(INSTALL_ROOT)/usr/include/ptsocket/
265
 
283
 
266
 
284
 
267
 uninstall_headers:  FORCE
285
 uninstall_headers:  FORCE
268
 	-$(DEL_FILE) -r $(INSTALL_ROOT)/usr/include/ptsocket/ptsocket.h 
286
 	-$(DEL_FILE) -r $(INSTALL_ROOT)/usr/include/ptsocket/ptsocket.h 
269
 	 -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/include/ptsocket/libptsocket_global.h 
287
 	 -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/include/ptsocket/libptsocket_global.h 
270
-	 -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/include/ptsocket/ptserver.h
288
+	 -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/include/ptsocket/ptserver.h 
289
+	 -$(DEL_FILE) -r $(INSTALL_ROOT)/usr/include/ptsocket/broadcast.h
271
 	-$(DEL_DIR) $(INSTALL_ROOT)/usr/include/ptsocket/ 
290
 	-$(DEL_DIR) $(INSTALL_ROOT)/usr/include/ptsocket/ 
272
 
291
 
273
 
292
 

+ 103
- 0
ptsocket/broadcast.cpp View File

1
+#include "broadcast.h"
2
+
3
+Broadcast::Broadcast(bool isServer, QObject* p) : QObject(p)
4
+{
5
+	m_isServer = isServer;
6
+	m_server = new QUdpSocket(this);
7
+	connect(m_server, SIGNAL(readyRead()), this, SLOT(readyRead()));
8
+	connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(clearData()));
9
+	connect(&m_bcTimer, SIGNAL(timeout()), this, SLOT(broadcastClient()));
10
+	m_timeoutTimer.setSingleShot(true);
11
+	m_bcTimer.setSingleShot(true);
12
+	setTimeout(2500);
13
+	setBroadcastInterval(5000);
14
+}
15
+
16
+QString Broadcast::getError() const
17
+{
18
+	return m_server->errorString();
19
+}
20
+
21
+bool Broadcast::isServer() const
22
+{
23
+	return m_isServer;
24
+}
25
+
26
+QByteArray Broadcast::clientData()
27
+{
28
+	return PTSocket::handshakeData() + "bcastc";
29
+}
30
+
31
+QByteArray Broadcast::serverData()
32
+{
33
+	return PTSocket::handshakeData() + "bcasts";
34
+}
35
+
36
+void Broadcast::setTimeout(int t)
37
+{
38
+	if(m_timeoutTimer.isActive())
39
+		m_timeoutTimer.start(t);
40
+	else
41
+		m_timeoutTimer.setInterval(t);
42
+}
43
+
44
+void Broadcast::setBroadcastInterval(int t)
45
+{
46
+	if(m_bcTimer.isActive())
47
+		m_bcTimer.start(t);
48
+	else
49
+		m_bcTimer.setInterval(t);
50
+}
51
+
52
+bool Broadcast::start(int port, int r, QHostAddress ad)
53
+{
54
+	m_remotePort = r;
55
+	bool ok = m_server->bind(ad, port);
56
+	if(m_isServer)
57
+		m_server->writeDatagram(serverData(), QHostAddress::Broadcast, m_remotePort);
58
+	else
59
+		broadcastClient();
60
+	return ok;
61
+}
62
+
63
+void Broadcast::broadcastClient()
64
+{
65
+	m_server->writeDatagram(clientData(), QHostAddress::Broadcast, m_remotePort);
66
+//	m_bcTimer.start();
67
+}
68
+
69
+void Broadcast::readyRead()
70
+{
71
+	while(m_server->hasPendingDatagrams())
72
+	{
73
+		QByteArray data;
74
+		data.resize(m_server->pendingDatagramSize());
75
+		QHostAddress host;
76
+		quint16 port = 0;
77
+		m_server->readDatagram(data.data(), data.size(), &host, &port);
78
+		BcClient client(host.toIPv4Address(), port);
79
+		m_data[client].append(data);
80
+		if(m_isServer)
81
+		{
82
+			if(m_data[client].size() < clientData().size())
83
+				continue;
84
+			if(m_data[client] == clientData())
85
+				m_server->writeDatagram(serverData(), QHostAddress(client.first), m_remotePort);
86
+			m_data.remove(client);
87
+		}
88
+		else
89
+		{
90
+			if(m_data[client].size() < serverData().size())
91
+				continue;
92
+			if(m_data[client] == serverData())
93
+				emit serverDiscovered(QHostAddress(client.first), client.second);
94
+			m_data.remove(client);
95
+		}
96
+	}
97
+	m_timeoutTimer.start();
98
+}
99
+
100
+void Broadcast::clearData()
101
+{
102
+	m_data.clear();
103
+}

+ 43
- 0
ptsocket/broadcast.h View File

1
+#ifndef BROADCAST_H
2
+#define BROADCAST_H
3
+
4
+#include <QUdpSocket>
5
+#include <QPair>
6
+#include "ptsocket.h"
7
+#include "libptsocket_global.h"
8
+
9
+typedef QPair<quint32, quint16> BcClient;
10
+
11
+class LIBPTSOCKETSHARED_EXPORT Broadcast : public QObject
12
+{
13
+	Q_OBJECT
14
+public:
15
+	Broadcast(bool isServer, QObject* p = 0);
16
+	bool isServer() const;
17
+	QString getError() const;
18
+	static QByteArray clientData();
19
+	static QByteArray serverData();
20
+
21
+signals:
22
+	void serverDiscovered(QHostAddress, quint16);
23
+
24
+public slots:
25
+	void setTimeout(int t);
26
+	void setBroadcastInterval(int i);
27
+	bool start(int port, int r, QHostAddress ad = QHostAddress::Any);
28
+	void broadcastClient();
29
+
30
+private slots:
31
+	void readyRead();
32
+	void clearData();
33
+
34
+private:
35
+	QUdpSocket* m_server;
36
+	bool m_isServer;
37
+	QTimer m_timeoutTimer;
38
+	QTimer m_bcTimer;
39
+	QMap<BcClient, QByteArray> m_data;
40
+	int m_remotePort;
41
+};
42
+
43
+#endif

+ 4
- 0
ptsocket/ptsocket.cpp View File

12
     m_timeoutTimer.setSingleShot(true);
12
     m_timeoutTimer.setSingleShot(true);
13
     setTimeout(5000);
13
     setTimeout(5000);
14
     m_pingTimer.setSingleShot(true);
14
     m_pingTimer.setSingleShot(true);
15
+#ifdef PT_DEBUG
15
     setPingInterval(1000 * 7);
16
     setPingInterval(1000 * 7);
17
+#else
18
+    setPingInterval(1000 * 60);
19
+#endif
16
     m_state = Disconnected;
20
     m_state = Disconnected;
17
     m_isServerSide = false;
21
     m_isServerSide = false;
18
     connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(m_timedout()));
22
     connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(m_timedout()));

+ 4
- 2
ptsocket/ptsocket.pro View File

5
 TEMPLATE = lib
5
 TEMPLATE = lib
6
 DEFINES += LIBPTSOCKET_LIBRARY
6
 DEFINES += LIBPTSOCKET_LIBRARY
7
 
7
 
8
-SOURCES += ptsocket.cpp ptserver.cpp
9
-HEADERS += ptsocket.h libptsocket_global.h ptserver.h
8
+SOURCES += ptsocket.cpp ptserver.cpp broadcast.cpp
9
+HEADERS += ptsocket.h libptsocket_global.h ptserver.h broadcast.h
10
 
10
 
11
 unix:!symbian {
11
 unix:!symbian {
12
     maemo5 {
12
     maemo5 {
19
     }
19
     }
20
     INSTALLS += target
20
     INSTALLS += target
21
 }
21
 }
22
+
23
+VERSION = 1.5.0

+ 30
- 9
tests/Makefile View File

1
 #############################################################################
1
 #############################################################################
2
 # Makefile for building: tests
2
 # Makefile for building: tests
3
-# Generated by qmake (2.01a) (Qt 4.8.2) on: mer. janv. 1 15:51:37 2014
3
+# Generated by qmake (2.01a) (Qt 4.8.2) on: jeu. janv. 2 15:46:24 2014
4
 # Project:  tests.pro
4
 # Project:  tests.pro
5
 # Template: app
5
 # Template: app
6
 # Command: /usr/bin/qmake -o Makefile tests.pro
6
 # Command: /usr/bin/qmake -o Makefile tests.pro
10
 
10
 
11
 CC            = gcc
11
 CC            = gcc
12
 CXX           = g++
12
 CXX           = g++
13
-DEFINES       = -DQT_WEBKIT -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
13
+DEFINES       = -DQT_WEBKIT -DPT_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
14
 CFLAGS        = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
14
 CFLAGS        = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
15
 CXXFLAGS      = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
15
 CXXFLAGS      = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
16
 INCPATH       = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4 -I../ptsocket -I.
16
 INCPATH       = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4 -I../ptsocket -I.
17
 LINK          = g++
17
 LINK          = g++
18
 LFLAGS        = -m64
18
 LFLAGS        = -m64
19
-LIBS          = $(SUBLIBS)  -L/usr/lib/x86_64-linux-gnu -L/pxeroot/root/share/libptsocket/tests/../ptsocket/ -lptsocket -lQtNetwork -lQtCore -lpthread 
19
+LIBS          = $(SUBLIBS)  -L/usr/lib/x86_64-linux-gnu -L/home/robin/libptsocket/tests/../ptsocket/ -lptsocket -lQtNetwork -lQtCore -lpthread 
20
 AR            = ar cqs
20
 AR            = ar cqs
21
 RANLIB        = 
21
 RANLIB        = 
22
 QMAKE         = /usr/bin/qmake
22
 QMAKE         = /usr/bin/qmake
44
 ####### Files
44
 ####### Files
45
 
45
 
46
 SOURCES       = main.cpp \
46
 SOURCES       = main.cpp \
47
-		test.cpp moc_test.cpp
47
+		test.cpp \
48
+		bctest.cpp moc_test.cpp \
49
+		moc_bctest.cpp
48
 OBJECTS       = main.o \
50
 OBJECTS       = main.o \
49
 		test.o \
51
 		test.o \
50
-		moc_test.o
52
+		bctest.o \
53
+		moc_test.o \
54
+		moc_bctest.o
51
 DIST          = /usr/share/qt4/mkspecs/common/unix.conf \
55
 DIST          = /usr/share/qt4/mkspecs/common/unix.conf \
52
 		/usr/share/qt4/mkspecs/common/linux.conf \
56
 		/usr/share/qt4/mkspecs/common/linux.conf \
53
 		/usr/share/qt4/mkspecs/common/gcc-base.conf \
57
 		/usr/share/qt4/mkspecs/common/gcc-base.conf \
169
 
173
 
170
 dist: 
174
 dist: 
171
 	@$(CHK_DIR_EXISTS) .tmp/tests1.0.0 || $(MKDIR) .tmp/tests1.0.0 
175
 	@$(CHK_DIR_EXISTS) .tmp/tests1.0.0 || $(MKDIR) .tmp/tests1.0.0 
172
-	$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/tests1.0.0/ && $(COPY_FILE) --parents test.h .tmp/tests1.0.0/ && $(COPY_FILE) --parents main.cpp test.cpp .tmp/tests1.0.0/ && (cd `dirname .tmp/tests1.0.0` && $(TAR) tests1.0.0.tar tests1.0.0 && $(COMPRESS) tests1.0.0.tar) && $(MOVE) `dirname .tmp/tests1.0.0`/tests1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/tests1.0.0
176
+	$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/tests1.0.0/ && $(COPY_FILE) --parents test.h bctest.h .tmp/tests1.0.0/ && $(COPY_FILE) --parents main.cpp test.cpp bctest.cpp .tmp/tests1.0.0/ && (cd `dirname .tmp/tests1.0.0` && $(TAR) tests1.0.0.tar tests1.0.0 && $(COMPRESS) tests1.0.0.tar) && $(MOVE) `dirname .tmp/tests1.0.0`/tests1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/tests1.0.0
173
 
177
 
174
 
178
 
175
 clean:compiler_clean 
179
 clean:compiler_clean 
190
 
194
 
191
 mocables: compiler_moc_header_make_all compiler_moc_source_make_all
195
 mocables: compiler_moc_header_make_all compiler_moc_source_make_all
192
 
196
 
193
-compiler_moc_header_make_all: moc_test.cpp
197
+compiler_moc_header_make_all: moc_test.cpp moc_bctest.cpp
194
 compiler_moc_header_clean:
198
 compiler_moc_header_clean:
195
-	-$(DEL_FILE) moc_test.cpp
199
+	-$(DEL_FILE) moc_test.cpp moc_bctest.cpp
196
 moc_test.cpp: ../ptsocket/ptserver.h \
200
 moc_test.cpp: ../ptsocket/ptserver.h \
197
 		../ptsocket/libptsocket_global.h \
201
 		../ptsocket/libptsocket_global.h \
198
 		../ptsocket/ptsocket.h \
202
 		../ptsocket/ptsocket.h \
199
 		test.h
203
 		test.h
200
 	/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) test.h -o moc_test.cpp
204
 	/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) test.h -o moc_test.cpp
201
 
205
 
206
+moc_bctest.cpp: ../ptsocket/broadcast.h \
207
+		../ptsocket/ptsocket.h \
208
+		../ptsocket/libptsocket_global.h \
209
+		bctest.h
210
+	/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) bctest.h -o moc_bctest.cpp
211
+
202
 compiler_rcc_make_all:
212
 compiler_rcc_make_all:
203
 compiler_rcc_clean:
213
 compiler_rcc_clean:
204
 compiler_image_collection_make_all: qmake_image_collection.cpp
214
 compiler_image_collection_make_all: qmake_image_collection.cpp
221
 main.o: main.cpp test.h \
231
 main.o: main.cpp test.h \
222
 		../ptsocket/ptserver.h \
232
 		../ptsocket/ptserver.h \
223
 		../ptsocket/libptsocket_global.h \
233
 		../ptsocket/libptsocket_global.h \
224
-		../ptsocket/ptsocket.h
234
+		../ptsocket/ptsocket.h \
235
+		bctest.h \
236
+		../ptsocket/broadcast.h
225
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
237
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
226
 
238
 
227
 test.o: test.cpp test.h \
239
 test.o: test.cpp test.h \
230
 		../ptsocket/ptsocket.h
242
 		../ptsocket/ptsocket.h
231
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o test.o test.cpp
243
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o test.o test.cpp
232
 
244
 
245
+bctest.o: bctest.cpp bctest.h \
246
+		../ptsocket/broadcast.h \
247
+		../ptsocket/ptsocket.h \
248
+		../ptsocket/libptsocket_global.h
249
+	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o bctest.o bctest.cpp
250
+
233
 moc_test.o: moc_test.cpp 
251
 moc_test.o: moc_test.cpp 
234
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_test.o moc_test.cpp
252
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_test.o moc_test.cpp
235
 
253
 
254
+moc_bctest.o: moc_bctest.cpp 
255
+	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_bctest.o moc_bctest.cpp
256
+
236
 ####### Install
257
 ####### Install
237
 
258
 
238
 install:   FORCE
259
 install:   FORCE

+ 41
- 4
tests/main.cpp View File

1
 #include <QCoreApplication>
1
 #include <QCoreApplication>
2
+#include <QStringList>
3
+#include <iostream>
2
 
4
 
3
 #include "test.h"
5
 #include "test.h"
6
+#include "bctest.h"
4
 
7
 
5
 int main(int argc, char *argv[])
8
 int main(int argc, char *argv[])
6
 {
9
 {
10
+#ifdef PT_DEBUG
11
+	std::cout<<"Debug mode"<<std::endl;
12
+#else
13
+	std::cout<<"Release mode"<<std::endl;
14
+#warning PTSocket is not in debug mode
15
+#endif
16
+
7
 	QCoreApplication a(argc, argv);
17
 	QCoreApplication a(argc, argv);
8
-    Test t;
9
-    t.testListen(6950);
10
-    t.test0IntConvert();
11
-	
18
+	bool pt = false, bc = false;
19
+	if(qApp->arguments().size() >= 2)
20
+	{
21
+		if(qApp->arguments().at(1) == "-bc")
22
+			bc = true;
23
+		else if(qApp->arguments().at(1) == "-pt")
24
+			pt = true;
25
+		else
26
+		{
27
+			std::cout<<"Usage: tests -bc|-pt"<<std::endl;
28
+			return 1;
29
+		}
30
+	}
31
+	else
32
+	{
33
+		std::cout<<"Usage: tests -bc|-pt"<<std::endl;
34
+		return 1;
35
+	}
36
+
37
+	BcTest bct;
38
+	Test t;
39
+	if(bc)
40
+	{
41
+		bct.test();
42
+	}
43
+	else if(pt)
44
+	{
45
+		t.testListen(6950);
46
+		t.test0IntConvert();
47
+	}
48
+
12
 	return a.exec();
49
 	return a.exec();
13
 }
50
 }

+ 0
- 6
tests/test.cpp View File

2
 
2
 
3
 Test::Test(QObject *parent) : QObject(parent)
3
 Test::Test(QObject *parent) : QObject(parent)
4
 {
4
 {
5
-#ifdef PT_DEBUG
6
-    qDebug()<<"Debug mode";
7
-#else
8
-    qDebug()<<"Release mode";
9
-#warning PTSocket is not in debug mode
10
-#endif
11
     m_serv = new PTServer(this);
5
     m_serv = new PTServer(this);
12
     m_timeoutTimer.setSingleShot(true);
6
     m_timeoutTimer.setSingleShot(true);
13
     connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(timedout()));
7
     connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(timedout()));

+ 2
- 3
tests/tests.pro View File

7
 CONFIG += debug
7
 CONFIG += debug
8
 include(../commons.pri)
8
 include(../commons.pri)
9
 
9
 
10
-SOURCES += main.cpp test.cpp
11
-HEADERS += test.h
10
+SOURCES += main.cpp test.cpp bctest.cpp
11
+HEADERS += test.h bctest.h
12
 
12
 
13
 win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../ptsocket/release/ -lptsocket
13
 win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../ptsocket/release/ -lptsocket
14
 else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../ptsocket/debug/ -lptsocket
14
 else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../ptsocket/debug/ -lptsocket
16
 
16
 
17
 INCLUDEPATH += $$PWD/../ptsocket
17
 INCLUDEPATH += $$PWD/../ptsocket
18
 DEPENDPATH += $$PWD/../ptsocket
18
 DEPENDPATH += $$PWD/../ptsocket
19
-

Loading…
Cancel
Save