1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef LOCATOR_AGENT_H 16 #define LOCATOR_AGENT_H 17 18 #include "request_config.h" 19 #include "i_locator_callback.h" 20 #include "constant_definition.h" 21 22 #include <singleton.h> 23 #include "iremote_object.h" 24 #include "iremote_proxy.h" 25 #include "iremote_broker.h" 26 #include "ilocator_service.h" 27 28 #include "native_location_callback_host.h" 29 #include "native_sv_callback_host.h" 30 #include "native_nmea_callback_host.h" 31 32 namespace OHOS { 33 namespace Location { 34 class LocatorAgentManager { 35 public: 36 static LocatorAgentManager* GetInstance(); 37 explicit LocatorAgentManager(); 38 ~LocatorAgentManager(); 39 40 /** 41 * @brief Subscribe location changed. 42 * 43 * @param callback Indicates the callback for reporting the location result. 44 */ 45 LocationErrCode StartGnssLocating(const LocationCallbackIfaces& callback); 46 47 /** 48 * @brief Subscribe satellite status changed. 49 * 50 * @param callback Indicates the callback for reporting the satellite status. 51 */ 52 LocationErrCode RegisterGnssStatusCallback(const SvStatusCallbackIfaces& callback); 53 54 /** 55 * @brief Subscribe nmea message changed. 56 * 57 * @param callback Indicates the callback for reporting the nmea message. 58 */ 59 LocationErrCode RegisterNmeaMessageCallback(const GnssNmeaCallbackIfaces& callback); 60 61 /** 62 * @brief Unsubscribe location changed. 63 */ 64 LocationErrCode StopGnssLocating(); 65 66 /** 67 * @brief Unsubscribe nmea message changed. 68 */ 69 LocationErrCode UnregisterNmeaMessageCallback(); 70 71 /** 72 * @brief Unsubscribe satellite status changed. 73 */ 74 LocationErrCode UnregisterGnssStatusCallback(); 75 void ResetLocatorAgent(const wptr<IRemoteObject> &remote); 76 private: 77 class LocatorAgentDeathRecipient : public IRemoteObject::DeathRecipient { 78 public: LocatorAgentDeathRecipient(LocatorAgentManager & impl)79 explicit LocatorAgentDeathRecipient(LocatorAgentManager &impl) : impl_(impl) {} 80 ~LocatorAgentDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)81 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 82 { 83 impl_.ResetLocatorAgent(remote); 84 } 85 private: 86 LocatorAgentManager &impl_; 87 }; 88 89 sptr<ILocatorService> GetLocatorAgent(); 90 sptr<IRemoteObject> CheckLocatorSystemAbilityLoaded(); 91 bool TryLoadLocatorSystemAbility(); 92 sptr<ILocatorService> InitLocatorAgent(sptr<IRemoteObject>& saObject); 93 94 sptr<ILocatorService> client_ { nullptr }; 95 sptr<IRemoteObject::DeathRecipient> recipient_ { nullptr }; 96 std::mutex mutex_; 97 sptr<NativeLocationCallbackHost> locationCallbackHost_; 98 sptr<NativeNmeaCallbackHost> nmeaCallbackHost_; 99 sptr<NativeSvCallbackHost> gnssCallbackHost_; 100 }; 101 } // namespace Location 102 } // namespace OHOS 103 #endif // LOCATOR_AGENT_H