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

Commit bf9dcea5 authored by Yu Shan's avatar Yu Shan Committed by Automerger Merge Worker
Browse files

Allow two service address to be registered. am: b02b7729 am: f666bb14

parents a6fe4bce f666bb14
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;