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 "idl_test_service_proxy.h" 17 18namespace OHOS { 19 20ErrCode IdlTestServiceProxy::TestIntTransaction( 21 int32_t val) 22{ 23 MessageParcel data; 24 MessageParcel reply; 25 MessageOption option(MessageOption::TF_SYNC); 26 27 if (!data.WriteInterfaceToken(GetDescriptor())) { 28 return ERR_INVALID_VALUE; 29 } 30 31 if (!data.WriteInt32(val)) { 32 return ERR_INVALID_DATA; 33 } 34 35 sptr<IRemoteObject> remote = Remote(); 36 if (!remote) { 37 return ERR_INVALID_DATA; 38 } 39 int32_t result = remote->SendRequest( 40 static_cast<uint32_t>(IIdlTestServiceIpcCode::COMMAND_TEST_INT_TRANSACTION), data, reply, option); 41 if (FAILED(result)) { 42 return result; 43 } 44 45 ErrCode errCode = reply.ReadInt32(); 46 if (FAILED(errCode)) { 47 return errCode; 48 } 49 50 return ERR_OK; 51} 52 53ErrCode IdlTestServiceProxy::TestStringTransaction( 54 const std::string& val) 55{ 56 MessageParcel data; 57 MessageParcel reply; 58 MessageOption option(MessageOption::TF_SYNC); 59 60 if (!data.WriteInterfaceToken(GetDescriptor())) { 61 return ERR_INVALID_VALUE; 62 } 63 64 if (!data.WriteString16(Str8ToStr16(val))) { 65 return ERR_INVALID_DATA; 66 } 67 68 sptr<IRemoteObject> remote = Remote(); 69 if (!remote) { 70 return ERR_INVALID_DATA; 71 } 72 int32_t result = remote->SendRequest( 73 static_cast<uint32_t>(IIdlTestServiceIpcCode::COMMAND_TEST_STRING_TRANSACTION), data, reply, option); 74 if (FAILED(result)) { 75 return result; 76 } 77 78 ErrCode errCode = reply.ReadInt32(); 79 if (FAILED(errCode)) { 80 return errCode; 81 } 82 83 return ERR_OK; 84} 85} // namespace OHOS 86