Changeset 1348 in ntrip
- Timestamp:
- Dec 27, 2008, 1:09:16 PM (16 years ago)
- Location:
- trunk/BNC
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncgetthread.cpp
r1346 r1348 310 310 // ----------------- 311 311 QString msg; 312 _socket = bncSocket::request(_mountPoint, _latitude, _longitude, 313 _nmea, _timeOut, msg); 314 if (!_socket) { 312 delete _socket; 313 _socket = new bncSocket; 314 if (_socket->request(_mountPoint, _latitude, _longitude, 315 _nmea, _timeOut, msg) != success) { 316 delete _socket; 317 _socket = 0; 315 318 return failure; 316 319 } … … 900 903 } 901 904 while (1) { 902 delete _socket; _socket = 0;903 905 sleep(_nextSleep); 904 906 if ( initRun() == success ) { -
trunk/BNC/bncrinex.cpp
r1346 r1348 157 157 QByteArray _longitude; 158 158 QByteArray _nmea; 159 bncSocket* socket = bncSocket::request(url, _latitude, _longitude, _nmea, timeOut, msg); 160 161 if (socket) { 162 _headerLines.clear(); 163 bool firstLineRead = false; 164 while (true) { 165 if (socket->canReadLine()) { 166 QString line = socket->readLine(); 167 line.chop(1); 168 if (line.indexOf("MARKER NAME") != -1) { 169 irc = success; 170 } 171 if (line.indexOf("RINEX VERSION") != -1) { 172 if (_rinexVers == 3) { 173 _headerLines.append(" 3.00 OBSERVATION DATA" 174 " M (MIXED)" 175 " RINEX VERSION / TYPE"); 176 } 177 else { 178 _headerLines.append(" 2.11 OBSERVATION DATA" 179 " M (MIXED)" 180 " RINEX VERSION / TYPE"); 181 } 182 _headerLines.append("PGM / RUN BY / DATE"); 183 firstLineRead = true; 184 } 185 else if (firstLineRead) { 186 if (line.indexOf("END OF HEADER") != -1) { 187 _headerLines.append("# / TYPES OF OBSERV"); 188 if (_rinexVers == 2) { 189 _headerLines.append( 190 QString(" 1 1").leftJustified(60, ' ', true) + 191 "WAVELENGTH FACT L1/2"); 192 } 193 _headerLines.append("TIME OF FIRST OBS"); 194 _headerLines.append( line ); 195 break; 196 } 197 else { 198 _headerLines.append( line ); 199 } 200 } 201 } 202 else { 203 socket->waitForReadyRead(timeOut); 204 if (socket->bytesAvailable() > 0) { 205 continue; 159 bncSocket* socket = new bncSocket(); 160 if (socket->request(url, _latitude, _longitude, 161 _nmea, timeOut, msg) != success) { 162 delete socket; 163 return failure; 164 } 165 166 _headerLines.clear(); 167 bool firstLineRead = false; 168 while (true) { 169 if (socket->canReadLine()) { 170 QString line = socket->readLine(); 171 line.chop(1); 172 if (line.indexOf("MARKER NAME") != -1) { 173 irc = success; 174 } 175 if (line.indexOf("RINEX VERSION") != -1) { 176 if (_rinexVers == 3) { 177 _headerLines.append(" 3.00 OBSERVATION DATA" 178 " M (MIXED)" 179 " RINEX VERSION / TYPE"); 206 180 } 207 181 else { 182 _headerLines.append(" 2.11 OBSERVATION DATA" 183 " M (MIXED)" 184 " RINEX VERSION / TYPE"); 185 } 186 _headerLines.append("PGM / RUN BY / DATE"); 187 firstLineRead = true; 188 } 189 else if (firstLineRead) { 190 if (line.indexOf("END OF HEADER") != -1) { 191 _headerLines.append("# / TYPES OF OBSERV"); 192 if (_rinexVers == 2) { 193 _headerLines.append( 194 QString(" 1 1").leftJustified(60, ' ', true) + 195 "WAVELENGTH FACT L1/2"); 196 } 197 _headerLines.append("TIME OF FIRST OBS"); 198 _headerLines.append( line ); 208 199 break; 209 200 } 210 } 211 } 212 delete socket; 201 else { 202 _headerLines.append( line ); 203 } 204 } 205 } 206 else { 207 socket->waitForReadyRead(timeOut); 208 if (socket->bytesAvailable() > 0) { 209 continue; 210 } 211 else { 212 break; 213 } 214 } 213 215 } 214 216 } -
trunk/BNC/bncsocket.cpp
r1346 r1348 26 26 // Constructor 27 27 //////////////////////////////////////////////////////////////////////////// 28 bncSocket::bncSocket( QTcpSocket* socket) {29 _socket = socket;28 bncSocket::bncSocket() { 29 _socket = 0; 30 30 } 31 31 … … 33 33 //////////////////////////////////////////////////////////////////////////// 34 34 bncSocket::~bncSocket() { 35 delete _socket; 35 36 } 36 37 … … 39 40 void bncSocket::connectToHost(const QString &hostName, quint16 port, 40 41 QIODevice::OpenMode mode) { 41 _socket->connectToHost(hostName, port, mode); 42 if (_socket) { 43 _socket->connectToHost(hostName, port, mode); 44 } 42 45 } 43 46 … … 45 48 //////////////////////////////////////////////////////////////////////////// 46 49 bool bncSocket::waitForConnected(int msecs) { 47 return _socket->waitForConnected(msecs); 50 if (_socket) { 51 return _socket->waitForConnected(msecs); 52 } 53 else { 54 return false; 55 } 48 56 } 49 57 … … 51 59 //////////////////////////////////////////////////////////////////////////// 52 60 QAbstractSocket::SocketState bncSocket::state() const { 53 return _socket->state(); 61 if (_socket) { 62 return _socket->state(); 63 } 64 else { 65 return QAbstractSocket::UnconnectedState; 66 } 54 67 } 55 68 … … 57 70 //////////////////////////////////////////////////////////////////////////// 58 71 void bncSocket::close() { 59 _socket->close(); 72 if (_socket) { 73 _socket->close(); 74 } 60 75 } 61 76 … … 63 78 //////////////////////////////////////////////////////////////////////////// 64 79 qint64 bncSocket::bytesAvailable() const { 65 return _socket->bytesAvailable(); 80 if (_socket) { 81 return _socket->bytesAvailable(); 82 } 83 else { 84 return 0; 85 } 66 86 } 67 87 … … 69 89 //////////////////////////////////////////////////////////////////////////// 70 90 bool bncSocket::canReadLine() const { 71 return _socket->canReadLine(); 91 if (_socket) { 92 return _socket->canReadLine(); 93 } 94 else { 95 return false; 96 } 72 97 } 73 98 … … 75 100 //////////////////////////////////////////////////////////////////////////// 76 101 QByteArray bncSocket::readLine(qint64 maxlen) { 77 return _socket->readLine(maxlen); 102 if (_socket) { 103 return _socket->readLine(maxlen); 104 } 105 else { 106 return ""; 107 } 78 108 } 79 109 … … 81 111 //////////////////////////////////////////////////////////////////////////// 82 112 bool bncSocket::waitForReadyRead(int msecs) { 83 return _socket->waitForReadyRead(msecs); 113 if (_socket) { 114 return _socket->waitForReadyRead(msecs); 115 } 116 else { 117 return false; 118 } 84 119 } 85 120 … … 87 122 //////////////////////////////////////////////////////////////////////////// 88 123 qint64 bncSocket::read(char* data, qint64 maxlen) { 89 return _socket->read(data, maxlen); 124 if (_socket) { 125 return _socket->read(data, maxlen); 126 } 127 else { 128 return -1; 129 } 90 130 } 91 131 … … 93 133 //////////////////////////////////////////////////////////////////////////// 94 134 qint64 bncSocket::write(const char* data, qint64 len) { 95 return _socket->write(data, len); 135 if (_socket) { 136 return _socket->write(data, len); 137 } 138 else { 139 return -1; 140 } 96 141 } 97 142 … … 99 144 //////////////////////////////////////////////////////////////////////////// 100 145 bool bncSocket::waitForBytesWritten(int msecs) { 101 return _socket->waitForBytesWritten(msecs); 146 if (_socket) { 147 return _socket->waitForBytesWritten(msecs); 148 } 149 else { 150 return false; 151 } 102 152 } 103 153 104 154 // Connect to Caster, send the Request (static) 105 155 //////////////////////////////////////////////////////////////////////////// 106 bncSocket* bncSocket::request(const QUrl& mountPoint, 107 QByteArray& latitude, QByteArray& longitude, 108 QByteArray& nmea, int timeOut, 109 QString& msg) { 156 t_irc bncSocket::request(const QUrl& mountPoint, const QByteArray& latitude, 157 const QByteArray& longitude, const QByteArray& nmea, 158 int timeOut, QString& msg) { 159 160 delete _socket; 161 _socket = new QTcpSocket(); 110 162 111 163 // Connect the Socket … … 115 167 int proxyPort = settings.value("proxyPort").toInt(); 116 168 117 bncSocket* socket = new bncSocket(new QTcpSocket());118 169 if ( proxyHost.isEmpty() ) { 119 socket->connectToHost(mountPoint.host(), mountPoint.port());120 } 121 else { 122 socket->connectToHost(proxyHost, proxyPort);123 } 124 if (! socket->waitForConnected(timeOut)) {170 _socket->connectToHost(mountPoint.host(), mountPoint.port()); 171 } 172 else { 173 _socket->connectToHost(proxyHost, proxyPort); 174 } 175 if (!_socket->waitForConnected(timeOut)) { 125 176 msg += "Connect timeout\n"; 126 delete socket; 127 return 0; 177 delete _socket; 178 _socket = 0; 179 return failure; 128 180 } 129 181 … … 205 257 msg += reqStr; 206 258 207 socket->write(reqStr, reqStr.length());208 209 if (! socket->waitForBytesWritten(timeOut)) {259 _socket->write(reqStr, reqStr.length()); 260 261 if (!_socket->waitForBytesWritten(timeOut)) { 210 262 msg += "Write timeout\n"; 211 delete socket; 212 return 0; 213 } 214 215 return socket; 216 } 217 263 delete _socket; 264 _socket = 0; 265 return failure; 266 } 267 268 return success; 269 } 270
Note:
See TracChangeset
for help on using the changeset viewer.