blob: dd240785a76ad2900762a100f0799a9866bc53c3 [file] [log] [blame]
Wei Wang84ce54e2018-10-18 13:56:03 -07001/*
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
17#define LOG_TAG "android.hardware.thermal@2.0-service-mock"
18
19#include <android-base/logging.h>
20#include <hidl/HidlTransportSupport.h>
21#include "Thermal.h"
22
23using ::android::OK;
24using ::android::status_t;
25
26// libhwbinder:
27using ::android::hardware::configureRpcThreadpool;
28using ::android::hardware::joinRpcThreadpool;
29
30// Generated HIDL files:
31using ::android::hardware::thermal::V2_0::IThermal;
32using ::android::hardware::thermal::V2_0::implementation::Thermal;
33
34static int shutdown() {
35 LOG(ERROR) << "Thermal Service is shutting down.";
36 return 1;
37}
38
39int main(int /* argc */, char** /* argv */) {
40 status_t status;
41 android::sp<IThermal> service = nullptr;
42
43 LOG(INFO) << "Thermal HAL Service Mock 2.0 starting...";
44
45 service = new Thermal();
46 if (service == nullptr) {
47 LOG(ERROR) << "Error creating an instance of ThermalHAL. 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) << "Thermal Service started successfully.";
60 joinRpcThreadpool();
61 // We should not get past the joinRpcThreadpool().
62 return shutdown();
63}