| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Defines a variant of libgps wrapper for use with the 2.38 release of the API. | |
| 6 | |
| 7 #include "content/browser/geolocation/libgps_wrapper_linux.h" | |
| 8 | |
| 9 // This lot needed for DataWaiting() | |
| 10 #include <sys/socket.h> | |
| 11 #include <sys/time.h> | |
| 12 | |
| 13 #include "base/logging.h" | |
| 14 #include "chrome/common/geoposition.h" | |
| 15 #include "third_party/gpsd/release-2.38/gps.h" | |
| 16 | |
| 17 class LibGpsV238 : public LibGps { | |
| 18 public: | |
| 19 explicit LibGpsV238(LibGpsLibraryWrapper* dl_wrapper) : LibGps(dl_wrapper) {} | |
| 20 | |
| 21 // LibGps | |
| 22 virtual bool StartStreaming() { | |
| 23 return library().query("w+x\n") == 0; | |
| 24 } | |
| 25 virtual bool DataWaiting() { | |
| 26 // Unfortunately the 2.38 API has no public method for non-blocking test | |
| 27 // for new data arrived, so we must contrive our own by doing a select() on | |
| 28 // the underlying struct's socket fd. | |
| 29 fd_set fds; | |
| 30 struct timeval timeout = {0}; | |
| 31 int fd = library().data().gps_fd; | |
| 32 | |
| 33 FD_ZERO(&fds); | |
| 34 FD_SET(fd, &fds); | |
| 35 | |
| 36 int ret = select(fd + 1, &fds, NULL, NULL, &timeout); | |
| 37 if (ret == -1) { | |
| 38 LOG(WARNING) << "libgps socket select failed: " << ret; | |
| 39 return false; | |
| 40 } | |
| 41 DCHECK_EQ(!!ret, !!FD_ISSET(fd, &fds)); | |
| 42 return ret; | |
| 43 } | |
| 44 virtual bool GetPositionIfFixed(Geoposition* position) { | |
| 45 // This function is duplicated between the library versions, however it | |
| 46 // cannot be shared as each one must be strictly compiled against the | |
| 47 // corresponding version of gps.h. | |
| 48 DCHECK(position); | |
| 49 const gps_data_t& gps_data = library().data(); | |
| 50 if (gps_data.status == STATUS_NO_FIX) | |
| 51 return false; | |
| 52 position->latitude = gps_data.fix.latitude; | |
| 53 position->longitude = gps_data.fix.longitude; | |
| 54 position->accuracy = gps_data.fix.eph; | |
| 55 position->altitude = gps_data.fix.altitude; | |
| 56 position->altitude_accuracy = gps_data.fix.epv; | |
| 57 position->heading = gps_data.fix.track; | |
| 58 position->speed = gps_data.fix.speed; | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 private: | |
| 63 DISALLOW_COPY_AND_ASSIGN(LibGpsV238); | |
| 64 }; | |
| 65 | |
| 66 LibGps* LibGps::NewV238(LibGpsLibraryWrapper* dl_wrapper) { | |
| 67 return new LibGpsV238(dl_wrapper); | |
| 68 } | |
| OLD | NEW |