return st.GetComments();
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
std::string str;
void CBodyGeneratorBase::GenStructureParcelSerializer(std::ofstream& stream,
const Structure& st) {
stream << SmartIndent(GenTemplateString(
- ReplaceAll(CB_STRUCT_SERIALIZER, "##", st.GetID()),
+ ReplaceAll(CB_STRUCT_SERIALIZER, "##", GetStructIdWithNamespace(st)),
[&]()->std::string {
std::string str;
for (auto& i : st.GetElements().GetElms()) {
void CBodyGeneratorBase::GenStructureParcelDeserializer(std::ofstream& stream,
const Structure& st) {
stream << SmartIndent(GenTemplateString(
- ReplaceAll(CB_STRUCT_DESERIALIZER, "##", st.GetID()),
+ ReplaceAll(CB_STRUCT_DESERIALIZER, "##", GetStructIdWithNamespace(st)),
[&]()->std::string {
std::string str;
for (auto& i : st.GetElements().GetElms()) {
void CBodyGeneratorBase::GenStructureConstructor(std::ofstream& stream,
const Structure& st) {
- stream << SmartIndent(ReplaceAll(CB_STRUCT_CTOR, "##", st.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_STRUCT_CTOR, "##", GetStructIdWithNamespace(st)));
}
void CBodyGeneratorBase::GenStructureDestructor(std::ofstream& stream,
const Structure& st) {
stream << SmartIndent(GenTemplateString(
- ReplaceAll(CB_STRUCT_DTOR, "##", st.GetID()),
+ ReplaceAll(CB_STRUCT_DTOR, "##",
+ GetStructIdWithNamespace(st)),
[&]()->std::string {
std::string str;
for (auto& i : st.GetElements().GetElms()) {
for (auto& i : st.GetElements().GetElms()) {
stream << SmartIndent(GenTemplateString(CB_STRUCT_SETTER,
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
if (i->GetType().ToString() == "list")
return i->GetID();
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
if (i->GetType().IsUserDefinedType())
stream << SmartIndent(GenTemplateString(CB_STRUCT_GETTER,
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
return i->GetID();
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
if (i->GetType().IsUserDefinedType())
stream << SmartIndent(GenTemplateString(CB_STRUCT_ITERATOR,
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
return i->GetID();
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
if (i->GetType().GetMetaType()->IsUserDefinedType() ||
void CBodyGeneratorBase::GenStructureCloner(std::ofstream& stream,
const Structure& st) {
stream << SmartIndent(GenTemplateString(
- ReplaceAll(CB_STRUCT_CLONER, "##", st.GetID()),
+ ReplaceAll(CB_STRUCT_CLONER, "##", GetStructIdWithNamespace(st)),
[&]()->std::string {
std::string str;
for (auto& i : st.GetElements().GetElms()) {
std::string ss;
ss += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to duplicate h->" + id + "\");" +
NLine(1);
- ss += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+ ss += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" +
NLine(1);
ss += "return -1;" + NLine(1);
return ss;
return GetParcelParamTypeString(*type.GetMetaType());
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
std::string s;
std::string ss;
ss += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to duplicate value\");" +
NLine(1);
- ss += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+ ss += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" +
NLine(1);
ss += "return -1;" + NLine(1);
return ss;
[&]()->std::string {
std::string tmp;
tmp += "dlog_print(DLOG_ERROR, LOG_TAG, \"Out of memory\");" + NLine(1);
- tmp += "rpc_port_" + st.GetID() + "_destroy(handle);" +
+ tmp += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" +
NLine(1);
tmp += "return -1;" + NLine(1);
return tmp;
if (type.IsUserDefinedType() ||
type.ToString() == "list" ||
type.ToString() == "array") {
- str += "rpc_port_" + GetFullNameFromType(type) +
+ str += GetHandlePrefix() + GetFullNameFromType(type) +
"_destroy(" + value + ");" + NLine(1);
} else if (type.ToString() == "bundle") {
str += "bundle_free(" + value + ");" + NLine(1);
std::string CBodyGeneratorBase::GetConstructorString(const BaseType& type,
const std::string& value) {
std::string str;
- str += "rpc_port_" + GetFullNameFromType(type) +
+ str += GetHandlePrefix() + GetFullNameFromType(type) +
"_create(&" + value + ");" + NLine(1);
return str;
}
if (type.IsUserDefinedType() ||
type.ToString() == "list" ||
type.ToString() == "array") {
- str += "rpc_port_" + GetFullNameFromType(type) +
+ str += GetHandlePrefix() + GetFullNameFromType(type) +
"_clone(" + rvalue + ", &" + lvalue +");" + NLine(1);
} else if (type.ToString() == "string") {
str += lvalue + " = strdup(" + rvalue + ");" + NLine(1);
stream << SmartIndent(GenTemplateString(CB_DELEGATE_ENUM,
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
std::string str;
str += GenTemplateString(CB_DELEGATE_ENUM_FORMAT,
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
return i->GetID();
std::ofstream& stream, const Interface& inf) {
stream << SmartIndent(GenTemplateString(CB_METHOD_ENUM,
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
std::string str;
continue;
str += GenTemplateString(CB_METHOD_ENUM_FORMAT,
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
return i->GetID();
ParameterType::Direction direction, const BaseType& type) {
if (type.IsUserDefinedType()) {
if (direction == ParameterType::Direction::IN)
- return "rpc_port_" + type.ToString() + "_h ";
+ return GetHandlePrefix() + type.ToString() + "_h ";
else
- return "rpc_port_" + type.ToString() + "_h *";
+ return GetHandlePrefix() + type.ToString() + "_h *";
}
if (type.ToString() == "array") {
std::string CGeneratorBase::GetParcelParamTypeString(const BaseType& type,
bool is_pointer) {
if (type.IsUserDefinedType())
- return "rpc_port_" + type.ToString() + "_h ";
+ return GetHandlePrefix() + type.ToString() + "_h ";
if (type.ToString() == "list" ||
type.ToString() == "array")
- return "rpc_port_" + GetFullNameFromType(type) + "_h ";
+ return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
if (type.ToString() == "string")
return "char *";
std::string CGeneratorBase::GetReturnTypeString(const BaseType& type) {
if (type.IsUserDefinedType())
- return "rpc_port_" + type.ToString() + "_h ";
+ return GetHandlePrefix() + type.ToString() + "_h ";
if (type.ToString() == "list" ||
type.ToString() == "array")
- return "rpc_port_" + GetFullNameFromType(type) + "_h ";
+ return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
return type_map_[type.ToString()];
}
type.ToString() == "list" ||
type.ToString() == "array") {
if (direction == ParameterType::Direction::IN)
- return "rpc_port_" + GetFullNameFromType(type) + "_h ";
+ return GetHandlePrefix() + GetFullNameFromType(type) + "_h ";
else
- return "rpc_port_" + GetFullNameFromType(type) + "_h *";
+ return GetHandlePrefix() + GetFullNameFromType(type) + "_h *";
}
if (type.ToString() == "string") {
std::string CGeneratorBase::GetStringFromElementType(const BaseType& type) {
if (type.IsUserDefinedType())
- return "rpc_port_" + type.ToString() + "_h ";
+ return GetHandlePrefix() + type.ToString() + "_h ";
if (type.ToString() == "array")
return GetReturnTypeString(*type.GetMetaType()) + "*";
return type_map_[type.ToString()];
}
+std::string CGeneratorBase::GetStructIdWithNamespace(const Structure& st) {
+ if (!HasNamespace())
+ return st.GetID();
+ return GetFileNamespace() + "_" + st.GetID();
+}
+
+std::string CGeneratorBase::GetInterfaceIdWithNamespace(const Interface& inf) {
+ if (!HasNamespace())
+ return inf.GetID();
+ return GetFileNamespace() + "_" + inf.GetID();
+}
+
+std::string CGeneratorBase::GetHandlePrefix() {
+ if (!HasNamespace())
+ return "rpc_port_";
+ return "rpc_port_" + GetFileNamespace() + "_";
+}
+
} // namespace tidl
void GenLicenseDescription(std::ofstream& stream);
void GenIncludeDefaultHeaders(std::ofstream& stream, bool body = true);
void GenGNUSourceDefinition(std::ofstream& stream);
+ std::string GetStructIdWithNamespace(const Structure& st);
+ std::string GetInterfaceIdWithNamespace(const Interface& inf);
+ std::string GetHandlePrefix();
private:
bool StructureExist(const Structure& st);
const Structure& st) {
GenTemplate(CB_STRUCT_DECL, stream,
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
}
);
}
const Structure& st) {
GenTemplate(CB_STRUCT_CTOR, stream,
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
}
);
}
const Structure& st) {
GenTemplate(CB_STRUCT_DTOR, stream,
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
}
);
}
for (auto& i : st.GetElements().GetElms()) {
GenTemplate(CB_STRUCT_SETTER, stream,
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
if (i->GetType().ToString() == "list")
return i->GetID();
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
if (i->GetType().IsUserDefinedType())
GenTemplate(CB_STRUCT_GETTER, stream,
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
return i->GetID();
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
if (i->GetType().IsUserDefinedType())
GenTemplate(CB_STRUCT_ITERATOR, stream,
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
return i->GetID();
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
if (i->GetType().GetMetaType()->IsUserDefinedType() ||
const Structure& st) {
GenTemplate(CB_STRUCT_CLONER, stream,
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
},
[&]()->std::string {
- return st.GetID();
+ return GetStructIdWithNamespace(st);
}
);
}
void CProxyBodyGen::GenInterfaceDeclaration(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_STRUCT, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_STRUCT, "##", GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceDelegators(std::ofstream& stream,
for (auto& i : inf.GetDeclarations().GetDecls()) {
if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
continue;
- GenInterfaceDelegator(stream, inf.GetID(), *i);
+ GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
}
}
continue;
str += GenTemplateString(delegate_format,
[&]()->std::string {
- return inf.GetID() + "_DELEGATE_" + i->GetID();
+ return GetInterfaceIdWithNamespace(inf) + "_DELEGATE_" + i->GetID();
},
[&]()->std::string {
- return "__" + inf.GetID() + "_delegate_" + i->GetID();
+ return "__" + GetInterfaceIdWithNamespace(inf) + "_delegate_" + i->GetID();
}
);
cnt++;
stream << SmartIndent(GenTemplateString(block,
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
return str;
}
stream << SmartIndent(GenTemplateString(
- ReplaceAll(CB_PROCESS_RECEIVED_EVENT, "##", inf.GetID()),
+ ReplaceAll(CB_PROCESS_RECEIVED_EVENT, "##", GetInterfaceIdWithNamespace(inf)),
[&]()->std::string {
if (cnt == 0)
return str;
- return ReplaceAll(CB_PROCESS_RECEIVED_EVENT_IMPL, "##", inf.GetID());
+ return ReplaceAll(CB_PROCESS_RECEIVED_EVENT_IMPL, "##", GetInterfaceIdWithNamespace(inf));
}
)
);
void CProxyBodyGen::GenInterfaceConsumeCommand(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_CONSUME_COMMAND, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_CONSUME_COMMAND, "##", GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_ON_CONNECTED, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_ON_CONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_ON_DISCONNECTED, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_ON_DISCONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceOnRejectedEventCB(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_ON_REJECTED, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_ON_REJECTED, "##", GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_ON_RECEIVED, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_ON_RECEIVED, "##", GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
continue;
stream << SmartIndent(GenTemplateString(
- ReplaceAll(CB_INTERFACE_METHODS, "##", inf.GetID()),
+ ReplaceAll(CB_INTERFACE_METHODS, "##", GetInterfaceIdWithNamespace(inf)),
[&]()->std::string {
return GetReturnTypeString(i->GetType());
},
for (auto& p : i->GetParameters().GetParams()) {
str += ", ";
if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
- str += "rpc_port_" + inf.GetID() + "_" +
+ str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
p->GetParameterType().GetBaseType().ToString() +
"_h " + p->GetID();
} else {
void CProxyBodyGen::GenInterfaceConstructor(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_CTOR, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_CTOR, "##", GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceDestructor(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_DTOR, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_DTOR, "##", GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceConnect(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_CONNECT, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_CONNECT, "##", GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceDisconnect(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_DISCONNECT, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_DISCONNECT, "##", GetInterfaceIdWithNamespace(inf)));
}
std::string CProxyBodyGen::GetMethodWriteString(const Interface& inf,
continue;
if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
str += GenTemplateString(ReplaceAll(CB_DELEGATE_BLOCK, "##",
- inf.GetID() + "_" + p->GetParameterType().GetBaseType().ToString()),
+ GetInterfaceIdWithNamespace(inf) + "_" + p->GetParameterType().GetBaseType().ToString()),
[&]()->std::string {
return p->GetID();
}
return s;
},
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
std::string s;
for (auto& i : inf.GetDeclarations().GetDecls()) {
if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
continue;
- GenInterfaceDelegator(stream, inf.GetID(), *i);
+ GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
}
}
void CProxyHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_DECL, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_DECL, "##", GetInterfaceIdWithNamespace(inf)));
}
void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
continue;
stream << GenTemplateString(
- ReplaceAll(CB_INTERFACE_METHODS, "##", inf.GetID()),
+ ReplaceAll(CB_INTERFACE_METHODS, "##", GetInterfaceIdWithNamespace(inf)),
[&]()->std::string {
return GetReturnTypeString(i->GetType());
},
for (auto& p : i->GetParameters().GetParams()) {
str += ", ";
if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
- str += "rpc_port_" + inf.GetID() + "_" +
+ str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
p->GetParameterType().GetBaseType().ToString() +
"_h " + p->GetID();
} else {
void CProxyHeaderGen::GenInterfaceConnect(std::ofstream& stream,
const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_CONNECT, "##", inf.GetID());
+ stream << ReplaceAll(CB_INTERFACE_CONNECT, "##", GetInterfaceIdWithNamespace(inf));
}
void CProxyHeaderGen::GenInterfaceDisconnect(std::ofstream& stream,
const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_DISCONNECT, "##", inf.GetID());
+ stream << ReplaceAll(CB_INTERFACE_DISCONNECT, "##", GetInterfaceIdWithNamespace(inf));
}
} // namespace tidl
stream << SmartIndent(GenTemplateString(CB_INTERFACE_METHOD,
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
return i->GetID();
},
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
return GetMethodString(inf, *i);
continue;
str += GenTemplateString(CB_INTERFACE_METHOD_FORMAT,
[&]()->std::string {
- return inf.GetID() + "_METHOD_" + i->GetID();
+ return GetInterfaceIdWithNamespace(inf) + "_METHOD_" + i->GetID();
},
[&]()->std::string {
- return "__" + inf.GetID() + "_method_" + i->GetID();
+ return "__" + GetInterfaceIdWithNamespace(inf) + "_method_" + i->GetID();
}
);
cnt++;
stream << NLine(1);
stream << SmartIndent(GenTemplateString(CB_INTERFACE_METHOD_TABLE,
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
return str;
void CStubBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(
- ReplaceAll(CB_INTERFACE_ON_CONNECTED, "##", inf.GetID()));
+ ReplaceAll(CB_INTERFACE_ON_CONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(
- ReplaceAll(CB_INTERFACE_ON_DISCONNECTED, "##", inf.GetID()));
+ ReplaceAll(CB_INTERFACE_ON_DISCONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(
- ReplaceAll(CB_INTERFACE_ON_RECEIVED, "##", inf.GetID()));
+ ReplaceAll(CB_INTERFACE_ON_RECEIVED, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceRegister(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_REGISTER, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_REGISTER, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceUnregister(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_UNREGISTER, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_UNREGISTER, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceGlobalVariables(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_GLOBALS, "##", inf.GetID()));
+ stream << SmartIndent(ReplaceAll(CB_GLOBALS, "##", GetInterfaceIdWithNamespace(inf)));
}
std::string CStubBodyGen::GetMethodString(const Interface& inf,
int cnt = 0;
for (auto& i : decl.GetParameters().GetParams()) {
if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
- str += "rpc_port_" + inf.GetID() + "_" +
+ str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
i->GetParameterType().GetBaseType().ToString() + "_h " +
i->GetID() + ";" + NLine(1);
} else {
i->GetParameterType().GetBaseType().ToString() == "list" ||
i->GetParameterType().GetBaseType().ToString() == "array") {
if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
- str += "rpc_port_" + inf.GetID() + "_" +
+ str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
i->GetParameterType().GetBaseType().ToString() +
"_create(&" + i->GetID() + ");" + NLine(1);
str += GenTemplateString(port_setter,
[&]()->std::string {
- return inf.GetID() + "_" +
+ return GetInterfaceIdWithNamespace(inf) + "_" +
i->GetParameterType().GetBaseType().ToString();
},
[&]()->std::string {
if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
str += GenTemplateString(do_while_block,
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
std::string s;
for (auto& i: decl.GetParameters().GetParams()) {
if (TypeIsDelegator(inf, i->GetParameterType().GetBaseType())) {
- str += "rpc_port_" + inf.GetID() + "_" +
+ str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
i->GetParameterType().GetBaseType().ToString() +
"_destroy(" + i->GetID() + ");" + NLine(1);
} else {
for (auto& i : inf.GetDeclarations().GetDecls()) {
if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
continue;
- GenInterfaceDelegator(stream, inf.GetID(), *i);
+ GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
}
}
void CStubBodyGen::GenInterfaceContextDeclaration(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(ReplaceAll(
- CB_INTERFACE_CONTEXT_DECL, "##", inf.GetID()));
+ CB_INTERFACE_CONTEXT_DECL, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceContextConstructor(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(ReplaceAll(
- CB_INTERFACE_CONTEXT_CTOR, "##", inf.GetID()));
+ CB_INTERFACE_CONTEXT_CTOR, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceContextDestructor(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(ReplaceAll(
- CB_INTERFACE_CONTEXT_DTOR, "##", inf.GetID()));
+ CB_INTERFACE_CONTEXT_DTOR, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceContextFinder(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(ReplaceAll(
- CB_INTERFACE_CONTEXT_FINDER, "##", inf.GetID()));
+ CB_INTERFACE_CONTEXT_FINDER, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceContextTagSetter(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(ReplaceAll(
- CB_INTERFACE_CONTEXT_TAG_SETTER, "##", inf.GetID()));
+ CB_INTERFACE_CONTEXT_TAG_SETTER, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceContextTagGetter(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(ReplaceAll(
- CB_INTERFACE_CONTEXT_TAG_GETTER, "##", inf.GetID()));
+ CB_INTERFACE_CONTEXT_TAG_GETTER, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceContextSenderGetter(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(ReplaceAll(
- CB_INTERFACE_CONTEXT_GET_SENDER, "##", inf.GetID()));
+ CB_INTERFACE_CONTEXT_GET_SENDER, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceContextPortExist(std::ofstream& stream,
return;
stream << SmartIndent(ReplaceAll(
- CB_INTERFACE_CONTEXT_PORT_EXIST, "##", inf.GetID()));
+ CB_INTERFACE_CONTEXT_PORT_EXIST, "##", GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenTypedefStubMethod(std::ofstream& stream) {
const Interface& inf) {
stream << SmartIndent(GenTemplateString(CB_INTERFACE_ADD_PRIVILEGE,
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
std::string str;
for (auto& a : inf.GetAttributes().GetAttrs()) {
if (a->GetKey() == "privilege") {
- str += GetAddPrivilegeString(inf.GetID(), *a);
+ str += GetAddPrivilegeString(GetInterfaceIdWithNamespace(inf), *a);
str += NLine(1);
} else if (a->GetKey() == "trusted" && a->GetValue() == "true") {
- str += GetTrustedModeString(inf.GetID(), *a);
+ str += GetTrustedModeString(GetInterfaceIdWithNamespace(inf), *a);
str += NLine(1);
}
}
void CStubHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(GenTemplateString(ReplaceAll(
- CB_INTERFACE_DECL, "##", inf.GetID()),
+ CB_INTERFACE_DECL, "##", GetInterfaceIdWithNamespace(inf)),
[&]()->std::string {
std::string str;
for (auto& i: inf.GetDeclarations().GetDecls()) {
return i->GetID();
},
[&]()->std::string {
- return inf.GetID();
+ return GetInterfaceIdWithNamespace(inf);
},
[&]()->std::string {
std::string s;
for (auto& p : i->GetParameters().GetParams()) {
if (TypeIsDelegator(inf, p->GetParameterType().GetBaseType())) {
- s += "rpc_port_" + inf.GetID() + "_" +
+ s += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
p->GetParameterType().GetBaseType().ToString() + "_h " +
p->GetID();
} else {
void CStubHeaderGen::GenInterfaceContextDeclaration(
std::ofstream& stream, const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_CONTEXT_DECL, "##", inf.GetID());
+ stream << ReplaceAll(CB_INTERFACE_CONTEXT_DECL, "##", GetInterfaceIdWithNamespace(inf));
}
void CStubHeaderGen::GenInterfaceContextTagSetter(
std::ofstream& stream, const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_CONTEXT_SET_TAG, "##", inf.GetID());
+ stream << ReplaceAll(CB_INTERFACE_CONTEXT_SET_TAG, "##", GetInterfaceIdWithNamespace(inf));
}
void CStubHeaderGen::GenInterfaceContextTagGetter(
std::ofstream& stream, const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_TAG, "##", inf.GetID());
+ stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_TAG, "##", GetInterfaceIdWithNamespace(inf));
}
void CStubHeaderGen::GenInterfaceContextSenderGetter(
std::ofstream& stream, const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_SENDER, "##", inf.GetID());
+ stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_SENDER, "##", GetInterfaceIdWithNamespace(inf));
}
void CStubHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
for (auto& i : inf.GetDeclarations().GetDecls()) {
if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
continue;
- GenInterfaceDelegator(stream, inf.GetID(), *i);
+ GenInterfaceDelegator(stream, GetInterfaceIdWithNamespace(inf), *i);
}
}
void CStubHeaderGen::GenInterfaceRegister(std::ofstream& stream,
const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_REGISTER, "##", inf.GetID());
+ stream << ReplaceAll(CB_INTERFACE_REGISTER, "##", GetInterfaceIdWithNamespace(inf));
}
void CStubHeaderGen::GenInterfaceUnregister(std::ofstream& stream,
const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_UNREGISTER, "##", inf.GetID());
+ stream << ReplaceAll(CB_INTERFACE_UNREGISTER, "##", GetInterfaceIdWithNamespace(inf));
}
} // namespace tidl
std::string AddIndent(int indent, std::string lines, bool space = true);
std::string GetFileNamespace() const;
+ void EnableNamespace(bool enable) {
+ hasNamespace_ = enable;
+ }
+
+ bool HasNamespace() const {
+ return hasNamespace_;
+ }
+
template<typename T, typename ...ARGS>
void GenTemplate(std::string templ, std::ofstream& stream, T cb, ARGS... args) {
size_t f = templ.find("$$");
private:
std::shared_ptr<Document> doc_;
std::ofstream out_file_;
+ bool hasNamespace_ = true;
};
} // namespace tidl
std::string GetLanguage() const { return language_; }
std::string GetInput() const { return input_; }
std::string GetOutput() const { return output_; }
+ bool HasNamespace() const { return hasNamespace_; }
private:
enum Cmd {
OPT_LANGUAGE,
OPT_INPUT,
OPT_OUTPUT,
+ OPT_NAMESPACE,
OPT_MAX
};
std::string input_;
std::string output_;
std::string help_;
+ bool hasNamespace_ = false;
};
void Options::PrintUsage() {
"A tidl interface file.", "INPUT" },
{ "output", 'o', 0, G_OPTION_ARG_STRING, &opt[OPT_OUTPUT],
"The generated interface file.", "OUTPUT" },
+ { "namespace", 'n', 0, G_OPTION_ARG_NONE, &opt[OPT_NAMESPACE],
+ "Add the prefix in the funtion name as output file name (C language only).",
+ NULL },
{ NULL }
};
options->language_ = static_cast<char*>(opt[OPT_LANGUAGE]);
options->input_ = static_cast<char*>(opt[OPT_INPUT]);
options->output_ = static_cast<char*>(opt[OPT_OUTPUT]);
+ options->hasNamespace_ = opt[OPT_NAMESPACE] ? true : false;
return options;
}
proxy_body.Run(options->GetOutput() + ".cc");
} else if (options->GetLanguage() == "C") {
tidl::CProxyHeaderGen proxy_header(ps.GetDoc());
+ proxy_header.EnableNamespace(options->HasNamespace());
proxy_header.Run(options->GetOutput() + ".h");
tidl::CProxyBodyGen proxy_body(ps.GetDoc());
+ proxy_body.EnableNamespace(options->HasNamespace());
proxy_body.Run(options->GetOutput() + ".c");
}
} else {
stub_body.Run(options->GetOutput() + ".cc");
} else if (options->GetLanguage() == "C") {
tidl::CStubHeaderGen stub_header(ps.GetDoc());
+ stub_header.EnableNamespace(options->HasNamespace());
stub_header.Run(options->GetOutput() + ".h");
tidl::CStubBodyGen stub_body(ps.GetDoc());
+ stub_body.EnableNamespace(options->HasNamespace());
stub_body.Run(options->GetOutput() + ".c");
}
}