LegacySupport.h revision e76c7a27eeb3763a2185c1502fd4572df1513b9a
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 17#include <hidl/HidlTransportSupport.h> 18#include <sys/wait.h> 19#include <utils/Log.h> 20#include <utils/Errors.h> 21#include <utils/StrongPointer.h> 22 23#ifndef ANDROID_HIDL_LEGACY_SUPPORT_H 24#define ANDROID_HIDL_LEGACY_SUPPORT_H 25 26namespace android { 27namespace hardware { 28 29/** 30 * Registers passthrough service implementation. 31 */ 32template<class Interface> 33status_t registerPassthroughServiceImplementation(std::string name) { 34 sp<Interface> service = Interface::getService(name, true /* getStub */); 35 36 if (service == nullptr) { 37 ALOGE("Could not get passthrough implementation for %s.", name.c_str()); 38 return EXIT_FAILURE; 39 } 40 41 LOG_FATAL_IF(service->isRemote(), "Implementation of %s is remote!", name.c_str()); 42 43 status_t status = service->registerAsService(name); 44 45 if (status == OK) { 46 ALOGI("Registration complete for %s.", name.c_str()); 47 } else { 48 ALOGE("Could not register service %s (%d).", name.c_str(), status); 49 } 50 51 return status; 52} 53 54/** 55 * Creates default passthrough service implementation. This method never returns. 56 * 57 * Return value is exit status. 58 */ 59template<class Interface> 60int defaultPassthroughServiceImplementation(std::string name, size_t maxThreads = 1) { 61 configureRpcThreadpool(maxThreads, true); 62 registerPassthroughServiceImplementation<Interface>(name); 63 joinRpcThreadpool(); 64 return 0; 65} 66 67} // namespace hardware 68} // namespace android 69 70#endif // ANDROID_HIDL_LEGACY_SUPPORT_H 71