Steven Moreland | 4f6935c | 2016-10-19 12:45:06 -0700 | [diff] [blame] | 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 <utils/Log.h> |
| 18 | |
Steven Moreland | 4f6935c | 2016-10-19 12:45:06 -0700 | [diff] [blame] | 19 | #include <hwbinder/IPCThreadState.h> |
| 20 | #include <hwbinder/ProcessState.h> |
| 21 | #include <utils/Errors.h> |
| 22 | #include <utils/StrongPointer.h> |
| 23 | |
| 24 | #ifndef ANDROID_HIDL_LEGACY_SUPPORT_H |
| 25 | #define ANDROID_HIDL_LEGACY_SUPPORT_H |
| 26 | |
| 27 | namespace android { |
| 28 | namespace hardware { |
| 29 | |
| 30 | /** |
| 31 | * Creates default passthrough service implementation. This method never returns. |
| 32 | * |
| 33 | * Return value is exit status. |
| 34 | */ |
| 35 | template<class Interface> |
| 36 | int defaultPassthroughServiceImplementation(std::string name) { |
| 37 | sp<Interface> service = Interface::getService(name, true /* getStub */); |
| 38 | |
| 39 | if (service == nullptr) { |
| 40 | ALOGE("Could not get passthrough implementation."); |
| 41 | return EXIT_FAILURE; |
| 42 | } |
| 43 | |
| 44 | LOG_FATAL_IF(service->isRemote(), "Implementation is remote!"); |
| 45 | |
| 46 | status_t status = service->registerAsService(name); |
| 47 | |
| 48 | if (status == OK) { |
| 49 | ALOGI("Registration complete."); |
| 50 | } else { |
| 51 | ALOGE("Could not register service (%d).", status); |
| 52 | } |
| 53 | |
| 54 | ProcessState::self()->setThreadPoolMaxThreadCount(0); |
| 55 | ProcessState::self()->startThreadPool(); |
| 56 | IPCThreadState::self()->joinThreadPool(); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | } // namespace hardware |
| 62 | } // namespace android |
| 63 | |
| 64 | #endif // ANDROID_HIDL_LEGACY_SUPPORT_H |