• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_opp_observer_proxy.h"
16 #include "bluetooth_log.h"
17 
18 namespace OHOS {
19 namespace Bluetooth {
OnReceiveIncomingFileChanged(const BluetoothIOppTransferInformation & oppInformation)20 ErrCode BluetoothOppObserverProxy::OnReceiveIncomingFileChanged(const BluetoothIOppTransferInformation &oppInformation)
21 {
22     HILOGI("BluetoothOppObserverProxy::OnReceiveIncomingFileChanged start");
23     MessageParcel data;
24     MessageParcel reply;
25     MessageOption option(MessageOption::TF_SYNC);
26     if (!data.WriteInterfaceToken(BluetoothOppObserverProxy::GetDescriptor())) {
27         HILOGE("BluetoothOppObserverProxy::OnReceiveIncomingFileChanged WriteInterfaceToken error");
28         return IPC_PROXY_TRANSACTION_ERR;
29     }
30     data.WriteParcelable(&oppInformation);
31     int32_t st = Remote()->SendRequest(static_cast<uint32_t>(
32         BluetoothOppObserverInterfaceCode::COMMAND_ON_RECEIVE_INCOMING_FILE_CHANGED), data, reply, option);
33     if (st != ERR_NONE) {
34         HILOGE("OnReceiveIncomingFileChanged failed, error code is %{public}d", st);
35         return st;
36     }
37 
38     ErrCode ec = reply.ReadInt32();
39     if (FAILED(ec)) {
40         return ec;
41     }
42 
43     return ERR_OK;
44 }
45 
OnTransferStateChanged(const BluetoothIOppTransferInformation & oppInformation)46 ErrCode BluetoothOppObserverProxy::OnTransferStateChanged(const BluetoothIOppTransferInformation &oppInformation)
47 {
48     HILOGI("BluetoothOppObserverProxy::OnTransferStateChanged start");
49     MessageParcel data;
50     MessageParcel reply;
51     MessageOption option(MessageOption::TF_SYNC);
52     if (!data.WriteInterfaceToken(BluetoothOppObserverProxy::GetDescriptor())) {
53         HILOGE("BluetoothOppObserverProxy::OnTransferStateChanged WriteInterfaceToken error");
54         return IPC_PROXY_TRANSACTION_ERR;
55     }
56     data.WriteParcelable(&oppInformation);
57     int32_t st = Remote()->SendRequest(static_cast<uint32_t>(
58         BluetoothOppObserverInterfaceCode::COMMAND_ON_TRANSFER_STATE_CHANGED), data, reply, option);
59     if (st != ERR_NONE) {
60         HILOGE("OnConnectionStateChanged failed, error code is %{public}d", st);
61         return st;
62     }
63 
64     ErrCode ec = reply.ReadInt32();
65     if (FAILED(ec)) {
66         return ec;
67     }
68 
69     return ERR_OK;
70 }
71 }  // namespace Bluetooth
72 }  // namespace OHOS