From: Hwankyu Jhun Date: Mon, 2 Jan 2023 07:45:50 +0000 (+0000) Subject: Support map & set container type X-Git-Tag: accepted/tizen/unified/20230420.153149~23 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bf2255bafcd792e60e57dd589126455d8938fe6d;p=platform%2Fcore%2Fappfw%2Ftidl.git Support map & set container type From protocol version 2, the map & set container types are supported. The developer can define the map and the set in the tidl files. Change-Id: I4195762b2fadaec5cdb7935390344c81f696e9f5 Signed-off-by: Hwankyu Jhun --- diff --git a/idlc/ast/tidlc.ll b/idlc/ast/tidlc.ll index b4faed03..4e2a8a12 100644 --- a/idlc/ast/tidlc.ll +++ b/idlc/ast/tidlc.ll @@ -121,6 +121,14 @@ yylval->token = new tidl::Token(yytext, comments); return yy::parser::token::T_ARRAY; } +"map" { + yylval->token = new tidl::Token(yytext, comments); + return yy::parser::token::T_MAP; + } +"set" { + yylval->token = new tidl::Token(yytext, comments); + return yy::parser::token::T_SET; + } "struct" { yylval->token = new tidl::Token(yytext, comments); return yy::parser::token::T_STRUCTURE; diff --git a/idlc/ast/tidlc.yy b/idlc/ast/tidlc.yy index f83e5a4d..80f2c12a 100644 --- a/idlc/ast/tidlc.yy +++ b/idlc/ast/tidlc.yy @@ -70,6 +70,8 @@ int yylex(yy::parser::semantic_type *, yy::parser::location_type *, void *); %token T_BOOL %token T_LIST %token T_ARRAY +%token T_MAP +%token T_SET %token T_VALUE %token T_SB_OPEN %token T_SB_CLOSE @@ -528,9 +530,25 @@ raw_type: container_type { ; container_type: container_type_name T_META_OPEN base_type T_META_CLOSE { - $$ = new tidl::BaseType($1->ToString(), $1->GetComments()); - $$->SetMetaType($3); - delete $1; + if ($1->ToString() == "map") { + ps->ReportError("syntax error. The value must be existed.", @1.begin.line); + delete $1; + } else { + $$ = new tidl::BaseType($1->ToString(), $1->GetComments()); + $$->SetMetaType($3); + delete $1; + } + } + | container_type_name T_META_OPEN base_type T_COMMA base_type T_META_CLOSE { + if ($1->ToString() != "map") { + ps->ReportError("syntax error. The container type must be \"map\".", @1.begin.line); + delete $1; + } else { + $$ = new tidl::BaseType($1->ToString(), $1->GetComments()); + $$->SetKeyType($3); + $$->SetValueType($5); + delete $1; + } } ; @@ -542,6 +560,22 @@ container_type_name: T_LIST { $$ = new tidl::Token("array", $1->GetComments()); delete $1; } + | T_MAP { + if (ps->GetVersion() < 2) { + ps->ReportError("syntax error. \"No identifier\".", @1.begin.line); + ps->ReportError("try to use protocol version 2.", @1.begin.line); + } + $$ = new tidl::Token("map", $1->GetComments()); + delete $1; + } + | T_SET { + if (ps->GetVersion() < 2) { + ps->ReportError("syntax error. \"No identifier\".", @1.begin.line); + ps->ReportError("try to use protocol version 2.", @1.begin.line); + } + $$ = new tidl::Token("set", $1->GetComments()); + delete $1; + } ; %% diff --git a/idlc/ast/type.cc b/idlc/ast/type.cc index a4a3bec3..adfcbd2c 100644 --- a/idlc/ast/type.cc +++ b/idlc/ast/type.cc @@ -33,15 +33,66 @@ BaseType::BaseType(std::string name, std::string comments, BaseType::BaseType(const BaseType& type) : Token(type.ToString(), type.GetComments()), user_defined_(type.IsUserDefinedType()) { - if (type.GetMetaType() != nullptr) { + if (type.GetMetaType() != nullptr) SetMetaType(new BaseType(*type.GetMetaType())); - } + + if (type.GetKeyType() != nullptr) + SetKeyType(new BaseType(*type.GetKeyType())); + + if (type.GetValueType() != nullptr) + SetValueType(new BaseType(*type.GetValueType())); } void BaseType::SetMetaType(BaseType* type) { meta_type_.reset(type); } +const BaseType* BaseType::GetMetaType() const { + return meta_type_.get(); +} + +void BaseType::SetKeyType(BaseType* type) { + key_type_.reset(type); +} + +const BaseType* BaseType::GetKeyType() const { + return key_type_.get(); +} + +void BaseType::SetValueType(BaseType* type) { + value_type_.reset(type); +} + +const BaseType* BaseType::GetValueType() const { + return value_type_.get(); +} + +std::string BaseType::GetFullName(bool use_underbar) const { + std::string name = ToString(); + + if (meta_type_.get() != nullptr) { + name += use_underbar ? "_" : "<"; + name += meta_type_->GetFullName(use_underbar); + name += use_underbar ? "" : ">"; + } else if (key_type_.get() != nullptr) { + name += use_underbar ? "_" : "<"; + name += key_type_->GetFullName(use_underbar); + + if (value_type_.get() != nullptr) { + name += use_underbar ? "_" : ", "; + name += value_type_->GetFullName(use_underbar); + } + + name += use_underbar ? "" : ">"; + } + + return name; +} + +bool BaseType::IsUserDefinedType() const { + return user_defined_; +} + ParameterType::ParameterType(BaseType* type) : type_(type), dir_(Direction::IN) { } diff --git a/idlc/ast/type.h b/idlc/ast/type.h index 77427ea4..f148e93b 100644 --- a/idlc/ast/type.h +++ b/idlc/ast/type.h @@ -42,28 +42,21 @@ class BaseType : public Token { BaseType(const BaseType& type); void SetMetaType(BaseType* type); - const BaseType* GetMetaType() const { - return meta_type_.get(); - } + const BaseType* GetMetaType() const; - std::string GetFullName() const { - std::string str = ToString(); + void SetKeyType(BaseType* type); + const BaseType* GetKeyType() const; - if (meta_type_.get() != nullptr) { - str += "<"; - str += meta_type_->GetFullName(); - str += ">"; - } + void SetValueType(BaseType* type); + const BaseType* GetValueType() const; - return str; - } - - bool IsUserDefinedType() const { - return user_defined_; - } + std::string GetFullName(bool use_underbar = false) const; + bool IsUserDefinedType() const; private: std::unique_ptr meta_type_; + std::unique_ptr key_type_; + std::unique_ptr value_type_; bool user_defined_; }; diff --git a/idlc/gen/c_gen_base.cc b/idlc/gen/c_gen_base.cc index df2ac1a1..39accc8b 100644 --- a/idlc/gen/c_gen_base.cc +++ b/idlc/gen/c_gen_base.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 - 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 - 2023 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,23 +14,71 @@ * limitations under the License. */ -#include +#include "idlc/gen/c_gen_base.h" + +#include #include -#include +#include #include -#include +#include +#include -#include "idlc/gen/c_gen_base.h" +#include "idlc/gen/c_gen_base_cb.h" +namespace tidl { namespace { -#include "idlc/gen/c_gen_base_cb.h" constexpr const char PREFIX_RPC_PORT_PROXY[] = "rpc_port_proxy"; constexpr const char PREFIX_RPC_PORT_STUB[] = "rpc_port_stub"; -} // namespace +Structure* CreateStructure(std::string type_name, BaseType* key_type, + BaseType* value_type) { + if (key_type == nullptr || value_type == nullptr) + return nullptr; + + auto* elms = new Elements(); + if (elms == nullptr) + return nullptr; + + elms->Add( + std::unique_ptr( + new Element(key_type->GetFullName(true), key_type, "", __LINE__))); + elms->Add( + std::unique_ptr( + new Element(value_type->GetFullName(true), value_type, "", __LINE__))); + + auto* st = new Structure(std::move(type_name), elms, "", __LINE__); + if (st == nullptr) { + delete elms; + return nullptr; + } -namespace tidl { + return st; +} + +Structure* CreateStructure(std::string type_name, BaseType* elm_type) { + if (elm_type == nullptr) + return nullptr; + + auto* elms = new Elements(); + if (elms == nullptr) + return nullptr; + + elms->Add( + std::unique_ptr( + new Element(elm_type->GetFullName(true), elm_type, "", __LINE__))); + + auto* st = new Structure( + std::move(type_name), elms, "", __LINE__); + if (st == nullptr) { + delete elms; + return nullptr; + } + + return st; +} + +} // namespace CGeneratorBase::CGeneratorBase(std::shared_ptr doc) : Generator(doc) { @@ -68,14 +116,7 @@ std::string CGeneratorBase::NLine(int cnt) { } std::string CGeneratorBase::GetFullNameFromType(const BaseType& type) { - std::string str = type.ToString(); - - if (type.GetMetaType() != nullptr) { - str += "_"; - str += GetFullNameFromType(*type.GetMetaType()); - } - - return str; + return type.GetFullName(true); } std::string CGeneratorBase::GetFullNameFromType(const BaseType& type, @@ -89,6 +130,11 @@ std::string CGeneratorBase::GetFullNameFromType(const BaseType& type, if (type.GetMetaType() != nullptr) { str += "_"; str += GetFullNameFromType(*type.GetMetaType(), iface); + } else if (type.GetKeyType() != nullptr) { + str += "_"; + str += GetFullNameFromType(*type.GetKeyType(), iface); + str += "_"; + str += GetFullNameFromType(*type.GetValueType(), iface); } return str; @@ -99,7 +145,7 @@ std::string CGeneratorBase::GetDataTypeString(const BaseType& type, if (type.IsUserDefinedType()) return GetHandlePrefix() + "_" + type.ToString() + "_h "; - if (type.GetMetaType() != nullptr) + if (type.GetMetaType() != nullptr || type.GetKeyType() != nullptr) return GetHandlePrefix() + "_" + GetFullNameFromType(type) + "_h "; if (type.ToString() == "string" || type.ToString() == "file") @@ -118,32 +164,32 @@ std::string CGeneratorBase::GetReturnTypeString(const BaseType& type) { if (type.IsUserDefinedType()) return GetHandlePrefix() + "_" + type.ToString() + "_h "; - if (type.GetMetaType() != nullptr) + if (type.GetMetaType() != nullptr || type.GetKeyType() != nullptr) return GetHandlePrefix() + "_" + GetFullNameFromType(type) + "_h "; return type_map_[type.ToString()]; } void CGeneratorBase::AddStructureFromType(const BaseType& type) { - if (type.GetMetaType() == nullptr) + auto* meta_type = type.GetMetaType(); + auto* key_type = type.GetKeyType(); + if (meta_type == nullptr && key_type == nullptr) return; - BaseType* t = new BaseType(*type.GetMetaType()); - assert(t != nullptr); - + Structure* st; std::string type_name = GetFullNameFromType(type); - auto elm = std::unique_ptr(new Element(type_name, t, "", __LINE__)); - assert(elm != nullptr); - - Elements* elms = new Elements(); - assert(elms != nullptr); - elms->Add(std::move(elm)); - - auto* st = new Structure(type_name, elms, "", __LINE__); + if (meta_type != nullptr) { + AddStructureFromType(*meta_type); + st = CreateStructure(type_name, new BaseType(*meta_type)); + } else { + AddStructureFromType(*key_type); + auto* value_type = type.GetValueType(); + AddStructureFromType(*value_type); + st = CreateStructure(type_name, new BaseType(*key_type), + new BaseType(*value_type)); + } assert(st != nullptr); - AddStructureFromType(*type.GetMetaType()); - if (StructureExist(st)) { delete st; return; @@ -154,30 +200,25 @@ void CGeneratorBase::AddStructureFromType(const BaseType& type) { void CGeneratorBase::AddStructureFromType(const BaseType& type, const Interface& iface) { - if (type.GetMetaType() == nullptr) + auto* meta_type = type.GetMetaType(); + auto* key_type = type.GetKeyType(); + if (meta_type == nullptr && key_type == nullptr) return; - BaseType* t = nullptr; - if (IsDelegateType(iface, *type.GetMetaType())) - t = new BaseType(GetFullNameFromType(*type.GetMetaType(), iface), "", true); - else - t = new BaseType(*type.GetMetaType()); - - assert(t != nullptr); - + Structure* st; std::string type_name = GetFullNameFromType(type, iface); - auto elm = std::unique_ptr(new Element(type_name, t, "", __LINE__)); - assert(elm != nullptr); - - Elements* elms = new Elements(); - assert(elms != nullptr); - elms->Add(std::move(elm)); - - auto* st = new Structure(type_name, elms, "", __LINE__); + if (meta_type != nullptr) { + AddStructureFromType(*meta_type, iface); + st = CreateStructure(type_name, new BaseType(*meta_type)); + } else { + AddStructureFromType(*key_type, iface); + auto* value_type = type.GetValueType(); + AddStructureFromType(*value_type); + st = CreateStructure(type_name, new BaseType(*key_type), + new BaseType(*value_type)); + } assert(st != nullptr); - AddStructureFromType(*type.GetMetaType(), iface); - if (StructureExist(st)) { delete st; return; @@ -382,7 +423,9 @@ bool CGeneratorBase::StructureExist(const Structure* st) { std::string CGeneratorBase::GetParamTypeString( ParameterType::Direction direction, const BaseType& type) { - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { if (direction == ParameterType::Direction::IN) return GetHandlePrefix() + "_" + GetFullNameFromType(type) + "_h "; else @@ -405,7 +448,9 @@ std::string CGeneratorBase::GetParamTypeString( std::string CGeneratorBase::GetParamTypeString( ParameterType::Direction direction, const BaseType& type, const Interface& iface) { - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { if (direction == ParameterType::Direction::IN) { return GetHandlePrefix() + "_" + GetFullNameFromType(type, iface) + "_h "; } else { @@ -429,7 +474,9 @@ std::string CGeneratorBase::GetParamTypeString( std::string CGeneratorBase::GetArgTypeString(const BaseType& type, const Interface& iface) { - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) return GetHandlePrefix() + "_" + GetFullNameFromType(type, iface) + "_h "; return type_map_[type.ToString()]; @@ -438,6 +485,7 @@ std::string CGeneratorBase::GetArgTypeString(const BaseType& type, std::string CGeneratorBase::GetErrorValue(const BaseType& type) { if (type.IsUserDefinedType() || type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr || type.ToString() == "bundle" || type.ToString() == "string"|| type.ToString() == "file") diff --git a/idlc/gen/version2/c_body_generator_base.cc b/idlc/gen/version2/c_body_generator_base.cc index 66832171..f6a7e423 100644 --- a/idlc/gen/version2/c_body_generator_base.cc +++ b/idlc/gen/version2/c_body_generator_base.cc @@ -18,12 +18,31 @@ #include +#include + #include "idlc/gen/version2/c_body_generator_array_base_cb.hh" #include "idlc/gen/version2/c_body_generator_base_cb.hh" #include "idlc/gen/version2/c_body_generator_list_base_cb.hh" +#include "idlc/gen/version2/c_body_generator_map_base_cb.hh" +#include "idlc/gen/version2/c_body_generator_set_base_cb.hh" namespace tidl { namespace version2 { +namespace { + +bool IsPtrType(const BaseType& type) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr || + type.ToString() == "string" || + type.ToString() == "bundle" || + type.ToString() == "file") + return true; + + return false; +} + +} // namespace CBodyGeneratorBase::CBodyGeneratorBase(std::shared_ptr doc) : tidl::CBodyGeneratorBase(std::move(doc)) { } @@ -76,10 +95,20 @@ void CBodyGeneratorBase::GenStructureListBaseDefinition(std::ofstream& stream, void CBodyGeneratorBase::GenStructureMapBaseDefinition(std::ofstream& stream, const Structure& st) { + ReplaceAll(CB_STRUCTURE_MAP_DEF) + .Change("", GetHandlePrefix()) + .Change("", st.GetID()) + .Transform([&](std::string code) { return SmartIndent(code); }) + .Out(stream); } void CBodyGeneratorBase::GenStructureSetBaseDefinition(std::ofstream& stream, const Structure& st) { + ReplaceAll(CB_STRUCTURE_SET_DEF) + .Change("", GetHandlePrefix()) + .Change("", st.GetID()) + .Transform([&](std::string code) { return SmartIndent(code); }) + .Out(stream); } std::string CBodyGeneratorBase::GenBaseElements(const Elements& elms) { @@ -135,7 +164,9 @@ std::string CBodyGeneratorBase::GenArrayUnitMapWrite( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { code = ReplaceAll(CB_STRUCTURE_ARRAY_USER_DEFINED_UNIT_MAP_WRITE) .Change("", GetFullNameFromType(type)); } else if (type.ToString() == "bundle") { @@ -154,7 +185,9 @@ std::string CBodyGeneratorBase::GenArrayUnitMapRead( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { code = ReplaceAll(CB_STRUCTURE_ARRAY_USER_DEFINED_UNIT_MAP_READ) .Change("", GetFullNameFromType(type)); } else if (type.ToString() == "bundle") { @@ -173,7 +206,9 @@ std::string CBodyGeneratorBase::GenArrayElementsFree( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { code = ReplaceAll(CB_STRUCTURE_ARRAY_USER_DEFINED_FREE) .Change("", GetHandlePrefix()) .Change("", GetFullNameFromType(type)); @@ -216,7 +251,9 @@ std::string CBodyGeneratorBase::GenListDataFree( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { code = ReplaceAll(CB_STRUCTURE_LIST_USER_DEFINED_FREE) .Change("", GetHandlePrefix()) .Change("", GetFullNameFromType(type)); @@ -235,7 +272,9 @@ std::string CBodyGeneratorBase::GenListUnitMapWrite( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { code = ReplaceAll(CB_STRUCTURE_LIST_USER_DEFINED_UNIT_MAP_WRITE) .Change("", GetFullNameFromType(type)); } else if (type.ToString() == "bundle") { @@ -254,7 +293,9 @@ std::string CBodyGeneratorBase::GenListUnitMapRead( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { code = ReplaceAll(CB_STRUCTURE_LIST_USER_DEFINED_UNIT_MAP_READ) .Change("", GetFullNameFromType(type)); } else if (type.ToString() == "bundle") { @@ -276,7 +317,9 @@ std::string CBodyGeneratorBase::GenListAdd( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { code = ReplaceAll(CB_STRUCTURE_LIST_USER_DEFINED_ADD) .Change("", GetHandlePrefix()) .Change("", GetFullNameFromType(type)); @@ -297,14 +340,10 @@ std::string CBodyGeneratorBase::GenListCallbackParamType( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || - type.GetMetaType() != nullptr || - type.ToString() == "bundle" || - type.ToString() == "string" || - type.ToString() == "file") + if (IsPtrType(type)) code = std::string("value"); else - code = std::string ("*value"); + code = std::string("*value"); return code; } @@ -329,19 +368,513 @@ void CBodyGeneratorBase::GenStructureListBase(std::ofstream& stream, .Out(stream); } +std::string CBodyGeneratorBase::GenMapContains(const BaseType& key_type) { + std::string code; + if (IsPtrType(key_type)) + code = CB_MAP_CONTAINS_KEY_PTR_TYPE; + else + code = CB_MAP_CONTAINS_KEY_BASE_TYPE; + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapKeyExistNullCheck( + const BaseType& key_type) { + std::string code; + if (IsPtrType(key_type)) + code = CB_MAP_HANDLE_KEY_EXIST_NULL_CHECK; + else + code = CB_MAP_HANDLE_EXIST_NULL_CHECK; + + return code; +} + +std::string CBodyGeneratorBase::GenMapForeachVarsDefinition( + const BaseType& key_type, const BaseType& value_type) { + std::string code; + bool is_key_ptr = IsPtrType(key_type); + bool is_value_ptr = IsPtrType(value_type); + if (is_key_ptr && is_value_ptr) + code = CB_MAP_FOREACH_VARS_DEF_KEY_PTR_VALUE_PTR_TYPE; + else if (is_key_ptr && !is_value_ptr) + code = CB_MAP_FOREACH_VARS_DEF_KEY_PTR_VALUE_BASE_TYPE; + else if (!is_key_ptr && is_value_ptr) + code = CB_MAP_FOREACH_VARS_DEF_KEY_BASE_VALUE_PTR_TYPE; + else + code = CB_MAP_FOREACH_VARS_DEF_KEY_BASE_VALUE_BASE_TYPE; + + code = ReplaceAll(code) + .Change("", + RemoveLastSpaces(GetDataTypeString(key_type, false))) + .Change("", + RemoveLastSpaces(GetDataTypeString(value_type, false))); + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapErase(const BaseType& key_type) { + std::string code; + if (IsPtrType(key_type)) + code = CB_MAP_ERASE_KEY_PTR_TYPE; + else + code = CB_MAP_ERASE_KEY_BASE_TYPE; + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapKeyNullCheck( + const BaseType& key_type) { + std::string code; + if (IsPtrType(key_type)) + code = CB_MAP_HANDLE_KEY_NULL_CHECK; + else + code = CB_MAP_HANDLE_NULL_CHECK; + + return code; +} + +std::string CBodyGeneratorBase::GenMapLookupValueSet( + const BaseType& value_type) { + std::string code; + if (value_type.IsUserDefinedType() || + value_type.GetMetaType() != nullptr || + value_type.GetKeyType() != nullptr) { + code = ReplaceAll(CB_MAP_LOOKUP_VALUE_USER_DEFINED_SET) + .Change("", GetHandlePrefix()) + .Change("", value_type.GetFullName(true)); + } else if (value_type.ToString() == "bundle") { + code = CB_MAP_LOOKUP_VALUE_BUNDLE_SET; + } else if (value_type.ToString() == "string") { + code = CB_MAP_LOOKUP_VALUE_STRING_SET; + } else { + code = ReplaceAll(CB_MAP_LOOKUP_VALUE_BASE_SET) + .Change("", + RemoveLastSpaces(GetDataTypeString(value_type, false))); + } + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapLookup( + const BaseType& key_type, const BaseType& value_type) { + std::string code; + if (IsPtrType(key_type)) { + code = ReplaceAll(CB_MAP_LOOKUP_KEY_PTR_TYPE) + .Change("", GenMapLookupValueSet(value_type)); + } else { + code = ReplaceAll(CB_MAP_LOOKUP_KEY_BASE_TYPE) + .Change("", GenMapLookupValueSet(value_type)); + } + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapKeyValueNullCheck( + const BaseType& key_type) { + std::string code; + if (IsPtrType(key_type)) + code = CB_MAP_HANDLE_KEY_VALUE_NULL_CHECK; + else + code = CB_MAP_HANDLE_VALUE_NULL_CHECK; + + return code; +} + +std::string CBodyGeneratorBase::GenMapInsertNewKeyFree( + const BaseType& key_type) { + std::string code; + if (key_type.IsUserDefinedType() || + key_type.GetMetaType() != nullptr || + key_type.GetKeyType() != nullptr) { + code = ReplaceAll(CB_MAP_INSERT_NEW_KEY_USER_DEFINED_FREE) + .Change("", GetHandlePrefix()) + .Change("", key_type.GetFullName(true)); + } else if (key_type.ToString() == "bundle") { + code = CB_MAP_INSERT_NEW_KEY_BUNDLE_FREE; + } else if (key_type.ToString() == "string" || key_type.ToString() == "file") { + code = CB_MAP_INSERT_NEW_KEY_STRING_FREE; + } else { + code = CB_MAP_INSERT_NEW_KEY_BASE_FREE; + } + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapInsertNewValueImpl( + const BaseType& key_type, const BaseType& value_type) { + std::string code; + if (value_type.IsUserDefinedType() || + value_type.GetMetaType() != nullptr || + value_type.GetKeyType() != nullptr) { + code = ReplaceAll(CB_MAP_INSERT_NEW_VALUE_USER_DEFINED_IMPL) + .Change("", GetHandlePrefix()) + .Change("", value_type.GetFullName(true)); + } else if (value_type.ToString() == "bundle") { + code = CB_MAP_INSERT_NEW_VALUE_BUNDLE_IMPL; + } else if (value_type.ToString() == "string" || + value_type.ToString() == "file") { + code = CB_MAP_INSERT_NEW_VALUE_STRING_IMPL; + } else { + code = ReplaceAll(CB_MAP_INSERT_NEW_VALUE_BASE_IMPL) + .Change("", + RemoveLastSpaces(GetDataTypeString(value_type, false))); + } + + code = ReplaceAll(code) + .Change("", GenMapInsertNewKeyFree(key_type)); + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapInsertNewKeyImpl( + const BaseType& key_type) { + std::string code; + if (key_type.IsUserDefinedType() || + key_type.GetMetaType() != nullptr || + key_type.GetKeyType() != nullptr) { + code = ReplaceAll(CB_MAP_INSERT_NEW_KEY_USER_DEFINED_IMPL) + .Change("", GetHandlePrefix()) + .Change("", key_type.GetFullName(true)); + } else if (key_type.ToString() == "bundle") { + code = CB_MAP_INSERT_NEW_KEY_BUNDLE_IMPL; + } else if (key_type.ToString() == "string" || key_type.ToString() == "file") { + code = CB_MAP_INSERT_NEW_KEY_STRING_IMPL; + } else { + code = ReplaceAll(CB_MAP_INSERT_NEW_KEY_BASE_IMPL) + .Change("", + RemoveLastSpaces(GetDataTypeString(key_type, false))); + } + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapInsert( + const BaseType& key_type, const BaseType& value_type) { + std::string code; + code = ReplaceAll(CB_MAP_INSERT) + .Change("", GenMapInsertNewKeyImpl(key_type)) + .Change("", + GenMapInsertNewValueImpl(key_type, value_type)); + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapKeyValueNullCheck( + const BaseType& key_type, const BaseType& value_type) { + std::string code; + bool is_key_ptr = IsPtrType(key_type); + bool is_value_ptr = IsPtrType(value_type); + if (is_key_ptr && is_value_ptr) + code = CB_MAP_HANDLE_KEY_VALUE_NULL_CHECK; + else if (is_key_ptr && !is_value_ptr) + code = CB_MAP_HANDLE_KEY_NULL_CHECK; + else if (!is_key_ptr && is_value_ptr) + code = CB_MAP_HANDLE_VALUE_NULL_CHECK; + else + code = CB_MAP_HANDLE_NULL_CHECK; + + return code; +} + +std::string CBodyGeneratorBase::GenMapFreeFunc( + const BaseType& type) { + std::string code; + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { + code = ReplaceAll(CB_MAP_USER_DEFINED_FREE_FUNC) + .Change("", GetHandlePrefix()) + .Change("", type.GetFullName(true)); + } else if (type.ToString() == "bundle") { + code = CB_MAP_BUNDLE_FREE_FUNC; + } else { + code = CB_MAP_FREE_FUNC; + } + + return code; +} + +std::string CBodyGeneratorBase::GenMapCompareKeyVarsDefinition( + const BaseType& type) { + std::string code; + if (IsPtrType(type)) { + code = ReplaceAll(CB_MAP_COMPARE_KEY_VARS_DEF_PTR_TYPE) + .Change("", RemoveLastSpaces(GetDataTypeString(type, false))); + } else { + code = ReplaceAll(CB_MAP_COMPARE_KEY_VARS_DEF_BASE_TYPE) + .Change("", RemoveLastSpaces(GetDataTypeString(type, false))); + } + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapUnitMapValueRead( + const BaseType& type) { + std::string code; + code = ReplaceAll(CB_MAP_UNIT_MAP_VALUE_READ) + .Change("", type.GetFullName(true)); + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapUnitMapKeyRead( + const BaseType& type) { + std::string code; + code = ReplaceAll(CB_MAP_UNIT_MAP_KEY_READ) + .Change("", type.GetFullName(true)); + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapUnitMapValueWrite( + const BaseType& type) { + std::string code; + if (IsPtrType(type)) { + code = ReplaceAll(CB_MAP_UNIT_MAP_VALUE_WRITE_PTR_TYPE) + .Change("", type.GetFullName(true)) + .Change("", + RemoveLastSpaces(GetDataTypeString(type, false))); + } else { + code = ReplaceAll(CB_MAP_UNIT_MAP_VALUE_WRITE_BASE_TYPE) + .Change("", type.GetFullName(true)) + .Change("", + RemoveLastSpaces(GetDataTypeString(type, false))); + } + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenMapUnitMapKeyWrite( + const BaseType& type) { + std::string code; + if (IsPtrType(type)) { + code = ReplaceAll(CB_MAP_UNIT_MAP_KEY_WRITE_PTR_TYPE) + .Change("", type.GetFullName(true)) + .Change("", RemoveLastSpaces(GetDataTypeString(type, false))); + } else { + code = ReplaceAll(CB_MAP_UNIT_MAP_KEY_WRITE_BASE_TYPE) + .Change("", type.GetFullName(true)) + .Change("", RemoveLastSpaces(GetDataTypeString(type, false))); + } + + return RemoveLine(code); +} + void CBodyGeneratorBase::GenStructureMapBase(std::ofstream& stream, const Structure& st) { + auto iter = st.GetElements().begin(); + if (std::next(iter) == st.GetElements().end()) + return; + + auto& key_elm = *(iter); + auto& key_type = key_elm->GetType(); + auto key_param_type = GetParamTypeString(ParameterType::Direction::IN, + key_type); + auto& value_elm = *(std::next(iter)); + auto& value_type = value_elm->GetType(); + auto value_param_type = GetParamTypeString(ParameterType::Direction::IN, + value_type); + auto value_param_type_out = GetParamTypeString(ParameterType::Direction::OUT, + value_type); + + ReplaceAll(CB_STRUCTURE_MAP_BASE) + .Change("", GetHandlePrefix()) + .Change("", st.GetID()) + .Change("", GetDataTypeString(key_type, false)) + .Change("", GetDataTypeString(value_type, false)) + .Change("", key_param_type) + .Change("", value_param_type) + .Change("", value_param_type_out) + .Change("", GenMapUnitMapKeyWrite(key_type)) + .Change("", GenMapUnitMapValueWrite(value_type)) + .Change("", GenMapUnitMapKeyRead(key_type)) + .Change("", GenMapUnitMapValueRead(value_type)) + .Change("", + GenMapCompareKeyVarsDefinition(key_type)) + .Change("", GenMapFreeFunc(key_type)) + .Change("", GenMapFreeFunc(value_type)) + .Change("", + GenMapKeyValueNullCheck(key_type, value_type)) + .Change("", GenMapInsert(key_type, value_type)) + .Change("", + GenMapKeyValueNullCheck(key_type)) + .Change("", GenMapLookup(key_type, value_type)) + .Change("", GenMapKeyNullCheck(key_type)) + .Change("", GenMapErase(key_type)) + .Change("", + GenMapKeyValueNullCheck(key_type, value_type)) + .Change("", + GenMapForeachVarsDefinition(key_type, value_type)) + .Change("", + GenMapKeyExistNullCheck(key_type)) + .Change("", GenMapContains(key_type)) + .Transform([&](std::string code) { return SmartIndent(code); }) + .Out(stream); +} + +std::string CBodyGeneratorBase::GenSetContains(const BaseType& type) { + std::string code; + if (IsPtrType(type)) + code = CB_SET_CONTAINS_KEY_PTR_TYPE; + else + code = CB_SET_CONTAINS_KEY_BASE_TYPE; + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenSetKeyExistNullCheck( + const BaseType& type) { + std::string code; + if (IsPtrType(type)) + code = CB_SET_HANDLE_KEY_EXIST_NULL_CHECK; + else + code = CB_SET_HANDLE_EXIST_NULL_CHECK; + + return code; +} + +std::string CBodyGeneratorBase::GenSetForeachKeyVarDefinition( + const BaseType& type) { + std::string code; + if (IsPtrType(type)) { + code = ReplaceAll(CB_SET_FOREACH_VARS_DEF_KEY_PTR_TYPE) + .Change("", RemoveLastSpaces(GetDataTypeString(type, false))); + } else { + code = ReplaceAll(CB_SET_FOREACH_VARS_DEF_KEY_BASE_TYPE) + .Change("", RemoveLastSpaces(GetDataTypeString(type, false))); + } + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenSetErase(const BaseType& type) { + std::string code; + if (IsPtrType(type)) + code = CB_SET_ERASE_KEY_PTR_TYPE; + else + code = CB_SET_ERASE_KEY_BASE_TYPE; + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenSetInsert(const BaseType& type) { + std::string code; + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { + code = ReplaceAll(CB_SET_INSERT_KEY_USER_DEFINED_IMPL) + .Change("", GetHandlePrefix()) + .Change("", type.GetFullName(true)); + } else if (type.ToString() == "bundle") { + code = CB_SET_INSERT_KEY_BUNDLE_IMPL; + } else if (type.ToString() == "string" || type.ToString() == "file") { + code = CB_SET_INSERT_KEY_STRING_IMPL; + } else { + code = ReplaceAll(CB_SET_INSERT_KEY_BASE_IMPL) + .Change("", + RemoveLastSpaces(GetDataTypeString(type, false))); + } + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenSetKeyNullCheck(const BaseType& type) { + std::string code; + if (IsPtrType(type)) + code = CB_SET_HANDLE_KEY_NULL_CHECK; + else + code = CB_SET_HANDLE_NULL_CHECK; + + return code; +} + +std::string CBodyGeneratorBase::GenSetKeyFreeFunc(const BaseType& type) { + std::string code; + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { + code = ReplaceAll(CB_SET_USER_DEFINED_FREE_FUNC) + .Change("", GetHandlePrefix()) + .Change("", type.GetFullName(true)); + } else if (type.ToString() == "bundle") { + code = CB_SET_BUNDLE_FREE_FUNC; + } else { + code = CB_SET_FREE_FUNC; + } + + return code; +} + +std::string CBodyGeneratorBase::GenSetCompareKeyVarsDefinition( + const BaseType& type) { + std::string code; + if (IsPtrType(type)) { + code = ReplaceAll(CB_SET_COMPARE_KEY_VARS_DEF_PTR_TYPE) + .Change("", RemoveLastSpaces(GetDataTypeString(type, false))); + } else { + code = ReplaceAll(CB_SET_COMPARE_KEY_VARS_DEF_BASE_TYPE) + .Change("", RemoveLastSpaces(GetDataTypeString(type, false))); + } + + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenSetUnitMapKeyRead(const BaseType& type) { + std::string code; + code = ReplaceAll(CB_SET_UNIT_MAP_KEY_READ) + .Change("", type.GetFullName(true)); + return RemoveLine(code); +} + +std::string CBodyGeneratorBase::GenSetUnitMapKeyWrite(const BaseType& type) { + std::string code; + if (IsPtrType(type)) { + code = ReplaceAll(CB_SET_UNIT_MAP_KEY_WRITE_PTR_TYPE) + .Change("", type.GetFullName(true)) + .Change("", RemoveLastSpaces(GetDataTypeString(type, false))); + } else { + code = ReplaceAll(CB_SET_UNIT_MAP_KEY_WRITE_BASE_TYPE) + .Change("", type.GetFullName(true)) + .Change("", RemoveLastSpaces(GetDataTypeString(type, false))); + } + + return RemoveLine(code); } void CBodyGeneratorBase::GenStructureSetBase(std::ofstream& stream, const Structure& st) { + auto& key_elm = *(st.GetElements().begin()); + auto& key_type = key_elm->GetType(); + auto key_param_type = GetParamTypeString(ParameterType::Direction::IN, + key_type); + + ReplaceAll(CB_STRUCTURE_SET_BASE) + .Change("", GetHandlePrefix()) + .Change("", st.GetID()) + .Change("", GetDataTypeString(key_type, false)) + .Change("", key_param_type) + .Change("", GenSetUnitMapKeyWrite(key_type)) + .Change("", GenSetUnitMapKeyRead(key_type)) + .Change("", + GenSetCompareKeyVarsDefinition(key_type)) + .Change("", GenSetKeyFreeFunc(key_type)) + .Change("", GenSetKeyNullCheck(key_type)) + .Change("", GenSetInsert(key_type)) + .Change("", GenSetKeyNullCheck(key_type)) + .Change("", GenSetErase(key_type)) + .Change("", + GenSetForeachKeyVarDefinition(key_type)) + .Change("", + GenSetKeyExistNullCheck(key_type)) + .Change("", GenSetContains(key_type)) + .Transform([&](std::string code) { return SmartIndent(code); }) + .Out(stream); } std::string CBodyGeneratorBase::GenBaseElementFree( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { code = ReplaceAll(CB_STRUCTURE_BASE_USER_DEFINED_FREE) .Change("", GetHandlePrefix()) .Change("", GetFullNameFromType(type)) @@ -393,7 +926,9 @@ std::string CBodyGeneratorBase::GenBaseSet( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { code = ReplaceAll(CB_STRUCTURE_BASE_USER_DEFINED_SET) .Change("", GetHandlePrefix()) .Change("", GetFullNameFromType(type)) @@ -419,7 +954,9 @@ std::string CBodyGeneratorBase::GenBaseGet( const std::unique_ptr& elm) { std::string code; auto& type = elm->GetType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { code = ReplaceAll(CB_STRUCTURE_BASE_USER_DEFINED_GET) .Change("", GetHandlePrefix()) .Change("", GetFullNameFromType(type)) @@ -479,14 +1016,56 @@ void CBodyGeneratorBase::GenStructureBase(std::ofstream& stream, void CBodyGeneratorBase::AddParameterType(const Interface& iface, const BaseType& type, ParameterType::Direction direction) { if (IsDelegateType(iface, type)) { + AddParameterType( + std::make_shared( + new BaseType("delegate", "delegate", true), + ParameterType::Direction::IN)); + AddParameterType( + std::make_shared( + new BaseType("delegate", "delegate", true), + ParameterType::Direction::OUT)); return; - } else if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + } else if (type.IsUserDefinedType()) { + AddParameterType( + std::make_shared( + new BaseType(type), ParameterType::Direction::IN)); + AddParameterType( + std::make_shared( + new BaseType(type), ParameterType::Direction::OUT)); + } else if (type.GetMetaType() != nullptr) { + AddParameterType( + std::make_shared( + new BaseType(type), ParameterType::Direction::IN)); + AddParameterType( + std::make_shared( + new BaseType(type), ParameterType::Direction::OUT)); + AddParameterType( + std::make_shared( + new BaseType(*type.GetMetaType()), ParameterType::Direction::IN)); + AddParameterType( + std::make_shared( + new BaseType(*type.GetMetaType()), ParameterType::Direction::OUT)); + } else if (type.GetKeyType() != nullptr) { AddParameterType( std::make_shared( new BaseType(type), ParameterType::Direction::IN)); AddParameterType( std::make_shared( new BaseType(type), ParameterType::Direction::OUT)); + AddParameterType( + std::make_shared( + new BaseType(*type.GetKeyType()), ParameterType::Direction::IN)); + AddParameterType( + std::make_shared( + new BaseType(*type.GetKeyType()), ParameterType::Direction::OUT)); + if (type.GetValueType() != nullptr) { + AddParameterType( + std::make_shared( + new BaseType(*type.GetValueType()), ParameterType::Direction::IN)); + AddParameterType( + std::make_shared( + new BaseType(*type.GetValueType()), ParameterType::Direction::OUT)); + } } else if (type.GetFullName() != "file") { AddParameterType( std::make_shared( @@ -496,7 +1075,7 @@ void CBodyGeneratorBase::AddParameterType(const Interface& iface, void CBodyGeneratorBase::AddParameterType( std::shared_ptr param_type) { - std::string key = param_type->GetBaseType().GetFullName() + + std::string key = param_type->GetBaseType().GetFullName(true) + std::to_string(static_cast(param_type->GetDirection())); if (param_types_.find(key) != param_types_.end()) @@ -547,11 +1126,7 @@ void CBodyGeneratorBase::GenParameterMap() { AddParameterType( std::make_shared( new BaseType("delegate", "delegate", true), - ParameterType::Direction::IN)); - AddParameterType( - std::make_shared( - new BaseType("delegate", "delegate", true), - ParameterType::Direction::OUT)); + ParameterType::Direction::OUT)); AddParameterType( std::make_shared( new BaseType(iface.GetID() + "_" + decl->GetID(), "", true), @@ -584,6 +1159,23 @@ void CBodyGeneratorBase::GenParameterMap() { } } } + + for (auto& i : GetStructures()) { + auto& st = *i.second; + AddParameterType( + std::make_shared( + new BaseType(st.GetID(), st.GetID(), true))); + + for (auto& elm : st.GetElements()) { + auto& type = elm->GetType(); + AddParameterType( + std::make_shared( + new BaseType(type), ParameterType::Direction::IN)); + AddParameterType( + std::make_shared( + new BaseType(type), ParameterType::Direction::OUT)); + } + } } void CBodyGeneratorBase::GenUnitMapBase(std::ofstream& stream) { @@ -624,7 +1216,9 @@ std::string CBodyGeneratorBase::GenUnitMapWrite( const ParameterType& param_type) { std::string code; auto& type = param_type.GetBaseType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { if (type.ToString() == "delegate") { code = std::string(CB_UNIT_MAP_DELEGATE_WRITE); } else { @@ -654,7 +1248,9 @@ std::string CBodyGeneratorBase::GenUnitMapRead( const ParameterType& param_type) { std::string code; auto& type = param_type.GetBaseType(); - if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) { + if (type.IsUserDefinedType() || + type.GetMetaType() != nullptr || + type.GetKeyType() != nullptr) { if (type.ToString() == "delegate") { code = std::string(CB_UNIT_MAP_DELEGATE_READ); } else { diff --git a/idlc/gen/version2/c_body_generator_base.hh b/idlc/gen/version2/c_body_generator_base.hh index 34f6cad1..aae3b421 100644 --- a/idlc/gen/version2/c_body_generator_base.hh +++ b/idlc/gen/version2/c_body_generator_base.hh @@ -59,7 +59,41 @@ class CBodyGeneratorBase : public tidl::CBodyGeneratorBase { std::string GenListAdd(const std::unique_ptr& elm); std::string GenListCallbackParamType(const std::unique_ptr& elm); void GenStructureListBase(std::ofstream& stream, const Structure& st); + std::string GenMapContains(const BaseType& key_type); + std::string GenMapKeyExistNullCheck(const BaseType& key_type); + std::string GenMapForeachVarsDefinition(const BaseType& key_type, + const BaseType& value_type); + std::string GenMapErase(const BaseType& key_type); + std::string GenMapKeyNullCheck(const BaseType& key_type); + std::string GenMapLookupValueSet(const BaseType& value_type); + std::string GenMapLookup(const BaseType& key_type, + const BaseType& value_type); + std::string GenMapKeyValueNullCheck(const BaseType& key_type); + std::string GenMapInsertNewKeyFree(const BaseType& key_type); + std::string GenMapInsertNewValueImpl(const BaseType& key_type, + const BaseType& value_type); + std::string GenMapInsertNewKeyImpl(const BaseType& key_type); + std::string GenMapInsert(const BaseType& key_type, + const BaseType& value_type); + std::string GenMapKeyValueNullCheck(const BaseType& key_type, + const BaseType& value_type); + std::string GenMapFreeFunc(const BaseType& type); + std::string GenMapCompareKeyVarsDefinition(const BaseType& type); + std::string GenMapUnitMapValueRead(const BaseType& type); + std::string GenMapUnitMapKeyRead(const BaseType& type); + std::string GenMapUnitMapValueWrite(const BaseType& type); + std::string GenMapUnitMapKeyWrite(const BaseType& type); void GenStructureMapBase(std::ofstream& stream, const Structure& st); + std::string GenSetContains(const BaseType& type); + std::string GenSetKeyExistNullCheck(const BaseType& type); + std::string GenSetForeachKeyVarDefinition(const BaseType& type); + std::string GenSetErase(const BaseType& type); + std::string GenSetInsert(const BaseType& type); + std::string GenSetKeyNullCheck(const BaseType& type); + std::string GenSetKeyFreeFunc(const BaseType& type); + std::string GenSetCompareKeyVarsDefinition(const BaseType& type); + std::string GenSetUnitMapKeyRead(const BaseType& type); + std::string GenSetUnitMapKeyWrite(const BaseType& type); void GenStructureSetBase(std::ofstream& stream, const Structure& st); std::string GenBaseElementFree(const std::unique_ptr& elm); std::string GenBaseElementsFree(const Elements& elms); diff --git a/idlc/gen/version2/c_body_generator_map_base_cb.hh b/idlc/gen/version2/c_body_generator_map_base_cb.hh new file mode 100644 index 00000000..93f76806 --- /dev/null +++ b/idlc/gen/version2/c_body_generator_map_base_cb.hh @@ -0,0 +1,789 @@ +/* + * Copyright (c) 2023 Samsung Electronics 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 IDLC_GEN_VERSION2_C_BODY_GENERATOR_MAP_BASE_CB_HH_ +#define IDLC_GEN_VERSION2_C_BODY_GENERATOR_MAP_BASE_CB_HH_ + +namespace tidl { +namespace version2 { + +/** + * The prefix of the map structure. + * The name of the map structure. + */ +constexpr const char CB_STRUCTURE_MAP_DEF[] = +R"__c_cb( +typedef struct __s { + rpc_port_parcelable_t parcelable; + GTree *node; + __compare_cb compare_cb; + void *user_data; +} __t; + +static __compare_cb ____compare_cb; +static void *____user_data; + +typedef struct __traverse_info_s { + rpc_port_unit_map_h map; + int number; +} __traverse_info_t; + +typedef struct __foreach_info_s { + __foreach_cb callback; + void *user_data; +} __foreach_info_t; +)__c_cb"; + +/** + * The prefix of the map structure. + * The name of the map structure. + * The type of the key of the map. + * The type of the value of the map. + * The parameter type of the key of the map. + * The parameter type of the value of the map. + * The output parameter type of the value of the map. + * The implementation to write the key to the unit map. + * The implementation to write the value to the unit map. + * The implementation to read the key from the unit map. + * The implementation to read the value from the unit map. + * The definition of the key variables of the compare callback function. + * The implementation to free the key. + * The implementation to free the value. + * The implementation to check whether the arg is nullptr or not. + * The implementation to insert the key and the value to the map. + * The implementation to check whether the arg is nullptr or not. + * The implementation to set the lookuped data to the output value. + * The implementation to check whether the arg is nullptr or not. + * The implementation to erase the element from the map. + * The impementation to check whether the arg is nullptr or not. + * The definition of the key variable of the foreach callback function. + * The definition of the value variable of the foreach callback function. + * The implementation to check whether the arg is nullptr or not. + * The implementation to check whether the key exists or not. + */ +constexpr const char CB_STRUCTURE_MAP_BASE[] = +R"__c_cb( +static gboolean ____traverse_cb(gpointer key, gpointer value, gpointer user_data) +{ + __traverse_info_t *info = user_data; + char name[32]; + + snprintf(name, sizeof(name), "key-%d", info->number); + + + snprintf(name, sizeof(name), "value-%d", info->number++); + + + return TRUE; +} + +static void ____to(rpc_port_parcel_h parcel, void *data) +{ + __traverse_info_t info; + __h h = data; + rpc_port_unit_map_h map; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + map = rpc_port_unit_map_create(); + if (map == nullptr) { + _E("Failed to create unit map"); + set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY); + return; + } + + rpc_port_unit_map_write_int(map, "size", g_tree_nnodes(h->node)); + + info.map = map; + info.number = 0; + g_tree_foreach(h->node, ____traverse_cb, &info); + + rpc_port_parcel_write(parcel, &map->parcelable, map); + rpc_port_unit_map_destroy(map); + set_last_result(RPC_PORT_ERROR_NONE); +} + +static void ____from(rpc_port_parcel_h parcel, void *data) +{ + __h h = data; + key; + value; + rpc_port_unit_map_h map; + char name[32]; + int size = 0; + int ret; + int i; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + map = rpc_port_unit_map_create(); + if (map == nullptr) { + _E("Failed to create unit map"); + set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY); + return; + } + + rpc_port_parcel_read(parcel, &map->parcelable, map); + + ret = rpc_port_unit_map_read_int(parcel, "size", &size); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to read size. error(%d)", ret); + rpc_port_unit_map_destroy(map); + set_last_result(ret); + return; + } + + for (i = 0; i < size; ++i) { + snprintf(name, sizeof(name), "key-%d", i); + + snprintf(name, sizeof(name), "value-%d", i); + + + ret = __insert(h, key, value); + if (ret != RPC_PORT_ERROR_NONE) { + rpc_port_unit_map_destroy(map); + set_last_result(ret); + return; + } + } + + rpc_port_unit_map_destroy(map); + set_last_result(RPC_PORT_ERROR_NONE); +} + +static gint ____comparison_cb(gconstpointer a, gconstpointer b, gpointer user_data) +{ + + + if (____compare_cb == nullptr) { + _E("__set_compare_cb() MUST be called"); + return -1; + } + + return ____compare_cb(key_a, key_b, ____user_data); +} + +int __create(__h *h) +{ + __t *handle; + + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (____compare_cb == nullptr) { + _E("__set_compare_cb() MUST be called"); + return RPC_PORT_ERROR_IO_ERROR; + } + + handle = calloc(1, sizeof(__t)); + if (handle == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + handle->node = g_tree_new_full((GCompareDataFunc)____comparison_cb, handle, (GDestroyNotify), (GDestroyNotify)); + if (handle->node == nullptr) { + _E("g_tree_new_full() is failed"); + free(handle); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + handle->parcelable.to = ____to; + handle->parcelable.from = ____from; + + *h = handle; + + return RPC_PORT_ERROR_NONE; +} + +int __destroy(__h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (h->node) + g_tree_destroy(h->node); + + free(h); + + return RPC_PORT_ERROR_NONE; +} + +int __clone(__h h, __h *clone) +{ + rpc_port_unit_map_h map; + int ret; + + if (h == nullptr || clone == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + map = rpc_port_unit_map_create(); + if (map == nullptr) { + _E("Failed to create unit map"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + ret = rpc_port_unit_map_write_(map, "clone", h); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to write . error(%d)", ret); + rpc_port_unit_map_destroy(map); + return ret; + } + + ret = rpc_port_unit_map_read_(map, "clone", clone); + rpc_port_unit_map_destroy(map); + + return ret; +} + +int __set_compare_cb(__compare_cb callback, void *user_data) +{ + if (callback == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ____compare_cb = callback; + ____user_data = user_data; + + return RPC_PORT_ERROR_NONE; +} + +int __insert(__h h, key, value) +{ + int ret; + + if () { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + + + return RPC_PORT_ERROR_NONE; +} + +int __lookup(__h h, key, value) +{ + gpointer data; + + if () { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + + + return RPC_PORT_ERROR_NONE; +} + +int __erase(__h h, key) +{ + if () { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + + + return RPC_PORT_ERROR_NONE; +} + +int __replace(__h h, key, value) +{ + if () { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + __erase(h, key); + return __insert(h, key, value); +} + +static gboolean ____foreach_cb(gpointer key, gpointer value, gpointer user_data) +{ + __foreach_info_t *info = user_data; + + + return info->callback(tmp_key, tmp_value, info->user_data); +} + +int __foreach(__h h, __foreach_cb callback, void *user_data) +{ + __foreach_info_t info; + + if (h == nullptr || callback == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + info.callback = callback; + info.user_data = user_data; + + g_tree_foreach(h->node, ____foreach_cb, &info); + + return RPC_PORT_ERROR_NONE; +} + +int __contains(__h h, key, bool *exist) +{ + gpointer data; + + if () { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + + + return RPC_PORT_ERROR_NONE; +} + +int __size(__h h, size_t *size) +{ + if (h == nullptr || size == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *size = g_tree_nnodes(h->node); + + return RPC_PORT_ERROR_NONE; +} + +int __clear(__h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + g_tree_remove_all(h->node); + + return RPC_PORT_ERROR_NONE; +} +)__c_cb"; + +/** + * The name of the key. + * The type of the key. + */ +constexpr const char CB_MAP_UNIT_MAP_KEY_WRITE_PTR_TYPE[] = +R"__c_cb( +rpc_port_unit_map_write_(info->map, name, ()key); +)__c_cb"; + +/** + * The name of the key. + * The pointer type of the key. + */ +constexpr const char CB_MAP_UNIT_MAP_KEY_WRITE_BASE_TYPE[] = +R"__c_cb( +rpc_port_unit_map_write_(info->map, name, *( *)key); +)__c_cb"; + +/** + * The name of the value. + * The type of the value. + */ +constexpr const char CB_MAP_UNIT_MAP_VALUE_WRITE_PTR_TYPE[] = +R"__c_cb( +rpc_port_unit_map_write_(info->map, name, ()value); +)__c_cb"; + +/** + * The name of the value. + * The pointer type of the value. + */ +constexpr const char CB_MAP_UNIT_MAP_VALUE_WRITE_BASE_TYPE[] = +R"__c_cb( +rpc_port_unit_map_write_(info->map, name, *( *)value); +)__c_cb"; + +/** + * The name of the key. + */ +constexpr const char CB_MAP_UNIT_MAP_KEY_READ[] = +R"__c_cb( +rpc_port_unit_map_read_(map, name, &key); +)__c_cb"; + +/** + * The name of the value. + */ +constexpr const char CB_MAP_UNIT_MAP_VALUE_READ[] = +R"__c_cb( +rpc_port_unit_map_read_(map, name, &value); +)__c_cb"; + +/** + * The type of the key. + */ +constexpr const char CB_MAP_COMPARE_KEY_VARS_DEF_PTR_TYPE[] = +R"__c_cb( + key_a = ()a; + key_b = ()b; +)__c_cb"; + +/** + * The type of the key. + */ +constexpr const char CB_MAP_COMPARE_KEY_VARS_DEF_BASE_TYPE[] = +R"__c_cb( + key_a = *( *)a; + key_b = *( *)b; +)__c_cb"; + +/** + * The prefix of the user defined type. + * The name of the user defined type. + */ +constexpr const char CB_MAP_USER_DEFINED_FREE_FUNC[] = +R"__c_cb(__destroy)__c_cb"; + +constexpr const char CB_MAP_BUNDLE_FREE_FUNC[] = +R"__c_cb(bundle_free)__c_cb"; + +constexpr const char CB_MAP_FREE_FUNC[] = +R"__c_cb(free)__c_cb"; + +constexpr const char CB_MAP_HANDLE_KEY_VALUE_NULL_CHECK[] = +R"__c_cb(h == nullptr || key == nullptr || value == nullptr)__c_cb"; + +constexpr const char CB_MAP_HANDLE_KEY_NULL_CHECK[] = +R"__c_cb(h == nullptr || key == nullptr)__c_cb"; + +constexpr const char CB_MAP_HANDLE_VALUE_NULL_CHECK[] = +R"__c_cb(h == nullptr || value == nullptr)__c_cb"; + +constexpr const char CB_MAP_HANDLE_KEY_EXIST_NULL_CHECK[] = +R"__c_cb(h == nullptr || key == nullptr || exist == nullptr)__c_cb"; + +constexpr const char CB_MAP_HANDLE_EXIST_NULL_CHECK[] = +R"__c_cb(h == nullptr || exist == nullptr)__c_cb"; + +constexpr const char CB_MAP_HANDLE_NULL_CHECK[] = +R"__c_cb(h == nullptr)__c_cb"; + +/** + * The implementation to create a new varaible of the key for the map container. + * The implementation to create a new varaible of the value for the map container. + */ +constexpr const char CB_MAP_INSERT[] = +R"__c_cb( + + + +g_tree_insert(h->node, (gpointer)new_key, (gpointer)new_value); +)__c_cb"; + +/** + * The prefix of the user defined type. + * The name of the user defined type. + */ +constexpr const char CB_MAP_INSERT_NEW_KEY_USER_DEFINED_IMPL[] = +R"__c_cb( +if (g_tree_lookup(h->node, (gpointer)key) != nullptr) { + _E("Already exists. Try to use replace function"); + return RPC_PORT_ERROR_INVALID_PARAMETER; +} + +__h new_key = nullptr; +ret = __clone(key, &new_key); +if (ret != RPC_PORT_ERROR_NONE) + return ret; +)__c_cb"; + +constexpr const char CB_MAP_INSERT_NEW_KEY_BUNDLE_IMPL[] = +R"__c_cb( +if (g_tree_lookup(h->node, (gpointer)key) != nullptr) { + _E("Already exists. Try to use replace function"); + return RPC_PORT_ERROR_INVALID_PARAMETER; +} + +bundle *new_key = bundle_dup(key); +if (new_key == nullptr) { + ret = RPC_PORT_ERROR_INVALID_PARAMETER; + return ret; +} +)__c_cb"; + +constexpr const char CB_MAP_INSERT_NEW_KEY_STRING_IMPL[] = +R"__c_cb( +if (g_tree_lookup(h->node, (gpointer)key) != nullptr) { + _E("Already exists. Try to use replace function"); + return RPC_PORT_ERROR_INVALID_PARAMETER; +} + +char *new_key = strdup(key); +if (new_key == nullptr) { + ret = RPC_PORT_ERROR_INVALID_PARAMETER; + return ret; +} +)__c_cb"; + +/** + * The type of the key. + */ +constexpr const char CB_MAP_INSERT_NEW_KEY_BASE_IMPL[] = +R"__c_cb( + *new_key = malloc(sizeof()); +if (new_key == nullptr) { + _E("malloc() is failed"); + ret = RPC_PORT_ERROR_OUT_OF_MEMORY; + return ret; +} + +*new_key = key; +if (g_tree_lookup(h->node, (gpointer)new_key) != nullptr) { + _E("Already exists. Try to use replace function"); + free(new_key); + return RPC_PORT_ERROR_INVALID_PARAMETER; +} +)__c_cb"; + +/** + * The prefix of the user defined type. + * The name of the user defined type. + * The implementation to free the newly key variable. + */ +constexpr const char CB_MAP_INSERT_NEW_VALUE_USER_DEFINED_IMPL[] = +R"__c_cb( +__h new_value = nullptr; +ret = __clone(value, &new_value); +if (ret != RPC_PORT_ERROR_NONE) { + + return ret; +} +)__c_cb"; + +/** + * The implementation to free the newly key variable. + */ +constexpr const char CB_MAP_INSERT_NEW_VALUE_BUNDLE_IMPL[] = +R"__c_cb( +bundle *new_value = bundle_dup(value); +if (new_value == nullptr) { + + return RPC_PORT_ERROR_OUT_OF_MEMORY; +} +)__c_cb"; + +/** + * The implementation to free the newly key variable. + */ +constexpr const char CB_MAP_INSERT_NEW_VALUE_STRING_IMPL[] = +R"__c_cb( +char *new_value = strdup(value); +if (new_value == nullptr) { + + return RPC_PORT_ERROR_OUT_OF_MEMORY; +} +)__c_cb"; + +/** + * The type of the value. + * The implementation to free the newly key variable. + */ +constexpr const char CB_MAP_INSERT_NEW_VALUE_BASE_IMPL[] = +R"__c_cb( + *new_value = malloc(sizeof()); +if (new_value == nullptr) { + + return RPC_PORT_ERROR_OUT_OF_MEMORY; +} + +*new_value = value; +)__c_cb"; + +/** + * The prefix of the user defined type. + * The name of the user defined type. + */ +constexpr const char CB_MAP_INSERT_NEW_KEY_USER_DEFINED_FREE[] = +R"__c_cb( +__destroy(new_key); +)__c_cb"; + +constexpr const char CB_MAP_INSERT_NEW_KEY_BUNDLE_FREE[] = +R"__c_cb( +bundle_free(new_key); +)__c_cb"; + +constexpr const char CB_MAP_INSERT_NEW_KEY_STRING_FREE[] = +R"__c_cb( +free(new_key); +)__c_cb"; + +constexpr const char CB_MAP_INSERT_NEW_KEY_BASE_FREE[] = +R"__c_cb( +free(new_key); +)__c_cb"; + +/** + * The implementation to set the value for the map container. + */ +constexpr const char CB_MAP_LOOKUP_KEY_PTR_TYPE[] = +R"__c_cb( +data = g_tree_lookup(h->node, (gpointer)key); +if (data == nullptr) { + _E("g_tree_lookup() is failed"); + return RPC_PORT_ERROR_INVALID_PARAMETER; +} + + +)__c_cb"; + +/** + * The implementation to set the value for the map container. + */ +constexpr const char CB_MAP_LOOKUP_KEY_BASE_TYPE[] = +R"__c_cb( +data = g_tree_lookup(h->node, (gpointer)&key); +if (data == nullptr) { + _E("g_tree_lookup() is failed"); + return RPC_PORT_ERROR_INVALID_PARAMETER; +} + + +)__c_cb"; + +/** + * The prefix of the user defined type. + * The name of the user defined type. + */ +constexpr const char CB_MAP_LOOKUP_VALUE_USER_DEFINED_SET[] = +R"__c_cb( +__h new_value = nullptr; +int ret = __clone((__h)data, &new_value); +if (ret != RPC_PORT_ERROR_NONE) + return ret; + +*value = (__h)new_value; +)__c_cb"; + +constexpr const char CB_MAP_LOOKUP_VALUE_BUNDLE_SET[] = +R"__c_cb( +bundle *new_value = bundle_dup((bundle *)data); +if (new_value == nullptr) { + _E("bundle_dup() is failed"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; +} + +*value = new_value; +)__c_cb"; + +constexpr const char CB_MAP_LOOKUP_VALUE_STRING_SET[] = +R"__c_cb( +char *new_value = strdup((char *)data); +if (new_value == nullptr) { + _E("strdup() is failed'0; + return RPC_PORT_ERROR_OUT_OF_MEMORY; +} + +*value = new_value; +)__c_cb"; + +/** + * The type of the value. + */ +constexpr const char CB_MAP_LOOKUP_VALUE_BASE_SET[] = +R"__c_cb( +*value = *( *)data; +)__c_cb"; + +constexpr const char CB_MAP_ERASE_KEY_PTR_TYPE[] = +R"__c_cb( +if (!g_tree_remove(h->node, (gpointer)key)) + _W("g_tree_remove() is failed"); +)__c_cb"; + +constexpr const char CB_MAP_ERASE_KEY_BASE_TYPE[] = +R"__c_cb( +if (!g_tree_remove(h->node, (gpointer)&key)) + _W("g_tree_remove() is failed"); +)__c_cb"; + +/** + * The type of the key. + * the type of the value. + */ +constexpr const char CB_MAP_FOREACH_VARS_DEF_KEY_PTR_VALUE_PTR_TYPE[] = +R"__c_cb( + tmp_key = ()key; + tmp_value = ()value; +)__c_cb"; + +/** + * The type of the key. + * the type of the value. + */ +constexpr const char CB_MAP_FOREACH_VARS_DEF_KEY_PTR_VALUE_BASE_TYPE[] = +R"__c_cb( + tmp_key = ()key; + tmp_value = *( *)value; +)__c_cb"; + +/** + * The type of the key. + * the type of the value. + */ +constexpr const char CB_MAP_FOREACH_VARS_DEF_KEY_BASE_VALUE_PTR_TYPE[] = +R"__c_cb( + tmp_key = *( *)key; + tmp_value = ()value; +)__c_cb"; + +/** + * The type of the key. + * the type of the value. + */ +constexpr const char CB_MAP_FOREACH_VARS_DEF_KEY_BASE_VALUE_BASE_TYPE[] = +R"__c_cb( + tmp_key = *( *)key; + tmp_value = *( *)value; +)__c_cb"; + +constexpr const char CB_MAP_CONTAINS_KEY_PTR_TYPE[] = +R"__c_cb( +data = g_tree_lookup(h->node, (gpointer)key); +*exist = (data != nullptr) ? true : false; +)__c_cb"; + +constexpr const char CB_MAP_CONTAINS_KEY_BASE_TYPE[] = +R"__c_cb( +data = g_tree_lookup(h->node, (gpointer)&key); +*exist = (data != nullptr) ? true : false; +)__c_cb"; + +} // namespace version2 +} // namespace tidl + +#endif // IDLC_GEN_VERSION2_C_BODY_GENERATOR_MAP_BASE_CB_HH_ diff --git a/idlc/gen/version2/c_body_generator_set_base_cb.hh b/idlc/gen/version2/c_body_generator_set_base_cb.hh new file mode 100644 index 00000000..2ea25548 --- /dev/null +++ b/idlc/gen/version2/c_body_generator_set_base_cb.hh @@ -0,0 +1,512 @@ +/* + * Copyright (c) 2023 Samsung Electronics 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 IDLC_GEN_VERSION2_C_BODY_GENERATOR_SET_BASE_CB_HH_ +#define IDLC_GEN_VERSION2_C_BODY_GENERATOR_SET_BASE_CB_HH_ + +namespace tidl { +namespace version2 { + +/** + * The prefix of the set structure. + * The name of the set structure. + */ +constexpr const char CB_STRUCTURE_SET_DEF[] = +R"__c_cb( +typedef struct __s { + rpc_port_parcelable_t parcelable; + GTree *node; +} __t; + +static __compare_cb ____compare_cb; +static void *____user_data; + +typedef struct __traverse_info_s { + rpc_port_unit_map_h map; + int number; +} __traverse_info_t; + +typedef struct __foreach_info_s { + __foreach_cb callback; + void *user_data; +} __foreach_info_t; +)__c_cb"; + +/** + * The prefix of the set structure. + * The name of the set structure. + * The type of the key of the set. + * The parameter type of the key of the set. + * The implementation to write the key to the unit map. + * The implementation to read the key from the unit map. + * The definition of the key variables of the compare callback function. + * The implementation to free the key. + * The implementation to check whether the arg is nullptr or not. + * The implementation to insert the key and the value to the set. + * The implementation to check whether the arg is nullptr or not. + * The implementation to erase the element from the set. + * The definition of the key variable of the foreach callback function. + * The implementation to check whether the arg is nullptr or not. + * The implementation to check whether the key exists or not. + */ +constexpr const char CB_STRUCTURE_SET_BASE[] = +R"__c_cb( +static gboolean ____traverse_cb(gpointer key, gpointer value, gpointer user_data) +{ + __traverse_info_t *info = user_data; + char name[32]; + + snprintf(name, sizeof(name), "key-%d", info->number++); + + + return TRUE; +} + +static void ____to(rpc_port_parcel_h parcel, void *data) +{ + __traverse_info_t info; + __h h = data; + rpc_port_unit_map_h map; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + map = rpc_port_unit_map_create(); + if (map == nullptr) { + _E("Failed to create unit map"); + set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY); + return; + } + + rpc_port_unit_map_write_int(map, "size", g_tree_nnodes(h->node)); + + info.map = map; + info.number = 0; + g_tree_foreach(h->node, ____traverse_cb, &info); + + rpc_port_parcel_write(parcel, &map->parcelable, map); + rpc_port_unit_map_destroy(map); + set_last_result(RPC_PORT_ERROR_NONE); +} + +static void ____from(rpc_port_parcel_h parcel, void *data) +{ + __h h = data; + key; + rpc_port_unit_map_h map; + char name[32]; + int size = 0; + int ret; + int i; + + if (parcel == nullptr || h == nullptr) { + _E("Invalid parameter"); + set_last_result(RPC_PORT_ERROR_INVALID_PARAMETER); + return; + } + + map = rpc_port_unit_map_create(); + if (map == nullptr) { + _E("Failed to create unit map"); + set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY); + return; + } + + rpc_port_parcel_read(parcel, &map->parcelable, map); + + ret = rpc_port_unit_map_read_int(parcel, "size", &size); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to read size. error(%d)", ret); + rpc_port_unit_map_destroy(map); + set_last_result(ret); + return; + } + + for (i = 0; i < size; ++i) { + snprintf(name, sizeof(name), "key-%d", i); + + + ret = __insert(h, key); + if (ret != RPC_PORT_ERROR_NONE) { + rpc_port_unit_map_destroy(map); + set_last_result(ret); + return; + } + } + + rpc_port_unit_map_destroy(map); + set_last_result(RPC_PORT_ERROR_NONE); +} + +static gint ____comparison_cb(gconstpointer a, gconstpointer b, gpointer user_data) +{ + + + if (____compare_cb == nullptr) { + _E("__set_compare_cb() MUST be called"); + return -1; + } + + return ____compare_cb(key_a, key_b, ____user_data); +} + +int __set_compare_cb(__compare_cb callback, void *user_data) +{ + if (callback == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + ____compare_cb = callback; + ____user_data = user_data; + + return RPC_PORT_ERROR_NONE; +} + +int __create(__h *h) +{ + __t *handle; + + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (____compare_cb == nullptr) { + _E("__set_compare_cb() MUST be called"); + return RPC_PORT_ERROR_IO_ERROR; + } + + handle = calloc(1, sizeof(__t)); + if (handle == nullptr) { + _E("Out of memory"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + handle->node = g_tree_new_full((GCompareDataFunc)____comparison_cb, handle, (GDestroyNotify), nullptr); + if (handle->node == nullptr) { + _E("g_tree_new_full() is failed"); + free(handle); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + handle->parcelable.to = ____to; + handle->parcelable.from = ____from; + + *h = handle; + + return RPC_PORT_ERROR_NONE; +} + +int __destroy(__h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + if (h->node) + g_tree_destroy(h->node); + + free(h); + + return RPC_PORT_ERROR_NONE; +} + +int __clone(__h h, __h *clone) +{ + rpc_port_unit_map_h map; + int ret; + + if (h == nullptr || clone == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + map = rpc_port_unit_map_create(); + if (map == nullptr) { + _E("Failed to create unit map"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; + } + + ret = rpc_port_unit_map_write_(map, "clone", h); + if (ret != RPC_PORT_ERROR_NONE) { + _E("Failed to write . error(%d)", ret); + rpc_port_unit_map_destroy(map); + return ret; + } + + ret = rpc_port_unit_map_read_(map, "clone", clone); + rpc_port_unit_map_destroy(map); + + return ret; +} + +int __insert(__h h, key) +{ + if () { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + + + return RPC_PORT_ERROR_NONE; +} + +int __erase(__h h, key) +{ + if () { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + + + return RPC_PORT_ERROR_NONE; +} + +static gboolean ____foreach_cb(gpointer key, gpointer value, gpointer user_data) +{ + __foreach_info_t *info = user_data; + + + return info->callback(tmp_key, info->user_data); +} + +int __foreach(__h h, __foreach_cb callback, void *user_data) +{ + __foreach_info_t info; + + if (h == nullptr || callback == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + info.callback = callback; + info.user_data = user_data; + + g_tree_foreach(h->node, ____foreach_cb, &info); + + return RPC_PORT_ERROR_NONE; +} + +int __contains(__h h, key, bool *exist) +{ + gpointer data; + + if () { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + + + return RPC_PORT_ERROR_NONE; +} + +int __size(__h h, size_t *size) +{ + if (h == nullptr || size == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + *size = g_tree_nnodes(h->node); + + return RPC_PORT_ERROR_NONE; +} + +int __clear(__h h) +{ + if (h == nullptr) { + _E("Invalid parameter"); + return RPC_PORT_ERROR_INVALID_PARAMETER; + } + + g_tree_remove_all(h->node); + + return RPC_PORT_ERROR_NONE; +} +)__c_cb"; + +/** + * The name of the key. + * The type of the key. + */ +constexpr const char CB_SET_UNIT_MAP_KEY_WRITE_PTR_TYPE[] = +R"__c_cb( +rpc_port_unit_map_write_(info->map, name, ()key); +)__c_cb"; + +/** + * The name of the key. + * The pointer type of the key. + */ +constexpr const char CB_SET_UNIT_MAP_KEY_WRITE_BASE_TYPE[] = +R"__c_cb( +rpc_port_unit_map_write_(info->map, name, *( *)key); +)__c_cb"; + +/** + * The name of the key. + */ +constexpr const char CB_SET_UNIT_MAP_KEY_READ[] = +R"__c_cb( +rpc_port_unit_map_read_(map, name, &key); +)__c_cb"; + +/** + * The type of the key. + */ +constexpr const char CB_SET_COMPARE_KEY_VARS_DEF_PTR_TYPE[] = +R"__c_cb( + key_a = ()a; + key_b = ()b; +)__c_cb"; + +/** + * The type of the key. + */ +constexpr const char CB_SET_COMPARE_KEY_VARS_DEF_BASE_TYPE[] = +R"__c_cb( + key_a = *( *)a; + key_b = *( *)b; +)__c_cb"; + +/** + * The prefix of the user defined type. + * The name of the user defined type. + */ +constexpr const char CB_SET_USER_DEFINED_FREE_FUNC[] = +R"__c_cb(__destroy)__c_cb"; + +constexpr const char CB_SET_BUNDLE_FREE_FUNC[] = +R"__c_cb(bundle_free)__c_cb"; + +constexpr const char CB_SET_FREE_FUNC[] = +R"__c_cb(free)__c_cb"; + +constexpr const char CB_SET_HANDLE_KEY_NULL_CHECK[] = +R"__c_cb(h == nullptr || key == nullptr)__c_cb"; + +constexpr const char CB_SET_HANDLE_KEY_EXIST_NULL_CHECK[] = +R"__c_cb(h == nullptr || key == nullptr || exist == nullptr)__c_cb"; + +constexpr const char CB_SET_HANDLE_EXIST_NULL_CHECK[] = +R"__c_cb(h == nullptr || exist == nullptr)__c_cb"; + +constexpr const char CB_SET_HANDLE_NULL_CHECK[] = +R"__c_cb(h == nullptr)__c_cb"; + +/** + * The prefix of the user defined type. + * The name of the user defined type. + */ +constexpr const char CB_SET_INSERT_KEY_USER_DEFINED_IMPL[] = +R"__c_cb( +__h new_key = nullptr; +int ret = __clone(key, &new_key); +if (ret != RPC_PORT_ERROR_NONE) + return ret; + +g_tree_replace(h->node, (gpointer)new_key, nullptr); +)__c_cb"; + +constexpr const char CB_SET_INSERT_KEY_BUNDLE_IMPL[] = +R"__c_cb( +bundle *new_key = bundle_dup(key); +if (new_key == nullptr) { + _E("bundle_dup() is failed"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; +} + +g_tree_replace(h->node, (gpointer)new_key, nullptr); +)__c_cb"; + +constexpr const char CB_SET_INSERT_KEY_STRING_IMPL[] = +R"__c_cb( +char *new_key = strdup(key); +if (new_key == nullptr) { + _E("strdup() is failed"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; +} + +g_tree_replace(h->node, (gpointer)new_key, nullptr); +)__c_cb"; + +/** + * *new_key = malloc(sizeof()); +if (new_key == nullptr) { + _E("malloc() is failed"); + return RPC_PORT_ERROR_OUT_OF_MEMORY; +} + +*new_key = key; +g_tree_replace(h->node, (gpointer)new_key, nullptr); +)__c_cb"; + +constexpr const char CB_SET_ERASE_KEY_PTR_TYPE[] = +R"__c_cb( +if (!g_tree_remove(h->node, (gpointer)key)) + _W("g_tree_remove() is failed"); +)__c_cb"; + +constexpr const char CB_SET_ERASE_KEY_BASE_TYPE[] = +R"__c_cb( +if (!g_tree_remove(h->node, &key)) + _W("g_tree_remove() is failed"); +)__c_cb"; + +/** + * The type of the key. + */ +constexpr const char CB_SET_FOREACH_VARS_DEF_KEY_PTR_TYPE[] = +R"__c_cb( + tmp_key = ()key; +)__c_cb"; + +/** + * The type of the key. + */ +constexpr const char CB_SET_FOREACH_VARS_DEF_KEY_BASE_TYPE[] = +R"__c_cb( + tmp_key = *( *)key; +)__c_cb"; + +constexpr const char CB_SET_CONTAINS_KEY_PTR_TYPE[] = +R"__c_cb( +data = g_tree_lookup(h->node, (gpointer)key); +*exist = (data != nullptr) ? true : false; +)__c_cb"; + +constexpr const char CB_SET_CONTAINS_KEY_BASE_TYPE[] = +R"__c_cb( +data = g_tree_lookup(h->node, &key); +*exist = (data != nullptr) ? true : false; +)__c_cb"; + +} // namespace version2 +} // namespace tidl + +#endif // IDLC_GEN_VERSION2_C_BODY_GENERATOR_SET_BASE_CB_HH_ diff --git a/idlc/gen/version2/c_header_generator_base.cc b/idlc/gen/version2/c_header_generator_base.cc index f46027a5..6d4d1fc7 100644 --- a/idlc/gen/version2/c_header_generator_base.cc +++ b/idlc/gen/version2/c_header_generator_base.cc @@ -24,6 +24,8 @@ #include "idlc/gen/version2/c_header_generator_array_base_cb.hh" #include "idlc/gen/version2/c_header_generator_base_cb.hh" #include "idlc/gen/version2/c_header_generator_list_base_cb.hh" +#include "idlc/gen/version2/c_header_generator_map_base_cb.hh" +#include "idlc/gen/version2/c_header_generator_set_base_cb.hh" namespace tidl { namespace version2 { @@ -78,10 +80,44 @@ void CHeaderGeneratorBase::GenStructureListBase(std::ofstream& stream, void CHeaderGeneratorBase::GenStructureMapBase(std::ofstream& stream, const Structure& st) { + auto iter = st.GetElements().begin(); + if (std::next(iter) == st.GetElements().end()) + return; + + auto& key_elm = *iter; + auto& key_type = key_elm->GetType(); + auto key_param_type = GetParamTypeString(ParameterType::Direction::IN, + key_type); + auto& value_elm = *(std::next(iter)); + auto& value_type = value_elm->GetType(); + auto value_param_type = GetParamTypeString(ParameterType::Direction::IN, + value_type); + auto value_param_type_out = GetParamTypeString(ParameterType::Direction::OUT, + value_type); + + ReplaceAll(CB_STRUCTURE_MAP_BASE) + .Change("", GetHandlePrefix()) + .Change("", st.GetID()) + .Change("", key_param_type) + .Change("", value_param_type) + .Change("", value_param_type_out) + .Transform([&](std::string code) { return SmartIndent(code); }) + .Out(stream); } void CHeaderGeneratorBase::GenStructureSetBase(std::ofstream& stream, const Structure& st) { + auto& elm = *(st.GetElements().begin()); + auto& key_type = elm->GetType(); + auto key_param_type = GetParamTypeString(ParameterType::Direction::IN, + key_type); + + ReplaceAll(CB_STRUCTURE_SET_BASE) + .Change("", GetHandlePrefix()) + .Change("", st.GetID()) + .Change("", key_param_type) + .Transform([&](std::string code) { return SmartIndent(code); }) + .Out(stream); } void CHeaderGeneratorBase::GenStructureBase(std::ofstream& stream, diff --git a/idlc/gen/version2/c_header_generator_map_base_cb.hh b/idlc/gen/version2/c_header_generator_map_base_cb.hh new file mode 100644 index 00000000..32a9697b --- /dev/null +++ b/idlc/gen/version2/c_header_generator_map_base_cb.hh @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2023 Samsung Electronics 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 IDLC_GEN_VERSION2_C_HEADER_GENERATOR_MAP_BASE_CB_HH_ +#define IDLC_GEN_VERSION2_C_HEADER_GENERATOR_MAP_BASE_CB_HH_ + +namespace tidl { +namespace version2 { + +/** + * The prefix of the map structure. + * The name of the map structure. + * The parameter type of the key of the map structure. + * The parameter type of the value of the map structure. + * The output parameter type of the value of the map structure. + */ +constexpr const char CB_STRUCTURE_MAP_BASE[] = +R"__c_cb( + +/** + * @brief Called to compare the keys in the _ handle. + * + * @param[in] a A key + * @param[in] b B key + * @param[in] user_data The user data passed from the registration function + * @return Nagative value if a < b, + * zero if a = b, + * positive value if a > b. + * @see __set_compare_cb() + */ +typedef int (*__compare_cb)(a, b, void *user_data); + +/** + * @brief Called to retrieve the key/value contained in the _ handle. + * + * @remarks The @a value MUST NOT be released by the application. + * @param[in] key The key of the map + * @param[in] value The value of the map + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * otherwise @c false to break out of the loop + * @see __foreach() + */ +typedef bool (*__foreach_cb)(key, value, void *user_data); + +/** + * @brief Sets the comparision callback function for the _ handle. + * @details The _ uses the registered callback function. + * If it's not set, calling the __create() returns a negative error value. + * + * @param[in] callback The comparison callback function + * @param[in] user_data The user data to be passed to the comparision callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see __create() + */ +int __set_compare_cb(__compare_cb callback, void *user_data); + +/** + * @brief Creates a _ handle. + * + * @remarks The @a h handle should be released using the __destroy() + * if it's no longer needed. + * @param[out] h The _ handle that is newly created + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_NONE Internal I/O error + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see __set_compare_cb() + * @see __destroy() + * @pre __set_compare_cb() + */ +int __create(__h *h); + +/** + * @brief Destroys the _ handle. + * + * @param[in] The _ handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see __create() + */ +int __destroy(__h h); + +/** + * @brief Creates and returns a copy of the given _ handle. + * + * @remarks A new created _ should be released using + * the __destroy() if it's no longer needed. + * @param[in] h The _ handle + * @param[out] clone If successful, a new created _ handle will be returned + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see __destroy() + */ +int __clone(__h h, __h *clone); + +/** + * @brief Inserts the key/value into the _ handle. + * + * @remarks The @a key and the @a value are copied internally. + * If you do the key data comparison based on the address, it makes a problem. + * @param[in] h The _ handle. + * @param[in] key The key to insert. + * @param[in] value The value corresponding to the key. + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see __erase() + */ +int __insert(__h h, key, value); + +/** + * @brief Gets the value corresponding to the given key. + * + * @remarks The @c value is copied internally. The data being returned is not a reference value. + * You should release it if it's no longer needed. The value such as integer does not need to be released. + * @param[in] h The _ handle. + * @param[in] key The key to look up. + * @param[out] value The value correspoding to the key. + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int __lookup(__h h, key, value); + +/** + * @breif Removes the key/value pair from the _ handle. + * + * @param[in] h The _ handle. + * @param[in] key The key to remove. + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int __erase(__h h, key); + +/** + * @brief Inserts the key/value into the _ handle. + * + * @remarks The @a key and the @a value are copied internally. + * If you do the key data comparison based on the address, it makes a problem. + * @param[in] h The _ handle. + * @param[in] key The key to insert. + * @param[in] value The value corresponding to the key. + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see __insert() + */ +int __replace(__h h, key, value); + +/** + * @brief Retrieves all values contained in the _ handle. + * @details This function called __foreach_cb once for each the key/value contained in the _ handle. + * If the __cb callback function returns @c false, the iteration will be finished. + * + * @param[in] h The _ handle + * @param[in] callback The iteration callback function + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see __foreach_cb() + */ +int __foreach(__h h, __foreach_cb callback, void *user_data); + +/** + * @brief Checks whether the key exists or not. + * + * @param[in] h The _ handle + * @param[in] key The key to check. + * @param[out] exist If it's true, the key exists. + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int __contains(__h h, key, bool *exist); + +/** + * @brief Gets the number of elements in the _ handle. + * + * @param[in] h The _ handle + * @param[out] size The number of elements + * @return @c on 0 success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int __size(__h h, size_t *size); + +/** + * @brief Removes all elements from the _ handle. + * + * @param[in] h The _ handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int __clear(__h h); +)__c_cb"; + +} // namespace version2 +} // namespace tidl + +#endif // IDLC_GEN_VERSION2_C_HEADER_GENERATOR_MAP_BASE_CB_HH_ diff --git a/idlc/gen/version2/c_header_generator_set_base_cb.hh b/idlc/gen/version2/c_header_generator_set_base_cb.hh new file mode 100644 index 00000000..8def3871 --- /dev/null +++ b/idlc/gen/version2/c_header_generator_set_base_cb.hh @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2023 Samsung Electronics 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 IDLC_GEN_VERSION2_C_HEADER_GENERATOR_SET_BASE_CB_HH_ +#define IDLC_GEN_VERSION2_C_HEADER_GENERATOR_SET_BASE_CB_HH_ + +namespace tidl { +namespace version2 { + +/** + * The prefix of the set structure. + * The name of the set structure. + * The parameter type of the key of the set structure. + */ +constexpr const char CB_STRUCTURE_SET_BASE[] = +R"__c_cb( + +/** + * @brief Called to compare the keys in the _ handle. + * + * @param[in] a A key + * @param[in] b B key + * @param[in] user_data The user data passed from the registration function + * @return Nagative value if a < b, + * zero if a = b, + * positive value if a > b. + * @see __set_compare_cb() + */ +typedef int (*__compare_cb)(a, b, void *user_data); + +/** + * @brief Called to retrieve the key contained in the _ handle. + * + * @remarks The @a value MUST NOT be released by the application. + * @param[in] key The key of the map + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * otherwise @c false to break out of the loop + * @see __foreach() + */ +typedef bool (*__foreach_cb)(key, void *user_data); + +/** + * @brief Sets the comparision callback function for the _ handle. + * @details The _ uses the registered callback function. + * If it's not set, calling the __create() returns a negative error value. + * + * @param[in] callback The comparison callback function + * @param[in] user_data The user data to be passed to the comparison callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see __create() + */ +int __set_compare_cb(__compare_cb callback, void *user_data); + +/** + * @brief Creates a _ handle. + * + * @remarks The @a h handle should be released using the __destroy() + * if it's no longer needed. + * @param[out] h The _ handle that is newly created + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_IO_ERROR Internal I/O error + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see __set_compare_cb() + * @see __destroy() + * @pre __set_compare_cb() + */ +int __create(__h *h); + +/** + * @brief Destroys the _ handle. + * + * @param[in] The _ handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see __create() + */ +int __destroy(__h h); + +/** + * @brief Creates and returns a copy of the given _ handle. + * + * @remarks A new created _ should be released using + * the __destroy() if it's no longer needed. + * @param[in] h The _ handle + * @param[out] clone If successful, a new created _ handle will be returned + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see __destroy() + */ +int __clone(__h h, __h *clone); + +/** + * @brief Inserts the key into the _ handle. + * + * @remarks The @a key is copied internally. + * If you do the key data comparison based on the address, it makes a problem. + * @param[in] h The _ handle. + * @param[in] key The key to insert. + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #RPC_PORT_ERROR_OUT_OF_MEMORY Out of memory + * @see __erase() + */ +int __insert(__h h, key); + +/** + * @breif Removes the key from the _ handle. + * + * @param[in] h The _ handle. + * @param[in] key The key to remove. + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int __erase(__h h, key); + +/** + * @brief Retrieves all keys contained in the _ handle. + * @details This function called __foreach_cb once for each the key contained in the _ handle. + * If the __cb callback function returns @c false, the iteration will be finished. + * + * @param[in] h The _ handle + * @param[in] callback The iteration callback function + * @param[in] user_data The user data to be passed to the callback function + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + * @see __foreach_cb() + */ +int __foreach(__h h, __foreach_cb callback, void *user_data); + +/** + * @brief Checks whether the key exists or not. + * + * @param[in] h The _ handle + * @param[in] key The key to check. + * @param[out] exist If it's true, the key exists. + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int __contains(__h h, key, bool *exist); + +/** + * @brief Gets the number of elements in the _ handle. + * + * @param[in] h The _ handle + * @param[out] size The number of elements + * @return @c on 0 success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int __size(__h h, size_t *size); + +/** + * @brief Removes all elements from the _ handle. + * + * @param[in] h The _ handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #RPC_PORT_ERROR_NONE Successful + * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter + */ +int __clear(__h h); +)__c_cb"; + +} // namespace version2 +} // namespace tidl + +#endif // IDLC_GEN_VERSION2_C_HEADER_GENERATOR_SET_BASE_CB_HH_ diff --git a/idlc/gen/version2/c_proxy_body_generator_cb.hh b/idlc/gen/version2/c_proxy_body_generator_cb.hh index 4a7b35b4..7840d087 100644 --- a/idlc/gen/version2/c_proxy_body_generator_cb.hh +++ b/idlc/gen/version2/c_proxy_body_generator_cb.hh @@ -1075,7 +1075,7 @@ constexpr const char CB_INTERFACE_METHOD_USER_DEFINED_UNIT_MAP_READ[] = R"__c_cb( res_ = rpc_port_unit_map_read_(map_, "", &); if (res_ != RPC_PORT_ERROR_NONE) { - _E("Failed to read . error(%d)", res); + _E("Failed to read . error(%d)", res_); rpc_port_unit_map_destroy(map_); break; }