Robin Thoni 11 роки тому
джерело
коміт
4cbd98321a
11 змінених файлів з 269 додано та 47 видалено
  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 Переглянути файл

@@ -1,6 +1,6 @@
1 1
 #############################################################################
2 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 4
 # Project:  libptsocket.pro
5 5
 # Template: subdirs
6 6
 # Command: /usr/bin/qmake -o Makefile libptsocket.pro
@@ -30,10 +30,10 @@ SUBTARGETS    =  \
30 30
 
31 31
 ptsocket//$(MAKEFILE): 
32 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 34
 sub-ptsocket-qmake_all:  FORCE
35 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 37
 sub-ptsocket: ptsocket//$(MAKEFILE) FORCE
38 38
 	cd ptsocket/ && $(MAKE) -f $(MAKEFILE)
39 39
 sub-ptsocket-make_default: ptsocket//$(MAKEFILE) FORCE
@@ -52,10 +52,10 @@ sub-ptsocket-uninstall_subtargets: ptsocket//$(MAKEFILE) FORCE
52 52
 	cd ptsocket/ && $(MAKE) -f $(MAKEFILE) uninstall
53 53
 tests//$(MAKEFILE): 
54 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 56
 sub-tests-qmake_all:  FORCE
57 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 59
 sub-tests: tests//$(MAKEFILE) FORCE
60 60
 	cd tests/ && $(MAKE) -f $(MAKEFILE)
61 61
 sub-tests-make_default: tests//$(MAKEFILE) FORCE

+ 1
- 1
commons.pri Переглянути файл

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

+ 36
- 17
ptsocket/Makefile Переглянути файл

@@ -1,6 +1,6 @@
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 4
 # Project:  ptsocket.pro
5 5
 # Template: lib
6 6
 # Command: /usr/bin/qmake -o Makefile ptsocket.pro
@@ -10,7 +10,7 @@
10 10
 
11 11
 CC            = gcc
12 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 14
 CFLAGS        = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
15 15
 CXXFLAGS      = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES)
16 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,12 +44,16 @@ OBJECTS_DIR   = ./
44 44
 ####### Files
45 45
 
46 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 51
 OBJECTS       = ptsocket.o \
50 52
 		ptserver.o \
53
+		broadcast.o \
51 54
 		moc_ptsocket.o \
52
-		moc_ptserver.o
55
+		moc_ptserver.o \
56
+		moc_broadcast.o
53 57
 DIST          = /usr/share/qt4/mkspecs/common/unix.conf \
54 58
 		/usr/share/qt4/mkspecs/common/linux.conf \
55 59
 		/usr/share/qt4/mkspecs/common/gcc-base.conf \
@@ -79,12 +83,12 @@ DIST          = /usr/share/qt4/mkspecs/common/unix.conf \
79 83
 		ptsocket.pro
80 84
 QMAKE_TARGET  = ptsocket
81 85
 DESTDIR       = 
82
-TARGET        = libptsocket.so.1.0.0
86
+TARGET        = libptsocket.so.1.5.0
83 87
 TARGETA       = libptsocket.a
84
-TARGETD       = libptsocket.so.1.0.0
88
+TARGETD       = libptsocket.so.1.5.0
85 89
 TARGET0       = libptsocket.so
86 90
 TARGET1       = libptsocket.so.1
87
-TARGET2       = libptsocket.so.1.0
91
+TARGET2       = libptsocket.so.1.5
88 92
 
89 93
 first: all
90 94
 ####### Implicit rules
@@ -186,8 +190,8 @@ qmake:  FORCE
186 190
 	@$(QMAKE) -o Makefile ptsocket.pro
187 191
 
188 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 197
 clean:compiler_clean 
@@ -209,9 +213,9 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean
209 213
 
210 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 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 219
 moc_ptsocket.cpp: libptsocket_global.h \
216 220
 		ptsocket.h
217 221
 	/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) ptsocket.h -o moc_ptsocket.cpp
@@ -221,6 +225,11 @@ moc_ptserver.cpp: libptsocket_global.h \
221 225
 		ptserver.h
222 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 233
 compiler_rcc_make_all:
225 234
 compiler_rcc_clean:
226 235
 compiler_image_collection_make_all: qmake_image_collection.cpp
@@ -249,25 +258,35 @@ ptserver.o: ptserver.cpp ptserver.h \
249 258
 		ptsocket.h
250 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 266
 moc_ptsocket.o: moc_ptsocket.cpp 
253 267
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_ptsocket.o moc_ptsocket.cpp
254 268
 
255 269
 moc_ptserver.o: moc_ptserver.cpp 
256 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 275
 ####### Install
259 276
 
260 277
 install_headers: first FORCE
261 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 285
 uninstall_headers:  FORCE
268 286
 	-$(DEL_FILE) -r $(INSTALL_ROOT)/usr/include/ptsocket/ptsocket.h 
269 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 290
 	-$(DEL_DIR) $(INSTALL_ROOT)/usr/include/ptsocket/ 
