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 #ifndef LOG_TAG
16 #define LOG_TAG "bt_ipc_map_mse_observer_stub"
17 #endif
18
19 #include "bluetooth_errorcode.h"
20 #include "bluetooth_log.h"
21 #include "bluetooth_map_mse_observer_stub.h"
22
23 namespace OHOS {
24 namespace Bluetooth {
BluetoothMapMseObserverStub()25 BluetoothMapMseObserverStub::BluetoothMapMseObserverStub()
26 {
27 HILOGI("start.");
28 memberFuncMap_[static_cast<uint32_t>(
29 BluetoothMapMseObserverInterfaceCode::MSE_ON_CONNECTION_STATE_CHANGED)] =
30 BluetoothMapMseObserverStub::OnConnectionStateChangedInner;
31 }
32
~BluetoothMapMseObserverStub()33 BluetoothMapMseObserverStub::~BluetoothMapMseObserverStub()
34 {
35 HILOGI("start.");
36 memberFuncMap_.clear();
37 }
38
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int32_t BluetoothMapMseObserverStub::OnRemoteRequest(
40 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
41 {
42 HILOGD("MapMseObserverStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
43 if (BluetoothMapMseObserverStub::GetDescriptor() != data.ReadInterfaceToken()) {
44 HILOGI("local descriptor is not equal to remote");
45 return ERR_INVALID_STATE;
46 }
47
48 auto itFunc = memberFuncMap_.find(code);
49 if (itFunc != memberFuncMap_.end()) {
50 auto memberFunc = itFunc->second;
51 if (memberFunc != nullptr) {
52 return memberFunc(this, data, reply);
53 }
54 }
55 HILOGW("OnRemoteRequest, default case, need check.");
56 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
57 }
58
OnConnectionStateChangedInner(BluetoothMapMseObserverStub * stub,MessageParcel & data,MessageParcel & reply)59 int32_t BluetoothMapMseObserverStub::OnConnectionStateChangedInner(
60 BluetoothMapMseObserverStub *stub, MessageParcel &data, MessageParcel &reply)
61 {
62 HILOGD("Enter.");
63 std::shared_ptr<BluetoothRawAddress> device(data.ReadParcelable<BluetoothRawAddress>());
64 CHECK_AND_RETURN_LOG_RET((device != nullptr), BT_ERR_INTERNAL_ERROR, "Read device error");
65 int32_t state = data.ReadInt32();
66 int32_t cause = data.ReadInt32();
67 stub->OnConnectionStateChanged(*device, state, cause);
68 return BT_NO_ERROR;
69 }
70 } // namespace Bluetooth
71 } // namespace OHOS
72