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 @@ -21,42 +21,13 @@ public: ClientGetReadReactor( tunnelbroker::TunnelbrokerService::Stub *stub, - std::string sessionID) - : sessionID{sessionID}, request{} { - request.set_sessionid(sessionID); - stub->async()->Get(&(this->context), &(this->request), this); - StartRead(&(this->response)); - StartCall(); - } + std::string sessionID); - void OnReadDone(bool ok) override { - if (!ok) { - return; - } - std::lock_guard guard{this->onReadDoneCallbackMutex}; - if (this->onReadDoneCallback) { - this->onReadDoneCallback(this->response.payload()); - } - StartRead(&(this->response)); - } + void OnReadDone(bool ok) override; + void close(); + void setOnOpenCallback(std::function onOpenCallback); void - setOnReadDoneCallback(std::function onReadDoneCallback) { - std::lock_guard guard{this->onReadDoneCallbackMutex}; - this->onReadDoneCallback = onReadDoneCallback; - } - - void setOnOpenCallback(std::function onOpenCallback) { - std::lock_guard guard{this->onOpenCallbackMutex}; - this->onOpenCallback = onOpenCallback; - } - - void setOnCloseCallback(std::function onCloseCallback) { - std::lock_guard guard{this->onCloseCallbackMutex}; - this->onCloseCallback = onCloseCallback; - } - - void close() { - this->context.TryCancel(); - } + setOnReadDoneCallback(std::function onReadDoneCallback); + void setOnCloseCallback(std::function onCloseCallback); }; diff --git a/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/grpc/ClientGetReadReactor.cpp @@ -0,0 +1,44 @@ +#include "ClientGetReadReactor.h" + +ClientGetReadReactor::ClientGetReadReactor( + tunnelbroker::TunnelbrokerService::Stub *stub, + std::string sessionID) + : sessionID{sessionID}, request{} { + request.set_sessionid(sessionID); + stub->async()->Get(&(this->context), &(this->request), this); + StartRead(&(this->response)); + StartCall(); +} + +void ClientGetReadReactor::OnReadDone(bool ok) { + if (!ok) { + return; + } + std::lock_guard guard{this->onReadDoneCallbackMutex}; + if (this->onReadDoneCallback) { + this->onReadDoneCallback(this->response.payload()); + } + StartRead(&(this->response)); +} + +void ClientGetReadReactor::close() { + this->context.TryCancel(); +} + +void ClientGetReadReactor::setOnOpenCallback( + std::function onOpenCallback) { + std::lock_guard guard{this->onOpenCallbackMutex}; + this->onOpenCallback = onOpenCallback; +} + +void ClientGetReadReactor::setOnReadDoneCallback( + std::function onReadDoneCallback) { + std::lock_guard guard{this->onReadDoneCallbackMutex}; + this->onReadDoneCallback = onReadDoneCallback; +} + +void ClientGetReadReactor::setOnCloseCallback( + std::function onCloseCallback) { + std::lock_guard guard{this->onCloseCallbackMutex}; + this->onCloseCallback = onCloseCallback; +} diff --git a/native/ios/Comm.xcodeproj/project.pbxproj b/native/ios/Comm.xcodeproj/project.pbxproj --- a/native/ios/Comm.xcodeproj/project.pbxproj +++ b/native/ios/Comm.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; + 2DDA0AE067906E18B83A455C /* ClientGetReadReactor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2DDA00CA889DFF0ECB7E338D /* ClientGetReadReactor.cpp */; }; 71009A7726FDCA67002C8453 /* tunnelbroker.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 71009A7326FDCA67002C8453 /* tunnelbroker.pb.cc */; }; 71009A7826FDCA67002C8453 /* tunnelbroker.grpc.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 71009A7526FDCA67002C8453 /* tunnelbroker.grpc.pb.cc */; }; 71009A7B26FDCD72002C8453 /* Client.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 71009A7926FDCD71002C8453 /* Client.cpp */; }; @@ -59,6 +60,7 @@ 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = Comm/Images.xcassets; sourceTree = ""; }; 13B07FB61A68108700A75B9A /* Info.release.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.release.plist; path = Comm/Info.release.plist; sourceTree = ""; }; 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Comm/main.m; sourceTree = ""; }; + 2DDA00CA889DFF0ECB7E338D /* ClientGetReadReactor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ClientGetReadReactor.cpp; sourceTree = ""; }; 2DDA05D6D8D20D885F22F82C /* SocketStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketStatus.h; sourceTree = ""; }; 71009A7326FDCA67002C8453 /* tunnelbroker.pb.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tunnelbroker.pb.cc; sourceTree = ""; }; 71009A7426FDCA67002C8453 /* tunnelbroker.pb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tunnelbroker.pb.h; sourceTree = ""; }; @@ -201,6 +203,7 @@ B7BEE748279B3F2E009CCA35 /* GRPCStreamHostObject.h */, 718A3C0626F22D0A00F04A8D /* _generated */, B72879B827A865EF008A04CC /* ClientGetReadReactor.h */, + 2DDA00CA889DFF0ECB7E338D /* ClientGetReadReactor.cpp */, ); path = grpc; sourceTree = ""; @@ -662,6 +665,7 @@ 726E5D782731A5E10032361D /* GlobalNetworkSingleton.cpp in Sources */, 13B07FC11A68108700A75B9A /* main.m in Sources */, 71BE844B2636A944002849D2 /* SQLiteQueryExecutor.cpp in Sources */, + 2DDA0AE067906E18B83A455C /* ClientGetReadReactor.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };