diff --git a/native/cpp/CommonCpp/NativeModules/InternalModules/NetworkModule.h b/native/cpp/CommonCpp/NativeModules/InternalModules/NetworkModule.h --- a/native/cpp/CommonCpp/NativeModules/InternalModules/NetworkModule.h +++ b/native/cpp/CommonCpp/NativeModules/InternalModules/NetworkModule.h @@ -8,7 +8,6 @@ namespace comm { class NetworkModule { std::unique_ptr networkClient; - std::function setReadyState; public: void initializeNetworkModule( diff --git a/native/cpp/CommonCpp/NativeModules/InternalModules/NetworkModule.cpp b/native/cpp/CommonCpp/NativeModules/InternalModules/NetworkModule.cpp --- a/native/cpp/CommonCpp/NativeModules/InternalModules/NetworkModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/InternalModules/NetworkModule.cpp @@ -77,7 +77,10 @@ void NetworkModule::assignSetReadyStateCallback( std::function callback) { - this->setReadyState = callback; + if (!this->networkClient) { + return; + } + this->networkClient->assignSetReadyStateCallback(callback); } } // namespace comm diff --git a/native/cpp/CommonCpp/grpc/Client.h b/native/cpp/CommonCpp/grpc/Client.h --- a/native/cpp/CommonCpp/grpc/Client.h +++ b/native/cpp/CommonCpp/grpc/Client.h @@ -45,6 +45,7 @@ void setOnOpenCallback(std::function callback); void setOnCloseCallback(std::function callback); void closeGetStream(); + void assignSetReadyStateCallback(std::function callback); }; } // namespace network diff --git a/native/cpp/CommonCpp/grpc/Client.cpp b/native/cpp/CommonCpp/grpc/Client.cpp --- a/native/cpp/CommonCpp/grpc/Client.cpp +++ b/native/cpp/CommonCpp/grpc/Client.cpp @@ -119,5 +119,13 @@ this->clientGetReadReactor->close(); } +void Client::assignSetReadyStateCallback( + std::function callback) { + if (!this->clientGetReadReactor) { + return; + } + this->clientGetReadReactor->assignSetReadyStateCallback(callback); +} + } // namespace network } // namespace comm diff --git a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h --- a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h +++ b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.h @@ -1,5 +1,6 @@ #pragma once +#include "../NativeModules/InternalModules/SocketStatus.h" #include #include "_generated/tunnelbroker.grpc.pb.h" @@ -14,9 +15,11 @@ std::mutex onReadDoneCallbackMutex; std::mutex onOpenCallbackMutex; std::mutex onCloseCallbackMutex; + std::mutex setReadyStateMutex; std::function onReadDoneCallback; std::function onOpenCallback; std::function onCloseCallback; + std::function setReadyState; public: ClientGetReadReactor( @@ -30,4 +33,5 @@ void setOnReadDoneCallback(std::function onReadDoneCallback); void setOnCloseCallback(std::function onCloseCallback); + void assignSetReadyStateCallback(std::function callback); }; diff --git a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp --- a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp +++ b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp @@ -42,3 +42,9 @@ std::lock_guard guard{this->onCloseCallbackMutex}; this->onCloseCallback = onCloseCallback; } + +void ClientGetReadReactor::assignSetReadyStateCallback( + std::function callback) { + std::lock_guard guard{this->setReadyStateMutex}; + this->setReadyState = callback; +}