272 291
 
273 292
 

+ 103
- 0
ptsocket/broadcast.cpp Переглянути файл

@@ -0,0 +1,103 @@
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 Переглянути файл

@@ -0,0 +1,43 @@
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 Переглянути файл

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

+ 4
- 2
ptsocket/ptsocket.pro Переглянути файл

@@ -5,8 +5,8 @@ TARGET = ptsocket
5 5
 TEMPLATE = lib
6 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 11
 unix:!symbian {
12 12
     maemo5 {
@@ -19,3 +19,5 @@ unix:!symbian {
19 19
     }
20 20
     INSTALLS += target
21 21
 }
22
+
23
+VERSION = 1.5.0

+ 30
- 9
tests/Makefile Переглянути файл

@@ -1,6 +1,6 @@
1 1
 #############################################################################
2 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 4
 # Project:  tests.pro
5 5
 # Template: app
6 6
 # Command: /usr/bin/qmake -o Makefile tests.pro
@@ -10,13 +10,13 @@
10 10
 
11 11
 CC            = gcc
12 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 14
 CFLAGS        = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
15 15
 CXXFLAGS      = -m64 -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
16 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 17
 LINK          = g++
18 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 20
 AR            = ar cqs
21 21
 RANLIB        = 
22 22
 QMAKE         = /usr/bin/qmake
@@ -44,10 +44,14 @@ OBJECTS_DIR   = ./
44 44
 ####### Files
45 45
 
46 46
 SOURCES       = main.cpp \
47
-		test.cpp moc_test.cpp
47
+		test.cpp \
48
+		bctest.cpp moc_test.cpp \
49
+		moc_bctest.cpp
48 50
 OBJECTS       = main.o \
49 51
 		test.o \
50
-		moc_test.o
52
+		bctest.o \
53
+		moc_test.o \
54
+		moc_bctest.o
51 55
 DIST          = /usr/share/qt4/mkspecs/common/unix.conf \
52 56
 		/usr/share/qt4/mkspecs/common/linux.conf \
53 57
 		/usr/share/qt4/mkspecs/common/gcc-base.conf \
@@ -169,7 +173,7 @@ qmake:  FORCE
169 173
 
170 174
 dist: 
171 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 179
 clean:compiler_clean 
@@ -190,15 +194,21 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean
190 194
 
191 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 198
 compiler_moc_header_clean:
195
-	-$(DEL_FILE) moc_test.cpp
199
+	-$(DEL_FILE) moc_test.cpp moc_bctest.cpp
196 200
 moc_test.cpp: ../ptsocket/ptserver.h \
197 201
 		../ptsocket/libptsocket_global.h \
198 202
 		../ptsocket/ptsocket.h \
199 203
 		test.h
200 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 212
 compiler_rcc_make_all:
203 213
 compiler_rcc_clean:
204 214
 compiler_image_collection_make_all: qmake_image_collection.cpp
@@ -221,7 +231,9 @@ compiler_clean: compiler_moc_header_clean
221 231
 main.o: main.cpp test.h \
222 232
 		../ptsocket/ptserver.h \
223 233
 		../ptsocket/libptsocket_global.h \
224
-		../ptsocket/ptsocket.h
234
+		../ptsocket/ptsocket.h \
235
+		bctest.h \
236
+		../ptsocket/broadcast.h
225 237
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
226 238
 
227 239
 test.o: test.cpp test.h \
@@ -230,9 +242,18 @@ test.o: test.cpp test.h \
230 242
 		../ptsocket/ptsocket.h
231 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 251
 moc_test.o: moc_test.cpp 
234 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 257
 ####### Install
237 258
 
238 259
 install:   FORCE

+ 41
- 4
tests/main.cpp Переглянути файл

@@ -1,13 +1,50 @@
1 1
 #include <QCoreApplication>
2
+#include <QStringList>
3
+#include <iostream>
2 4
 
3 5
 #include "test.h"
6
+#include "bctest.h"
4 7
 
5 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 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 49
 	return a.exec();
13 50
 }

+ 0
- 6
tests/test.cpp Переглянути файл

@@ -2,12 +2,6 @@
2 2
 
3 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 5
     m_serv = new PTServer(this);
12 6
     m_timeoutTimer.setSingleShot(true);
13 7
     connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(timedout()));

+ 2
- 3
tests/tests.pro Переглянути файл

@@ -7,8 +7,8 @@ CONFIG -= app_bundle
7 7
 CONFIG += debug
8 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 13
 win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../ptsocket/release/ -lptsocket
14 14
 else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../ptsocket/debug/ -lptsocket
@@ -16,4 +16,3 @@ else:unix:!macx: LIBS += -L$$OUT_PWD/../ptsocket/ -lptsocket
16 16
 
17 17
 INCLUDEPATH += $$PWD/../ptsocket
18 18
 DEPENDPATH += $$PWD/../ptsocket
19
-

Завантаження…
Відмінити
Зберегти