Merge "Split defaultPassthroughServiceImplementation into reusable parts"
diff --git a/include/hidl/LegacySupport.h b/include/hidl/LegacySupport.h
index 6e030ce..2ff1785 100644
--- a/include/hidl/LegacySupport.h
+++ b/include/hidl/LegacySupport.h
@@ -28,37 +28,55 @@
 namespace hardware {
 
 /**
- * Creates default passthrough service implementation. This method never returns.
- *
- * Return value is exit status.
+ * Registers passthrough service implementation.
  */
 template<class Interface>
-int defaultPassthroughServiceImplementation(std::string name) {
+status_t registerPassthroughServiceImplementation(std::string name) {
     sp<Interface> service = Interface::getService(name, true /* getStub */);
 
     if (service == nullptr) {
-        ALOGE("Could not get passthrough implementation.");
+        ALOGE("Could not get passthrough implementation for %s.", name.c_str());
         return EXIT_FAILURE;
     }
 
-    LOG_FATAL_IF(service->isRemote(), "Implementation is remote!");
+    LOG_FATAL_IF(service->isRemote(), "Implementation of %s is remote!", name.c_str());
 
     status_t status = service->registerAsService(name);
 
     if (status == OK) {
-        ALOGI("Registration complete.");
+        ALOGI("Registration complete for %s.", name.c_str());
     } else {
-        ALOGE("Could not register service (%d).", status);
+        ALOGE("Could not register service %s (%d).", name.c_str(), status);
     }
 
-    ProcessState::self()->setThreadPoolMaxThreadCount(0);
+    return status;
+}
+
+/**
+ * Launches the RPC threadpool. This method never returns.
+ *
+ * Return value is exit status.
+ */
+inline int launchRpcServer(size_t maxThreads) {
+    ProcessState::self()->setThreadPoolMaxThreadCount(maxThreads);
     ProcessState::self()->startThreadPool();
     IPCThreadState::self()->joinThreadPool();
 
     return 0;
 }
 
+/**
+ * Creates default passthrough service implementation. This method never returns.
+ *
+ * Return value is exit status.
+ */
+template<class Interface>
+int defaultPassthroughServiceImplementation(std::string name) {
+    registerPassthroughServiceImplementation<Interface>(name);
+    return launchRpcServer(0);
+}
+
 }  // namespace hardware
 }  // namespace android
 
-#endif  // ANDROID_HIDL_LEGACY_SUPPORT_H
\ No newline at end of file
+#endif  // ANDROID_HIDL_LEGACY_SUPPORT_H