1 /*
2  * Copyright (C) 2019 Google Inc. All Rights Reserved.
3  */
4 
5 #include "ExtraCanClient.h"
6 
7 #include <android/binder_manager.h>
8 #include <android-base/logging.h>
9 #include <android/binder_process.h>
10 #include <hidl/HidlTransportSupport.h>
11 
12 
13 namespace android::hardware::automotive::vehicle::V2_0::impl {
14 
15 using ::aidl::device::generic::car::emulator::IVehicleBus;
16 using ::aidl::android::hardware::automotive::vehicle::VehicleBus;
17 
protocanbusService()18 static void protocanbusService() {
19     base::SetDefaultTag("ProtoCanBusSrv");
20     base::SetMinimumLogSeverity(base::VERBOSE);
21     ABinderProcess_setThreadPoolMaxThreadCount(4);
22     LOG(DEBUG) << "ProtoCAN service starting...";
23 
24     std::shared_ptr<VehicleBus> vehicleBus = ::ndk::SharedRefBase::make<ExtraCanClient>();
25 
26     auto serviceName = std::string(IVehicleBus::descriptor) + "/protocanbus";
27     auto status = AServiceManager_addService(vehicleBus->asBinder().get(),
28                                              serviceName.c_str());
29     CHECK_EQ(status, OK) << "Failed to register ProtoCAN VehicleBus HAL implementation";
30 
31     vehicleBus->start();
32     ABinderProcess_startThreadPool();
33     ABinderProcess_joinThreadPool();
34 };
35 
36 }  // namespace android::hardware::automotive::vehicle::V2_0::impl
37 
main()38 int main() {
39     ::android::hardware::automotive::vehicle::V2_0::impl::protocanbusService();
40     return 1;  // protocanbusService (joinRpcThreadpool) shouldn't exit
41 }
42