Loading automotive/vehicle/TEST_MAPPING +5 −0 Original line number Diff line number Diff line Loading @@ -55,5 +55,10 @@ { "name": "VehicleHalProtoMessageConverterTest" } ], "postsubmit": [ { "name": "VehicleHalProtoMessageConverterTest" } ] } automotive/vehicle/aidl/impl/grpc/Android.bp +2 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ genrule { "aprotoc", "protoc-gen-grpc-cpp-plugin", ], cmd: "$(location aprotoc) -I$$(dirname $(location proto/VehicleServer.proto)) -Ihardware/interfaces/automotive/vehicle/aidl/impl/proto -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(location proto/VehicleServer.proto) --grpc_out=$(genDir) --cpp_out=$(genDir)", cmd: "$(location aprotoc) -I$$(dirname $(location proto/VehicleServer.proto)) -Ihardware/interfaces/automotive/vehicle/aidl/impl/proto -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(location proto/VehicleServer.proto) --grpc_opt=generate_mock_code=true --grpc_out=$(genDir) --cpp_out=$(genDir)", srcs: [ "proto/VehicleServer.proto", ":libprotobuf-internal-protos", Loading @@ -31,6 +31,7 @@ genrule { out: [ "VehicleServer.pb.h", "VehicleServer.grpc.pb.h", "VehicleServer_mock.grpc.pb.h", ], visibility: ["//visibility:private"], } Loading automotive/vehicle/aidl/impl/grpc/GRPCVehicleHardware.cpp +25 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,13 @@ GRPCVehicleHardware::GRPCVehicleHardware(std::string service_addr) mGrpcStub(proto::VehicleServer::NewStub(mGrpcChannel)), mValuePollingThread([this] { ValuePollingLoop(); }) {} // Only used for unit testing. GRPCVehicleHardware::GRPCVehicleHardware(std::unique_ptr<proto::VehicleServer::StubInterface> stub) : mServiceAddr(""), mGrpcChannel(nullptr), mGrpcStub(std::move(stub)), mValuePollingThread([] {}) {} GRPCVehicleHardware::~GRPCVehicleHardware() { { std::lock_guard lck(mShutdownMutex); Loading Loading @@ -181,6 +188,24 @@ aidlvhal::StatusCode GRPCVehicleHardware::checkHealth() { return static_cast<aidlvhal::StatusCode>(protoStatus.status_code()); } aidlvhal::StatusCode GRPCVehicleHardware::subscribe(aidlvhal::SubscribeOptions options) { proto::SubscribeRequest request; ::grpc::ClientContext context; proto::VehicleHalCallStatus protoStatus; proto_msg_converter::aidlToProto(options, request.mutable_options()); auto grpc_status = mGrpcStub->Subscribe(&context, request, &protoStatus); if (!grpc_status.ok()) { if (grpc_status.error_code() == ::grpc::StatusCode::UNIMPLEMENTED) { // This is a legacy sever. It should handle updateSampleRate. LOG(INFO) << __func__ << ": GRPC Subscribe is not supported by the server"; return aidlvhal::StatusCode::OK; } LOG(ERROR) << __func__ << ": GRPC Subscribe Failed: " << grpc_status.error_message(); return aidlvhal::StatusCode::INTERNAL_ERROR; } return static_cast<aidlvhal::StatusCode>(protoStatus.status_code()); } aidlvhal::StatusCode GRPCVehicleHardware::updateSampleRate(int32_t propId, int32_t areaId, float sampleRate) { ::grpc::ClientContext context; Loading automotive/vehicle/aidl/impl/grpc/GRPCVehicleHardware.h +6 −1 Original line number Diff line number Diff line Loading @@ -43,6 +43,9 @@ class GRPCVehicleHardware : public IVehicleHardware { public: explicit GRPCVehicleHardware(std::string service_addr); // Only used for unit testing. explicit GRPCVehicleHardware(std::unique_ptr<proto::VehicleServer::StubInterface> stub); ~GRPCVehicleHardware(); // Get all the property configs. Loading Loading @@ -80,6 +83,8 @@ class GRPCVehicleHardware : public IVehicleHardware { aidlvhal::StatusCode updateSampleRate(int32_t propId, int32_t areaId, float sampleRate) override; aidlvhal::StatusCode subscribe(aidlvhal::SubscribeOptions options) override; bool waitForConnected(std::chrono::milliseconds waitTime); protected: Loading @@ -91,7 +96,7 @@ class GRPCVehicleHardware : public IVehicleHardware { std::string mServiceAddr; std::shared_ptr<::grpc::Channel> mGrpcChannel; std::unique_ptr<proto::VehicleServer::Stub> mGrpcStub; std::unique_ptr<proto::VehicleServer::StubInterface> mGrpcStub; std::thread mValuePollingThread; std::unique_ptr<const PropertySetErrorCallback> mOnSetErr; Loading automotive/vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -164,6 +164,17 @@ GrpcVehicleProxyServer::GrpcVehicleProxyServer(std::string serverAddr, return ::grpc::Status::OK; } ::grpc::Status GrpcVehicleProxyServer::Subscribe(::grpc::ServerContext* context, const proto::SubscribeRequest* request, proto::VehicleHalCallStatus* status) { const auto& protoSubscribeOptions = request->options(); aidlvhal::SubscribeOptions aidlSubscribeOptions = {}; proto_msg_converter::protoToAidl(protoSubscribeOptions, &aidlSubscribeOptions); const auto status_code = mHardware->subscribe(aidlSubscribeOptions); status->set_status_code(static_cast<proto::StatusCode>(status_code)); return ::grpc::Status::OK; } ::grpc::Status GrpcVehicleProxyServer::CheckHealth(::grpc::ServerContext* context, const ::google::protobuf::Empty*, proto::VehicleHalCallStatus* status) { Loading Loading
automotive/vehicle/TEST_MAPPING +5 −0 Original line number Diff line number Diff line Loading @@ -55,5 +55,10 @@ { "name": "VehicleHalProtoMessageConverterTest" } ], "postsubmit": [ { "name": "VehicleHalProtoMessageConverterTest" } ] }
automotive/vehicle/aidl/impl/grpc/Android.bp +2 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ genrule { "aprotoc", "protoc-gen-grpc-cpp-plugin", ], cmd: "$(location aprotoc) -I$$(dirname $(location proto/VehicleServer.proto)) -Ihardware/interfaces/automotive/vehicle/aidl/impl/proto -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(location proto/VehicleServer.proto) --grpc_out=$(genDir) --cpp_out=$(genDir)", cmd: "$(location aprotoc) -I$$(dirname $(location proto/VehicleServer.proto)) -Ihardware/interfaces/automotive/vehicle/aidl/impl/proto -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(location proto/VehicleServer.proto) --grpc_opt=generate_mock_code=true --grpc_out=$(genDir) --cpp_out=$(genDir)", srcs: [ "proto/VehicleServer.proto", ":libprotobuf-internal-protos", Loading @@ -31,6 +31,7 @@ genrule { out: [ "VehicleServer.pb.h", "VehicleServer.grpc.pb.h", "VehicleServer_mock.grpc.pb.h", ], visibility: ["//visibility:private"], } Loading
automotive/vehicle/aidl/impl/grpc/GRPCVehicleHardware.cpp +25 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,13 @@ GRPCVehicleHardware::GRPCVehicleHardware(std::string service_addr) mGrpcStub(proto::VehicleServer::NewStub(mGrpcChannel)), mValuePollingThread([this] { ValuePollingLoop(); }) {} // Only used for unit testing. GRPCVehicleHardware::GRPCVehicleHardware(std::unique_ptr<proto::VehicleServer::StubInterface> stub) : mServiceAddr(""), mGrpcChannel(nullptr), mGrpcStub(std::move(stub)), mValuePollingThread([] {}) {} GRPCVehicleHardware::~GRPCVehicleHardware() { { std::lock_guard lck(mShutdownMutex); Loading Loading @@ -181,6 +188,24 @@ aidlvhal::StatusCode GRPCVehicleHardware::checkHealth() { return static_cast<aidlvhal::StatusCode>(protoStatus.status_code()); } aidlvhal::StatusCode GRPCVehicleHardware::subscribe(aidlvhal::SubscribeOptions options) { proto::SubscribeRequest request; ::grpc::ClientContext context; proto::VehicleHalCallStatus protoStatus; proto_msg_converter::aidlToProto(options, request.mutable_options()); auto grpc_status = mGrpcStub->Subscribe(&context, request, &protoStatus); if (!grpc_status.ok()) { if (grpc_status.error_code() == ::grpc::StatusCode::UNIMPLEMENTED) { // This is a legacy sever. It should handle updateSampleRate. LOG(INFO) << __func__ << ": GRPC Subscribe is not supported by the server"; return aidlvhal::StatusCode::OK; } LOG(ERROR) << __func__ << ": GRPC Subscribe Failed: " << grpc_status.error_message(); return aidlvhal::StatusCode::INTERNAL_ERROR; } return static_cast<aidlvhal::StatusCode>(protoStatus.status_code()); } aidlvhal::StatusCode GRPCVehicleHardware::updateSampleRate(int32_t propId, int32_t areaId, float sampleRate) { ::grpc::ClientContext context; Loading
automotive/vehicle/aidl/impl/grpc/GRPCVehicleHardware.h +6 −1 Original line number Diff line number Diff line Loading @@ -43,6 +43,9 @@ class GRPCVehicleHardware : public IVehicleHardware { public: explicit GRPCVehicleHardware(std::string service_addr); // Only used for unit testing. explicit GRPCVehicleHardware(std::unique_ptr<proto::VehicleServer::StubInterface> stub); ~GRPCVehicleHardware(); // Get all the property configs. Loading Loading @@ -80,6 +83,8 @@ class GRPCVehicleHardware : public IVehicleHardware { aidlvhal::StatusCode updateSampleRate(int32_t propId, int32_t areaId, float sampleRate) override; aidlvhal::StatusCode subscribe(aidlvhal::SubscribeOptions options) override; bool waitForConnected(std::chrono::milliseconds waitTime); protected: Loading @@ -91,7 +96,7 @@ class GRPCVehicleHardware : public IVehicleHardware { std::string mServiceAddr; std::shared_ptr<::grpc::Channel> mGrpcChannel; std::unique_ptr<proto::VehicleServer::Stub> mGrpcStub; std::unique_ptr<proto::VehicleServer::StubInterface> mGrpcStub; std::thread mValuePollingThread; std::unique_ptr<const PropertySetErrorCallback> mOnSetErr; Loading
automotive/vehicle/aidl/impl/grpc/GRPCVehicleProxyServer.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -164,6 +164,17 @@ GrpcVehicleProxyServer::GrpcVehicleProxyServer(std::string serverAddr, return ::grpc::Status::OK; } ::grpc::Status GrpcVehicleProxyServer::Subscribe(::grpc::ServerContext* context, const proto::SubscribeRequest* request, proto::VehicleHalCallStatus* status) { const auto& protoSubscribeOptions = request->options(); aidlvhal::SubscribeOptions aidlSubscribeOptions = {}; proto_msg_converter::protoToAidl(protoSubscribeOptions, &aidlSubscribeOptions); const auto status_code = mHardware->subscribe(aidlSubscribeOptions); status->set_status_code(static_cast<proto::StatusCode>(status_code)); return ::grpc::Status::OK; } ::grpc::Status GrpcVehicleProxyServer::CheckHealth(::grpc::ServerContext* context, const ::google::protobuf::Empty*, proto::VehicleHalCallStatus* status) { Loading