1 /*
2 * Copyright (c) 2022-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
16 #include "daudio_sink_proxy.h"
17
18 #include "daudio_constants.h"
19 #include "daudio_errorcode.h"
20 #include "daudio_ipc_interface_code.h"
21 #include "daudio_log.h"
22
23 #undef DH_LOG_TAG
24 #define DH_LOG_TAG "DAudioSinkProxy"
25
26 namespace OHOS {
27 namespace DistributedHardware {
InitSink(const std::string & params)28 int32_t DAudioSinkProxy::InitSink(const std::string ¶ms)
29 {
30 MessageParcel data;
31 MessageParcel reply;
32 MessageOption option;
33 if (!data.WriteInterfaceToken(GetDescriptor())) {
34 return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED;
35 }
36
37 if (!data.WriteString(params)) {
38 return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED;
39 }
40
41 Remote()->SendRequest(static_cast<uint32_t>(IDAudioSinkInterfaceCode::INIT_SINK), data, reply, option);
42 int32_t ret = reply.ReadInt32();
43 return ret;
44 }
45
ReleaseSink()46 int32_t DAudioSinkProxy::ReleaseSink()
47 {
48 MessageParcel data;
49 MessageParcel reply;
50 MessageOption option;
51 if (!data.WriteInterfaceToken(GetDescriptor())) {
52 return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED;
53 }
54
55 Remote()->SendRequest(static_cast<uint32_t>(IDAudioSinkInterfaceCode::RELEASE_SINK), data, reply, option);
56 int32_t ret = reply.ReadInt32();
57 return ret;
58 }
59
SubscribeLocalHardware(const std::string & dhId,const std::string & param)60 int32_t DAudioSinkProxy::SubscribeLocalHardware(const std::string &dhId, const std::string ¶m)
61 {
62 MessageParcel data;
63 MessageParcel reply;
64 MessageOption option;
65 if (!data.WriteInterfaceToken(GetDescriptor())) {
66 return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED;
67 }
68 if (dhId.length() > DAUDIO_MAX_DEVICE_ID_LEN) {
69 return ERR_DH_AUDIO_SA_DEVID_ILLEGAL;
70 }
71 if (!data.WriteString(dhId) || !data.WriteString(param)) {
72 return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED;
73 }
74
75 Remote()->SendRequest(static_cast<uint32_t>(IDAudioSinkInterfaceCode::SUBSCRIBE_LOCAL_HARDWARE),
76 data, reply, option);
77 int32_t ret = reply.ReadInt32();
78 return ret;
79 }
80
UnsubscribeLocalHardware(const std::string & dhId)81 int32_t DAudioSinkProxy::UnsubscribeLocalHardware(const std::string &dhId)
82 {
83 MessageParcel data;
84 MessageParcel reply;
85 MessageOption option;
86 if (!data.WriteInterfaceToken(GetDescriptor())) {
87 return ERR_DH_AUDIO_SA_WRITE_INTERFACE_TOKEN_FAILED;
88 }
89 if (dhId.length() > DAUDIO_MAX_DEVICE_ID_LEN) {
90 return ERR_DH_AUDIO_SA_DEVID_ILLEGAL;
91 }
92 if (!data.WriteString(dhId)) {
93 return ERR_DH_AUDIO_SA_WRITE_PARAM_FAIED;
94 }
95
96 Remote()->SendRequest(static_cast<uint32_t>(IDAudioSinkInterfaceCode::UNSUBSCRIBE_LOCAL_HARDWARE),
97 data, reply, option);
98 int32_t ret = reply.ReadInt32();
99 return ret;
100 }
101
DAudioNotify(const std::string & devId,const std::string & dhId,const int32_t eventType,const std::string & eventContent)102 void DAudioSinkProxy::DAudioNotify(const std::string &devId, const std::string &dhId, const int32_t eventType,
103 const std::string &eventContent)
104 {
105 MessageParcel data;
106 MessageParcel reply;
107 MessageOption option;
108 if (!data.WriteInterfaceToken(GetDescriptor())) {
109 return;
110 }
111 if (devId.length() > DAUDIO_MAX_DEVICE_ID_LEN || dhId.length() > DAUDIO_MAX_DEVICE_ID_LEN) {
112 return;
113 }
114 if (!data.WriteString(devId) || !data.WriteString(dhId) || !data.WriteInt32(eventType) ||
115 !data.WriteString(eventContent)) {
116 return;
117 }
118
119 Remote()->SendRequest(static_cast<uint32_t>(IDAudioSinkInterfaceCode::DAUDIO_NOTIFY), data, reply, option);
120 }
121 } // namespace DistributedHardware
122 } // namespace OHOS