Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Inter-Dependent Protos #11

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Template/ClientCPP.tt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ FGrpcContextHandle U<#=service.Name#>Client::Init<#=method.Name#>()
return context->GetHandle();
}

void U<#=service.Name#>Client::<#=method.Name#>(FGrpcContextHandle Handle, const <#=method.InputType#>& Request)
void U<#=service.Name#>Client::<#=method.Name#>(FGrpcContextHandle Handle, const <#=method.InputType#>& Request, TMap<FString, FString>& MetaData)
{
auto context = UGrpcClient::GetContext(Handle);
if (context != nullptr)
{
for (auto const& Pair : MetaData)
{
context->Get()->RpcContext->AddMetadata(TCHAR_TO_UTF8(*Pair.Key), TCHAR_TO_UTF8(*Pair.Value));
}
auto context<#=method.Name#> = StaticCastSharedPtr<GrpcContext_<#=service.Name#>_<#=method.Name#>>(*context);
context<#=method.Name#>->Call(Request);
}
Expand Down
2 changes: 1 addition & 1 deletion Template/ClientH.tt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ foreach (GrpcServiceMethod method in service.MethodArray)
FGrpcContextHandle Init<#=method.Name#>();

UFUNCTION(BlueprintCallable, Category = TurboLink)
void <#=method.Name#>(FGrpcContextHandle Handle, const <#=method.InputType#>& Request);
void <#=method.Name#>(FGrpcContextHandle Handle, const <#=method.InputType#>& Request, TMap<FString, FString>& MetaData);

<#
if(method.ClientStreaming && !method.ServerStreaming) {
Expand Down
8 changes: 8 additions & 0 deletions Template/ContextCPP.tt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#include "<#=s.TurboLinkBasicFileName#>Client.h"
#include "<#=s.CamelFileName#>Service_Private.h"
#include "<#=s.CamelFileName#>Marshaling.h"
<#
foreach(String dependency in s.DependencyFiles)
{
#>
#include "<#=dependency#>Marshaling.h"
<#
}
#>
#include "TurboLinkGrpcManager.h"
<#
foreach(GrpcService service in s.ServiceArray)
Expand Down
1 change: 1 addition & 0 deletions Template/MarshalingH.tt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="Google.Protobuf.Reflection" #>
//Generated by TurboLink CodeGenerator, do not edit!
#pragma once
#include "<#=s.TurboLinkBasicFileName#>Message.h"
<# if(g.GenerateServiceCode) {#>
#include "TurboLinkGrpcContext.h"
Expand Down
5 changes: 3 additions & 2 deletions Template/NodeCPP.tt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ foreach(GrpcService service in s.ServiceArray)
if(!method.ClientStreaming) {
#>

UCall<#=service.Name#><#=method.Name#>* UCall<#=service.Name#><#=method.Name#>::<#=method.Name#>(UObject* WorldContextObject, const <#=method.InputType#>& Request)
UCall<#=service.Name#><#=method.Name#>* UCall<#=service.Name#><#=method.Name#>::<#=method.Name#>(UObject* WorldContextObject, const <#=method.InputType#>& Request, TMap<FString, FString>& MetaData)
{
UCall<#=service.Name#><#=method.Name#>* node = NewObject<UCall<#=service.Name#><#=method.Name#>>(WorldContextObject);
UTurboLinkGrpcManager* turboLinkManager = UTurboLinkGrpcUtilities::GetTurboLinkGrpcManager(WorldContextObject);
Expand All @@ -32,6 +32,7 @@ UCall<#=service.Name#><#=method.Name#>* UCall<#=service.Name#><#=method.Name#>::
}
node->Request = Request;
node->ServiceState = EGrpcServiceState::Idle;
node->MetaData = MetaData;

node-><#=service.Name#>->OnServiceStateChanged.AddUniqueDynamic(node, &UCall<#=service.Name#><#=method.Name#>::OnServiceStateChanged);
return node;
Expand Down Expand Up @@ -66,7 +67,7 @@ void UCall<#=service.Name#><#=method.Name#>::OnServiceStateChanged(EGrpcServiceS
<#=service.Name#>Client->On<#=method.Name#>Response.AddUniqueDynamic(this, &UCall<#=service.Name#><#=method.Name#>::OnResponse);

Context = <#=service.Name#>Client->Init<#=method.Name#>();
<#=service.Name#>Client-><#=method.Name#>(Context, Request);
<#=service.Name#>Client-><#=method.Name#>(Context, Request, MetaData);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Template/NodeH.tt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public:
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(F<#=service.Name#><#=method.Name#>Delegate, const FGrpcResult&, GrpcResult, const <#=method.OutputType#>&, Response);

UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", DisplayName = "Call <#=service.Name#> <#=method.Name#>"), Category = "TurboLink|<#=service.Name#>")
static UCall<#=service.Name#><#=method.Name#>* <#=method.Name#>(UObject* WorldContextObject, const <#=method.InputType#>& Request);
static UCall<#=service.Name#><#=method.Name#>* <#=method.Name#>(UObject* WorldContextObject, const <#=method.InputType#>& Request, TMap<FString, FString>& MetaData);

UPROPERTY(BlueprintAssignable)
F<#=service.Name#><#=method.Name#>Delegate On<#=method.Name#>Response;
Expand All @@ -69,6 +69,7 @@ private:
FGrpcContextHandle Context;
<#=method.InputType#> Request;
EGrpcServiceState ServiceState;
TMap<FString, FString> MetaData;

UFUNCTION()
void OnServiceStateChanged(EGrpcServiceState NewState);
Expand Down
14 changes: 11 additions & 3 deletions Template/ServiceCPP.tt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#include "<#=s.TurboLinkBasicFileName#>Client.h"
#include "<#=s.CamelFileName#>Service_Private.h"
#include "<#=s.CamelFileName#>Marshaling.h"
<#
foreach(String dependency in s.DependencyFiles)
{
#>
#include "<#=dependency#>Marshaling.h"
<#
}
#>
#include "TurboLinkGrpcManager_Private.h"
#include "TurboLinkGrpcUtilities.h"
<#
Expand Down Expand Up @@ -75,9 +83,9 @@ void U<#=service.Name#>::Shutdown()
#>

<# if(method.ServerStreaming) { #>
void U<#=service.Name#>::Call<#=method.Name#>(const <#=method.InputType#>& Request, F<#=method.Name#>ResponseLambda ResponseLambda, F<#=method.Name#>FinishLambda FinishLambda)
void U<#=service.Name#>::Call<#=method.Name#>(const <#=method.InputType#>& Request, F<#=method.Name#>ResponseLambda ResponseLambda, F<#=method.Name#>FinishLambda FinishLambda, TMap<FString, FString>& MetaData)
<# } else {#>
void U<#=service.Name#>::Call<#=method.Name#>(const <#=method.InputType#>& Request, F<#=method.Name#>ResponseLambda ResponseLambda)
void U<#=service.Name#>::Call<#=method.Name#>(const <#=method.InputType#>& Request, F<#=method.Name#>ResponseLambda ResponseLambda, TMap<FString, FString>& MetaData)
<#}#>
{
if (InnerClient == nullptr)
Expand All @@ -99,7 +107,7 @@ void U<#=service.Name#>::Call<#=method.Name#>(const <#=method.InputType#>& Reque
<#
}
#>
InnerClient-><#=method.Name#>(lambdaWrapper->Handle, Request);
InnerClient-><#=method.Name#>(lambdaWrapper->Handle, Request, MetaData);
}
<#
}
Expand Down
4 changes: 2 additions & 2 deletions Template/ServiceH.tt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ foreach (GrpcServiceMethod method in service.MethodArray)
typedef TFunction<void(const FGrpcResult& GrpcResult, const <#=method.OutputType#>& Response)> F<#=method.Name#>ResponseLambda;
<# if(method.ServerStreaming) { #>
typedef TFunction<void()> F<#=method.Name#>FinishLambda;
void Call<#=method.Name#>(const <#=method.InputType#>& Request, F<#=method.Name#>ResponseLambda ResponseLambda, F<#=method.Name#>FinishLambda FinishLambda);
void Call<#=method.Name#>(const <#=method.InputType#>& Request, F<#=method.Name#>ResponseLambda ResponseLambda, F<#=method.Name#>FinishLambda FinishLambda, TMap<FString, FString>& MetaData);
<#} else {#>
void Call<#=method.Name#>(const <#=method.InputType#>& Request, F<#=method.Name#>ResponseLambda ResponseLambda);
void Call<#=method.Name#>(const <#=method.InputType#>& Request, F<#=method.Name#>ResponseLambda ResponseLambda, TMap<FString, FString>& MetaData);
<#}#>

<#
Expand Down