1 /*
2 * Copyright (C) 2025 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 #include "bluetooth_scan_result_callback_taihe.h"
17
18 #include "ipc_object_stub.h"
19 #include "ipc_skeleton.h"
20 #include "message_option.h"
21 #include "message_parcel.h"
22
23 #include "constant_definition.h"
24 #include "util.h"
25
26 namespace OHOS {
27 namespace Location {
BluetoothScanResultCallbackTaihe()28 BluetoothScanResultCallbackTaihe::BluetoothScanResultCallbackTaihe()
29 {
30 }
31
~BluetoothScanResultCallbackTaihe()32 BluetoothScanResultCallbackTaihe::~BluetoothScanResultCallbackTaihe()
33 {
34 }
35
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int BluetoothScanResultCallbackTaihe::OnRemoteRequest(
37 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
38 {
39 LBSLOGD(LOCATOR_CALLBACK, "BluetoothScanResultCallbackTaihe::OnRemoteRequest!");
40 if (data.ReadInterfaceToken() != GetDescriptor()) {
41 LBSLOGE(LOCATOR_CALLBACK, "invalid token.");
42 return -1;
43 }
44 switch (code) {
45 case RECEIVE_INFO_EVENT: {
46 std::unique_ptr<BluetoothScanResult> res = BluetoothScanResult::Unmarshalling(data);
47 OnBluetoothScanResultChange(res);
48 break;
49 }
50 default: {
51 IPCObjectStub::OnRemoteRequest(code, data, reply, option);
52 break;
53 }
54 }
55 return 0;
56 }
57
OnBluetoothScanResultChange(const std::unique_ptr<BluetoothScanResult> & bluetoothScanResult)58 void BluetoothScanResultCallbackTaihe::OnBluetoothScanResultChange(
59 const std::unique_ptr<BluetoothScanResult>& bluetoothScanResult)
60 {
61 ::ohos::geoLocationManager::BluetoothScanResult bluetoothScanResultTaihe =
62 ::ohos::geoLocationManager::BluetoothScanResult{};
63 Util::BluetoothScanResultToTaihe(bluetoothScanResultTaihe, bluetoothScanResult);
64 if (callback_) {
65 (*callback_)(bluetoothScanResultTaihe);
66 }
67 }
68 } // namespace Location
69 } // namespace OHOS
70