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