Iliyan Malchev | 3db0f60 | 2016-09-26 09:57:20 -0700 | [diff] [blame^] | 1 | #define LOG_TAG "android.hardware.nfc@1.0-service" |
| 2 | #include <utils/Log.h> |
| 3 | |
| 4 | #include <iostream> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | #include <android/hardware/nfc/1.0/INfc.h> |
| 8 | |
| 9 | #include <hidl/IServiceManager.h> |
| 10 | #include <hwbinder/IPCThreadState.h> |
| 11 | #include <hwbinder/ProcessState.h> |
| 12 | #include <utils/Errors.h> |
| 13 | #include <utils/StrongPointer.h> |
| 14 | |
| 15 | using android::sp; |
| 16 | |
| 17 | // libhwbinder: |
| 18 | using android::hardware::IPCThreadState; |
| 19 | using android::hardware::ProcessState; |
| 20 | |
| 21 | // Generated HIDL files |
| 22 | using android::hardware::nfc::V1_0::INfc; |
| 23 | |
| 24 | int main() { |
| 25 | ALOGI("Service is starting."); |
| 26 | const char instance[] = "nfc_nci"; |
| 27 | ALOGI("Retrieving default implementation of instance %s.", |
| 28 | instance); |
| 29 | android::sp<INfc> service = INfc::getService(instance, true); |
| 30 | if (service.get() == nullptr) { |
| 31 | ALOGE("INfc::getService returned NULL, exiting"); |
| 32 | return -1; |
| 33 | } |
| 34 | ALOGI("Default implementation using %s is %s", |
| 35 | instance, (service->isRemote() ? "REMOTE" : "LOCAL")); |
| 36 | LOG_FATAL_IF(service->isRemote(), "Implementation is REMOTE!"); |
| 37 | ALOGI("Registering instance %s.", instance); |
| 38 | service->registerAsService("nfc_nci"); |
| 39 | ALOGI("Ready."); |
| 40 | |
| 41 | ProcessState::self()->setThreadPoolMaxThreadCount(0); |
| 42 | ProcessState::self()->startThreadPool(); |
| 43 | IPCThreadState::self()->joinThreadPool(); |
| 44 | } |