xref: /aosp_15_r20/hardware/interfaces/automotive/vehicle/2.0/default/VehicleService.cpp (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
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 "[email protected]"
18 #include <android/log.h>
19 #include <hidl/HidlTransportSupport.h>
20 
21 #include <iostream>
22 
23 #include <vhal_v2_0/DefaultVehicleConnector.h>
24 #include <vhal_v2_0/DefaultVehicleHal.h>
25 #include <vhal_v2_0/VehicleHalManager.h>
26 
27 using ::android::hardware::automotive::vehicle::V2_0::VehicleHalManager;
28 using ::android::hardware::automotive::vehicle::V2_0::VehiclePropertyStore;
29 using ::android::hardware::automotive::vehicle::V2_0::impl::DefaultVehicleConnector;
30 using ::android::hardware::automotive::vehicle::V2_0::impl::DefaultVehicleHal;
31 
main(int,char * [])32 int main(int /* argc */, char* /* argv */ []) {
33     auto store = std::make_unique<VehiclePropertyStore>();
34     auto connector = std::make_unique<DefaultVehicleConnector>();
35     auto hal = std::make_unique<DefaultVehicleHal>(store.get(), connector.get());
36     auto service = android::sp<VehicleHalManager>::make(hal.get());
37     connector->setValuePool(hal->getValuePool());
38 
39     android::hardware::configureRpcThreadpool(4, true /* callerWillJoin */);
40 
41     ALOGI("Registering as service...");
42     android::status_t status = service->registerAsService();
43 
44     if (status != android::OK) {
45         ALOGE("Unable to register vehicle service (%d)", status);
46         return 1;
47     }
48 
49     ALOGI("Ready");
50     android::hardware::joinRpcThreadpool();
51 
52     return 0;
53 }
54