Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: content/browser/geolocation/gps_location_provider_linux.h

Issue 11571036: Linux: use generated library loader for libgps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixlets Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/linux/system.gyp ('k') | content/browser/geolocation/gps_location_provider_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 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 // This file declares GPS providers that run on linux. Currently, just uses 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 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 7 // header should not be required, as location_provider.h declares the needed
8 // factory function. 8 // factory function.
9 9
10 #ifndef CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ 10 #ifndef CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_
11 #define CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ 11 #define CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_
12 12
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "content/browser/geolocation/location_provider.h" 16 #include "content/browser/geolocation/location_provider.h"
17 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
18 #include "content/public/common/geoposition.h" 18 #include "content/public/common/geoposition.h"
19 19
20 #if defined(USE_LIBGPS)
21 #include "library_loaders/libgps.h"
22 #endif
23
20 struct gps_data_t; 24 struct gps_data_t;
21 25
22 namespace content { 26 namespace content {
23 27
24 // Defines a wrapper around the C libgps API (gps.h). Similar to the libgpsmm.h 28 // Defines a wrapper around the C libgps API (gps.h). Similar to the libgpsmm.h
25 // API provided by that package. 29 // API provided by that package.
26 class CONTENT_EXPORT LibGps { 30 class CONTENT_EXPORT LibGps {
27 public: 31 public:
28 virtual ~LibGps(); 32 virtual ~LibGps();
29 // Attempts to dynamically load the libgps.so library and returns NULL on 33 // Attempts to dynamically load the libgps.so library and returns NULL on
30 // failure. 34 // failure.
31 static LibGps* New(); 35 static LibGps* New();
32 36
33 bool Start(); 37 bool Start();
34 void Stop(); 38 void Stop();
35 bool Read(content::Geoposition* position); 39 bool Read(content::Geoposition* position);
36 40
37 protected: 41 protected:
38 typedef int (*gps_open_fn)(const char*, const char*, struct gps_data_t*); 42 LibGps();
39 typedef int (*gps_close_fn)(struct gps_data_t*);
40 typedef int (*gps_read_fn)(struct gps_data_t*);
41
42 explicit LibGps(void* dl_handle,
43 gps_open_fn gps_open,
44 gps_close_fn gps_close,
45 gps_read_fn gps_read);
46 43
47 // Returns false if there is no fix available. 44 // Returns false if there is no fix available.
48 virtual bool GetPositionIfFixed(content::Geoposition* position); 45 virtual bool GetPositionIfFixed(content::Geoposition* position);
49 46
50 private:
51 #if defined(USE_LIBGPS) 47 #if defined(USE_LIBGPS)
52 void* dl_handle_; 48 LibGpsLoader libgps_loader_;
53 gps_open_fn gps_open_;
54 gps_close_fn gps_close_;
55 gps_read_fn gps_read_;
56 49
57 scoped_ptr<gps_data_t> gps_data_; 50 scoped_ptr<gps_data_t> gps_data_;
58 bool is_open_; 51 bool is_open_;
59 #endif // defined(USE_LIBGPS) 52 #endif // defined(USE_LIBGPS)
60 53
54 private:
61 DISALLOW_COPY_AND_ASSIGN(LibGps); 55 DISALLOW_COPY_AND_ASSIGN(LibGps);
62 }; 56 };
63 57
64 // Location provider for Linux, that uses libgps/gpsd to obtain position fixes. 58 // 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 59 // 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, 60 // 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 61 // there's a chance it could block, so better move this into its own worker
68 // thread. 62 // thread.
69 class CONTENT_EXPORT GpsLocationProviderLinux : public LocationProviderBase { 63 class CONTENT_EXPORT GpsLocationProviderLinux : public LocationProviderBase {
70 public: 64 public:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 scoped_ptr<LibGps> gps_; 99 scoped_ptr<LibGps> gps_;
106 Geoposition position_; 100 Geoposition position_;
107 101
108 // Holder for the tasks which run on the thread; takes care of cleanup. 102 // Holder for the tasks which run on the thread; takes care of cleanup.
109 base::WeakPtrFactory<GpsLocationProviderLinux> weak_factory_; 103 base::WeakPtrFactory<GpsLocationProviderLinux> weak_factory_;
110 }; 104 };
111 105
112 } // namespace content 106 } // namespace content
113 107
114 #endif // CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_ 108 #endif // CONTENT_BROWSER_GEOLOCATION_GPS_LOCATION_PROVIDER_LINUX_H_
OLDNEW
« no previous file with comments | « build/linux/system.gyp ('k') | content/browser/geolocation/gps_location_provider_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698