Changeset 25791 in osm for applications/editors/josm
- Timestamp:
- 2011-04-04T21:43:54+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java
r23191 r25791 121 121 while (!shutdownFlag) { 122 122 123 try{124 if (!connected) 123 while (!connected) { 124 try { 125 125 connect(); 126 127 if (connected) { 126 } catch (IOException iox) { 127 fireGpsStatusChangeEvent( LiveGpsStatus.GpsStatus.CONNECTION_FAILED, tr("Connection Failed")); 128 try { 129 Thread.sleep(1000); 130 } catch (InterruptedException ignore) {} 131 }; 132 } 133 134 assert (connected); 135 136 try { 128 137 String line; 129 138 … … 134 143 // </FIXXME> 135 144 if (line == null) 136 break;145 throw new IOException(); 137 146 138 147 if (JSONProtocol == true) … … 146 155 fireGpsDataChangeEvent(oldGpsData, gpsData); 147 156 oldGpsData = gpsData; 148 } else {149 fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.DISCONNECTED, tr("Not connected"));150 try {151 Thread.sleep(1000);152 } catch (InterruptedException ignore) {}153 }154 157 } catch (IOException iox) { 155 connected = false; 156 if (gpsData != null) { 157 gpsData.setFix(false); 158 fireGpsDataChangeEvent(oldGpsData, gpsData); 159 } 158 System.out.println("LiveGps: lost connection to gpsd"); 160 159 fireGpsStatusChangeEvent( 161 160 LiveGpsStatus.GpsStatus.CONNECTION_FAILED, 162 161 tr("Connection Failed")); 162 disconnect(); 163 163 try { 164 164 Thread.sleep(1000); … … 168 168 } 169 169 170 System.out.println("LiveGps: Disconnected from gpsd"); 170 171 fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.DISCONNECTED, 171 172 tr("Not connected")); 172 if (gpsdSocket != null) { 173 try { 174 gpsdSocket.close(); 175 gpsdSocket = null; 176 System.out.println("LiveGps: Disconnected from gpsd"); 177 } catch (Exception e) { 178 System.out.println("LiveGps: Unable to close socket; reconnection may not be possible"); 179 } 180 } 173 disconnect(); 181 174 } 182 175 … … 197 190 gpsdSocket = new Socket(addrs[i], gpsdPort); 198 191 break; 199 } catch ( Exception e) {192 } catch (IOException e) { 200 193 System.out.println("LiveGps: Could not open connection to gpsd: " + e); 201 194 gpsdSocket = null; … … 203 196 } 204 197 205 if (gpsdSocket == null) 206 return; 207 208 fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.CONNECTING, tr("Connecting")); 198 if (gpsdSocket == null || gpsdSocket.isConnected() == false) 199 throw new IOException(); 209 200 210 201 /* … … 248 239 fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.CONNECTED, tr("Connected")); 249 240 } 241 } 242 243 private void disconnect() { 244 assert(gpsdSocket != null); 245 246 connected = false; 247 248 try { 249 gpsdSocket.close(); 250 gpsdSocket = null; 251 } catch (Exception e) { 252 System.out.println("LiveGps: Unable to close socket; reconnection may not be possible"); 253 } 250 254 } 251 255
Note:
See TracChangeset
for help on using the changeset viewer.