|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* Copyright 2012 Mozilla Foundation and Mozilla contributors |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 #ifndef GonkGPSGeolocationProvider_h |
|
18 #define GonkGPSGeolocationProvider_h |
|
19 |
|
20 #include <hardware/gps.h> // for GpsInterface |
|
21 #include "nsCOMPtr.h" |
|
22 #include "nsIGeolocationProvider.h" |
|
23 #include "nsIObserver.h" |
|
24 #ifdef MOZ_B2G_RIL |
|
25 #include "nsIRadioInterfaceLayer.h" |
|
26 #endif |
|
27 #include "nsISettingsService.h" |
|
28 |
|
29 class nsIThread; |
|
30 |
|
31 #define GONK_GPS_GEOLOCATION_PROVIDER_CID \ |
|
32 { 0x48525ec5, 0x5a7f, 0x490a, { 0x92, 0x77, 0xba, 0x66, 0xe0, 0xd2, 0x2c, 0x8b } } |
|
33 |
|
34 #define GONK_GPS_GEOLOCATION_PROVIDER_CONTRACTID \ |
|
35 "@mozilla.org/gonk-gps-geolocation-provider;1" |
|
36 |
|
37 class GonkGPSGeolocationProvider : public nsIGeolocationProvider |
|
38 , public nsIObserver |
|
39 , public nsISettingsServiceCallback |
|
40 { |
|
41 public: |
|
42 NS_DECL_THREADSAFE_ISUPPORTS |
|
43 NS_DECL_NSIGEOLOCATIONPROVIDER |
|
44 NS_DECL_NSIOBSERVER |
|
45 NS_DECL_NSISETTINGSSERVICECALLBACK |
|
46 |
|
47 static already_AddRefed<GonkGPSGeolocationProvider> GetSingleton(); |
|
48 |
|
49 private: |
|
50 |
|
51 /* Client should use GetSingleton() to get the provider instance. */ |
|
52 GonkGPSGeolocationProvider(); |
|
53 GonkGPSGeolocationProvider(const GonkGPSGeolocationProvider &); |
|
54 GonkGPSGeolocationProvider & operator = (const GonkGPSGeolocationProvider &); |
|
55 virtual ~GonkGPSGeolocationProvider(); |
|
56 |
|
57 static void LocationCallback(GpsLocation* location); |
|
58 static void StatusCallback(GpsStatus* status); |
|
59 static void SvStatusCallback(GpsSvStatus* sv_info); |
|
60 static void NmeaCallback(GpsUtcTime timestamp, const char* nmea, int length); |
|
61 static void SetCapabilitiesCallback(uint32_t capabilities); |
|
62 static void AcquireWakelockCallback(); |
|
63 static void ReleaseWakelockCallback(); |
|
64 static pthread_t CreateThreadCallback(const char* name, void (*start)(void*), void* arg); |
|
65 static void RequestUtcTimeCallback(); |
|
66 #ifdef MOZ_B2G_RIL |
|
67 static void AGPSStatusCallback(AGpsStatus* status); |
|
68 static void AGPSRILSetIDCallback(uint32_t flags); |
|
69 static void AGPSRILRefLocCallback(uint32_t flags); |
|
70 #endif |
|
71 |
|
72 static GpsCallbacks mCallbacks; |
|
73 #ifdef MOZ_B2G_RIL |
|
74 static AGpsCallbacks mAGPSCallbacks; |
|
75 static AGpsRilCallbacks mAGPSRILCallbacks; |
|
76 #endif |
|
77 |
|
78 void Init(); |
|
79 void StartGPS(); |
|
80 void ShutdownGPS(); |
|
81 void InjectLocation(double latitude, double longitude, float accuracy); |
|
82 void RequestSettingValue(char* aKey); |
|
83 #ifdef MOZ_B2G_RIL |
|
84 void SetupAGPS(); |
|
85 int32_t GetDataConnectionState(); |
|
86 void SetAGpsDataConn(nsAString& aApn); |
|
87 void RequestDataConnection(); |
|
88 void ReleaseDataConnection(); |
|
89 void RequestSetID(uint32_t flags); |
|
90 void SetReferenceLocation(); |
|
91 #endif |
|
92 |
|
93 const GpsInterface* GetGPSInterface(); |
|
94 |
|
95 static GonkGPSGeolocationProvider* sSingleton; |
|
96 |
|
97 bool mStarted; |
|
98 |
|
99 bool mSupportsScheduling; |
|
100 #ifdef MOZ_B2G_RIL |
|
101 bool mSupportsMSB; |
|
102 bool mSupportsMSA; |
|
103 #endif |
|
104 bool mSupportsSingleShot; |
|
105 bool mSupportsTimeInjection; |
|
106 |
|
107 const GpsInterface* mGpsInterface; |
|
108 #ifdef MOZ_B2G_RIL |
|
109 const AGpsInterface* mAGpsInterface; |
|
110 const AGpsRilInterface* mAGpsRilInterface; |
|
111 nsCOMPtr<nsIRadioInterface> mRadioInterface; |
|
112 #endif |
|
113 nsCOMPtr<nsIGeolocationUpdate> mLocationCallback; |
|
114 PRTime mLastGPSDerivedLocationTime; |
|
115 nsCOMPtr<nsIThread> mInitThread; |
|
116 nsCOMPtr<nsIGeolocationProvider> mNetworkLocationProvider; |
|
117 |
|
118 class NetworkLocationUpdate : public nsIGeolocationUpdate |
|
119 { |
|
120 public: |
|
121 NS_DECL_ISUPPORTS |
|
122 NS_DECL_NSIGEOLOCATIONUPDATE |
|
123 |
|
124 NetworkLocationUpdate() {} |
|
125 |
|
126 private: |
|
127 virtual ~NetworkLocationUpdate() {} |
|
128 }; |
|
129 }; |
|
130 |
|
131 #endif /* GonkGPSGeolocationProvider_h */ |