• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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_ble_advertise_callback_stub.h"
17 #include "bluetooth_log.h"
18 #include "ipc_types.h"
19 #include "string_ex.h"
20 
21 namespace OHOS {
22 namespace Bluetooth {
23 const std::map<uint32_t, std::function<ErrCode(BluetoothBleAdvertiseCallbackStub *, MessageParcel &, MessageParcel &)>>
24     BluetoothBleAdvertiseCallbackStub::memberFuncMap_ = {
25         {IBluetoothBleAdvertiseCallback::Code::BT_BLE_ADVERTISE_CALLBACK_AUTO_STOP_EVENT,
26             std::bind(&BluetoothBleAdvertiseCallbackStub::OnAutoStopAdvEventInner, std::placeholders::_1,
27                 std::placeholders::_2, std::placeholders::_3)},
28         {IBluetoothBleAdvertiseCallback::Code::BT_BLE_ADVERTISE_CALLBACK_RESULT_EVENT,
29             std::bind(&BluetoothBleAdvertiseCallbackStub::OnStartResultEventInner, std::placeholders::_1,
30                 std::placeholders::_2, std::placeholders::_3)},
31 };
32 
BluetoothBleAdvertiseCallbackStub()33 BluetoothBleAdvertiseCallbackStub::BluetoothBleAdvertiseCallbackStub()
34 {
35     HILOGD("%{public}s start.", __func__);
36 }
37 
~BluetoothBleAdvertiseCallbackStub()38 BluetoothBleAdvertiseCallbackStub::~BluetoothBleAdvertiseCallbackStub()
39 {
40     HILOGD("%{public}s start.", __func__);
41 }
42 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)43 int BluetoothBleAdvertiseCallbackStub::OnRemoteRequest(
44     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
45 {
46     HILOGD("BluetoothBleAdvertiseCallbackStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d",
47         code,
48         option.GetFlags());
49     std::u16string descriptor = BluetoothBleAdvertiseCallbackStub::GetDescriptor();
50     std::u16string remoteDescriptor = data.ReadInterfaceToken();
51     if (descriptor != remoteDescriptor) {
52         HILOGI("local descriptor is not equal to remote");
53         return ERR_INVALID_STATE;
54     }
55 
56     auto itFunc = memberFuncMap_.find(code);
57     if (itFunc != memberFuncMap_.end()) {
58         auto memberFunc = itFunc->second;
59         if (memberFunc != nullptr) {
60             return memberFunc(this, data, reply);
61         }
62     }
63 
64     HILOGW("BluetoothBleAdvertiseCallbackStub::OnRemoteRequest, default case, need check.");
65     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
66 }
67 
OnStartResultEventInner(MessageParcel & data,MessageParcel & reply)68 ErrCode BluetoothBleAdvertiseCallbackStub::OnStartResultEventInner(MessageParcel &data, MessageParcel &reply)
69 {
70     const int32_t result = static_cast<int32_t>(data.ReadInt32());
71     const int32_t advHandle = static_cast<int32_t>(data.ReadInt32());
72     const int32_t opcode = static_cast<int32_t>(data.ReadInt32());
73 
74     OnStartResultEvent(result, advHandle, opcode);
75     return NO_ERROR;
76 }
77 
OnAutoStopAdvEventInner(MessageParcel & data,MessageParcel & reply)78 ErrCode BluetoothBleAdvertiseCallbackStub::OnAutoStopAdvEventInner(MessageParcel &data, MessageParcel &reply)
79 {
80     const int32_t advHandle = static_cast<int32_t>(data.ReadInt32());
81     OnAutoStopAdvEvent(advHandle);
82     return NO_ERROR;
83 }
84 }  // namespace Bluetooth
85 }  // namespace OHOS
86