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_proxy.h"
16 #include <message_parcel.h>
17 #include "dump_errors.h"
18 #include "hilog_wrapper.h"
19 namespace OHOS {
20 namespace HiviewDFX {
Request(std::vector<std::u16string> & args,int outfd)21 int32_t DumpBrokerProxy::Request(std::vector<std::u16string> &args, int outfd)
22 {
23 int32_t ret = -1;
24 sptr<IRemoteObject> remote = Remote();
25 if (remote == nullptr) {
26 return ret;
27 }
28 MessageParcel data;
29 MessageParcel reply;
30 MessageOption option;
31 if (!data.WriteInterfaceToken(DumpBrokerProxy::GetDescriptor())) {
32 return ret;
33 }
34 if (!data.WriteString16Vector(args)) {
35 return ERROR_WRITE_PARCEL;
36 }
37 if (!data.WriteFileDescriptor(outfd)) {
38 return ERROR_WRITE_PARCEL;
39 }
40 int res = remote->SendRequest(static_cast<int>(IDumpBroker::DUMP_REQUEST_FILEFD),
41 data, reply, option);
42 if (res != ERR_OK) {
43 DUMPER_HILOGE(MODULE_ZIDL, "error|SendRequest error code: %{public}d", res);
44 return ret;
45 }
46 if (!reply.ReadInt32(ret)) {
47 return ERROR_READ_PARCEL;
48 }
49 return ret;
50 }
51 } // namespace HiviewDFX
52 } // namespace OHOS
53