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 "av_trans_control_center_callback_stub.h"
17
18 #include "av_trans_errno.h"
19 #include "distributed_hardware_log.h"
20
21 namespace OHOS {
22 namespace DistributedHardware {
AVTransControlCenterCallbackStub()23 AVTransControlCenterCallbackStub::AVTransControlCenterCallbackStub()
24 {
25 }
26
~AVTransControlCenterCallbackStub()27 AVTransControlCenterCallbackStub::~AVTransControlCenterCallbackStub()
28 {
29 }
30
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t AVTransControlCenterCallbackStub::OnRemoteRequest(uint32_t code,
32 MessageParcel &data, MessageParcel &reply, MessageOption &option)
33 {
34 (void)option;
35 if (data.ReadInterfaceToken() != GetDescriptor()) {
36 DHLOGE("Read valid token failed");
37 return ERR_INVALID_DATA;
38 }
39 switch (code) {
40 case (uint32_t)IAVTransControlCenterCallback::Message::SET_PARAMETER: {
41 return SetParameterInner(data, reply);
42 }
43 case (uint32_t)IAVTransControlCenterCallback::Message::SET_SHARED_MEMORY: {
44 return SetSharedMemoryInner(data, reply);
45 }
46 case (uint32_t)IAVTransControlCenterCallback::Message::NOTIFY_AV_EVENT: {
47 return NotifyInner(data, reply);
48 }
49 default:
50 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
51 }
52
53 return NO_ERROR;
54 }
55
SetParameterInner(MessageParcel & data,MessageParcel & reply)56 int32_t AVTransControlCenterCallbackStub::SetParameterInner(MessageParcel &data, MessageParcel &reply)
57 {
58 uint32_t transTag = data.ReadUint32();
59 std::string tagValue = data.ReadString();
60 int32_t ret = SetParameter((AVTransTag)transTag, tagValue);
61 if (!reply.WriteInt32(ret)) {
62 DHLOGE("Write ret code failed");
63 return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL;
64 }
65 return NO_ERROR;
66 }
67
SetSharedMemoryInner(MessageParcel & data,MessageParcel & reply)68 int32_t AVTransControlCenterCallbackStub::SetSharedMemoryInner(MessageParcel &data, MessageParcel &reply)
69 {
70 int32_t fd = data.ReadFileDescriptor();
71 int32_t size = data.ReadInt32();
72 std::string name = data.ReadString();
73 int32_t ret = SetSharedMemory(AVTransSharedMemory{ fd, size, name });
74 if (!reply.WriteInt32(ret)) {
75 DHLOGE("Write ret code failed");
76 return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL;
77 }
78 return NO_ERROR;
79 }
80
NotifyInner(MessageParcel & data,MessageParcel & reply)81 int32_t AVTransControlCenterCallbackStub::NotifyInner(MessageParcel &data, MessageParcel &reply)
82 {
83 uint32_t type = data.ReadUint32();
84 std::string content = data.ReadString();
85 std::string peerDevId = data.ReadString();
86 int32_t ret = Notify(AVTransEvent{(EventType)type, content, peerDevId});
87 if (!reply.WriteInt32(ret)) {
88 DHLOGE("Write ret code failed");
89 return ERR_DH_AVT_SERVICE_WRITE_INFO_FAIL;
90 }
91 return NO_ERROR;
92 }
93 } // namespace DistributedHardware
94 } // namespace OHOS