C/C++教程

Android HIDL第一个demo编写: HIDL Test——实现Framework&App层与HAL进程IPC~Binderized模式

本文主要是介绍Android HIDL第一个demo编写: HIDL Test——实现Framework&App层与HAL进程IPC~Binderized模式,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

基于上一篇文章:
Android HIDL第一个demo编写: HIDL Test——实现Framework&App层与HAL进程IPC
使用的是Passthrough模式,这里修改为使用Binderized模式:
service.cpp文件写法:

#define LOG_TAG "vendor.mobis.hidltest@1.0-service"

#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include <hidl/LegacySupport.h>
#include "HidlTest.h"

// libhwbinder
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;

using vendor::mobis::hidltest::V1_0::IHidlTest;
using vendor::mobis::hidltest::V1_0::implementation::HidlTest;

using android::sp;
using android::OK;
using android::status_t;

int main() {
    //和dev/hwbinder进行通信,设置最大的线程个数为4
    configureRpcThreadpool(1, true);

    // register HidlTest service
    sp<IHidlTest> mHidlTestService = new HidlTest();
    status_t status = mHidlTestService->registerAsService();
    if (status != OK) {
        ALOGE("Cannot register HidlTest HAL service");
        return 1;
    }
    ALOGI("TRIMBLE HidlTest HAL Ready.");

    //把当前线程加入到线程池
    joinRpcThreadpool();
    return 1;
}

该service对应的bp文件中要增加HidlTest.cpp:

cc_binary {
    proprietary: true,
    relative_install_path: "hw",
    defaults: ["hidl_defaults"],
    name: "vendor.mobis.hidltest@1.0-service",
    init_rc: ["vendor.mobis.hidltest@1.0-service.rc"],
    srcs: ["service.cpp", "HidlTest.cpp"],

    cflags: [
        "-Wall",
        "-Werror",
    ],

    shared_libs: [
        "liblog",
        "libdl",
        "libutils",
        "libhardware",
        "libhidlbase",
        "libhidltransport",
        "vendor.mobis.hidltest@1.0",
    ],

}

打印log查看结果:

junmatek@junmatek-HP-EliteDesk-800-G3-TWR:~$ adb logcat | grep -Ei "hello|HidlTest"
03-03 11:11:51.707  4546  4546 I vendor.mobis.hidltest@1.0-service: TRIMBLE HidlTest HAL Ready.
03-03 11:12:24.921  4460  4460 I android_os_HwBinder: HwBinder: Starting thread pool for default::vendor.mobis.hidltest@1.0::IHidlTest
03-03 11:12:24.921  4546  4546 I HidlTest: SLOGI HidlTest::helloWorld: Hello World, Mr.White
03-03 11:12:24.922  4460  4460 E EngineeringModeMainActivity: IHidlTestService.helloWorld:Hello World, Mr.White
这篇关于Android HIDL第一个demo编写: HIDL Test——实现Framework&App层与HAL进程IPC~Binderized模式的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!