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
16 #include "daudio_ipc_callback_proxy.h"
17
18 #include "daudio_errorcode.h"
19
20 #undef DH_LOG_TAG
21 #define DH_LOG_TAG "DAudioIpcCallbackProxy"
22
23 namespace OHOS {
24 namespace DistributedHardware {
OnNotifyRegResult(const std::string & devId,const std::string & dhId,const std::string & reqId,int32_t status,const std::string & resultData)25 int32_t DAudioIpcCallbackProxy::OnNotifyRegResult(const std::string &devId, const std::string &dhId,
26 const std::string &reqId, int32_t status, const std::string &resultData)
27 {
28 MessageParcel data;
29 MessageParcel reply;
30 MessageOption option;
31 if (!data.WriteInterfaceToken(GetDescriptor())) {
32 return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED;
33 }
34
35 if (!data.WriteString(devId) || !data.WriteString(dhId) || !data.WriteString(reqId) ||
36 !data.WriteInt32(status) || !data.WriteString(resultData)) {
37 return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED;
38 }
39
40 Remote()->SendRequest(NOTIFY_REGRESULT, data, reply, option);
41 int32_t ret = reply.ReadInt32();
42 return ret;
43 }
44
OnNotifyUnregResult(const std::string & devId,const std::string & dhId,const std::string & reqId,int32_t status,const std::string & resultData)45 int32_t DAudioIpcCallbackProxy::OnNotifyUnregResult(const std::string &devId, const std::string &dhId,
46 const std::string &reqId, int32_t status, const std::string &resultData)
47 {
48 MessageParcel data;
49 MessageParcel reply;
50 MessageOption option;
51
52 if (!data.WriteInterfaceToken(GetDescriptor())) {
53 return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED;
54 }
55
56 if (!data.WriteString(devId) || !data.WriteString(dhId) || !data.WriteString(reqId) ||
57 !data.WriteInt32(status) || !data.WriteString(resultData)) {
58 return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED;
59 }
60
61 Remote()->SendRequest(NOTIFY_UNREGRESULT, data, reply, option);
62 int32_t ret = reply.ReadInt32();
63 return ret;
64 }
65
OnHardwareStateChanged(const std::string & devId,const std::string & dhId,int32_t status)66 int32_t DAudioIpcCallbackProxy::OnHardwareStateChanged(const std::string &devId, const std::string &dhId,
67 int32_t status)
68 {
69 MessageParcel data;
70 MessageParcel reply;
71 MessageOption option;
72
73 if (!data.WriteInterfaceToken(GetDescriptor())) {
74 return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED;
75 }
76
77 if (!data.WriteString(devId) || !data.WriteString(dhId) || !data.WriteInt32(status)) {
78 return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED;
79 }
80
81 Remote()->SendRequest(NOTIFY_STATE_CHANGED, data, reply, option);
82 int32_t ret = reply.ReadInt32();
83 return ret;
84 }
85
OnDataSyncTrigger(const std::string & devId)86 int32_t DAudioIpcCallbackProxy::OnDataSyncTrigger(const std::string &devId)
87 {
88 MessageParcel data;
89 MessageParcel reply;
90 MessageOption option;
91
92 if (!data.WriteInterfaceToken(GetDescriptor())) {
93 return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED;
94 }
95
96 if (!data.WriteString(devId)) {
97 return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED;
98 }
99
100 Remote()->SendRequest(NOTIFY_DATASYNC_TRIGGER, data, reply, option);
101 int32_t ret = reply.ReadInt32();
102 return ret;
103 }
104 } // namespace DistributedHardware
105 } // namespace OHOS