blob: 582d2249d9714787351c62fe16fa283642042cdf [file] [log] [blame]
Steven Moreland41db6ab2016-10-03 09:20:36 -07001#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
15using android::sp;
16
17// libhwbinder:
18using android::hardware::IPCThreadState;
19using android::hardware::ProcessState;
20
21// Generated HIDL files
22using android::hardware::light::V2_0::ILight;
23
24int 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}