• 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 
16 #include "daudio_ipc_callback_stub.h"
17 
18 #include "daudio_errorcode.h"
19 #include "daudio_log.h"
20 
21 #undef DH_LOG_TAG
22 #define DH_LOG_TAG "DAudioIpcCallbackStub"
23 
24 namespace OHOS {
25 namespace DistributedHardware {
DAudioIpcCallbackStub()26 DAudioIpcCallbackStub::DAudioIpcCallbackStub()
27 {
28     memberFuncMap_[NOTIFY_REGRESULT] = &DAudioIpcCallbackStub::OnNotifyRegResultInner;
29     memberFuncMap_[NOTIFY_UNREGRESULT] = &DAudioIpcCallbackStub::OnNotifyUnregResultInner;
30 }
31 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t DAudioIpcCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
33     MessageOption &option)
34 {
35     DHLOGI("On remote request, code: %u", code);
36     std::u16string desc = DAudioIpcCallbackStub::GetDescriptor();
37     std::u16string remoteDesc = data.ReadInterfaceToken();
38     if (desc != remoteDesc) {
39         DHLOGE("RemoteDesc is invalid.");
40         return ERR_DH_AUDIO_SA_INVALID_INTERFACE_TOKEN;
41     }
42 
43     std::map<int32_t, DAudioCallbackFunc>::iterator iter = memberFuncMap_.find(code);
44     if (iter == memberFuncMap_.end()) {
45         DHLOGE("Invalid request code.");
46         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
47     }
48     DAudioCallbackFunc &func = iter->second;
49     return (this->*func)(data, reply, option);
50 }
51 
OnNotifyRegResultInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)52 int32_t DAudioIpcCallbackStub::OnNotifyRegResultInner(MessageParcel &data, MessageParcel &reply, MessageOption &option)
53 {
54     std::string networkId = data.ReadString();
55     std::string dhId = data.ReadString();
56     std::string reqId = data.ReadString();
57     int32_t status = data.ReadInt32();
58     std::string resultData = data.ReadString();
59     int32_t ret = OnNotifyRegResult(networkId, dhId, reqId, status, resultData);
60     return ret;
61 }
62 
OnNotifyUnregResultInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)63 int32_t DAudioIpcCallbackStub::OnNotifyUnregResultInner(MessageParcel &data, MessageParcel &reply,
64     MessageOption &option)
65 {
66     std::string networkId = data.ReadString();
67     std::string dhId = data.ReadString();
68     std::string reqId = data.ReadString();
69     int32_t status = data.ReadInt32();
70     std::string resultData = data.ReadString();
71     int32_t ret = OnNotifyUnregResult(networkId, dhId, reqId, status, resultData);
72     return ret;
73 }
74 } // DistributedHardware
75 } // OHOS