1 /*
2  * Copyright (C) 2018 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 #include <android-base/logging.h>
17 #include <hidl/HidlTransportSupport.h>
18 #include "Thermal.h"
19 
20 constexpr std::string_view kThermalLogTag("pixel-thermal");
21 
22 using ::android::OK;
23 using ::android::status_t;
24 
25 // libhwbinder:
26 using ::android::hardware::configureRpcThreadpool;
27 using ::android::hardware::joinRpcThreadpool;
28 
29 // Generated HIDL files:
30 using ::android::hardware::thermal::V2_0::IThermal;
31 using ::android::hardware::thermal::V2_0::implementation::Thermal;
32 
shutdown()33 static int shutdown() {
34     LOG(ERROR) << "Pixel Thermal HAL Service is shutting down.";
35     return 1;
36 }
37 
main(int,char **)38 int main(int /* argc */, char ** /* argv */) {
39     android::base::SetDefaultTag(kThermalLogTag.data());
40     status_t status;
41     android::sp<IThermal> service = nullptr;
42 
43     LOG(INFO) << "Pixel Thermal HAL Service 2.0 starting...";
44 
45     service = new Thermal();
46     if (service == nullptr) {
47         LOG(ERROR) << "Error creating an instance of Thermal HAL. Exiting...";
48         return shutdown();
49     }
50 
51     configureRpcThreadpool(1, true /* callerWillJoin */);
52 
53     status = service->registerAsService();
54     if (status != OK) {
55         LOG(ERROR) << "Could not register service for ThermalHAL (" << status << ")";
56         return shutdown();
57     }
58 
59     LOG(INFO) << "Pixel Thermal HAL Service 2.0 started successfully.";
60     joinRpcThreadpool();
61     // We should not get past the joinRpcThreadpool().
62     return shutdown();
63 }
64