void CBodyGeneratorBase::GenStructureConstructor(std::ofstream& stream,
const Structure& st) {
const char block[] =
- "int rpc_port_create_##(rpc_port_##_h *h)\n" \
+ "int rpc_port_##_create(rpc_port_##_h *h)\n" \
"{\n" \
" struct ##_s *handle;\n" \
"\n" \
void CBodyGeneratorBase::GenStructureDestructor(std::ofstream& stream,
const Structure& st) {
const char block[] =
- "int rpc_port_destroy_##(rpc_port_##_h h)\n" \
+ "int rpc_port_##_destroy(rpc_port_##_h h)\n" \
"{\n" \
" if (!h) {\n" \
" LOGE(\"Invalid parameter\");\n" \
stream << NLine(1);
stream << SmartIndent(GenTemplateString(block,
[&]()->std::string {
+ return st.GetID();
+ },
+ [&]()->std::string {
if (i->GetType().ToString() == "list" ||
i->GetType().ToString() == "array")
return "add";
return "set";
},
[&]()->std::string {
- return st.GetID();
- },
- [&]()->std::string {
return i->GetID();
},
[&]()->std::string {
void CBodyGeneratorBase::GenStructureGetter(std::ofstream& stream,
const Structure& st) {
const char block[] =
- "int rpc_port_get_$$_$$(rpc_port_$$_h h, $$$$)\n" \
+ "int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$)\n" \
"{\n" \
" if (!h || $$) {\n" \
" LOGE(\"Invalid parameter\");\n" \
void CBodyGeneratorBase::GenStructureIterator(std::ofstream& stream,
const Structure& st) {
const char block[] =
- "int rpc_port_foreach_$$_$$(rpc_port_$$_h h, " \
+ "int rpc_port_$$_foreach_$$(rpc_port_$$_h h, " \
"void (*callback)($$$$, void *user_data), void *user_data)\n" \
"{\n" \
" if (!h || !callback) {\n" \
void CBodyGeneratorBase::GenStructureCloner(std::ofstream& stream,
const Structure& st) {
const char block[] =
- "int rpc_port_clone_##(rpc_port_##_h h, rpc_port_##_h *clone)\n" \
+ "int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone)\n" \
"{\n" \
" rpc_port_##_h handle = NULL;\n" \
"\n" \
" return -1;\n" \
" }\n" \
"\n" \
- " rpc_port_create_##(&handle);\n" \
+ " rpc_port_##_create(&handle);\n" \
" if (!handle) {\n" \
" LOGE(\"Failed to create ## handle\");\n" \
" return -1;\n" \
std::string str;
for (auto& i : st.GetElements().GetElms()) {
str += NLine(1);
- str += GetClonerString(i->GetID(), i->GetType());
+ str += GetClonerString(i->GetID(), i->GetType(), st);
}
return str;
}
type.ToString() == "bundle") {
str += GenTemplateString(if_statement_with_braces,
[&]()->std::string {
- return "!" + id;
+ return "*" + id + " == NULL";
},
[&]()->std::string {
std::string s;
}
std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
- const BaseType& type) {
+ const BaseType& type,
+ const Structure& st) {
std::string str;
const char if_statement_with_braces[] =
"if ($$) {\n" \
"\n" \
" if (!value) {\n" \
" LOGE(\"Error: value is NULL\");\n" \
- " break;\n" \
+ " rpc_port_$$_destroy(handle);\n"
+ " return -1;\n" \
" }\n" \
"\n" \
" $$" \
std::string ss;
ss += "LOGE(\"Failed to duplicate h->" + id + "\");" +
NLine(1);
+ ss += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+ NLine(1);
ss += "return -1;" + NLine(1);
return ss;
}
return GetParcelParamTypeString(*type.GetMetaType());
},
[&]()->std::string {
+ return st.GetID();
+ },
+ [&]()->std::string {
std::string s;
if (type.GetMetaType()->IsUserDefinedType() ||
type.GetMetaType()->ToString() == "list" ||
std::string ss;
ss += "LOGE(\"Failed to duplicate value\");" +
NLine(1);
+ ss += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+ NLine(1);
ss += "return -1;" + NLine(1);
return ss;
}
[&]()->std::string {
std::string tmp;
tmp += "LOGE(\"Out of memory\");" + NLine(1);
+ tmp += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+ NLine(1);
tmp += "return -1;" + NLine(1);
return tmp;
}
);
s += NLine(1);
s += GetSetterString(*type.GetMetaType(),
- "*new_value", "value");
+ "*new_value", "*value");
}
s += NLine(1);
return s;
if (type.IsUserDefinedType() ||
type.ToString() == "list" ||
type.ToString() == "array") {
- str += "rpc_port_destroy_" + GetFullNameFromType(type) +
- "(" + value + ");" + NLine(1);
+ str += "rpc_port_" + GetFullNameFromType(type) +
+ "_destroy(" + value + ");" + NLine(1);
} else if (type.ToString() == "bundle") {
str += "bundle_free(" + value + ");" + NLine(1);
} else if (type.ToString() == "string" || container_value) {
std::string CBodyGeneratorBase::GetConstructorString(const BaseType& type,
const std::string& value) {
std::string str;
- str += "rpc_port_create_" + GetFullNameFromType(type) +
- "(&" + value + ");" + NLine(1);
+ str += "rpc_port_" + GetFullNameFromType(type) +
+ "_create(&" + value + ");" + NLine(1);
return str;
}
if (type.IsUserDefinedType() ||
type.ToString() == "list" ||
type.ToString() == "array") {
- str += "rpc_port_clone_" + GetFullNameFromType(type) +
- "(" + rvalue + ", &" + lvalue +");" + NLine(1);
+ str += "rpc_port_" + GetFullNameFromType(type) +
+ "_clone(" + rvalue + ", &" + lvalue +");" + NLine(1);
} else if (type.ToString() == "string") {
str += lvalue + " = strdup(" + rvalue + ");" + NLine(1);
} else if (type.ToString() == "bundle") {
std::string GetSetterString(const std::string& id, const BaseType& type);
std::string GetGetterString(const std::string& id, const BaseType& type);
std::string GetIteratorString(const std::string& id, const BaseType& type);
- std::string GetClonerString(const std::string& id, const BaseType& type);
+ std::string GetClonerString(const std::string& id, const BaseType& type,
+ const Structure& st);
std::string GetSetterString(const BaseType& type, const std::string& lvalue,
const std::string& rvalue);
std::string GetSetterString(const std::string& lvalue,
if (type.ToString() == "string")
return "char *";
+ if (type.ToString() == "bundle")
+ return "bundle *";
+
return type.ToString() + " ";
}
void CHeaderGeneratorBase::GenStructureConstructor(std::ofstream& stream,
const Structure& st) {
- const char format[] = "int rpc_port_create_$$(rpc_port_$$_h *h);\n";
+ const char format[] = "int rpc_port_$$_create(rpc_port_$$_h *h);\n";
stream << NLine(1);
GenTemplate(format, stream,
void CHeaderGeneratorBase::GenStructureDestructor(std::ofstream& stream,
const Structure& st) {
- const char format[] = "int rpc_port_destroy_$$(rpc_port_$$_h h);\n";
+ const char format[] = "int rpc_port_$$_destroy(rpc_port_$$_h h);\n";
stream << NLine(1);
GenTemplate(format, stream,
stream << NLine(1);
GenTemplate(format, stream,
[&]()->std::string {
+ return st.GetID();
+ },
+ [&]()->std::string {
if (i->GetType().ToString() == "list" ||
i->GetType().ToString() == "array")
return "add";
return "set";
},
[&]()->std::string {
- return st.GetID();
- },
- [&]()->std::string {
return i->GetID();
},
[&]()->std::string {
void CHeaderGeneratorBase::GenStructureGetter(std::ofstream& stream,
const Structure& st) {
- const char format[] = "int rpc_port_get_$$_$$(rpc_port_$$_h h, $$$$);\n";
+ const char format[] = "int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$);\n";
for (auto& i : st.GetElements().GetElms()) {
if (i->GetType().ToString() == "list" ||
void CHeaderGeneratorBase::GenStructureIterator(std::ofstream& stream,
const Structure& st) {
const char format[] =
- "int rpc_port_foreach_$$_$$(rpc_port_$$_h h, " \
+ "int rpc_port_$$_foreach_$$(rpc_port_$$_h h, " \
"void (*callback)($$$$, void *user_data), void *user_data);\n";
for (auto& i : st.GetElements().GetElms()) {
void CHeaderGeneratorBase::GenStructureCloner(std::ofstream& stream,
const Structure& st) {
const char format[] =
- "int rpc_port_clone_$$(rpc_port_$$_h h, rpc_port_$$_h *clone);\n";
+ "int rpc_port_$$_clone(rpc_port_$$_h h, rpc_port_$$_h *clone);\n";
stream << NLine(1);
GenTemplate(format, stream,
" ## callback;\n" \
"};\n";
stream << NLine(1);
- stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+ stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
}
void CProxyBodyGen::GenInterfaceDelegatorSerializer(
" rpc_port_parcel_write_int32(parcel, handle->seq_id);\n" \
"}\n";
stream << NLine(1);
- stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+ stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
}
void CProxyBodyGen::GenInterfaceDelegatorDeserializer(
" rpc_port_parcel_read_int32(parcel, &handle->seq_id);\n" \
"}\n";
stream << NLine(1);
- stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+ stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
}
void CProxyBodyGen::GenInterfaceDelegatorConstructor(
"\n" \
" handle->parcelable.to = __##_to;\n" \
" handle->parcelable.from= __##_from;\n" \
- " handle->id = $$_DELEGATE_##;\n" \
+ " handle->id = $$_DELEGATE_$$;\n" \
" handle->seq_id = seq_num++;\n" \
" handle->callback = callback;\n" \
"\n" \
" return handle;\n" \
"}\n";
stream << NLine(1);
- stream << SmartIndent(GenTemplateString(ReplaceAll(block, "##", decl.GetID()),
+ stream << SmartIndent(GenTemplateString(
+ ReplaceAll(block, "##", id + "_" + decl.GetID()),
[&]()->std::string {
return id;
+ },
+ [&]()->std::string {
+ return decl.GetID();
}
)
);
std::ofstream& stream, const std::string& id, const Declaration& decl) {
const char parcel[] = "$$(parcel, $$);\n";
const char block[] =
- "static void __$$_delegate_##(GList *list, rpc_port_parcel_h parcel, int seq_id)\n" \
+ "static void __$$_delegate_$$(GList *list, rpc_port_parcel_h parcel, int seq_id)\n" \
"{\n" \
"$$" \
" do {\n" \
"$$" \
"}\n";
stream << NLine(1);
- stream << SmartIndent(GenTemplateString(ReplaceAll(block, "##", decl.GetID()),
+ stream << SmartIndent(GenTemplateString(
+ ReplaceAll(block, "##", id + "_" + decl.GetID()),
[&]()->std::string {
return id;
},
[&]()->std::string {
+ return decl.GetID();
+ },
+ [&]()->std::string {
std::string str;
int cnt = 0;
for (auto& i : decl.GetParameters().GetParams()) {
for (auto& p : i->GetParameters().GetParams()) {
str += ", ";
if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
- str += p->GetParameterType().GetBaseType().ToString() + " " +
- p->GetID();
+ str += inf.GetID() + "_" +
+ p->GetParameterType().GetBaseType().ToString() +
+ " " + p->GetID();
} else {
str += ConvertTypeToString(p->GetParameterType().GetDirection(),
p->GetParameterType().GetBaseType()) + p->GetID();
continue;
if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
str += GenTemplateString(ReplaceAll(delegate_block,
- "##", p->GetParameterType().GetBaseType().ToString()),
+ "##", inf.GetID() + "_" + p->GetParameterType().GetBaseType().ToString()),
[&]()->std::string {
return p->GetID();
}
void CProxyHeaderGen::GenInterfaceDelegator(std::ofstream& stream,
const std::string& id,
const Declaration& decl) {
- const char format[] = "typedef $$ (*$$)($$);\n";
+ const char format[] = "typedef $$(*$$)($$);\n";
stream << NLine(1);
stream << GenTemplateString(format,
[&]()->std::string {
return GetReturnTypeString(decl.GetType());
},
[&]()->std::string {
- return decl.GetID();
+ return id + "_" + decl.GetID();
},
[&]()->std::string {
std::string str;
void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
const Interface& inf) {
const char format[] =
- "$$ rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$);\n";
+ "$$rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$);\n";
for (auto& i : inf.GetDeclarations().GetDecls()) {
if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
continue;
for (auto& p : i->GetParameters().GetParams()) {
str += ", ";
if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
- str += p->GetParameterType().GetBaseType().ToString() + " " +
- p->GetID();
+ str += inf.GetID() + "_" +
+ p->GetParameterType().GetBaseType().ToString() +
+ " " + p->GetID();
} else {
str += ConvertTypeToString(p->GetParameterType().GetDirection(),
p->GetParameterType().GetBaseType()) + p->GetID();
std::string CStubBodyGen::GetMethodString(const Interface& inf,
const Declaration& decl) {
std::string str;
- const char port_setter[] = "rpc_port_set_$$_port($$, port);\n";
+ const char port_setter[] = "rpc_port_$$_set_port($$, port);\n";
const char parcel[] = "$$(parcel, $$);\n";
const char do_while_block[] =
"do {\n" \
"} while (0);\n";
int cnt = 0;
for (auto& i : decl.GetParameters().GetParams()) {
- str += GetParcelParamTypeString(i->GetParameterType().GetBaseType()) +
- i->GetID() + ";" + NLine(1);
+ if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
+ str += "rpc_port_" + inf.GetID() + "_" +
+ i->GetParameterType().GetBaseType().ToString() + "_h " +
+ i->GetID() + ";" + NLine(1);
+ } else {
+ str += GetReturnTypeString(i->GetParameterType().GetBaseType()) +
+ i->GetID() + ";" + NLine(1);
+ }
if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN)
cnt++;
}
if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
i->GetParameterType().GetBaseType().ToString() == "list" ||
i->GetParameterType().GetBaseType().ToString() == "array") {
- str += GetConstructorString(i->GetParameterType().GetBaseType(),
- i->GetID());
if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
+ str += "rpc_port_" + inf.GetID() + "_" +
+ i->GetParameterType().GetBaseType().ToString() +
+ "_create(&" + i->GetID() + ");" + NLine(1);
str += GenTemplateString(port_setter,
[&]()->std::string {
- return i->GetParameterType().GetBaseType().ToString();
+ return inf.GetID() + "_" +
+ i->GetParameterType().GetBaseType().ToString();
},
[&]()->std::string {
return i->GetID();
}
);
+ } else {
+ str += GetConstructorString(i->GetParameterType().GetBaseType(),
+ i->GetID());
}
}
}
for (auto& i: decl.GetParameters().GetParams()) {
- str += GetDestructorString(i->GetParameterType().GetBaseType(),
- i->GetID());
+ if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
+ str += "rpc_port_" + inf.GetID() + "_" +
+ i->GetParameterType().GetBaseType().ToString() +
+ "_destroy(" + i->GetID() + ");" + NLine(1);
+ } else {
+ str += GetDestructorString(i->GetParameterType().GetBaseType(),
+ i->GetID());
+ }
}
return str;
stream << NLine(1);
stream << SmartIndent(GenTemplateString(block,
[&]()->std::string {
- return decl.GetID();
+ return id + "_" + decl.GetID();
}
)
);
const std::string& id,
const Declaration& decl) {
const char block[] =
- "int rpc_port_create_##(rpc_port_##_h *h)\n" \
+ "int rpc_port_##_create(rpc_port_##_h *h)\n" \
"{\n" \
" struct ##_s *handle;\n" \
" static int seq_num;\n" \
"\n" \
" handle->parcelable.to = __##_to;\n" \
" handle->parcelable.from = __##_from;\n" \
- " handle->id = $$_DELEGATE_##;\n" \
+ " handle->id = $$_DELEGATE_$$;\n" \
" handle->seq_id = seq_num++;\n" \
"\n" \
" *h = handle;\n" \
stream << NLine(1);
stream << SmartIndent(GenTemplateString(
- ReplaceAll(block, "##", decl.GetID()),
+ ReplaceAll(block, "##", id + "_" + decl.GetID()),
[&]()->std::string {
return id;
+ },
+ [&]()->std::string {
+ return decl.GetID();
}
)
);
const std::string& id,
const Declaration& decl) {
const char block[] =
- "int rpc_port_destroy_##(rpc_port_##_h h)\n" \
+ "int rpc_port_##_destroy(rpc_port_##_h h)\n" \
"{\n" \
" if (!h) {\n" \
" LOGE(\"Invalid parameter\");\n" \
"}\n";
stream << NLine(1);
- stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+ stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
}
void CStubBodyGen::GenInterfaceDelegatorSerializer(std::ofstream& stream,
"}\n";
stream << NLine(1);
- stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+ stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
}
void CStubBodyGen::GenInterfaceDelegatorDeserializer(std::ofstream& stream,
"}\n";
stream << NLine(1);
- stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+ stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
}
void CStubBodyGen::GenInterfaceDelegatorCloner(std::ofstream& stream,
const std::string& id,
const Declaration& decl) {
const char block[] =
- "int rpc_port_clone_##(rpc_port_##_h h, rpc_port_##_h *clone)\n" \
+ "int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone)\n" \
"{\n" \
" rpc_port_##_h handle;\n" \
"\n" \
"}\n";
stream << NLine(1);
- stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+ stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
}
void CStubBodyGen::GenInterfaceDelegatorInvoker(std::ofstream& stream,
const Declaration& decl) {
const char parcel[] = "$$(parcel, $$);\n";
const char block[] =
- "int rpc_port_invoke_$$($$)\n" \
+ "int rpc_port_$$_invoke($$)\n" \
"{\n" \
" rpc_port_parcel_h parcel = NULL;\n" \
"\n" \
stream << NLine(1);
stream << SmartIndent(GenTemplateString(block,
[&]()->std::string {
- return decl.GetID();
+ return id + "_" + decl.GetID();
},
[&]()->std::string {
std::string str;
- str += "rpc_port_" + decl.GetID() + "_h h";
+ str += "rpc_port_" + id + "_" + decl.GetID() + "_h h";
for (auto& i : decl.GetParameters().GetParams()) {
str += ", ";
str += GetParamTypeString(i->GetParameterType().GetDirection(),
str += GenTemplateString(parcel,
[&]()->std::string {
return GetParcelWriteFunctionString(
- i->GetParameterType().GetBaseType());
+ i->GetParameterType().GetBaseType(), true);
},
[&]()->std::string {
if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
const std::string& id,
const Declaration& decl) {
const char block[] =
- "int rpc_port_set_##_port(rpc_port_##_h h, rpc_port_h port)\n" \
+ "int rpc_port_##_set_port(rpc_port_##_h h, rpc_port_h port)\n" \
"{\n" \
" if (!h || !port) {\n" \
" LOGE(\"Invalid parameter\");\n" \
"}\n";
stream << NLine(1);
- stream << SmartIndent(ReplaceAll(block, "##", decl.GetID()));
+ stream << SmartIndent(ReplaceAll(block, "##", id + "_" + decl.GetID()));
}
void CStubBodyGen::GenInterfaceContext(std::ofstream& stream,
void CStubHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
const Interface& inf) {
- const char callback[] = "$$ (*$$)(rpc_port_stub_$$_context_h context, $$void *user_data);\n";
+ const char callback[] = "$$(*$$)(rpc_port_stub_$$_context_h context, $$void *user_data);\n";
const char block[] =
"typedef struct {\n" \
" void (*create)(rpc_port_stub_##_context_h context, void *user_data);\n" \
std::string s;
for (auto& p : i->GetParameters().GetParams()) {
if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
- s += GetParcelParamTypeString(p->GetParameterType().GetBaseType()) +
+ s += "rpc_port_" + inf.GetID() + "_" +
+ p->GetParameterType().GetBaseType().ToString() + "_h " +
p->GetID();
} else {
s += GetParamTypeString(p->GetParameterType().GetDirection(),
std::ofstream& stream, const std::string& id, const Declaration& decl) {
const char format[] = "typedef struct ##_s *rpc_port_##_h;\n";
stream << NLine(1);
- stream << ReplaceAll(format, "##", decl.GetID());
+ stream << ReplaceAll(format, "##", id + "_" + decl.GetID());
}
void CStubHeaderGen::GenInterfaceDelegatorDestructor(
std::ofstream& stream, const std::string& id, const Declaration& decl) {
const char format[] =
- "int rpc_port_destroy_##(rpc_port_##_h h);\n";
+ "int rpc_port_##_destroy(rpc_port_##_h h);\n";
stream << NLine(1);
- stream << ReplaceAll(format, "##", decl.GetID());
+ stream << ReplaceAll(format, "##", id + "_" + decl.GetID());
}
void CStubHeaderGen::GenInterfaceDelegatorCloner(
std::ofstream& stream, const std::string& id, const Declaration& decl) {
const char format[] =
- "int rpc_port_clone_##(rpc_port_##_h h, rpc_port_##_h *clone);\n";
+ "int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone);\n";
stream << NLine(1);
- stream << ReplaceAll(format, "##", decl.GetID());
+ stream << ReplaceAll(format, "##", id + "_" + decl.GetID());
}
void CStubHeaderGen::GenInterfaceDelegatorInvoker(
std::ofstream& stream, const std::string& id, const Declaration& decl) {
const char format[] =
- "int rpc_port_invoke_##(rpc_port_##_h h$$);\n";
+ "int rpc_port_##_invoke(rpc_port_##_h h$$);\n";
stream << NLine(1);
- stream << GenTemplateString(ReplaceAll(format, "##", decl.GetID()),
+ stream << GenTemplateString(ReplaceAll(format, "##", id + "_" + decl.GetID()),
[&]()->std::string {
std::string str;
for (auto& i : decl.GetParameters().GetParams()) {