Kumar Anand | fc72a8d | 2017-01-26 12:23:09 -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.power@1.1-service" |
| 18 | |
| 19 | #include <android/log.h> |
| 20 | #include <hidl/HidlTransportSupport.h> |
| 21 | #include <android/hardware/power/1.1/IPower.h> |
| 22 | #include <hardware/power.h> |
| 23 | #include "Power.h" |
| 24 | |
| 25 | using android::sp; |
| 26 | using android::status_t; |
| 27 | using android::OK; |
| 28 | |
| 29 | // libhwbinder: |
| 30 | using android::hardware::configureRpcThreadpool; |
| 31 | using android::hardware::joinRpcThreadpool; |
| 32 | |
| 33 | // Generated HIDL files |
| 34 | using android::hardware::power::V1_1::IPower; |
| 35 | using android::hardware::power::V1_1::implementation::Power; |
| 36 | |
| 37 | int main() { |
| 38 | |
| 39 | status_t status; |
| 40 | android::sp<IPower> service = nullptr; |
| 41 | const hw_module_t* hw_module = nullptr; |
| 42 | power_module_t* power_module = nullptr; |
| 43 | int err; |
| 44 | |
| 45 | ALOGI("Power HAL Service 1.1 (Default) is starting."); |
| 46 | |
| 47 | err = hw_get_module(POWER_HARDWARE_MODULE_ID, &hw_module); |
| 48 | if (err) { |
| 49 | ALOGE("hw_get_module %s failed: %d", POWER_HARDWARE_MODULE_ID, err); |
| 50 | goto shutdown; |
| 51 | } |
| 52 | |
| 53 | if (!hw_module->methods || !hw_module->methods->open) { |
| 54 | power_module = reinterpret_cast<power_module_t*>( |
| 55 | const_cast<hw_module_t*>(hw_module)); |
| 56 | } else { |
| 57 | err = hw_module->methods->open(hw_module, POWER_HARDWARE_MODULE_ID, |
| 58 | reinterpret_cast<hw_device_t**>(&power_module)); |
| 59 | if (err) { |
| 60 | ALOGE("Passthrough failed to load legacy HAL."); |
| 61 | goto shutdown; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | service = new Power(power_module); |
| 66 | if (service == nullptr) { |
| 67 | ALOGE("Can not create an instance of Power HAL Iface, exiting."); |
| 68 | |
| 69 | goto shutdown; |
| 70 | } |
| 71 | |
| 72 | configureRpcThreadpool(1, true /*callerWillJoin*/); |
| 73 | |
| 74 | status = service->registerAsService(); |
| 75 | if (status != OK) { |
| 76 | ALOGE("Could not register service for Power HAL Iface (%d).", status); |
| 77 | goto shutdown; |
| 78 | } |
| 79 | |
| 80 | ALOGI("Power Service is ready"); |
| 81 | joinRpcThreadpool(); |
| 82 | //Should not pass this line |
| 83 | |
| 84 | shutdown: |
| 85 | // In normal operation, we don't expect the thread pool to exit |
| 86 | |
| 87 | ALOGE("Power Service is shutting down"); |
| 88 | return 1; |
| 89 | } |