summaryrefslogtreecommitdiff
path: root/light/2.0/default/service.cpp
blob: e4468784ba2f3e8f6bb36c636c651a2095740f96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#define LOG_TAG "android.hardware.light@2.0-service"
#include <utils/Log.h>

#include <iostream>
#include <unistd.h>

#include <android/hardware/light/2.0/ILight.h>

#include <hidl/IServiceManager.h>
#include <hwbinder/IPCThreadState.h>
#include <hwbinder/ProcessState.h>
#include <utils/Errors.h>
#include <utils/StrongPointer.h>

using android::sp;

// libhwbinder:
using android::hardware::IPCThreadState;
using android::hardware::ProcessState;

// Generated HIDL files
using android::hardware::light::V2_0::ILight;

int main() {
    ALOGI("Service is starting.");
    const char instance[] = "light";
    ALOGI("Retrieving default implementation of instance %s.",
          instance);

    android::sp<ILight> service = ILight::getService(instance, true /* getStub */);

    if (service.get() == nullptr) {
        ALOGE("ILight::getService returned NULL, exiting");
        return EXIT_FAILURE;
    }

    LOG_FATAL_IF(service->isRemote(), "Implementation is REMOTE!");

    ALOGI("Registering instance %s.", instance);
    service->registerAsService(instance);
    ALOGI("Ready.");

    ProcessState::self()->setThreadPoolMaxThreadCount(0);
    ProcessState::self()->startThreadPool();
    IPCThreadState::self()->joinThreadPool();
}