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 #ifndef LOG_TAG
16 #define LOG_TAG "bt_ipc_pan_observer_stub"
17 #endif
18 
19 #include "bluetooth_pan_observer_stub.h"
20 #include "bluetooth_log.h"
21 
22 namespace OHOS {
23 namespace Bluetooth {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int BluetoothPanObserverStub::OnRemoteRequest(
25     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
26 {
27     switch (code) {
28         case static_cast<uint32_t>(BluetoothPanObserverInterfaceCode::COMMAND_ON_CONNECTION_STATE_CHANGED): {
29             if (BluetoothPanObserverStub::GetDescriptor() != data.ReadInterfaceToken()) {
30                 HILOGE("local descriptor is not equal to remote");
31                 return IPC_INVOKER_TRANSLATE_ERR;
32             }
33             std::shared_ptr<BluetoothRawAddress> address(data.ReadParcelable<BluetoothRawAddress>());
34             if (address == nullptr) {
35                 HILOGE("null pointer");
36                 return ERR_TRANSACTION_FAILED;
37             }
38             int state = data.ReadInt32();
39             int cause = data.ReadInt32();
40             OnConnectionStateChanged(*address, state, cause);
41             return NO_ERROR;
42         }
43         default:
44             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
45     }
46 
47     return ERR_TRANSACTION_FAILED;
48 }
49 }  // namespace Bluetooth
50 }  // namespace OHOS