service.cpp revision 5e4eb5ed985198610f5ce5527709db21c098a950
1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16#define LOG_TAG "android.hardware.vibrator@1.0-service" 17#include <utils/Log.h> 18 19#include <iostream> 20#include <unistd.h> 21 22#include <android/hardware/vibrator/1.0/IVibrator.h> 23 24#include <hidl/IServiceManager.h> 25#include <hwbinder/IPCThreadState.h> 26#include <hwbinder/ProcessState.h> 27#include <utils/Errors.h> 28#include <utils/StrongPointer.h> 29 30using android::sp; 31 32// libhwbinder: 33using android::hardware::IPCThreadState; 34using android::hardware::ProcessState; 35 36// Generated HIDL files 37using android::hardware::vibrator::V1_0::IVibrator; 38 39int main() { 40 ALOGI("Service is starting."); 41 const char instance[] = "vibrator"; 42 ALOGI("Retrieving default implementation of instance %s.", 43 instance); 44 android::sp<IVibrator> service = IVibrator::getService(instance, true); 45 if (service.get() == nullptr) { 46 ALOGE("IVibrator::getService returned NULL, exiting"); 47 return -1; 48 } 49 ALOGI("Default implementation using %s is %s", 50 instance, (service->isRemote() ? "REMOTE" : "LOCAL")); 51 LOG_FATAL_IF(service->isRemote(), "Implementation is REMOTE!"); 52 ALOGI("Registering instance %s.", instance); 53 service->registerAsService(instance); 54 ALOGI("Ready."); 55 56 ProcessState::self()->setThreadPoolMaxThreadCount(0); 57 ProcessState::self()->startThreadPool(); 58 IPCThreadState::self()->joinThreadPool(); 59} 60