mirror of
https://gitee.com/openharmony/ability_idl_tool
synced 2024-11-27 01:20:37 +00:00
增加对 unsigned char/short/int/long 和 fd 数据类型的支持
Signed-off-by: wenyu <wenyu16@huawei.com>
This commit is contained in:
parent
22d8add51d
commit
96981964c3
10
BUILD.gn
10
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 += [
|
||||
|
@ -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:
|
||||
|
@ -13,6 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#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 <cctype>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#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> &ast, const std::string &targetDirectory, GenMode mode)
|
||||
|
62
idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp
Normal file
62
idl_tool_2/codegen/SA/type/sa_fd_type_emitter.cpp
Normal file
@ -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
|
38
idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h
Normal file
38
idl_tool_2/codegen/SA/type/sa_fd_type_emitter.h
Normal file
@ -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
|
62
idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp
Normal file
62
idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.cpp
Normal file
@ -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
|
38
idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h
Normal file
38
idl_tool_2/codegen/SA/type/sa_uchar_type_emitter.h
Normal file
@ -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
|
62
idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp
Normal file
62
idl_tool_2/codegen/SA/type/sa_uint_type_emitter.cpp
Normal file
@ -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
|
38
idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h
Normal file
38
idl_tool_2/codegen/SA/type/sa_uint_type_emitter.h
Normal file
@ -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
|
62
idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp
Normal file
62
idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.cpp
Normal file
@ -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
|
38
idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h
Normal file
38
idl_tool_2/codegen/SA/type/sa_ulong_type_emitter.h
Normal file
@ -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
|
62
idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp
Normal file
62
idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.cpp
Normal file
@ -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
|
38
idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h
Normal file
38
idl_tool_2/codegen/SA/type/sa_ushort_type_emitter.h
Normal file
@ -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
|
@ -97,7 +97,6 @@ bool IntfTypeChecker::CheckIntfSaAstTypes()
|
||||
for (const auto &pair : ast_->GetTypes()) {
|
||||
AutoPtr<ASTType> 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;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "util/string_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
|
35
test/sa_test/type_single_unsigned_fd.py
Normal file
35
test/sa_test/type_single_unsigned_fd.py
Normal file
@ -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()
|
22
test/sa_test/type_single_unsigned_fd/foo/IFoo.idl
Normal file
22
test/sa_test/type_single_unsigned_fd/foo/IFoo.idl
Normal file
@ -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);
|
||||
}
|
@ -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<IRemoteObject> 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<IRemoteObject> 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<IRemoteObject> 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<IRemoteObject> 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<IRemoteObject> 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
|
@ -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 <iremote_proxy.h>
|
||||
|
||||
namespace test {
|
||||
class FooProxy : public IRemoteProxy<IFoo> {
|
||||
public:
|
||||
explicit FooProxy(
|
||||
const sptr<IRemoteObject>& remote)
|
||||
: IRemoteProxy<IFoo>(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<FooProxy> delegator_;
|
||||
};
|
||||
} // namespace test
|
||||
#endif // TEST_FOOPROXY_H
|
||||
|
147
test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt
Normal file
147
test/sa_test/type_single_unsigned_fd/target_cpp/foo_stub.cpp.txt
Normal file
@ -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
|
@ -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 <iremote_stub.h>
|
||||
|
||||
namespace test {
|
||||
class FooStub : public IRemoteStub<IFoo> {
|
||||
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
|
||||
|
64
test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt
Normal file
64
test/sa_test/type_single_unsigned_fd/target_cpp/ifoo.h.txt
Normal file
@ -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 <cstdint>
|
||||
#include <iremote_broker.h>
|
||||
#include <string_ex.h>
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user