1 /*
2 * Copyright (c) 2021 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 #include "dump_broker_stub.h"
16 #include <message_parcel.h>
17 #include "dump_errors.h"
18 #include "hilog_wrapper.h"
19 namespace OHOS {
20 namespace HiviewDFX {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)21 int DumpBrokerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
22 {
23 std::u16string descripter = DumpBrokerStub::GetDescriptor();
24 std::u16string remoteDescripter = data.ReadInterfaceToken();
25 if (descripter != remoteDescripter) {
26 return ERROR_GET_DUMPER_SERVICE;
27 }
28 int ret = ERR_OK;
29 switch (code) {
30 case static_cast<int>(IDumpBroker::DUMP_REQUEST_FILEFD): {
31 DUMPER_HILOGD(MODULE_ZIDL, "debug|RequestFileFdStub");
32 ret = RequestFileFdStub(data, reply);
33 break;
34 }
35 case static_cast<int>(IDumpBroker::DUMP_REQUEST_FILEFD_CALLBACK): {
36 DUMPER_HILOGD(MODULE_ZIDL, "debug|RequestFileFdCallbackStub");
37 ret = RequestFileFdCallbackStub(data, reply);
38 break;
39 }
40 default: {
41 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
42 break;
43 }
44 }
45 return ret;
46 }
47
RequestFileFdStub(MessageParcel & data,MessageParcel & reply)48 int32_t DumpBrokerStub::RequestFileFdStub(MessageParcel& data, MessageParcel& reply)
49 {
50 int32_t ret = ERR_OK;
51 std::vector<std::u16string> args;
52 if (!data.ReadString16Vector(&args)) {
53 return ERROR_READ_PARCEL;
54 }
55 int outfd = data.ReadFileDescriptor();
56 int32_t res = Request(args, outfd);
57 if (!reply.WriteInt32(res)) {
58 return ERROR_WRITE_PARCEL;
59 }
60 return ret;
61 }
62
RequestFileFdCallbackStub(MessageParcel & data,MessageParcel & reply)63 int32_t DumpBrokerStub::RequestFileFdCallbackStub(MessageParcel& data, MessageParcel& reply)
64 {
65 int32_t ret = ERR_OK;
66 std::vector<std::u16string> args;
67 if (!data.ReadString16Vector(&args)) {
68 return ERROR_READ_PARCEL;
69 }
70 int outfd = data.ReadFileDescriptor();
71 sptr<IRemoteObject> obj = data.ReadRemoteObject();
72 if (obj == nullptr) {
73 return ERROR_READ_PARCEL;
74 }
75 sptr<IDumpCallbackBroker> callback = iface_cast<IDumpCallbackBroker>(obj);
76 if (callback == nullptr) {
77 return ERROR_READ_PARCEL;
78 }
79 int32_t res = Request(args, outfd, callback);
80 if (!reply.WriteInt32(res)) {
81 return ERROR_WRITE_PARCEL;
82 }
83 return ret;
84 }
85 } // namespace HiviewDFX
86 } // namespace OHOS
87