From 0cd4e50d6f5bce1ea252fecffa0249b550a6630f Mon Sep 17 00:00:00 2001 From: Sebastiano Barezzi Date: Mon, 13 Sep 2021 01:16:43 +0200 Subject: sdm660-common: ir: Binderize Change-Id: Ib704750a56eec2e26440bdfee92976776db58812 --- ir/Android.bp | 21 +++++---------------- ir/ConsumerIr.cpp | 39 +++++++++++++++++++-------------------- ir/ConsumerIr.h | 5 ++--- ir/service.cpp | 23 +++++++++++++++++++---- 4 files changed, 45 insertions(+), 43 deletions(-) (limited to 'ir') 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 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 transmit(int32_t carrierFreq, const hidl_vec& pattern) override; Return 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 -#include +#include +#include +#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(); + android::sp 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 } -- cgit v1.2.3