• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_source_stub.h"
17 
18 #include "daudio_constants.h"
19 #include "daudio_errorcode.h"
20 #include "daudio_ipc_callback_proxy.h"
21 #include "daudio_ipc_interface_code.h"
22 #include "daudio_log.h"
23 
24 #undef DH_LOG_TAG
25 #define DH_LOG_TAG "DAudioSourceStub"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
DAudioSourceStub()29 DAudioSourceStub::DAudioSourceStub()
30 {
31     memberFuncMap_[static_cast<uint32_t>(IDAudioSourceInterfaceCode::INIT_SOURCE)] =
32         &DAudioSourceStub::InitSourceInner;
33     memberFuncMap_[static_cast<uint32_t>(IDAudioSourceInterfaceCode::RELEASE_SOURCE)] =
34         &DAudioSourceStub::ReleaseSourceInner;
35     memberFuncMap_[static_cast<uint32_t>(IDAudioSourceInterfaceCode::REGISTER_DISTRIBUTED_HARDWARE)] =
36         &DAudioSourceStub::RegisterDistributedHardwareInner;
37     memberFuncMap_[static_cast<uint32_t>(IDAudioSourceInterfaceCode::UNREGISTER_DISTRIBUTED_HARDWARE)] =
38         &DAudioSourceStub::UnregisterDistributedHardwareInner;
39     memberFuncMap_[static_cast<uint32_t>(IDAudioSourceInterfaceCode::CONFIG_DISTRIBUTED_HARDWARE)] =
40         &DAudioSourceStub::ConfigDistributedHardwareInner;
41     memberFuncMap_[static_cast<uint32_t>(IDAudioSourceInterfaceCode::DAUDIO_NOTIFY)] =
42         &DAudioSourceStub::DAudioNotifyInner;
43 }
44 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)45 int32_t DAudioSourceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
46     MessageOption &option)
47 {
48     std::u16string desc = DAudioSourceStub::GetDescriptor();
49     std::u16string remoteDesc = data.ReadInterfaceToken();
50     if (desc != remoteDesc) {
51         DHLOGE("Remote desc is invalid.");
52         return ERR_DH_AUDIO_SA_INVALID_INTERFACE_TOKEN;
53     }
54 
55     const auto &iter = memberFuncMap_.find(code);
56     if (iter == memberFuncMap_.end()) {
57         DHLOGE("Invalid request code.");
58         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
59     }
60     DAudioSourceServiceFunc &func = iter->second;
61     return (this->*func)(data, reply, option);
62 }
63 
InitSourceInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)64 int32_t DAudioSourceStub::InitSourceInner(MessageParcel &data, MessageParcel &reply, MessageOption &option)
65 {
66     std::string param = data.ReadString();
67     sptr<IRemoteObject> remoteObject = data.ReadRemoteObject();
68     if (remoteObject == nullptr) {
69         DHLOGE("Read param failed.");
70         return ERR_DH_AUDIO_SA_READ_PARAM_FAILED;
71     }
72 
73     sptr<DAudioIpcCallbackProxy> dAudioIpcCallbackProxy(new DAudioIpcCallbackProxy(remoteObject));
74     int32_t ret = InitSource(param, dAudioIpcCallbackProxy);
75     reply.WriteInt32(ret);
76     return DH_SUCCESS;
77 }
78 
ReleaseSourceInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)79 int32_t DAudioSourceStub::ReleaseSourceInner(MessageParcel &data, MessageParcel &reply, MessageOption &option)
80 {
81     int32_t ret = ReleaseSource();
82     reply.WriteInt32(ret);
83     return DH_SUCCESS;
84 }
85 
RegisterDistributedHardwareInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)86 int32_t DAudioSourceStub::RegisterDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
87     MessageOption &option)
88 {
89     std::string networkId = data.ReadString();
90     std::string dhId = data.ReadString();
91     std::string version = data.ReadString();
92     std::string attrs = data.ReadString();
93     std::string reqId = data.ReadString();
94     EnableParam enableParam;
95     enableParam.version = version;
96     enableParam.attrs = attrs;
97 
98     int32_t ret = RegisterDistributedHardware(networkId, dhId, enableParam, reqId);
99     reply.WriteInt32(ret);
100     return DH_SUCCESS;
101 }
102 
UnregisterDistributedHardwareInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)103 int32_t DAudioSourceStub::UnregisterDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
104     MessageOption &option)
105 {
106     std::string networkId = data.ReadString();
107     std::string dhId = data.ReadString();
108     std::string reqId = data.ReadString();
109 
110     int32_t ret = UnregisterDistributedHardware(networkId, dhId, reqId);
111     reply.WriteInt32(ret);
112     return DH_SUCCESS;
113 }
114 
ConfigDistributedHardwareInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)115 int32_t DAudioSourceStub::ConfigDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
116     MessageOption &option)
117 {
118     std::string networkId = data.ReadString();
119     std::string dhId = data.ReadString();
120     std::string key = data.ReadString();
121     std::string value = data.ReadString();
122 
123     int32_t ret = ConfigDistributedHardware(networkId, dhId, key, value);
124     reply.WriteInt32(ret);
125     return DH_SUCCESS;
126 }
127 
DAudioNotifyInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)128 int32_t DAudioSourceStub::DAudioNotifyInner(MessageParcel &data, MessageParcel &reply, MessageOption &option)
129 {
130     std::string networkId = data.ReadString();
131     std::string dhId = data.ReadString();
132     int32_t eventType = data.ReadInt32();
133     std::string eventContent = data.ReadString();
134 
135     DAudioNotify(networkId, dhId, eventType, eventContent);
136     return DH_SUCCESS;
137 }
138 } // namespace DistributedHardware
139 } // namespace OHOS
140