1 /*
2  * Copyright (c) 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_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 "DAudioSinkIpcCallbackStub"
23 
24 namespace OHOS {
25 namespace DistributedHardware {
DAudioSinkIpcCallbackStub()26 DAudioSinkIpcCallbackStub::DAudioSinkIpcCallbackStub() : IRemoteStub(true)
27 {
28     memberFuncMap_[NOTIFY_RESOURCEINFO] = &DAudioSinkIpcCallbackStub::OnNotifyResourceInfoInner;
29 }
30 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t DAudioSinkIpcCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
32     MessageOption &option)
33 {
34     DHLOGI("On remote request, code: %{public}u", code);
35     std::u16string desc = DAudioSinkIpcCallbackStub::GetDescriptor();
36     std::u16string remoteDesc = data.ReadInterfaceToken();
37     if (desc != remoteDesc) {
38         DHLOGE("RemoteDesc is invalid.");
39         return ERR_DH_AUDIO_SA_INVALID_INTERFACE_TOKEN;
40     }
41 
42     switch (code) {
43         case NOTIFY_RESOURCEINFO:
44             return OnNotifyResourceInfoInner(data, reply, option);
45         default:
46             DHLOGE("Invalid request code.");
47             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48     }
49     return ERR_DH_AUDIO_NOT_FOUND_KEY;
50 }
51 
OnNotifyResourceInfoInner(MessageParcel & data,MessageParcel & reply,MessageOption & option)52 int32_t DAudioSinkIpcCallbackStub::OnNotifyResourceInfoInner(MessageParcel &data, MessageParcel &reply,
53     MessageOption &option)
54 {
55     int32_t ret = DH_SUCCESS;
56     bool isSensitive;
57     bool isSameAccount;
58     do {
59         ResourceEventType type = static_cast<ResourceEventType>(data.ReadInt32());
60         std::string subType = data.ReadString();
61         std::string networkId = data.ReadString();
62         ret = OnNotifyResourceInfo(type, subType, networkId, isSensitive, isSameAccount);
63     } while (0);
64     reply.WriteInt32(ret);
65     reply.WriteBool(isSensitive);
66     reply.WriteBool(isSameAccount);
67     return DH_SUCCESS;
68 }
69 } // DistributedHardware
70 } // OHOS