From: hyunho Date: Fri, 22 May 2020 07:38:50 +0000 (+0900) Subject: Add file sharing grammar for the C language X-Git-Tag: submit/tizen/20200820.052329~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F56%2F234156%2F3;p=platform%2Fcore%2Fappfw%2Ftidl.git Add file sharing grammar for the C language Change-Id: Ib2b88e08465d29398a365a996176704626a693d7 Signed-off-by: hyunho --- diff --git a/idlc/gen/c_body_gen_base.cc b/idlc/gen/c_body_gen_base.cc index 63354b0..50f61bb 100644 --- a/idlc/gen/c_body_gen_base.cc +++ b/idlc/gen/c_body_gen_base.cc @@ -36,6 +36,7 @@ CBodyGeneratorBase::CBodyGeneratorBase(std::shared_ptr doc) {"float", "float"}, {"double", "double"}, {"bundle", "bundle"}, + {"file", "string"}, }; } @@ -203,14 +204,16 @@ void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream, [&]()->std::string { if ((i->GetType().IsUserDefinedType() || i->GetType().ToString() == "string" || - i->GetType().ToString() == "bundle") || + i->GetType().ToString() == "bundle" || + i->GetType().ToString() == "file") || ((i->GetType().ToString() == "list" || i->GetType().ToString() == "array") && (i->GetType().GetMetaType()->IsUserDefinedType() || i->GetType().GetMetaType()->ToString() == "list" || i->GetType().GetMetaType()->ToString() == "array" || i->GetType().GetMetaType()->ToString() == "string" || - i->GetType().GetMetaType()->ToString() == "bundle"))) + i->GetType().GetMetaType()->ToString() == "bundle" || + i->GetType().GetMetaType()->ToString() == "file"))) return "!h || !" + i->GetID(); return "!h"; @@ -338,7 +341,8 @@ void CBodyGeneratorBase::GenStructureRemover(std::ofstream& stream, i->GetType().GetMetaType()->ToString() == "list" || i->GetType().GetMetaType()->ToString() == "array" || i->GetType().GetMetaType()->ToString() == "string" || - i->GetType().GetMetaType()->ToString() == "bundle") + i->GetType().GetMetaType()->ToString() == "bundle" || + i->GetType().GetMetaType()->ToString() == "file") return GetParcelParamTypeString(*i->GetType().GetMetaType()); return ConvertTypeToString(ParameterType::Direction::IN, @@ -473,7 +477,8 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, return "&value->parcelable, value"; if (type.GetMetaType()->ToString() == "bundle") return "value"; - if (type.GetMetaType()->ToString() == "string") + if (type.GetMetaType()->ToString() == "string" + || type.GetMetaType()->ToString() == "file") return ReplaceAll(ternary_operation, "##", "value"); return "*value"; }); @@ -493,7 +498,8 @@ std::string CBodyGeneratorBase::GetParcelWriteString(const std::string& id, type.GetMetaType()->ToString() == "list" || type.GetMetaType()->ToString() == "array") return "&h->" + id + "[i]->parcelable, h->" + id +"[i]"; - if (type.GetMetaType()->ToString() == "string") + if (type.GetMetaType()->ToString() == "string" || + type.GetMetaType()->ToString() == "file") return ReplaceAll(ternary_operation, "##", "h->" + id + "[i]"); return "h->" + id + "[i]"; @@ -559,7 +565,8 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id, return "&value->parcelable, value"; }); } else if (type.GetMetaType()->ToString() == "string" || - type.GetMetaType()->ToString() == "bundle") { + type.GetMetaType()->ToString() == "bundle"|| + type.GetMetaType()->ToString() == "file") { s += GenTemplateString(parcel, [&]()->std::string { return GetParcelReadFunctionString(*type.GetMetaType()); @@ -679,7 +686,8 @@ std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id, type.ToString() != "list" && type.ToString() != "array" && type.ToString() != "string" && - type.ToString() != "bundle") + type.ToString() != "bundle" && + type.ToString() != "file") return str; if (type.ToString() == "list") { @@ -708,7 +716,8 @@ std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id, type.GetMetaType()->ToString() != "list" && type.GetMetaType()->ToString() != "array" && type.GetMetaType()->ToString() != "string" && - type.GetMetaType()->ToString() != "bundle") { + type.GetMetaType()->ToString() != "bundle" && + type.GetMetaType()->ToString() != "file") { return GenTemplateString(CB_IF_STATEMENT, [&]()->std::string { return handle + id; @@ -753,7 +762,8 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, if (type.IsUserDefinedType() || type.ToString() == "string" || - type.ToString() == "bundle") { + type.ToString() == "bundle" || + type.ToString() == "file") { str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, [&]()->std::string { return "h->" + id; @@ -789,6 +799,7 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, if (type.GetMetaType()->IsUserDefinedType() || type.GetMetaType()->ToString() == "string" || type.GetMetaType()->ToString() == "bundle" || + type.GetMetaType()->ToString() == "file" || type.GetMetaType()->ToString() == "list" || type.GetMetaType()->ToString() == "array") { s += GetSetterString(*type.GetMetaType(), "value", id); @@ -855,7 +866,8 @@ std::string CBodyGeneratorBase::GetGetterString(const std::string& id, } else { if (type.IsUserDefinedType() || type.ToString() == "string" || - type.ToString() == "bundle") { + type.ToString() == "bundle" || + type.ToString() == "file") { str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, [&]()->std::string { return "!h->" + id; @@ -879,7 +891,8 @@ std::string CBodyGeneratorBase::GetGetterString(const std::string& id, if (type.IsUserDefinedType() || type.ToString() == "string" || - type.ToString() == "bundle") { + type.ToString() == "bundle" || + type.ToString() == "file") { str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, [&]()->std::string { return "*" + id + " == NULL"; @@ -912,7 +925,8 @@ std::string CBodyGeneratorBase::GetIteratorString(const std::string& id, type.GetMetaType()->ToString() == "list" || type.GetMetaType()->ToString() == "array" || type.GetMetaType()->ToString() == "string" || - type.GetMetaType()->ToString() == "bundle") + type.GetMetaType()->ToString() == "bundle" || + type.GetMetaType()->ToString() == "file") return "value"; return "*value"; @@ -928,7 +942,8 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, if (type.IsUserDefinedType() || type.ToString() == "string" || - type.ToString() == "bundle") { + type.ToString() == "bundle" || + type.ToString() == "file") { str += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, [&]()->std::string { return "h->" + id; @@ -971,7 +986,8 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, type.GetMetaType()->ToString() == "list" || type.GetMetaType()->ToString() == "array" || type.GetMetaType()->ToString() == "string" || - type.GetMetaType()->ToString() == "bundle") { + type.GetMetaType()->ToString() == "bundle" || + type.GetMetaType()->ToString() == "file") { s += GetSetterString(*type.GetMetaType(), "new_value", "value"); s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES, @@ -1041,7 +1057,7 @@ std::string CBodyGeneratorBase::GetDestructorString(const BaseType& type, "_destroy(" + value + ");"; } else if (type.ToString() == "bundle") { str += "bundle_free(" + value + ");"; - } else if (type.ToString() == "string" || container_value) { + } else if (type.ToString() == "string" || type.ToString() == "file" || container_value) { str += "free(" + value + ");"; } @@ -1066,7 +1082,7 @@ std::string CBodyGeneratorBase::GetSetterString(const BaseType& type, type.ToString() == "array") { str += GetHandlePrefix() + GetFullNameFromType(type) + "_clone(" + rvalue + ", &" + lvalue +");" + NLine(1); - } else if (type.ToString() == "string") { + } else if (type.ToString() == "string" || type.ToString() == "file") { str += lvalue + " = strdup(" + rvalue + ");" + NLine(1); } else if (type.ToString() == "bundle") { str += lvalue + " = bundle_dup(" + rvalue + ");" + NLine(1); diff --git a/idlc/gen/c_gen_base.cc b/idlc/gen/c_gen_base.cc index 4741359..dbf7a40 100644 --- a/idlc/gen/c_gen_base.cc +++ b/idlc/gen/c_gen_base.cc @@ -35,7 +35,7 @@ CGeneratorBase::CGeneratorBase(std::shared_ptr doc) {"char", "char "}, {"int", "int "}, {"short", "short "}, {"long", "long long "}, {"bool", "bool "}, {"string", "char *"}, {"list", "GList *"}, {"float", "float "}, {"double", "double "}, - {"bundle", "bundle *"}, {"void", "void "} + {"bundle", "bundle *"}, {"void", "void "}, {"file", "char *"} }; } @@ -76,7 +76,7 @@ std::string CGeneratorBase::ConvertTypeToString( } } - if (type.ToString() == "string") { + if (type.ToString() == "string" || type.ToString() == "file") { if (direction == ParameterType::Direction::IN) { if (!bconst) return "char *"; @@ -111,7 +111,7 @@ std::string CGeneratorBase::GetParcelParamTypeString(const BaseType& type, type.ToString() == "array") return GetHandlePrefix() + GetFullNameFromType(type) + "_h "; - if (type.ToString() == "string") + if (type.ToString() == "string" || type.ToString() == "file") return "char *"; if (type.ToString() == "bundle") @@ -318,7 +318,8 @@ std::string CGeneratorBase::GetErrorValue(const BaseType& type) { type.ToString() == "list" || type.ToString() == "array" || type.ToString() == "bundle" || - type.ToString() == "string") + type.ToString() == "string"|| + type.ToString() == "file") return "NULL"; if (type.ToString() == "bool") return "false"; diff --git a/idlc/gen/c_gen_base_cb.h b/idlc/gen/c_gen_base_cb.h index 5af4d66..015399a 100644 --- a/idlc/gen/c_gen_base_cb.h +++ b/idlc/gen/c_gen_base_cb.h @@ -39,6 +39,7 @@ R"__c_cb( #include #include #include +#include )__c_cb"; #endif // IDLC_C_GEN_C_GEN_BASE_CB_H_ diff --git a/idlc/gen/c_proxy_body_gen.cc b/idlc/gen/c_proxy_body_gen.cc index 662b57e..54df1c8 100644 --- a/idlc/gen/c_proxy_body_gen.cc +++ b/idlc/gen/c_proxy_body_gen.cc @@ -59,6 +59,7 @@ void CProxyBodyGen::GenInterfaces(std::ofstream& stream) { } void CProxyBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) { + GenInterfaceFileSharing(stream, inf); GenInterfaceEnumerations(stream, inf); GenInterfaceDeclaration(stream, inf); GenInterfaceDelegators(stream, inf); @@ -77,6 +78,25 @@ void CProxyBodyGen::GenInterface(std::ofstream& stream, const Interface& inf) { GenInterfaceDtor(stream, inf); } +void CProxyBodyGen::GenInterfaceFileSharing(std::ofstream& stream, + const Interface& inf) { + + for (auto& i : inf.GetDeclarations().GetDecls()) { + for (auto& p : i->GetParameters().GetParams()) { + if ((p->GetParameterType().GetBaseType().ToString() == "list" || + p->GetParameterType().GetBaseType().ToString() == "array") && + p->GetParameterType().GetBaseType().GetMetaType()->ToString() == "file") { + if (p->GetParameterType().GetBaseType().ToString() == "array") { + stream << SmartIndent(std::string(CB_FILE_ARRAY_SHARING)); + } else { + stream << SmartIndent(std::string(CB_FILE_LIST_SHARING)); + } + } + } + } +} + + void CProxyBodyGen::GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf) { stream << SmartIndent(ReplaceAll(CB_INTERFACE_STRUCT, "##", @@ -309,6 +329,7 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream, for (auto& i : inf.GetDeclarations().GetDecls()) { if (i->GetMethodType() == Declaration::MethodType::DELEGATE) continue; + stream << SmartIndent(GenTemplateString( ReplaceAll(CB_INTERFACE_METHODS, "##", GetInterfaceIdWithNamespace(inf)), @@ -363,6 +384,30 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream, return ""; }, [&]()->std::string { + for (auto& p : i->GetParameters().GetParams()) { + if (p->GetParameterType().GetDirection() == + ParameterType::Direction::IN && + p->GetParameterType().GetBaseType().ToString() == "file") { + return ReplaceAll(CB_PRIVATE_SHARING_BLOCK, "##", + p->GetID()); + } + + if ((p->GetParameterType().GetBaseType().ToString() == "list" || + p->GetParameterType().GetBaseType().ToString() == "array") && + p->GetParameterType().GetBaseType().GetMetaType()->ToString() == "file") { + if (p->GetParameterType().GetBaseType().ToString() == "array") { + + return ReplaceAll(CB_ARRAY_PRIVATE_SHARING_BLOCK, "##", + p->GetID()); + } else { + return ReplaceAll(CB_LIST_PRIVATE_SHARING_BLOCK, "##", + p->GetID()); + } + } + } + return ""; + }, + [&]()->std::string { return i->GetID(); }, [&]()->std::string { @@ -440,11 +485,12 @@ std::string CProxyBodyGen::GetMethodWriteString(const Interface& inf, return "&" + p->GetID() + "->parcelable, " + p->GetID(); } else if (p->GetParameterType().GetDirection() == ParameterType::Direction::REF) { - if (p->GetParameterType().GetBaseType().ToString() == "string") + if (p->GetParameterType().GetBaseType().ToString() == "string" + || p->GetParameterType().GetBaseType().ToString() == "file") return ReplaceAll(ternary_operation, "##", "*" + p->GetID()); return "*" + p->GetID(); - } else if (p->GetParameterType().GetBaseType().ToString() == - "string") { + } else if (p->GetParameterType().GetBaseType().ToString() == "string" + || p->GetParameterType().GetBaseType().ToString() == "file") { return ReplaceAll(ternary_operation, "##", p->GetID()); } return p->GetID(); diff --git a/idlc/gen/c_proxy_body_gen.h b/idlc/gen/c_proxy_body_gen.h index 5e07115..815f418 100644 --- a/idlc/gen/c_proxy_body_gen.h +++ b/idlc/gen/c_proxy_body_gen.h @@ -38,6 +38,7 @@ class CProxyBodyGen : public CBodyGeneratorBase { private: void GenInterface(std::ofstream& stream, const Interface& inf); + void GenInterfaceFileSharing(std::ofstream& stream, const Interface& st); void GenInterfaceDeclaration(std::ofstream& stream, const Interface& inf); void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf); void GenInterfaceDelegatorTable(std::ofstream& stream, const Interface& inf); diff --git a/idlc/gen/c_proxy_body_gen_cb.h b/idlc/gen/c_proxy_body_gen_cb.h index 7b2b740..a8717df 100644 --- a/idlc/gen/c_proxy_body_gen_cb.h +++ b/idlc/gen/c_proxy_body_gen_cb.h @@ -31,6 +31,37 @@ struct ##_s { }; )__c_cb"; +const char CB_FILE_LIST_SHARING[] = +R"__c_cb( +int __file_list_set_private_sharing(rpc_port_h port, GList *list_files) { + const char **arr = calloc(g_list_length(list_files), sizeof(char*)); + GList *iter; + int idx = 0; + int r = 0; + iter = list_files; + while (iter) { + char *value = iter->data; + if (!value) { + _W("Warning: value is NULL"); + continue; + } + arr[idx++] = value; + iter = g_list_next(iter); + } + if (idx > 0) + r = rpc_port_set_private_sharing_array(port, arr, idx); + return r; +} +)__c_cb"; + +const char CB_FILE_ARRAY_SHARING[] = +R"__c_cb( +int __file_array_set_private_sharing(rpc_port_h port, + const char **files, int files_size) { + return rpc_port_set_private_sharing_array(port, files, files_size); +} +)__c_cb"; + const char CB_DELEGATE_STRUCT[] = R"__c_cb( struct ##_s { @@ -314,7 +345,7 @@ $$ _E("Not connected"); return$$; } - +$$ rpc_port_parcel_create(&parcel); rpc_port_parcel_write_int32(parcel, ##_METHOD_$$); $$ @@ -501,4 +532,32 @@ $$ g_rec_mutex_unlock(&h->mutex); )__c_cb"; +const char CB_LIST_PRIVATE_SHARING_BLOCK[] = +R"__c_cb( + r = __file_list_set_private_sharing(h->port, ##->list_files); + if (r != RPC_PORT_ERROR_NONE) { + _E("Fail to set private sharing"); + return ret; + } +)__c_cb"; + +const char CB_ARRAY_PRIVATE_SHARING_BLOCK[] = +R"__c_cb( + r = __file_array_set_private_sharing(h->port, + (const char **)##->array_files, ##->array_files_size); + if (r != RPC_PORT_ERROR_NONE) { + _E("Fail to set private sharing"); + return ret; + } +)__c_cb"; + +const char CB_PRIVATE_SHARING_BLOCK[] = +R"__c_cb( + r = rpc_port_set_private_sharing(h->port, ##); + if (r != RPC_PORT_ERROR_NONE) { + _E("Fail to set private sharing"); + return ret; + } +)__c_cb"; + #endif // IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_ diff --git a/idlc/gen/c_stub_body_gen.cc b/idlc/gen/c_stub_body_gen.cc index f9ebec9..74909f6 100644 --- a/idlc/gen/c_stub_body_gen.cc +++ b/idlc/gen/c_stub_body_gen.cc @@ -284,7 +284,7 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf, if (t.IsUserDefinedType() || t.ToString() == "list" || t.ToString() == "array") return "&" + i->GetID() + "->parcelable, " + i->GetID(); - else if (t.ToString() == "string") + else if (t.ToString() == "string" || t.ToString() == "file") return ReplaceAll(ternary_operation, "##", i->GetID()); return i->GetID(); }); @@ -302,7 +302,8 @@ std::string CStubBodyGen::GetMethodString(const Interface& inf, decl.GetType().ToString() == "list" || decl.GetType().ToString() == "array") return "&ret->parcelable, ret"; - else if (decl.GetType().ToString() == "string") + else if (decl.GetType().ToString() == "string" || + decl.GetType().ToString() == "file") return ReplaceAll(ternary_operation, "##", "ret"); return "ret"; }); @@ -465,7 +466,7 @@ void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream, if (t.IsUserDefinedType() || t.ToString() == "list" || t.ToString() == "array") return "&" + i->GetID() + "->parcelable, " + i->GetID(); - else if (t.ToString() == "string") + else if (t.ToString() == "string" || t.ToString() == "file") return ReplaceAll(ternary_operation, "##", i->GetID()); return i->GetID(); }); diff --git a/idlc/gen/cpp_gen_base.cc b/idlc/gen/cpp_gen_base.cc index 626fff2..e05aee0 100644 --- a/idlc/gen/cpp_gen_base.cc +++ b/idlc/gen/cpp_gen_base.cc @@ -497,7 +497,7 @@ std::string CppGeneratorBase::GenPrivateSharingRequest(const BaseType& type, + std::string(" std::vector v;\n") + std::string(" std::string name = i.GetFileName();\n") + std::string(" v.push_back(name.c_str());\n") - + std::string(" int r = rpc_port_set_private_sharing(port_, v.data(), v.size());\n") + + std::string(" int r = rpc_port_set_private_sharing_array(port_, v.data(), v.size());\n") + std::string(" if (r != RPC_PORT_ERROR_NONE) {\n") + std::string(" _E(\"Failed to set private sharing\");\n") + std::string(" throw InvalidIOException();\n") @@ -507,7 +507,7 @@ std::string CppGeneratorBase::GenPrivateSharingRequest(const BaseType& type, ret += "std::vector v;\n" + std::string("std::string name = " + id + ".GetFileName();\n") + std::string("v.push_back(name.c_str());\n") - + std::string("int r = rpc_port_set_private_sharing(port_, v.data(), v.size());\n") + + std::string("int r = rpc_port_set_private_sharing_array(port_, v.data(), v.size());\n") + std::string("if (r != RPC_PORT_ERROR_NONE) {\n") + std::string(" _E(\"Failed to set private sharing\");\n") + std::string(" throw InvalidIOException();\n") diff --git a/unit_tests/test.tidl b/unit_tests/test.tidl index c495b13..2624814 100644 --- a/unit_tests/test.tidl +++ b/unit_tests/test.tidl @@ -39,7 +39,4 @@ interface School { int GetStudent(in string c_name, in string s_name, out Student student); string GetName(out string name); int SetName(in string name); - int ShareFile(file myFile); - int ShareFilesList(list myFile); - int ShareFilesArray(array myFile); }