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
This commit is contained in:
Yu Shan
2024-06-18 17:38:11 -07:00
parent 8e3aaa2f5e
commit b02b772954
2 changed files with 12 additions and 3 deletions

View File

@@ -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";

View File

@@ -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;