From 96981964c31fdb5041f1a67dfa9141653847bc57 Mon Sep 17 00:00:00 2001 From: wenyu Date: Thu, 14 Nov 2024 11:34:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=20unsigned=20char/s?= =?UTF-8?q?hort/int/long=20=E5=92=8C=20fd=20=E6=95=B0=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wenyu --- BUILD.gn | 10 + .../cpp/sa_cpp_service_stub_code_emitter.cpp | 5 + idl_tool_2/codegen/SA/sa_code_emitter.cpp | 16 +- .../codegen/SA/type/sa_fd_type_emitter.cpp | 62 +++++ .../codegen/SA/type/sa_fd_type_emitter.h | 38 +++ .../codegen/SA/type/sa_uchar_type_emitter.cpp | 62 +++++ .../codegen/SA/type/sa_uchar_type_emitter.h | 38 +++ .../codegen/SA/type/sa_uint_type_emitter.cpp | 62 +++++ .../codegen/SA/type/sa_uint_type_emitter.h | 38 +++ .../codegen/SA/type/sa_ulong_type_emitter.cpp | 62 +++++ .../codegen/SA/type/sa_ulong_type_emitter.h | 38 +++ .../SA/type/sa_ushort_type_emitter.cpp | 62 +++++ .../codegen/SA/type/sa_ushort_type_emitter.h | 38 +++ idl_tool_2/parser/intf_type_check.cpp | 5 - idl_tool_2/util/string_pool.h | 1 + test/sa_test/type_single_unsigned_fd.py | 35 +++ .../type_single_unsigned_fd/foo/IFoo.idl | 22 ++ .../target_cpp/foo_proxy.cpp.txt | 223 ++++++++++++++++++ .../target_cpp/foo_proxy.h.txt | 74 ++++++ .../target_cpp/foo_stub.cpp.txt | 147 ++++++++++++ .../target_cpp/foo_stub.h.txt | 40 ++++ .../target_cpp/ifoo.h.txt | 64 +++++ 22 files changed, 1133 insertions(+), 9 deletions(-) create mode 100644 idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp create mode 100644 idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h create mode 100644 idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp create mode 100644 idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h create mode 100644 idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp create mode 100644 idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h create mode 100644 idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp create mode 100644 idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h create mode 100644 idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp create mode 100644 idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h create mode 100644 test/sa_test/type_single_unsigned_fd.py create mode 100644 test/sa_test/type_single_unsigned_fd/foo/IFoo.idl create mode 100644 test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt create mode 100644 test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt create mode 100644 test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt create mode 100644 test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt create mode 100644 test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt diff --git a/BUILD.gn b/BUILD.gn index c764976..a79f9f2 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -232,6 +232,8 @@ common_sources += [ "idl_tool_2/codegen/SA/type/sa_char_type_emitter.h", "idl_tool_2/codegen/SA/type/sa_double_type_emitter.cpp", "idl_tool_2/codegen/SA/type/sa_double_type_emitter.h", + "idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp", + "idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h", "idl_tool_2/codegen/SA/type/sa_float_type_emitter.cpp", "idl_tool_2/codegen/SA/type/sa_float_type_emitter.h", "idl_tool_2/codegen/SA/type/sa_int_type_emitter.cpp", @@ -248,6 +250,14 @@ common_sources += [ "idl_tool_2/codegen/SA/type/sa_short_type_emitter.h", "idl_tool_2/codegen/SA/type/sa_string_type_emitter.cpp", "idl_tool_2/codegen/SA/type/sa_string_type_emitter.h", + "idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp", + "idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h", + "idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp", + "idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h", + "idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp", + "idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h", + "idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp", + "idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h", ] common_sources += [ diff --git a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp index a40e030..e092176 100644 --- a/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/cpp/sa_cpp_service_stub_code_emitter.cpp @@ -238,6 +238,11 @@ void SaCppServiceStubCodeEmitter::EmitSaReturnParameter(const std::string &name, case TypeKind::TYPE_LIST: case TypeKind::TYPE_MAP: case TypeKind::TYPE_ARRAY: + case TypeKind::TYPE_UCHAR: + case TypeKind::TYPE_UINT: + case TypeKind::TYPE_ULONG: + case TypeKind::TYPE_USHORT: + case TypeKind::TYPE_FILEDESCRIPTOR: sb.Append(name.c_str()); break; default: diff --git a/idl_tool_2/codegen/SA/sa_code_emitter.cpp b/idl_tool_2/codegen/SA/sa_code_emitter.cpp index cc929ac..efe8423 100644 --- a/idl_tool_2/codegen/SA/sa_code_emitter.cpp +++ b/idl_tool_2/codegen/SA/sa_code_emitter.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#include +#include #include "sa_code_emitter.h" #include "ast/ast_map_type.h" #include "type/sa_boolean_type_emitter.h" @@ -28,10 +30,11 @@ #include "type/sa_interface_type_emitter.h" #include "type/sa_map_type_emitter.h" #include "type/sa_array_type_emitter.h" - -#include -#include -#include +#include "type/sa_uchar_type_emitter.h" +#include "type/sa_uint_type_emitter.h" +#include "type/sa_ulong_type_emitter.h" +#include "type/sa_ushort_type_emitter.h" +#include "type/sa_fd_type_emitter.h" #include "util/file.h" #include "util/options.h" #include "util/logger.h" @@ -49,6 +52,11 @@ SACodeEmitter::TypeEmitterMap SACodeEmitter::basicEmitters_ = { {TypeKind::TYPE_DOUBLE, new SaDoubleTypeEmitter() }, {TypeKind::TYPE_CHAR, new SaCharTypeEmitter() }, {TypeKind::TYPE_STRING, new SaStringTypeEmitter() }, + {TypeKind::TYPE_UCHAR, new SaUcharTypeEmitter() }, + {TypeKind::TYPE_UINT, new SaUintTypeEmitter() }, + {TypeKind::TYPE_ULONG, new SaUlongTypeEmitter() }, + {TypeKind::TYPE_USHORT, new SaUshortTypeEmitter() }, + {TypeKind::TYPE_FILEDESCRIPTOR, new SaFdTypeEmitter() }, }; bool SACodeEmitter::OutPut(const AutoPtr &ast, const std::string &targetDirectory, GenMode mode) diff --git a/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp new file mode 100644 index 0000000..aca1c02 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sa_fd_type_emitter.h" + +namespace OHOS { +namespace Idl { +TypeKind SaFdTypeEmitter::GetTypeKind() +{ + return TypeKind::TYPE_FILEDESCRIPTOR; +} + +std::string SaFdTypeEmitter::EmitCppType(TypeMode mode) const +{ + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + case TypeMode::PARAM_INOUT: + case TypeMode::LOCAL_VAR: + return "int"; + case TypeMode::PARAM_OUT: + return "int&"; + default: + return "unknown type"; + } +} + +void SaFdTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const +{ + sb.Append(prefix).AppendFormat("if (!%sWriteFileDescriptor(%s)) {\n", parcelName.c_str(), name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n"); +} + +void SaFdTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = %sReadFileDescriptor();\n", + EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadFileDescriptor();\n", name.c_str(), parcelName.c_str()); + } +} +} // namespace Idl +} // namespace OHOS \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h b/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h new file mode 100644 index 0000000..cd86835 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDL_SA_FDTYPE_EMITTER_H +#define OHOS_IDL_SA_FDTYPE_EMITTER_H + +#include "codegen/SA/sa_type_emitter.h" + +namespace OHOS { +namespace Idl { +class SaFdTypeEmitter : public SaTypeEmitter { +public: + TypeKind GetTypeKind() override; + + std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; + + void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const override; + + void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const override; +}; +} // namespace Idl +} // namespace OHOS + +#endif // OHOS_IDL_SA_FDTYPE_EMITTER_H \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp new file mode 100644 index 0000000..61181d0 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sa_uchar_type_emitter.h" + +namespace OHOS { +namespace Idl { +TypeKind SaUcharTypeEmitter::GetTypeKind() +{ + return TypeKind::TYPE_UCHAR; +} + +std::string SaUcharTypeEmitter::EmitCppType(TypeMode mode) const +{ + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + case TypeMode::PARAM_INOUT: + case TypeMode::LOCAL_VAR: + return "uint8_t"; + case TypeMode::PARAM_OUT: + return "uint8_t&"; + default: + return "unknown type"; + } +} + +void SaUcharTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const +{ + sb.Append(prefix).AppendFormat("if (!%sWriteUint8(%s)) {\n", parcelName.c_str(), name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n"); +} + +void SaUcharTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = %sReadUint8();\n", + EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadUint8();\n", name.c_str(), parcelName.c_str()); + } +} +} // namespace Idl +} // namespace OHOS \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h b/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h new file mode 100644 index 0000000..7711287 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDL_SA_UCHARTYPE_EMITTER_H +#define OHOS_IDL_SA_UCHARTYPE_EMITTER_H + +#include "codegen/SA/sa_type_emitter.h" + +namespace OHOS { +namespace Idl { +class SaUcharTypeEmitter : public SaTypeEmitter { +public: + TypeKind GetTypeKind() override; + + std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; + + void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const override; + + void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const override; +}; +} // namespace Idl +} // namespace OHOS + +#endif // OHOS_IDL_SA_UCHARTYPE_EMITTER_H \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp new file mode 100644 index 0000000..e0d12d0 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sa_uint_type_emitter.h" + +namespace OHOS { +namespace Idl { +TypeKind SaUintTypeEmitter::GetTypeKind() +{ + return TypeKind::TYPE_UINT; +} + +std::string SaUintTypeEmitter::EmitCppType(TypeMode mode) const +{ + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + case TypeMode::PARAM_INOUT: + case TypeMode::LOCAL_VAR: + return "uint32_t"; + case TypeMode::PARAM_OUT: + return "uint32_t&"; + default: + return "unknown type"; + } +} + +void SaUintTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const +{ + sb.Append(prefix).AppendFormat("if (!%sWriteUint32(%s)) {\n", parcelName.c_str(), name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n"); +} + +void SaUintTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = %sReadUint32();\n", + EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadUint32();\n", name.c_str(), parcelName.c_str()); + } +} +} // namespace Idl +} // namespace OHOS \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h b/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h new file mode 100644 index 0000000..9f510c7 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDL_SA_UINTTYPE_EMITTER_H +#define OHOS_IDL_SA_UINTTYPE_EMITTER_H + +#include "codegen/SA/sa_type_emitter.h" + +namespace OHOS { +namespace Idl { +class SaUintTypeEmitter : public SaTypeEmitter { +public: + TypeKind GetTypeKind() override; + + std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; + + void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const override; + + void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const override; +}; +} // namespace Idl +} // namespace OHOS + +#endif // OHOS_IDL_SA_UINTTYPE_EMITTER_H \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp new file mode 100644 index 0000000..98ec468 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sa_ulong_type_emitter.h" + +namespace OHOS { +namespace Idl { +TypeKind SaUlongTypeEmitter::GetTypeKind() +{ + return TypeKind::TYPE_ULONG; +} + +std::string SaUlongTypeEmitter::EmitCppType(TypeMode mode) const +{ + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + case TypeMode::PARAM_INOUT: + case TypeMode::LOCAL_VAR: + return "uint64_t"; + case TypeMode::PARAM_OUT: + return "uint64_t&"; + default: + return "unknown type"; + } +} + +void SaUlongTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const +{ + sb.Append(prefix).AppendFormat("if (!%sWriteUint64(%s)) {\n", parcelName.c_str(), name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n"); +} + +void SaUlongTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = %sReadUint64();\n", + EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadUint64();\n", name.c_str(), parcelName.c_str()); + } +} +} // namespace Idl +} // namespace OHOS \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h b/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h new file mode 100644 index 0000000..a916c22 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDL_SA_ULONGTYPE_EMITTER_H +#define OHOS_IDL_SA_ULONGTYPE_EMITTER_H + +#include "codegen/SA/sa_type_emitter.h" + +namespace OHOS { +namespace Idl { +class SaUlongTypeEmitter : public SaTypeEmitter { +public: + TypeKind GetTypeKind() override; + + std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; + + void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const override; + + void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const override; +}; +} // namespace Idl +} // namespace OHOS + +#endif // OHOS_IDL_SA_ULONGTYPE_EMITTER_H \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp b/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp new file mode 100644 index 0000000..1afca68 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sa_ushort_type_emitter.h" + +namespace OHOS { +namespace Idl { +TypeKind SaUshortTypeEmitter::GetTypeKind() +{ + return TypeKind::TYPE_USHORT; +} + +std::string SaUshortTypeEmitter::EmitCppType(TypeMode mode) const +{ + switch (mode) { + case TypeMode::NO_MODE: + case TypeMode::PARAM_IN: + case TypeMode::PARAM_INOUT: + case TypeMode::LOCAL_VAR: + return "uint16_t"; + case TypeMode::PARAM_OUT: + return "uint16_t&"; + default: + return "unknown type"; + } +} + +void SaUshortTypeEmitter::EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const +{ + sb.Append(prefix).AppendFormat("if (!%sWriteUint16(%s)) {\n", parcelName.c_str(), name.c_str()); + if (logOn_) { + sb.Append(prefix).Append(TAB).AppendFormat("HiLog::Error(LABEL, \"Write [%s] failed!\");\n", name.c_str()); + } + sb.Append(prefix).Append(TAB).Append("return ERR_INVALID_DATA;\n"); + sb.Append(prefix).Append("}\n"); +} + +void SaUshortTypeEmitter::EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const +{ + if (emitType) { + sb.Append(prefix).AppendFormat("%s %s = %sReadUint16();\n", + EmitCppType(TypeMode::LOCAL_VAR).c_str(), name.c_str(), parcelName.c_str()); + } else { + sb.Append(prefix).AppendFormat("%s = %sReadUint16();\n", name.c_str(), parcelName.c_str()); + } +} +} // namespace Idl +} // namespace OHOS \ No newline at end of file diff --git a/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h b/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h new file mode 100644 index 0000000..8296813 --- /dev/null +++ b/idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IDL_SA_USHORTTYPE_EMITTER_H +#define OHOS_IDL_SA_USHORTTYPE_EMITTER_H + +#include "codegen/SA/sa_type_emitter.h" + +namespace OHOS { +namespace Idl { +class SaUshortTypeEmitter : public SaTypeEmitter { +public: + TypeKind GetTypeKind() override; + + std::string EmitCppType(TypeMode mode = TypeMode::NO_MODE) const override; + + void EmitCppWriteVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix) const override; + + void EmitCppReadVar(const std::string &parcelName, const std::string &name, StringBuilder &sb, + const std::string &prefix, bool emitType) const override; +}; +} // namespace Idl +} // namespace OHOS + +#endif // OHOS_IDL_SA_USHORTTYPE_EMITTER_H \ No newline at end of file diff --git a/idl_tool_2/parser/intf_type_check.cpp b/idl_tool_2/parser/intf_type_check.cpp index 72588dc..8860f9d 100644 --- a/idl_tool_2/parser/intf_type_check.cpp +++ b/idl_tool_2/parser/intf_type_check.cpp @@ -97,7 +97,6 @@ bool IntfTypeChecker::CheckIntfSaAstTypes() for (const auto &pair : ast_->GetTypes()) { AutoPtr type = pair.second; switch (type->GetTypeKind()) { - case TypeKind::TYPE_FILEDESCRIPTOR: case TypeKind::TYPE_ASHMEM: case TypeKind::TYPE_NATIVE_BUFFER: case TypeKind::TYPE_POINTER: @@ -105,10 +104,6 @@ bool IntfTypeChecker::CheckIntfSaAstTypes() case TypeKind::TYPE_ENUM: case TypeKind::TYPE_STRUCT: case TypeKind::TYPE_UNION: - case TypeKind::TYPE_UCHAR: - case TypeKind::TYPE_USHORT: - case TypeKind::TYPE_UINT: - case TypeKind::TYPE_ULONG: Logger::E(TAG, StringHelper::Format("[%s:%d] error:intf sa: type '%s' not support", __func__, __LINE__, pair.first.c_str()).c_str()); return false; diff --git a/idl_tool_2/util/string_pool.h b/idl_tool_2/util/string_pool.h index 4261ffa..1e189ea 100644 --- a/idl_tool_2/util/string_pool.h +++ b/idl_tool_2/util/string_pool.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "util/string_helper.h" namespace OHOS { diff --git a/test/sa_test/type_single_unsigned_fd.py b/test/sa_test/type_single_unsigned_fd.py new file mode 100644 index 0000000..b01c8d4 --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from test_base import Test + + +class TypeSingleUnsignedFd(Test): + def get_file_name(self): + return __file__ + + def run_cpp(self): + self.set_gen_cpp_env() + return self.run_choose(True) + + def run(self): + return self.run_cpp() + + +if __name__ == "__main__": + TypeSingleUnsignedFd().test() diff --git a/test/sa_test/type_single_unsigned_fd/foo/IFoo.idl b/test/sa_test/type_single_unsigned_fd/foo/IFoo.idl new file mode 100644 index 0000000..dcc6338 --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/foo/IFoo.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface test.IFoo { + unsigned char uchar_test_func([in] unsigned char inParam, [out] unsigned char outParam, [inout] unsigned char inoutParam); + unsigned short ushort_test_func([in] unsigned short inParam, [out] unsigned short outParam, [inout] unsigned short inoutParam); + unsigned int uint_test_func([in] unsigned int inParam, [out] unsigned int outParam, [inout] unsigned int inoutParam); + unsigned long ulong_test_func([in] unsigned long inParam, [out] unsigned long outParam, [inout] unsigned long inoutParam); + FileDescriptor fd_test_func([in] FileDescriptor inParam, [out] FileDescriptor outParam, [inout] FileDescriptor inoutParam); +} diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt new file mode 100644 index 0000000..a36e957 --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.cpp.txt @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foo_proxy.h" + +namespace test { +ErrCode FooProxy::uchar_test_func( + uint8_t inParam, + uint8_t& outParam, + uint8_t inoutParam, + uint8_t& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteUint8(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteUint8(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_UCHAR_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadUint8(); + inoutParam = reply.ReadUint8(); + funcResult = reply.ReadUint8(); + return ERR_OK; +} + +ErrCode FooProxy::ushort_test_func( + uint16_t inParam, + uint16_t& outParam, + uint16_t inoutParam, + uint16_t& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteUint16(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteUint16(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_USHORT_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadUint16(); + inoutParam = reply.ReadUint16(); + funcResult = reply.ReadUint16(); + return ERR_OK; +} + +ErrCode FooProxy::uint_test_func( + uint32_t inParam, + uint32_t& outParam, + uint32_t inoutParam, + uint32_t& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteUint32(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteUint32(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_UINT_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadUint32(); + inoutParam = reply.ReadUint32(); + funcResult = reply.ReadUint32(); + return ERR_OK; +} + +ErrCode FooProxy::ulong_test_func( + uint64_t inParam, + uint64_t& outParam, + uint64_t inoutParam, + uint64_t& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteUint64(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteUint64(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_ULONG_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadUint64(); + inoutParam = reply.ReadUint64(); + funcResult = reply.ReadUint64(); + return ERR_OK; +} + +ErrCode FooProxy::fd_test_func( + int inParam, + int& outParam, + int inoutParam, + int& funcResult) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERR_INVALID_VALUE; + } + + if (!data.WriteFileDescriptor(inParam)) { + return ERR_INVALID_DATA; + } + if (!data.WriteFileDescriptor(inoutParam)) { + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (remote == nullptr) { + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest(COMMAND_FD_TEST_FUNC, data, reply, option); + if (FAILED(result)) { + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + return errCode; + } + + outParam = reply.ReadFileDescriptor(); + inoutParam = reply.ReadFileDescriptor(); + funcResult = reply.ReadFileDescriptor(); + return ERR_OK; +} +} // namespace test diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt new file mode 100644 index 0000000..9b36d7b --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_proxy.h.txt @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FOOPROXY_H +#define TEST_FOOPROXY_H + +#include "ifoo.h" +#include + +namespace test { +class FooProxy : public IRemoteProxy { +public: + explicit FooProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} + + virtual ~FooProxy() + {} + + ErrCode uchar_test_func( + uint8_t inParam, + uint8_t& outParam, + uint8_t inoutParam, + uint8_t& funcResult) override; + + ErrCode ushort_test_func( + uint16_t inParam, + uint16_t& outParam, + uint16_t inoutParam, + uint16_t& funcResult) override; + + ErrCode uint_test_func( + uint32_t inParam, + uint32_t& outParam, + uint32_t inoutParam, + uint32_t& funcResult) override; + + ErrCode ulong_test_func( + uint64_t inParam, + uint64_t& outParam, + uint64_t inoutParam, + uint64_t& funcResult) override; + + ErrCode fd_test_func( + int inParam, + int& outParam, + int inoutParam, + int& funcResult) override; + +private: + static constexpr int32_t COMMAND_UCHAR_TEST_FUNC = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_USHORT_TEST_FUNC = MIN_TRANSACTION_ID + 1; + static constexpr int32_t COMMAND_UINT_TEST_FUNC = MIN_TRANSACTION_ID + 2; + static constexpr int32_t COMMAND_ULONG_TEST_FUNC = MIN_TRANSACTION_ID + 3; + static constexpr int32_t COMMAND_FD_TEST_FUNC = MIN_TRANSACTION_ID + 4; + + static inline BrokerDelegator delegator_; +}; +} // namespace test +#endif // TEST_FOOPROXY_H + diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt new file mode 100644 index 0000000..6ca7a8b --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foo_stub.h" + +namespace test { +int32_t FooStub::OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) +{ + std::u16string localDescriptor = GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (localDescriptor != remoteDescriptor) { + return ERR_TRANSACTION_FAILED; + } + switch (code) { + case COMMAND_UCHAR_TEST_FUNC: { + uint8_t inParam = data.ReadUint8(); + uint8_t outParam; + uint8_t inoutParam = data.ReadUint8(); + uint8_t result; + ErrCode errCode = uchar_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteUint8(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint8(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint8(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_USHORT_TEST_FUNC: { + uint16_t inParam = data.ReadUint16(); + uint16_t outParam; + uint16_t inoutParam = data.ReadUint16(); + uint16_t result; + ErrCode errCode = ushort_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteUint16(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint16(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint16(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_UINT_TEST_FUNC: { + uint32_t inParam = data.ReadUint32(); + uint32_t outParam; + uint32_t inoutParam = data.ReadUint32(); + uint32_t result; + ErrCode errCode = uint_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteUint32(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint32(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint32(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_ULONG_TEST_FUNC: { + uint64_t inParam = data.ReadUint64(); + uint64_t outParam; + uint64_t inoutParam = data.ReadUint64(); + uint64_t result; + ErrCode errCode = ulong_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteUint64(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint64(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteUint64(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + case COMMAND_FD_TEST_FUNC: { + int inParam = data.ReadFileDescriptor(); + int outParam; + int inoutParam = data.ReadFileDescriptor(); + int result; + ErrCode errCode = fd_test_func(inParam, outParam, inoutParam, result); + if (!reply.WriteInt32(errCode)) { + return ERR_INVALID_VALUE; + } + if (SUCCEEDED(errCode)) { + if (!reply.WriteFileDescriptor(outParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteFileDescriptor(inoutParam)) { + return ERR_INVALID_DATA; + } + if (!reply.WriteFileDescriptor(result)) { + return ERR_INVALID_DATA; + } + } + return ERR_NONE; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + return ERR_TRANSACTION_FAILED; +} +} // namespace test diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt new file mode 100644 index 0000000..046573a --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.h.txt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FOOSTUB_H +#define TEST_FOOSTUB_H + +#include "ifoo.h" +#include + +namespace test { +class FooStub : public IRemoteStub { +public: + int32_t OnRemoteRequest( + uint32_t code, + MessageParcel& data, + MessageParcel& reply, + MessageOption& option) override; + +private: + static constexpr int32_t COMMAND_UCHAR_TEST_FUNC = MIN_TRANSACTION_ID + 0; + static constexpr int32_t COMMAND_USHORT_TEST_FUNC = MIN_TRANSACTION_ID + 1; + static constexpr int32_t COMMAND_UINT_TEST_FUNC = MIN_TRANSACTION_ID + 2; + static constexpr int32_t COMMAND_ULONG_TEST_FUNC = MIN_TRANSACTION_ID + 3; + static constexpr int32_t COMMAND_FD_TEST_FUNC = MIN_TRANSACTION_ID + 4; +}; +} // namespace test +#endif // TEST_FOOSTUB_H + diff --git a/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt new file mode 100644 index 0000000..d6612c8 --- /dev/null +++ b/test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_IFOO_H +#define TEST_IFOO_H + +#include +#include +#include + +namespace test { +class IFoo : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"test.IFoo"); + + virtual ErrCode uchar_test_func( + uint8_t inParam, + uint8_t& outParam, + uint8_t inoutParam, + uint8_t& funcResult) = 0; + + virtual ErrCode ushort_test_func( + uint16_t inParam, + uint16_t& outParam, + uint16_t inoutParam, + uint16_t& funcResult) = 0; + + virtual ErrCode uint_test_func( + uint32_t inParam, + uint32_t& outParam, + uint32_t inoutParam, + uint32_t& funcResult) = 0; + + virtual ErrCode ulong_test_func( + uint64_t inParam, + uint64_t& outParam, + uint64_t inoutParam, + uint64_t& funcResult) = 0; + + virtual ErrCode fd_test_func( + int inParam, + int& outParam, + int inoutParam, + int& funcResult) = 0; +protected: + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace test +#endif // TEST_IFOO_H +