c++-impl: gen server stub boilerplate
-Lc++-impl now generates a default implementation for all
the interfaces in the specified package. The method
implementations are all left empty.
The default implementation also contains a special function,
HIDL_FETCH_IFOO(), which is used to retrieve an instance of
a particular interface in pass-through mode. For that to work,
the default implementation must live in a shared-library with
a well-known name, eg android.hardware.tests.foo@1.0.impl.so.
Sample invocation:
hidl-gen -o tmp/impl/ -Lc++-impl -randroid.hardware:hardware/interfaces
android.hardware.tests.foo@1.0
Bug: 31228745
Change-Id: I747aa47cb76931eed85179b8131d2efd3f887471
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 3668fd6..f11137c 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -74,15 +74,8 @@
}
std::string AST::makeHeaderGuard(const std::string &baseName) const {
- std::vector<std::string> packageComponents;
- getPackageAndVersionComponents(
- &packageComponents, true /* cpp_compatible */);
-
- std::string guard = "HIDL_GENERATED";
- for (const auto &component : packageComponents) {
- guard += "_";
- guard += component;
- }
+ std::string guard = "HIDL_GENERATED_";
+ guard += mPackage.tokenName();
guard += "_";
guard += baseName;
@@ -456,10 +449,10 @@
return OK;
}
-status_t AST::generateProxyMethod(Formatter &out,
- const std::string &className,
- const Method *method,
- bool specifyNamespaces) const {
+status_t AST::generateProxyDeclaration(Formatter &out,
+ const std::string &className,
+ const Method *method,
+ bool specifyNamespaces) const {
method->generateCppSignature(out,
className,
@@ -500,12 +493,25 @@
specifyNamespaces);
break;
case PROXY_HEADER:
- err = generateProxyMethod(out,
- className,
- method,
- specifyNamespaces);
+ err = generateProxyDeclaration(out,
+ className,
+ method,
+ specifyNamespaces);
+ break;
+ case IMPL_HEADER:
+ err = generateStubImplDeclaration(out,
+ className,
+ method,
+ specifyNamespaces);
+ break;
+ case IMPL_SOURCE:
+ err = generateStubImplMethod(out,
+ className,
+ method,
+ specifyNamespaces);
break;
default:
+ LOG(ERROR) << "Unkown method type: " << type;
err = UNKNOWN_ERROR;
}
@@ -587,10 +593,15 @@
out.unindent();
out.unindent();
- generateMethods(out,
- "" /* class name */,
- MethodLocation::STUB_HEADER,
- true /* specify namespaces */);
+ status_t err = generateMethods(out,
+ "" /* class name */,
+ MethodLocation::STUB_HEADER,
+ true /* specify namespaces */);
+
+ if (err != OK) {
+ return err;
+ }
+
out.unindent();
out << "};\n\n";
@@ -662,10 +673,14 @@
out << "virtual bool isRemote() const { return true; }\n\n";
- generateMethods(out,
- "" /* class name */,
- MethodLocation::PROXY_HEADER,
- true /* generate specify namespaces */);
+ status_t err = generateMethods(out,
+ "" /* class name */,
+ MethodLocation::PROXY_HEADER,
+ true /* generate specify namespaces */);
+
+ if (err != OK) {
+ return err;
+ }
out.unindent();
@@ -745,7 +760,13 @@
}
if (err == OK && isInterface) {
- out << "IMPLEMENT_REGISTER_AND_GET_SERVICE(" << baseName << ")\n";
+ const Interface *iface = mRootScope->getInterface();
+
+ out << "IMPLEMENT_REGISTER_AND_GET_SERVICE("
+ << baseName << ", "
+ << "\"" << iface->fqName().package()
+ << iface->fqName().version() << ".impl.so\""
+ << ")\n";
}
enterLeaveNamespace(out, false /* enter */);