summaryrefslogtreecommitdiff
path: root/adapter/include
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2017-09-15 16:22:48 -0700
committerSteven Moreland <smoreland@google.com>2017-09-25 10:07:58 -0700
commitff189a023ccda656aa26f421c516f7feb9a138d1 (patch)
tree2389651b12b19379d82c1dfe7093ca162c5a8232 /adapter/include
parent10618f3d4688b8b0c1f06054a9049b906d6159c3 (diff)
downloadlibhidl-ff189a023ccda656aa26f421c516f7feb9a138d1.tar.gz
libhidladapter: Support for HIDL adapters
A HIDL adapter takes an x.(y+1) interface and registers it as an x.y interface for testing. This library allows someone or something to run an adapter. Note: this requires b/62303973 to properly mock a lower interface version. Note: this requires adapters to run as root to get around sepolicy. Bug: 37518178 Test: can switch out implementations ~/android/master$ lshal | grep hidl.allocator Y android.hidl.allocator@1.0::IAllocator/ashmem 0/1 652 471 ~/android/master$ lshal | grep hidl.allocator Y android.hidl.allocator@1.0::IAllocator/ashmem 0/1 7635 471 ~/android/master$ lshal | grep hidl.allocator Y android.hidl.allocator@1.0::IAllocator/ashmem 0/1 652 471 Change-Id: Ic72feb3a2fd4649e67b396c33b9a292e9c0a944a
Diffstat (limited to 'adapter/include')
-rw-r--r--adapter/include/hidladapter/HidlBinderAdapter.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/adapter/include/hidladapter/HidlBinderAdapter.h b/adapter/include/hidladapter/HidlBinderAdapter.h
new file mode 100644
index 0000000..46df554
--- /dev/null
+++ b/adapter/include/hidladapter/HidlBinderAdapter.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <android/hidl/base/1.0/IBase.h>
+#include <hidl/HidlSupport.h>
+
+#include <map>
+
+namespace android {
+namespace hardware {
+
+namespace details {
+
+using IBase = ::android::hidl::base::V1_0::IBase;
+
+// AdapterFactory(impl) -> adapter
+using AdapterFactory = std::function<sp<IBase>(sp<IBase>)>;
+// AdaptersFactory(package@interface)(impl) -> adapter
+using AdaptersFactory = std::map<std::string, AdapterFactory>;
+
+int adapterMain(const std::string& package, int argc, char** argv, const AdaptersFactory& adapters);
+
+sp<IBase> adaptWithDefault(const sp<IBase>& something,
+ const std::function<sp<IBase>()>& makeDefault);
+
+} // namespace details
+
+template <typename... Adapters>
+int adapterMain(const std::string& package, int argc, char** argv) {
+ return details::adapterMain(
+ package, argc, argv,
+ {{Adapters::Pure::descriptor, [](sp<::android::hidl::base::V1_0::IBase> base) {
+ return details::adaptWithDefault(
+ base, [&] { return new Adapters(Adapters::Pure::castFrom(base)); });
+ }}...});
+}
+
+} // namespace hardware
+} // namespace android \ No newline at end of file