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
3 // found in the LICENSE file.
5 // This file declares GPS providers that run on linux. Currently, just uses
6 // the libgps (gpsd) API. Public for testing only - for normal usage this
7 // header should not be required, as location_provider.h declares the needed
10 #ifndef CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_
11 #define CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "content/browser/geolocation/location_provider.h"
17 #include "content/common/content_export.h"
18 #include "content/public/common/geoposition.h"
24 // Defines a wrapper around the C libgps API (gps.h). Similar to the libgpsmm.h
25 // API provided by that package.
26 class CONTENT_EXPORT LibGps
{
29 // Attempts to dynamically load the libgps.so library and returns NULL on
35 bool Read(content::Geoposition
* position
);
38 typedef int (*gps_open_fn
)(const char*, const char*, struct gps_data_t
*);
39 typedef int (*gps_close_fn
)(struct gps_data_t
*);
40 typedef int (*gps_read_fn
)(struct gps_data_t
*);
42 explicit LibGps(void* dl_handle
,
44 gps_close_fn gps_close
,
45 gps_read_fn gps_read
);
47 // Returns false if there is no fix available.
48 virtual bool GetPositionIfFixed(content::Geoposition
* position
);
51 #if defined(USE_LIBGPS)
53 gps_open_fn gps_open_
;
54 gps_close_fn gps_close_
;
55 gps_read_fn gps_read_
;
57 scoped_ptr
<gps_data_t
> gps_data_
;
59 #endif // defined(USE_LIBGPS)
61 DISALLOW_COPY_AND_ASSIGN(LibGps
);
64 // Location provider for Linux, that uses libgps/gpsd to obtain position fixes.
65 // TODO(joth): Currently this runs entirely in the client thread (i.e. Chrome's
66 // IO thread). As the older libgps API is not designed to support polling,
67 // there's a chance it could block, so better move this into its own worker
69 class CONTENT_EXPORT GpsLocationProviderLinux
: public LocationProviderBase
{
71 typedef LibGps
* (*LibGpsFactory
)();
72 // |factory| will be used to create the gpsd client library wrapper. (Note
73 // NewSystemLocationProvider() will use the default factory).
74 explicit GpsLocationProviderLinux(LibGpsFactory libgps_factory
);
75 virtual ~GpsLocationProviderLinux();
77 void SetGpsdReconnectIntervalMillis(int value
) {
78 gpsd_reconnect_interval_millis_
= value
;
80 void SetPollPeriodMovingMillis(int value
) {
81 poll_period_moving_millis_
= value
;
83 void SetPollPeriodStationaryMillis(int value
) {
84 poll_period_stationary_millis_
= value
;
88 virtual bool StartProvider(bool high_accuracy
) OVERRIDE
;
89 virtual void StopProvider() OVERRIDE
;
90 virtual void GetPosition(Geoposition
* position
) OVERRIDE
;
91 virtual void UpdatePosition() OVERRIDE
;
94 // Task which run in the child thread.
97 // Will schedule a poll; i.e. enqueue DoGpsPollTask deferred task.
98 void ScheduleNextGpsPoll(int interval
);
100 int gpsd_reconnect_interval_millis_
;
101 int poll_period_moving_millis_
;
102 int poll_period_stationary_millis_
;
104 const LibGpsFactory libgps_factory_
;
105 scoped_ptr
<LibGps
> gps_
;
106 Geoposition position_
;
108 // Holder for the tasks which run on the thread; takes care of cleanup.
109 base::WeakPtrFactory
<GpsLocationProviderLinux
> weak_factory_
;
112 } // namespace content
114 #endif // CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_