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