Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b02b7729 authored by Yu Shan's avatar Yu Shan
Browse files

Allow two service address to be registered.

Allow Grpc vehicle proxy server bind to two addrs. We need one
for vsock to be used by VHAL and another one for local ethernet
connection. vsock local loopback does not work on the host.

Flag: EXEMPT host-side component.
Test: Manual test.
Bug: 328316981
Change-Id: I4efc802121b780b663fd8a26b65dc56a001feff6
parent 8e3aaa2f
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -40,7 +40,11 @@ static std::shared_ptr<::grpc::ServerCredentials> getServerCredentials() {

GrpcVehicleProxyServer::GrpcVehicleProxyServer(std::string serverAddr,
                                               std::unique_ptr<IVehicleHardware>&& hardware)
    : mServiceAddr(std::move(serverAddr)), mHardware(std::move(hardware)) {
    : GrpcVehicleProxyServer(std::vector<std::string>({serverAddr}), std::move(hardware)){};

GrpcVehicleProxyServer::GrpcVehicleProxyServer(std::vector<std::string> serverAddrs,
                                               std::unique_ptr<IVehicleHardware>&& hardware)
    : mServiceAddrs(std::move(serverAddrs)), mHardware(std::move(hardware)) {
    mHardware->registerOnPropertyChangeEvent(
            std::make_unique<const IVehicleHardware::PropertyChangeCallback>(
                    [this](std::vector<aidlvhal::VehiclePropValue> values) {
@@ -254,7 +258,9 @@ GrpcVehicleProxyServer& GrpcVehicleProxyServer::Start() {
    }
    ::grpc::ServerBuilder builder;
    builder.RegisterService(this);
    builder.AddListeningPort(mServiceAddr, getServerCredentials());
    for (const std::string& serviceAddr : mServiceAddrs) {
        builder.AddListeningPort(serviceAddr, getServerCredentials());
    }
    mServer = builder.BuildAndStart();
    CHECK(mServer) << __func__ << ": failed to create the GRPC server, "
                   << "please make sure the configuration and permissions are correct";
+4 −1
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ class GrpcVehicleProxyServer : public proto::VehicleServer::Service {
  public:
    GrpcVehicleProxyServer(std::string serverAddr, std::unique_ptr<IVehicleHardware>&& hardware);

    GrpcVehicleProxyServer(std::vector<std::string> serverAddrs,
                           std::unique_ptr<IVehicleHardware>&& hardware);

    ::grpc::Status GetAllPropertyConfig(
            ::grpc::ServerContext* context, const ::google::protobuf::Empty* request,
            ::grpc::ServerWriter<proto::VehiclePropConfig>* stream) override;
@@ -116,7 +119,7 @@ class GrpcVehicleProxyServer : public proto::VehicleServer::Service {
        static std::atomic<uint64_t> connection_id_counter_;
    };

    std::string mServiceAddr;
    std::vector<std::string> mServiceAddrs;
    std::unique_ptr<::grpc::Server> mServer{nullptr};
    std::unique_ptr<IVehicleHardware> mHardware;