Steven Moreland | 41db6ab | 2016-10-03 09:20:36 -0700 | [diff] [blame^] | 1 | #define LOG_TAG "android.hardware.light@2.0-service" |
| 2 | #include <utils/Log.h> |
| 3 | |
| 4 | #include <iostream> |
| 5 | #include <unistd.h> |
| 6 | |
| 7 | #include <android/hardware/light/2.0/ILight.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::light::V2_0::ILight; |
| 23 | |
| 24 | int main() { |
| 25 | ALOGI("Service is starting."); |
| 26 | const char instance[] = "light"; |
| 27 | ALOGI("Retrieving default implementation of instance %s.", |
| 28 | instance); |
| 29 | |
| 30 | android::sp<ILight> service = ILight::getService(instance, true); |
| 31 | |
| 32 | if (service.get() == nullptr) { |
| 33 | ALOGE("ILight::getService returned NULL, exiting"); |
| 34 | return -1; |
| 35 | } |
| 36 | |
| 37 | LOG_FATAL_IF(service->isRemote(), "Implementation is REMOTE!"); |
| 38 | |
| 39 | ALOGI("Registering instance %s.", instance); |
| 40 | service->registerAsService(instance); |
| 41 | ALOGI("Ready."); |
| 42 | |
| 43 | ProcessState::self()->setThreadPoolMaxThreadCount(0); |
| 44 | ProcessState::self()->startThreadPool(); |
| 45 | IPCThreadState::self()->joinThreadPool(); |
| 46 | } |