1 /* 2 * Copyright (C) 2022 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 16 #ifndef GNSS_ABILITY_SKELETON_H 17 #define GNSS_ABILITY_SKELETON_H 18 #ifdef FEATURE_GNSS_SUPPORT 19 #include <map> 20 #include "message_option.h" 21 #include "message_parcel.h" 22 #include "iremote_object.h" 23 #include "iremote_stub.h" 24 25 #include "constant_definition.h" 26 #include "subability_common.h" 27 28 #include "app_identity.h" 29 #include "geofence_request.h" 30 31 namespace OHOS { 32 namespace Location { 33 class IGnssAbility : public ISubAbility { 34 public: 35 DECLARE_INTERFACE_DESCRIPTOR(u"location.IGnssAbility"); 36 virtual LocationErrCode RefrashRequirements() = 0; 37 virtual LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity) = 0; 38 virtual LocationErrCode UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) = 0; 39 virtual LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, AppIdentity &identity) = 0; 40 virtual LocationErrCode UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) = 0; 41 virtual LocationErrCode RegisterCachedCallback(const std::unique_ptr<CachedGnssLocationsRequest>& request, 42 const sptr<IRemoteObject>& callback) = 0; 43 virtual LocationErrCode UnregisterCachedCallback(const sptr<IRemoteObject>& callback) = 0; 44 45 virtual LocationErrCode GetCachedGnssLocationsSize(int &size) = 0; 46 virtual LocationErrCode FlushCachedGnssLocations() = 0; 47 virtual LocationErrCode SendCommand(std::unique_ptr<LocationCommand>& commands) = 0; 48 virtual LocationErrCode AddFence(std::shared_ptr<GeofenceRequest>& request) = 0; 49 virtual LocationErrCode RemoveFence(std::shared_ptr<GeofenceRequest>& request) = 0; 50 virtual LocationErrCode AddGnssGeofence(std::shared_ptr<GeofenceRequest>& request) = 0; 51 virtual LocationErrCode RemoveGnssGeofence(std::shared_ptr<GeofenceRequest>& request) = 0; 52 virtual LocationErrCode QuerySupportCoordinateSystemType( 53 std::vector<CoordinateSystemType>& coordinateSystemTypes) = 0; 54 virtual LocationErrCode SendNetworkLocation(const std::unique_ptr<Location>& location) = 0; 55 }; 56 57 class GnssAbilityStub : public IRemoteStub<IGnssAbility> { 58 public: 59 using GnssMsgHandle = std::function<int(MessageParcel &, MessageParcel &, AppIdentity &)>; 60 using GnssMsgHandleMap = std::map<int, GnssMsgHandle>; 61 GnssAbilityStub(); 62 virtual ~GnssAbilityStub() = default; 63 void InitGnssMsgHandleMap(); 64 void InitGnssEnhanceMsgHandleMap(); 65 int32_t OnRemoteRequest(uint32_t code, 66 MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 67 virtual void SendMessage(uint32_t code, MessageParcel &data, MessageParcel &reply) = 0; 68 virtual bool CancelIdleState() = 0; 69 virtual void UnloadGnssSystemAbility() = 0; 70 private: 71 int SendLocationRequestInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 72 int SetMockLocationsInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 73 int SetEnableInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 74 int RefreshRequirementsInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 75 int RegisterGnssStatusCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 76 int UnregisterGnssStatusCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 77 int RegisterNmeaMessageCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 78 int UnregisterNmeaMessageCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 79 int RegisterCachedCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 80 int UnregisterCachedCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 81 int GetCachedGnssLocationsSizeInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 82 int FlushCachedGnssLocationsInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 83 int SendCommandInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 84 int EnableMockInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 85 int DisableMockInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 86 int AddFenceInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 87 int RemoveFenceInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 88 int AddGnssGeofenceInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 89 int RemoveGnssGeofenceInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 90 int QuerySupportCoordinateSystemTypeInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 91 int SendNetworkLocationInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity); 92 private: 93 bool isMessageRequest_ = false; 94 GnssMsgHandleMap GnssMsgHandleMap_; 95 }; 96 97 class GnssStatusCallbackDeathRecipient : public IRemoteObject::DeathRecipient { 98 public: 99 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 100 GnssStatusCallbackDeathRecipient(); 101 ~GnssStatusCallbackDeathRecipient() override; 102 }; 103 104 class NmeaCallbackDeathRecipient : public IRemoteObject::DeathRecipient { 105 public: 106 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 107 NmeaCallbackDeathRecipient(); 108 ~NmeaCallbackDeathRecipient() override; 109 }; 110 111 class CachedLocationCallbackDeathRecipient : public IRemoteObject::DeathRecipient { 112 public: 113 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 114 CachedLocationCallbackDeathRecipient(); 115 ~CachedLocationCallbackDeathRecipient() override; 116 }; 117 118 class GnssGeofenceCallbackDeathRecipient : public IRemoteObject::DeathRecipient { 119 public: 120 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 121 GnssGeofenceCallbackDeathRecipient(); 122 ~GnssGeofenceCallbackDeathRecipient() override; 123 }; 124 } // namespace Location 125 } // namespace OHOS 126 #endif // FEATURE_GNSS_SUPPORT 127 #endif // GNSS_ABILITY_SKELETON_H 128