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_stub.h" 17 18namespace OHOS { 19 20int32_t IdlTestServiceStub::OnRemoteRequest( 21 uint32_t code, 22 MessageParcel& data, 23 MessageParcel& reply, 24 MessageOption& option) 25{ 26 std::u16string localDescriptor = GetDescriptor(); 27 std::u16string remoteDescriptor = data.ReadInterfaceToken(); 28 if (localDescriptor != remoteDescriptor) { 29 return ERR_TRANSACTION_FAILED; 30 } 31 switch (static_cast<IIdlTestServiceIpcCode>(code)) { 32 case IIdlTestServiceIpcCode::COMMAND_TEST_INT_TRANSACTION: { 33 int32_t val = data.ReadInt32(); 34 ErrCode errCode = TestIntTransaction(val); 35 if (!reply.WriteInt32(errCode)) { 36 return ERR_INVALID_VALUE; 37 } 38 return ERR_NONE; 39 } 40 case IIdlTestServiceIpcCode::COMMAND_TEST_STRING_TRANSACTION: { 41 std::string val = Str16ToStr8(data.ReadString16()); 42 ErrCode errCode = TestStringTransaction(val); 43 if (!reply.WriteInt32(errCode)) { 44 return ERR_INVALID_VALUE; 45 } 46 return ERR_NONE; 47 } 48 default: 49 return IPCObjectStub::OnRemoteRequest(code, data, reply, option); 50 } 51 52 return ERR_TRANSACTION_FAILED; 53} 54} // namespace OHOS 55