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

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

Issue 6597044: Revert 76228 - Move core pieces of geolocation from chrome to content.This is... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 9 months 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
OLDNEW
(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 wrapper around the C libgps API (gps.h). Similar to the libgpsmm.h
6 // API provided by that package, but adds:
7 // - shared object dynamic loading
8 // - support for (and abstraction from) different libgps.so versions
9 // - configurable for testing
10 // - more convenient error handling.
11
12 #ifndef CONTENT_BROWSER_GEOLOCATION_LIBGPS_WRAPPER_LINUX_H_
13 #define CONTENT_BROWSER_GEOLOCATION_LIBGPS_WRAPPER_LINUX_H_
14 #pragma once
15
16 #include <string>
17
18 #include "base/scoped_ptr.h"
19 #include "base/time.h"
20
21 struct Geoposition;
22 class LibGpsLibraryWrapper;
23
24 class LibGps {
25 public:
26 virtual ~LibGps();
27 // Attempts to dynamically load the libgps.so library, and creates and
28 // appropriate LibGps instance for the version loaded. Returns NULL on
29 // failure.
30 static LibGps* New();
31
32 bool Start();
33 void Stop();
34 bool Poll();
35 bool GetPosition(Geoposition* position);
36
37 protected:
38 // Takes ownership of |dl_wrapper|.
39 explicit LibGps(LibGpsLibraryWrapper* dl_wrapper);
40
41 LibGpsLibraryWrapper& library() {
42 return *library_;
43 }
44 // Called be start Start after successful |gps_open| to setup streaming.
45 virtual bool StartStreaming() = 0;
46 virtual bool DataWaiting() = 0;
47 // Returns false if there is not fix available.
48 virtual bool GetPositionIfFixed(Geoposition* position) = 0;
49
50 private:
51 // Factory functions to create instances of LibGps using the corresponding
52 // libgps API versions (v2.38 => libgps.so.17, v2.94 => libgps.so.19).
53 // See LibGps::New() for the public API to this.
54 // Takes ownership of |dl_wrapper|.
55 static LibGps* NewV238(LibGpsLibraryWrapper* dl_wrapper);
56 static LibGps* NewV294(LibGpsLibraryWrapper* dl_wrapper);
57
58 scoped_ptr<LibGpsLibraryWrapper> library_;
59 std::string last_error_;
60
61 DISALLOW_COPY_AND_ASSIGN(LibGps);
62 };
63
64 struct gps_data_t;
65
66 // Wraps the low-level shared object, binding C++ member functions onto the
67 // underlying C functions obtained from the library.
68 class LibGpsLibraryWrapper {
69 public:
70 typedef gps_data_t* (*gps_open_fn)(const char*, const char*);
71 typedef int (*gps_close_fn)(gps_data_t*);
72 typedef int (*gps_poll_fn)(gps_data_t*);
73 // v2.34 only
74 typedef int (*gps_query_fn)(gps_data_t*, const char*, ...);
75 // v2.90+
76 typedef int (*gps_stream_fn)(gps_data_t*, unsigned int, void*);
77 typedef bool (*gps_waiting_fn)(gps_data_t*);
78
79 LibGpsLibraryWrapper(void* dl_handle,
80 gps_open_fn gps_open,
81 gps_close_fn gps_close,
82 gps_poll_fn gps_poll,
83 gps_query_fn gps_query,
84 gps_stream_fn gps_stream,
85 gps_waiting_fn gps_waiting);
86 ~LibGpsLibraryWrapper();
87
88 // Analogs of gps_xxx methods in gps.h
89 bool open(const char* host, const char* port);
90 void close();
91 int poll();
92 int query(const char* fmt);
93 int stream(int flags);
94 bool waiting();
95 const gps_data_t& data() const;
96 bool is_open() const;
97
98 private:
99 void* dl_handle_;
100 gps_open_fn gps_open_;
101 gps_close_fn gps_close_;
102 gps_poll_fn gps_poll_;
103 gps_query_fn gps_query_;
104 gps_stream_fn gps_stream_;
105 gps_waiting_fn gps_waiting_;
106
107 gps_data_t* gps_data_;
108
109 DISALLOW_COPY_AND_ASSIGN(LibGpsLibraryWrapper);
110 };
111
112 #endif // CONTENT_BROWSER_GEOLOCATION_LIBGPS_WRAPPER_LINUX_H_
OLDNEW
« no previous file with comments | « content/browser/geolocation/libgps_2_94_wrapper_linux.cc ('k') | content/browser/geolocation/libgps_wrapper_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698