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