GenInterfaceOnConnectedEventCB(stream, inf);
GenInterfaceOnDisconnectedEventCB(stream, inf);
GenInterfaceOnReceivedEventCB(stream, inf);
+ GenInterfaceAddPrivileges(stream, inf);
GenInterfaceRegister(stream, inf);
GenInterfaceUnregister(stream, inf);
}
" return r;\n" \
" }\n" \
"\n" \
- "$$" \
+ " r = __##_add_privileges();\n" \
+ " if (r != 0) {\n" \
+ " LOGE(\"Failed to add privileges\");\n" \
+ " rpc_port_stub_destroy(__##_stub);\n" \
+ " __##_stub = NULL;\n" \
+ " return r;\n" \
+ " }\n" \
"\n" \
" r = rpc_port_stub_listen(__##_stub);\n" \
" if (r != 0) {\n" \
"}\n";
stream << NLine(1);
- stream << SmartIndent(GenTemplateString(
- ReplaceAll(block, "##", inf.GetID()),
- [&]()->std::string {
- std::string str;
- for (auto& a : inf.GetAttributes().GetAttrs()) {
- if (a->GetKey() != "privilege")
- continue;
- str += NLine(1);
- str += GetAddPrivilegeString(inf.GetID(), *a);
- }
- return str;
- }
- )
- );
+ stream << SmartIndent(ReplaceAll(block, "##", inf.GetID()));
}
void CStubBodyGen::GenInterfaceUnregister(std::ofstream& stream,
const Attribute& attr) {
const char format[] =
"r = $$;\n" \
- "if (r != 0) {\n" \
- " LOGE(\"$$\");\n" \
- " rpc_port_stub_destroy(__$$_stub);\n" \
- " __$$_stub = NULL;\n" \
+ "if (r != 0) {\n" \
+ " LOGE(\"Failed to add privilege($$)\");\n" \
" return r;\n" \
"}\n";
std::string str;
"_stub, \"" + attr.GetValue() + "\")";
},
[&]()->std::string {
- return "Failed to add privilege";
- },
- [&]()->std::string {
- return id;
- },
- [&]()->std::string {
- return id;
+ return attr.GetValue();
}
);
return str;
stream << std::string(format);
}
+void CStubBodyGen::GenInterfaceAddPrivileges(std::ofstream& stream,
+ const Interface& inf) {
+ const char block[] =
+ "static int __$$_add_privileges(void)\n" \
+ "{\n" \
+ "$$" \
+ " return 0;\n" \
+ "}\n";
+ stream << NLine(1);
+ stream << SmartIndent(GenTemplateString(block,
+ [&]()->std::string {
+ return inf.GetID();
+ },
+ [&]()->std::string {
+ std::string str;
+ for (auto& a : inf.GetAttributes().GetAttrs()) {
+ if (a->GetKey() != "privilege")
+ continue;
+ str += GetAddPrivilegeString(inf.GetID(), *a);
+ str += NLine(1);
+ }
+ return str;
+ }
+ )
+ );
+}
+
} // namespace tidl
void GenInterfaceGlobalVariables(std::ofstream& stream, const Interface& inf);
void GenInterfaceDelegators(std::ofstream& stream, const Interface& inf);
void GenInterfaceContext(std::ofstream& stream, const Interface& inf);
+ void GenInterfaceAddPrivileges(std::ofstream& stream, const Interface& inf);
private:
void GenInterfaceContextDeclaration(std::ofstream& stream,