IHidlInterfaceBase for all autogenerated interfaces.

Add an interfaceChain() method to each interface
to facilitate casting between interfaces.

Add ::descriptor for each interface (so that
IFoo::descriptor won't fall back to
IHidlInterfaceBase::descriptor.

Test: hidl_test
Test: cd system/tools/hidl && mma
Test: cd hardware/interfaces/test && mma

Bug: 32337854
Change-Id: I317b7905750db0bfefc4c5fd608a07080923c719
diff --git a/Method.cpp b/Method.cpp
index 95a688a..dfac662 100644
--- a/Method.cpp
+++ b/Method.cpp
@@ -20,6 +20,7 @@
 #include "ScalarType.h"
 #include "Type.h"
 
+#include <android-base/logging.h>
 #include <hidl-util/Formatter.h>
 
 namespace android {
@@ -36,6 +37,24 @@
       mAnnotations(annotations) {
 }
 
+// HIDL reserved methods.
+Method::Method(const char *name,
+       std::vector<TypedVar *> *args,
+       std::vector<TypedVar *> *results,
+       bool oneway,
+       std::vector<Annotation *> *annotations,
+       size_t serial,
+       MethodImpl cppImpl,
+       MethodImpl javaImpl)
+    : Method(name, args, results, oneway, annotations) {
+
+    mIsHidlReserved = true;
+    mSerial = serial;
+    mCppImpl = cppImpl;
+    mJavaImpl = javaImpl;
+}
+
+
 std::string Method::name() const {
     return mName;
 }
@@ -52,7 +71,22 @@
     return *mAnnotations;
 }
 
+void Method::cppImpl(Formatter &out) const {
+    CHECK(mIsHidlReserved);
+    if (mCppImpl) {
+        mCppImpl(out);
+    }
+}
+
+void Method::javaImpl(Formatter &out) const {
+    CHECK(mIsHidlReserved);
+    if (mJavaImpl) {
+        mJavaImpl(out);
+    }
+}
+
 void Method::setSerialId(size_t serial) {
+    CHECK(!mIsHidlReserved);
     mSerial = serial;
 }