1 /*
2 * Copyright (c) 2024 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 "child_process_request.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "parcel_macro_base.h"
20 #include "string_ex.h"
21
22 namespace OHOS {
23 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)24 bool ChildProcessRequest::ReadFromParcel(Parcel &parcel)
25 {
26 std::u16string srcEntryTemp;
27 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, srcEntryTemp);
28 srcEntry = Str16ToStr8(srcEntryTemp);
29
30 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, childProcessType);
31 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, childProcessCount);
32 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isStartWithDebug);
33
34 std::unique_ptr<ChildProcessArgs> argsRead(parcel.ReadParcelable<ChildProcessArgs>());
35 if (!argsRead) {
36 TAG_LOGE(AAFwkTag::APPMGR, "Read ChildProcessArgs failed.");
37 return false;
38 }
39 args = *argsRead;
40
41 std::unique_ptr<ChildProcessOptions> optionsRead(parcel.ReadParcelable<ChildProcessOptions>());
42 if (!optionsRead) {
43 TAG_LOGE(AAFwkTag::APPMGR, "Read ChildProcessOptions failed.");
44 return false;
45 }
46 options = *optionsRead;
47
48 return true;
49 }
50
Unmarshalling(Parcel & parcel)51 ChildProcessRequest *ChildProcessRequest::Unmarshalling(Parcel &parcel)
52 {
53 ChildProcessRequest *data = new (std::nothrow) ChildProcessRequest();
54 if (data && !data->ReadFromParcel(parcel)) {
55 TAG_LOGW(AAFwkTag::APPMGR, "Read from parcel failed.");
56 delete data;
57 data = nullptr;
58 }
59 return data;
60 }
61
Marshalling(Parcel & parcel) const62 bool ChildProcessRequest::Marshalling(Parcel &parcel) const
63 {
64 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcEntry));
65 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(childProcessType));
66 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(childProcessCount));
67 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isStartWithDebug);
68 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &args);
69 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &options);
70 return true;
71 }
72 } // namespace AppExecFwk
73 } // namespace OHOS
74