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 
16 #ifndef NATIVE_LOCATION_CALLBACK_HOST_H
17 #define NATIVE_LOCATION_CALLBACK_HOST_H
18 
19 #include "iremote_stub.h"
20 
21 #include "common_utils.h"
22 #include "constant_definition.h"
23 #include "i_locator_callback.h"
24 #include "location.h"
25 
26 namespace OHOS {
27 namespace Location {
28 typedef void (* LocationUpdate)(const std::unique_ptr<Location>& location);
29 
30 typedef struct {
31     LocationUpdate locationUpdate;
32 } LocationCallbackIfaces;
33 
34 class NativeLocationCallbackHost : public IRemoteStub<ILocatorCallback> {
35 public:
36     virtual int OnRemoteRequest(uint32_t code,
37         MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
38     void OnLocationReport(const std::unique_ptr<Location>& location) override;
39     void OnLocatingStatusChange(const int status) override;
40     void OnErrorReport(const int errorCode) override;
41 
SetCallback(const LocationCallbackIfaces & locationCallback)42     inline void SetCallback(const LocationCallbackIfaces& locationCallback)
43     {
44         locationCallback_ = locationCallback;
45     }
46 
GetCallback()47     inline LocationCallbackIfaces GetCallback()
48     {
49         return locationCallback_;
50     }
51 
52 private:
53     LocationCallbackIfaces locationCallback_;
54 };
55 } // namespace Location
56 } // namespace OHOS
57 #endif // NATIVE_LOCATION_CALLBACK_HOST_H
58