Scott Randolph | 5c99d85 | 2016-11-15 17:01:23 -0800 | [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 | #define LOG_TAG "android.hardware.evs@1.0-service" |
| 18 | |
| 19 | #include <unistd.h> |
| 20 | |
| 21 | #include <hwbinder/IPCThreadState.h> |
| 22 | #include <hwbinder/ProcessState.h> |
| 23 | #include <utils/Errors.h> |
| 24 | #include <utils/StrongPointer.h> |
| 25 | #include <utils/Log.h> |
| 26 | |
| 27 | #include "ServiceNames.h" |
| 28 | #include "EvsEnumerator.h" |
| 29 | #include "EvsDisplay.h" |
| 30 | |
| 31 | |
| 32 | // libhwbinder: |
| 33 | using android::hardware::IPCThreadState; |
| 34 | using android::hardware::ProcessState; |
| 35 | |
| 36 | // Generated HIDL files |
| 37 | using android::hardware::evs::V1_0::IEvsEnumerator; |
| 38 | using android::hardware::evs::V1_0::IEvsDisplay; |
| 39 | |
| 40 | // The namespace in which all our implementation code lives |
| 41 | using namespace android::hardware::evs::V1_0::implementation; |
| 42 | using namespace android; |
| 43 | |
| 44 | |
| 45 | int main() { |
| 46 | ALOGI("EVS Hardware Enumerator service is starting"); |
| 47 | android::sp<IEvsEnumerator> service = new EvsEnumerator(); |
| 48 | |
| 49 | // Register our service -- if somebody is already registered by our name, |
| 50 | // they will be killed (their thread pool will throw an exception). |
| 51 | status_t status = service->registerAsService(kEnumeratorServiceName); |
| 52 | if (status == OK) { |
| 53 | ALOGD("%s is ready.", kEnumeratorServiceName); |
| 54 | |
| 55 | // Set thread pool size to ensure the API is not called in parallel. |
| 56 | // By setting the size to zero, the main thread will be the only one |
| 57 | // serving requests once we "joinThreadPool". |
| 58 | ProcessState::self()->setThreadPoolMaxThreadCount(0); |
| 59 | |
| 60 | // Note: We don't start the thread pool because it'll add at least one (default) |
| 61 | // thread to it, which we don't want. See b/31226656 |
| 62 | // ProcessState::self()->startThreadPool(); |
| 63 | |
| 64 | // Send this main thread to become a permanent part of the thread pool. |
| 65 | // This bumps up the thread count by 1 (from zero in this case). |
| 66 | // This is not expected to return. |
| 67 | IPCThreadState::self()->joinThreadPool(); |
| 68 | } else { |
| 69 | ALOGE("Could not register service %s (%d).", kEnumeratorServiceName, status); |
| 70 | } |
| 71 | |
| 72 | // In normal operation, we don't expect the thread pool to exit |
| 73 | ALOGE("EVS Hardware Enumerator is shutting down"); |
| 74 | return 1; |
| 75 | } |