2012-01-19 06:53:51 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-07-20 02:10:44 -07:00
|
|
|
/* Copyright 2012 Mozilla Foundation and Mozilla contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-01-19 06:53:51 -08:00
|
|
|
#ifndef GonkGPSGeolocationProvider_h
|
|
|
|
#define GonkGPSGeolocationProvider_h
|
|
|
|
|
|
|
|
#include <hardware/gps.h> // for GpsInterface
|
2012-07-16 17:38:46 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2012-01-19 06:53:51 -08:00
|
|
|
#include "nsIGeolocationProvider.h"
|
2014-03-29 00:18:11 -07:00
|
|
|
#include "nsIObserver.h"
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
#include "nsIRadioInterfaceLayer.h"
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2014-04-11 07:28:01 -07:00
|
|
|
#include "nsISettingsService.h"
|
2012-01-19 06:53:51 -08:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
class nsIThread;
|
|
|
|
|
2012-10-14 23:40:51 -07:00
|
|
|
#define GONK_GPS_GEOLOCATION_PROVIDER_CID \
|
|
|
|
{ 0x48525ec5, 0x5a7f, 0x490a, { 0x92, 0x77, 0xba, 0x66, 0xe0, 0xd2, 0x2c, 0x8b } }
|
|
|
|
|
|
|
|
#define GONK_GPS_GEOLOCATION_PROVIDER_CONTRACTID \
|
|
|
|
"@mozilla.org/gonk-gps-geolocation-provider;1"
|
|
|
|
|
2012-01-19 06:53:51 -08:00
|
|
|
class GonkGPSGeolocationProvider : public nsIGeolocationProvider
|
2014-03-29 00:18:11 -07:00
|
|
|
, public nsIObserver
|
2012-10-23 00:18:11 -07:00
|
|
|
, public nsISettingsServiceCallback
|
2012-01-19 06:53:51 -08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 19:21:20 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-01-19 06:53:51 -08:00
|
|
|
NS_DECL_NSIGEOLOCATIONPROVIDER
|
2014-03-29 00:18:11 -07:00
|
|
|
NS_DECL_NSIOBSERVER
|
2012-10-23 00:18:11 -07:00
|
|
|
NS_DECL_NSISETTINGSSERVICECALLBACK
|
2012-01-19 06:53:51 -08:00
|
|
|
|
|
|
|
static already_AddRefed<GonkGPSGeolocationProvider> GetSingleton();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/* Client should use GetSingleton() to get the provider instance. */
|
|
|
|
GonkGPSGeolocationProvider();
|
|
|
|
GonkGPSGeolocationProvider(const GonkGPSGeolocationProvider &);
|
|
|
|
GonkGPSGeolocationProvider & operator = (const GonkGPSGeolocationProvider &);
|
2014-03-22 00:42:55 -07:00
|
|
|
virtual ~GonkGPSGeolocationProvider();
|
2012-01-19 06:53:51 -08:00
|
|
|
|
2012-07-16 17:38:46 -07:00
|
|
|
static void LocationCallback(GpsLocation* location);
|
|
|
|
static void StatusCallback(GpsStatus* status);
|
|
|
|
static void SvStatusCallback(GpsSvStatus* sv_info);
|
|
|
|
static void NmeaCallback(GpsUtcTime timestamp, const char* nmea, int length);
|
|
|
|
static void SetCapabilitiesCallback(uint32_t capabilities);
|
|
|
|
static void AcquireWakelockCallback();
|
|
|
|
static void ReleaseWakelockCallback();
|
|
|
|
static pthread_t CreateThreadCallback(const char* name, void (*start)(void*), void* arg);
|
|
|
|
static void RequestUtcTimeCallback();
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
static void AGPSStatusCallback(AGpsStatus* status);
|
|
|
|
static void AGPSRILSetIDCallback(uint32_t flags);
|
|
|
|
static void AGPSRILRefLocCallback(uint32_t flags);
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-07-16 17:38:46 -07:00
|
|
|
|
|
|
|
static GpsCallbacks mCallbacks;
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
static AGpsCallbacks mAGPSCallbacks;
|
|
|
|
static AGpsRilCallbacks mAGPSRILCallbacks;
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-07-16 17:38:46 -07:00
|
|
|
|
|
|
|
void Init();
|
|
|
|
void StartGPS();
|
2012-10-03 19:00:59 -07:00
|
|
|
void ShutdownGPS();
|
2014-03-22 00:42:55 -07:00
|
|
|
void InjectLocation(double latitude, double longitude, float accuracy);
|
2014-04-11 07:28:01 -07:00
|
|
|
void RequestSettingValue(char* aKey);
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
|
|
|
void SetupAGPS();
|
|
|
|
int32_t GetDataConnectionState();
|
|
|
|
void SetAGpsDataConn(nsAString& aApn);
|
2012-07-16 17:38:46 -07:00
|
|
|
void RequestDataConnection();
|
|
|
|
void ReleaseDataConnection();
|
|
|
|
void RequestSetID(uint32_t flags);
|
|
|
|
void SetReferenceLocation();
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-07-16 17:38:46 -07:00
|
|
|
|
2012-01-19 06:53:51 -08:00
|
|
|
const GpsInterface* GetGPSInterface();
|
|
|
|
|
|
|
|
static GonkGPSGeolocationProvider* sSingleton;
|
|
|
|
|
|
|
|
bool mStarted;
|
2012-07-16 17:38:46 -07:00
|
|
|
|
|
|
|
bool mSupportsScheduling;
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
bool mSupportsMSB;
|
|
|
|
bool mSupportsMSA;
|
2013-10-29 01:12:47 -07:00
|
|
|
#endif
|
2012-07-16 17:38:46 -07:00
|
|
|
bool mSupportsSingleShot;
|
|
|
|
bool mSupportsTimeInjection;
|
|
|
|
|
2012-01-19 06:53:51 -08:00
|
|
|
const GpsInterface* mGpsInterface;
|
2013-10-29 01:12:47 -07:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2012-07-16 17:38:46 -07:00
|
|
|
const AGpsInterface* mAGpsInterface;
|
|
|
|
const AGpsRilInterface* mAGpsRilInterface;
|
2013-10-29 01:12:47 -07:00
|
|
|
nsCOMPtr<nsIRadioInterface> mRadioInterface;
|
|
|
|
#endif
|
2012-01-19 06:53:51 -08:00
|
|
|
nsCOMPtr<nsIGeolocationUpdate> mLocationCallback;
|
2014-03-22 00:42:55 -07:00
|
|
|
PRTime mLastGPSDerivedLocationTime;
|
2012-07-16 17:38:46 -07:00
|
|
|
nsCOMPtr<nsIThread> mInitThread;
|
2014-03-22 00:42:55 -07:00
|
|
|
nsCOMPtr<nsIGeolocationProvider> mNetworkLocationProvider;
|
|
|
|
|
|
|
|
class NetworkLocationUpdate : public nsIGeolocationUpdate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIGEOLOCATIONUPDATE
|
|
|
|
|
|
|
|
NetworkLocationUpdate() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~NetworkLocationUpdate() {}
|
|
|
|
};
|
2012-01-19 06:53:51 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GonkGPSGeolocationProvider_h */
|