1 /* 2 * Copyright (C) 2024 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 GEOFENCE_SDK_H 16 #define GEOFENCE_SDK_H 17 18 #include "iremote_object.h" 19 #include "iremote_proxy.h" 20 #include "iremote_broker.h" 21 #include "geofence_request.h" 22 #include "constant_definition.h" 23 #include "locationhub_ipc_interface_code.h" 24 #include "ilocator_service.h" 25 #include "want_agent.h" 26 27 namespace OHOS { 28 namespace Location { 29 class GeofenceManager { 30 public: 31 static GeofenceManager* GetInstance(); 32 explicit GeofenceManager(); 33 ~GeofenceManager(); 34 35 /** 36 * @brief Add a geofence and subscribe geo fence status changed. 37 * 38 * @param request Indicates the Geofence configuration parameters. 39 * @return Returns ERRCODE_SUCCESS if the fence has been added successfully. 40 */ 41 LocationErrCode AddFenceV9(std::shared_ptr<GeofenceRequest>& request); 42 /** 43 * @brief Remove a geofence and unsubscribe geo fence status changed. 44 * 45 * @param request Indicates the Geofence configuration parameters. 46 * @return Returns ERRCODE_SUCCESS if the fence has been removed successfully. 47 */ 48 LocationErrCode RemoveFenceV9(std::shared_ptr<GeofenceRequest>& request); 49 LocationErrCode AddGnssGeofence(std::shared_ptr<GeofenceRequest>& request); 50 LocationErrCode RemoveGnssGeofence(std::shared_ptr<GeofenceRequest>& request); 51 LocationErrCode GetGeofenceSupportedCoordTypes( 52 std::vector<CoordinateSystemType>& coordinateSystemTypes); 53 void ResetGeofenceSdkProxy(const wptr<IRemoteObject> &remote); 54 private: 55 sptr<ILocatorService> GetProxy(); 56 57 sptr<ILocatorService> client_ { nullptr }; 58 sptr<IRemoteObject::DeathRecipient> recipient_ { nullptr }; 59 std::mutex mutex_; 60 bool isServerExist_ = false; 61 62 private: 63 class GeofenceManagerDeathRecipient : public IRemoteObject::DeathRecipient { 64 public: GeofenceManagerDeathRecipient(GeofenceManager & impl)65 explicit GeofenceManagerDeathRecipient(GeofenceManager &impl) : impl_(impl) {} 66 ~GeofenceManagerDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)67 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 68 { 69 impl_.ResetGeofenceSdkProxy(remote); 70 } 71 private: 72 GeofenceManager &impl_; 73 }; 74 }; 75 } // namespace Location 76 } // namespace OHOS 77 #endif // GEOFENCE_SDK_H