summaryrefslogtreecommitdiff
path: root/ir
diff options
context:
space:
mode:
authorSebastiano Barezzi <barezzisebastiano@gmail.com>2021-09-13 01:16:43 +0200
committerSebastiano Barezzi <barezzisebastiano@gmail.com>2021-09-20 14:19:36 +0200
commit0cd4e50d6f5bce1ea252fecffa0249b550a6630f (patch)
tree2e17aee6cdd6dc4c8117eec62d91c20628fccfc6 /ir
parentec4147512ce8d3519e8b345370f4425ca7158d35 (diff)
sdm660-common: ir: Binderize
Change-Id: Ib704750a56eec2e26440bdfee92976776db58812
Diffstat (limited to 'ir')
-rw-r--r--ir/Android.bp21
-rw-r--r--ir/ConsumerIr.cpp39
-rw-r--r--ir/ConsumerIr.h5
-rw-r--r--ir/service.cpp23
4 files changed, 45 insertions, 43 deletions
diff --git a/ir/Android.bp b/ir/Android.bp
index f352f20..03d89e6 100644
--- a/ir/Android.bp
+++ b/ir/Android.bp
@@ -4,28 +4,17 @@
// SPDX-License-Identifier: Apache-2.0
//
-cc_library_shared {
- name: "android.hardware.ir@1.0-impl",
- defaults: ["hidl_defaults"],
- relative_install_path: "hw",
- srcs: ["ConsumerIr.cpp"],
- shared_libs: [
- "libhidlbase",
- "libhardware",
- "libbase",
- "libutils",
- "android.hardware.ir@1.0",
- ],
- vendor: true,
-}
-
cc_binary {
name: "android.hardware.ir@1.0-service",
defaults: ["hidl_defaults"],
relative_install_path: "hw",
init_rc: ["android.hardware.ir@1.0-service.rc"],
- srcs: ["service.cpp"],
+ srcs: [
+ "ConsumerIr.cpp",
+ "service.cpp",
+ ],
shared_libs: [
+ "libbase",
"libhardware",
"libhidlbase",
"libutils",
diff --git a/ir/ConsumerIr.cpp b/ir/ConsumerIr.cpp
index 3e7ea35..14aa26a 100644
--- a/ir/ConsumerIr.cpp
+++ b/ir/ConsumerIr.cpp
@@ -19,8 +19,25 @@ namespace ir {
namespace V1_0 {
namespace implementation {
-ConsumerIr::ConsumerIr(consumerir_device_t *device) {
- mDevice = device;
+ConsumerIr::ConsumerIr() : mDevice(nullptr) {
+ const hw_module_t *hw_module = NULL;
+
+ int ret = hw_get_module(CONSUMERIR_HARDWARE_MODULE_ID, &hw_module);
+ if (ret != 0) {
+ LOG(FATAL) << "hw_get_module " CONSUMERIR_HARDWARE_MODULE_ID " failed: " << ret;
+ }
+ ret = hw_module->methods->open(hw_module, CONSUMERIR_TRANSMITTER, (hw_device_t **) &mDevice);
+ if (ret < 0) {
+ LOG(FATAL) << "Can't open consumer IR transmitter, error: " << ret;
+ }
+}
+
+ConsumerIr::~ConsumerIr() {
+ if (mDevice == nullptr)
+ return;
+
+ mDevice->common.close((hw_device_t *) mDevice);
+ mDevice = nullptr;
}
// Methods from ::android::hardware::consumerir::V1_0::IConsumerIr follow.
@@ -52,24 +69,6 @@ Return<void> ConsumerIr::getCarrierFreqs(getCarrierFreqs_cb _hidl_cb) {
return Void();
}
-
-IConsumerIr* HIDL_FETCH_IConsumerIr(const char * /*name*/) {
- consumerir_device_t *dev;
- const hw_module_t *hw_module = NULL;
-
- int ret = hw_get_module(CONSUMERIR_HARDWARE_MODULE_ID, &hw_module);
- if (ret != 0) {
- LOG(ERROR) << "hw_get_module " CONSUMERIR_HARDWARE_MODULE_ID " failed: " << ret;
- return nullptr;
- }
- ret = hw_module->methods->open(hw_module, CONSUMERIR_TRANSMITTER, (hw_device_t **) &dev);
- if (ret < 0) {
- LOG(ERROR) << "Can't open consumer IR transmitter, error: " << ret;
- return nullptr;
- }
- return new ConsumerIr(dev);
-}
-
} // namespace implementation
} // namespace V1_0
} // namespace ir
diff --git a/ir/ConsumerIr.h b/ir/ConsumerIr.h
index 65acddd..3c90250 100644
--- a/ir/ConsumerIr.h
+++ b/ir/ConsumerIr.h
@@ -28,7 +28,8 @@ using ::android::hardware::Void;
using ::android::sp;
struct ConsumerIr : public IConsumerIr {
- ConsumerIr(consumerir_device_t *device);
+ ConsumerIr();
+ ~ConsumerIr();
// Methods from ::android::hardware::ir::V1_0::IConsumerIr follow.
Return<bool> transmit(int32_t carrierFreq, const hidl_vec<int32_t>& pattern) override;
Return<void> getCarrierFreqs(getCarrierFreqs_cb _hidl_cb) override;
@@ -36,8 +37,6 @@ private:
consumerir_device_t *mDevice;
};
-extern "C" IConsumerIr* HIDL_FETCH_IConsumerIr(const char* name);
-
} // namespace implementation
} // namespace V1_0
} // namespace ir
diff --git a/ir/service.cpp b/ir/service.cpp
index 8e199ed..3af6202 100644
--- a/ir/service.cpp
+++ b/ir/service.cpp
@@ -6,12 +6,27 @@
#define LOG_TAG "android.hardware.ir@1.0-service"
-#include <android/hardware/ir/1.0/IConsumerIr.h>
-#include <hidl/LegacySupport.h>
+#include <android-base/logging.h>
+#include <hidl/HidlTransportSupport.h>
+#include "ConsumerIr.h"
using android::hardware::ir::V1_0::IConsumerIr;
-using android::hardware::defaultPassthroughServiceImplementation;
+using android::hardware::ir::V1_0::implementation::ConsumerIr;
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
int main() {
- return defaultPassthroughServiceImplementation<IConsumerIr>();
+ android::sp<IConsumerIr> service = new ConsumerIr();
+
+ configureRpcThreadpool(1, true /*callerWillJoin*/);
+
+ android::status_t status = service->registerAsService();
+ if (status != android::OK) {
+ LOG(ERROR) << "Cannot register ConsumerIr service";
+ return 1;
+ }
+
+ joinRpcThreadpool();
+
+ return 1; // should never get here
}