• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
30 namespace OHOS {
31 namespace Location {
32 class IGnssAbility : public ISubAbility {
33 public:
34     DECLARE_INTERFACE_DESCRIPTOR(u"location.IGnssAbility");
35     virtual LocationErrCode RefrashRequirements() = 0;
36     virtual LocationErrCode RegisterGnssStatusCallback(const sptr<IRemoteObject>& callback, pid_t uid) = 0;
37     virtual LocationErrCode UnregisterGnssStatusCallback(const sptr<IRemoteObject>& callback) = 0;
38     virtual LocationErrCode RegisterNmeaMessageCallback(const sptr<IRemoteObject>& callback, pid_t uid) = 0;
39     virtual LocationErrCode UnregisterNmeaMessageCallback(const sptr<IRemoteObject>& callback) = 0;
40     virtual LocationErrCode RegisterCachedCallback(const std::unique_ptr<CachedGnssLocationsRequest>& request,
41         const sptr<IRemoteObject>& callback) = 0;
42     virtual LocationErrCode UnregisterCachedCallback(const sptr<IRemoteObject>& callback) = 0;
43 
44     virtual LocationErrCode GetCachedGnssLocationsSize(int &size) = 0;
45     virtual LocationErrCode FlushCachedGnssLocations() = 0;
46     virtual LocationErrCode SendCommand(std::unique_ptr<LocationCommand>& commands) = 0;
47     virtual LocationErrCode AddFence(std::unique_ptr<GeofenceRequest>& request) = 0;
48     virtual LocationErrCode RemoveFence(std::unique_ptr<GeofenceRequest>& request) = 0;
49 };
50 
51 class GnssAbilityStub : public IRemoteStub<IGnssAbility> {
52 public:
53     using GnssMsgHandle = int (GnssAbilityStub::*)(
54         MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
55     using GnssMsgHandleMap = std::map<int, GnssMsgHandle>;
56     GnssAbilityStub();
57     virtual ~GnssAbilityStub() = default;
58     void InitGnssMsgHandleMap();
59     int32_t OnRemoteRequest(uint32_t code,
60         MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
61     virtual void SendMessage(uint32_t code, MessageParcel &data, MessageParcel &reply) = 0;
62     virtual void UnloadGnssSystemAbility() = 0;
63 private:
64     int SendLocationRequestInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
65     int SetMockLocationsInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
66     int SetEnableInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
67     int RefreshRequirementsInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
68     int RegisterGnssStatusCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
69     int UnregisterGnssStatusCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
70     int RegisterNmeaMessageCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
71     int UnregisterNmeaMessageCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
72     int RegisterCachedCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
73     int UnregisterCachedCallbackInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
74     int GetCachedGnssLocationsSizeInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
75     int FlushCachedGnssLocationsInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
76     int SendCommandInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
77     int EnableMockInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
78     int DisableMockInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
79     int AddFenceInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
80     int RemoveFenceInner(MessageParcel &data, MessageParcel &reply, AppIdentity &identity);
81 private:
82     bool isMessageRequest_ = false;
83     GnssMsgHandleMap GnssMsgHandleMap_;
84 };
85 
86 class GnssStatusCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
87 public:
88     void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
89     GnssStatusCallbackDeathRecipient();
90     ~GnssStatusCallbackDeathRecipient() override;
91 };
92 
93 class NmeaCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
94 public:
95     void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
96     NmeaCallbackDeathRecipient();
97     ~NmeaCallbackDeathRecipient() override;
98 };
99 
100 class CachedLocationCallbackDeathRecipient : public IRemoteObject::DeathRecipient {
101 public:
102     void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
103     CachedLocationCallbackDeathRecipient();
104     ~CachedLocationCallbackDeathRecipient() override;
105 };
106 } // namespace Location
107 } // namespace OHOS
108 #endif // FEATURE_GNSS_SUPPORT
109 #endif // GNSS_ABILITY_SKELETON_H
110