15c735df2Sopenharmony_ci/*
25c735df2Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd.
35c735df2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45c735df2Sopenharmony_ci * you may not use this file except in compliance with the License.
55c735df2Sopenharmony_ci * You may obtain a copy of the License at
65c735df2Sopenharmony_ci *
75c735df2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85c735df2Sopenharmony_ci *
95c735df2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105c735df2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115c735df2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125c735df2Sopenharmony_ci * See the License for the specific language governing permissions and
135c735df2Sopenharmony_ci * limitations under the License.
145c735df2Sopenharmony_ci */
155c735df2Sopenharmony_ci#ifndef GEOFENCE_SDK_H
165c735df2Sopenharmony_ci#define GEOFENCE_SDK_H
175c735df2Sopenharmony_ci
185c735df2Sopenharmony_ci#include "iremote_object.h"
195c735df2Sopenharmony_ci#include "iremote_proxy.h"
205c735df2Sopenharmony_ci#include "iremote_broker.h"
215c735df2Sopenharmony_ci#include "i_locator.h"
225c735df2Sopenharmony_ci#include "geofence_request.h"
235c735df2Sopenharmony_ci#include "constant_definition.h"
245c735df2Sopenharmony_ci#include "locationhub_ipc_interface_code.h"
255c735df2Sopenharmony_ci#include "constant_definition.h"
265c735df2Sopenharmony_ci
275c735df2Sopenharmony_cinamespace OHOS {
285c735df2Sopenharmony_cinamespace Location {
295c735df2Sopenharmony_ciclass GeofenceSdk : public IRemoteProxy<ILocator> {
305c735df2Sopenharmony_cipublic:
315c735df2Sopenharmony_ci    explicit GeofenceSdk(const sptr<IRemoteObject> &impl);
325c735df2Sopenharmony_ci    ~GeofenceSdk() = default;
335c735df2Sopenharmony_ci    LocationErrCode AddFenceV9(std::shared_ptr<GeofenceRequest>& request);
345c735df2Sopenharmony_ci    LocationErrCode RemoveFenceV9(std::shared_ptr<GeofenceRequest>& request);
355c735df2Sopenharmony_ci    LocationErrCode AddGnssGeofence(std::shared_ptr<GeofenceRequest>& request);
365c735df2Sopenharmony_ci    LocationErrCode RemoveGnssGeofence(std::shared_ptr<GeofenceRequest>& request);
375c735df2Sopenharmony_ci    LocationErrCode GetGeofenceSupportedCoordTypes(
385c735df2Sopenharmony_ci        std::vector<CoordinateSystemType>& coordinateSystemTypes);
395c735df2Sopenharmony_ci    LocationErrCode HandleGnssfenceRequest(LocatorInterfaceCode code,
405c735df2Sopenharmony_ci        std::shared_ptr<GeofenceRequest>& request);
415c735df2Sopenharmony_ciprivate:
425c735df2Sopenharmony_ci	LocationErrCode SendMsgWithDataReplyV9(const int msgId, MessageParcel& data, MessageParcel& reply);
435c735df2Sopenharmony_ci    static inline BrokerDelegator<GeofenceSdk> delegator_;
445c735df2Sopenharmony_ci};
455c735df2Sopenharmony_ci
465c735df2Sopenharmony_ciclass GeofenceManager {
475c735df2Sopenharmony_cipublic:
485c735df2Sopenharmony_ci    static GeofenceManager* GetInstance();
495c735df2Sopenharmony_ci    explicit GeofenceManager();
505c735df2Sopenharmony_ci    ~GeofenceManager();
515c735df2Sopenharmony_ci
525c735df2Sopenharmony_ci    /**
535c735df2Sopenharmony_ci     * @brief Add a geofence and subscribe geo fence status changed.
545c735df2Sopenharmony_ci     *
555c735df2Sopenharmony_ci     * @param request Indicates the Geofence configuration parameters.
565c735df2Sopenharmony_ci     * @return Returns ERRCODE_SUCCESS if the fence has been added successfully.
575c735df2Sopenharmony_ci     */
585c735df2Sopenharmony_ci    LocationErrCode AddFenceV9(std::shared_ptr<GeofenceRequest>& request);
595c735df2Sopenharmony_ci    /**
605c735df2Sopenharmony_ci     * @brief Remove a geofence and unsubscribe geo fence status changed.
615c735df2Sopenharmony_ci     *
625c735df2Sopenharmony_ci     * @param request Indicates the Geofence configuration parameters.
635c735df2Sopenharmony_ci     * @return Returns ERRCODE_SUCCESS if the fence has been removed successfully.
645c735df2Sopenharmony_ci     */
655c735df2Sopenharmony_ci    LocationErrCode RemoveFenceV9(std::shared_ptr<GeofenceRequest>& request);
665c735df2Sopenharmony_ci    LocationErrCode AddGnssGeofence(std::shared_ptr<GeofenceRequest>& request);
675c735df2Sopenharmony_ci    LocationErrCode RemoveGnssGeofence(std::shared_ptr<GeofenceRequest>& request);
685c735df2Sopenharmony_ci    LocationErrCode GetGeofenceSupportedCoordTypes(
695c735df2Sopenharmony_ci        std::vector<CoordinateSystemType>& coordinateSystemTypes);
705c735df2Sopenharmony_ci    void ResetGeofenceSdkProxy(const wptr<IRemoteObject> &remote);
715c735df2Sopenharmony_ciprivate:
725c735df2Sopenharmony_ci    sptr<GeofenceSdk> GetProxy();
735c735df2Sopenharmony_ci
745c735df2Sopenharmony_ci    sptr<GeofenceSdk> client_ { nullptr };
755c735df2Sopenharmony_ci    sptr<IRemoteObject::DeathRecipient> recipient_ { nullptr };
765c735df2Sopenharmony_ci    std::mutex mutex_;
775c735df2Sopenharmony_ci    bool isServerExist_ = false;
785c735df2Sopenharmony_ci
795c735df2Sopenharmony_ciprivate:
805c735df2Sopenharmony_ci    class GeofenceManagerDeathRecipient : public IRemoteObject::DeathRecipient {
815c735df2Sopenharmony_ci    public:
825c735df2Sopenharmony_ci        explicit GeofenceManagerDeathRecipient(GeofenceManager &impl) : impl_(impl) {}
835c735df2Sopenharmony_ci        ~GeofenceManagerDeathRecipient() override = default;
845c735df2Sopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject> &remote) override
855c735df2Sopenharmony_ci        {
865c735df2Sopenharmony_ci            impl_.ResetGeofenceSdkProxy(remote);
875c735df2Sopenharmony_ci        }
885c735df2Sopenharmony_ci    private:
895c735df2Sopenharmony_ci        GeofenceManager &impl_;
905c735df2Sopenharmony_ci    };
915c735df2Sopenharmony_ci};
925c735df2Sopenharmony_ci}  // namespace Location
935c735df2Sopenharmony_ci}  // namespace OHOS
945c735df2Sopenharmony_ci#endif // GEOFENCE_SDK_H