OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/geolocation/libgps_wrapper_linux.h" | 5 #include "content/browser/geolocation/libgps_wrapper_linux.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
9 #include <errno.h> | 9 #include <errno.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "content/common/geoposition.h" | 13 #include "content/public/common/geoposition.h" |
14 #include "third_party/gpsd/release-3.1/gps.h" | 14 #include "third_party/gpsd/release-3.1/gps.h" |
15 | 15 |
16 COMPILE_ASSERT(GPSD_API_MAJOR_VERSION == 5, GPSD_API_version_is_not_5); | 16 COMPILE_ASSERT(GPSD_API_MAJOR_VERSION == 5, GPSD_API_version_is_not_5); |
17 | 17 |
18 namespace { | 18 namespace { |
19 const char kLibGpsName[] = "libgps.so.20"; | 19 const char kLibGpsName[] = "libgps.so.20"; |
20 } // namespace | 20 } // namespace |
21 | 21 |
22 LibGps::LibGps(void* dl_handle, | 22 LibGps::LibGps(void* dl_handle, |
23 gps_open_fn gps_open, | 23 gps_open_fn gps_open, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 is_open_ = true; | 90 is_open_ = true; |
91 return true; | 91 return true; |
92 } | 92 } |
93 void LibGps::Stop() { | 93 void LibGps::Stop() { |
94 if (is_open_) | 94 if (is_open_) |
95 gps_close_(gps_data_.get()); | 95 gps_close_(gps_data_.get()); |
96 is_open_ = false; | 96 is_open_ = false; |
97 } | 97 } |
98 | 98 |
99 bool LibGps::Read(Geoposition* position) { | 99 bool LibGps::Read(content::Geoposition* position) { |
100 DCHECK(position); | 100 DCHECK(position); |
101 position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 101 position->error_code = content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
102 if (!is_open_) { | 102 if (!is_open_) { |
103 DLOG(WARNING) << "No gpsd connection"; | 103 DLOG(WARNING) << "No gpsd connection"; |
104 position->error_message = "No gpsd connection"; | 104 position->error_message = "No gpsd connection"; |
105 return false; | 105 return false; |
106 } | 106 } |
107 | 107 |
108 if (gps_read_(gps_data_.get()) < 0) { | 108 if (gps_read_(gps_data_.get()) < 0) { |
109 DLOG(WARNING) << "gps_read() fails"; | 109 DLOG(WARNING) << "gps_read() fails"; |
110 position->error_message = "gps_read() fails"; | 110 position->error_message = "gps_read() fails"; |
111 return false; | 111 return false; |
112 } | 112 } |
113 | 113 |
114 if (!GetPositionIfFixed(position)) { | 114 if (!GetPositionIfFixed(position)) { |
115 DLOG(WARNING) << "No fixed position"; | 115 DLOG(WARNING) << "No fixed position"; |
116 position->error_message = "No fixed position"; | 116 position->error_message = "No fixed position"; |
117 return false; | 117 return false; |
118 } | 118 } |
119 | 119 |
120 position->error_code = Geoposition::ERROR_CODE_NONE; | 120 position->error_code = content::Geoposition::ERROR_CODE_NONE; |
121 position->timestamp = base::Time::Now(); | 121 position->timestamp = base::Time::Now(); |
122 if (!position->IsValidFix()) { | 122 if (!position->Validate()) { |
123 // GetPositionIfFixed returned true, yet we've not got a valid fix. | 123 // GetPositionIfFixed returned true, yet we've not got a valid fix. |
124 // This shouldn't happen; something went wrong in the conversion. | 124 // This shouldn't happen; something went wrong in the conversion. |
125 NOTREACHED() << "Invalid position from GetPositionIfFixed: lat,long " | 125 NOTREACHED() << "Invalid position from GetPositionIfFixed: lat,long " |
126 << position->latitude << "," << position->longitude | 126 << position->latitude << "," << position->longitude |
127 << " accuracy " << position->accuracy << " time " | 127 << " accuracy " << position->accuracy << " time " |
128 << position->timestamp.ToDoubleT(); | 128 << position->timestamp.ToDoubleT(); |
129 position->error_code = Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | 129 position->error_code = |
| 130 content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; |
130 position->error_message = "Bad fix from gps"; | 131 position->error_message = "Bad fix from gps"; |
131 return false; | 132 return false; |
132 } | 133 } |
133 return true; | 134 return true; |
134 } | 135 } |
135 | 136 |
136 bool LibGps::GetPositionIfFixed(Geoposition* position) { | 137 bool LibGps::GetPositionIfFixed(content::Geoposition* position) { |
137 DCHECK(position); | 138 DCHECK(position); |
138 if (gps_data_->status == STATUS_NO_FIX) { | 139 if (gps_data_->status == STATUS_NO_FIX) { |
139 DVLOG(2) << "Status_NO_FIX"; | 140 DVLOG(2) << "Status_NO_FIX"; |
140 return false; | 141 return false; |
141 } | 142 } |
142 | 143 |
143 if (isnan(gps_data_->fix.latitude) || isnan(gps_data_->fix.longitude)) { | 144 if (isnan(gps_data_->fix.latitude) || isnan(gps_data_->fix.longitude)) { |
144 DVLOG(2) << "No valid lat/lon value"; | 145 DVLOG(2) << "No valid lat/lon value"; |
145 return false; | 146 return false; |
146 } | 147 } |
(...skipping 18 matching lines...) Expand all Loading... |
165 if (!isnan(gps_data_->fix.epv)) | 166 if (!isnan(gps_data_->fix.epv)) |
166 position->altitude_accuracy = gps_data_->fix.epv; | 167 position->altitude_accuracy = gps_data_->fix.epv; |
167 } | 168 } |
168 | 169 |
169 if (!isnan(gps_data_->fix.track)) | 170 if (!isnan(gps_data_->fix.track)) |
170 position->heading = gps_data_->fix.track; | 171 position->heading = gps_data_->fix.track; |
171 if (!isnan(gps_data_->fix.speed)) | 172 if (!isnan(gps_data_->fix.speed)) |
172 position->speed = gps_data_->fix.speed; | 173 position->speed = gps_data_->fix.speed; |
173 return true; | 174 return true; |
174 } | 175 } |
OLD | NEW |