Initial commit
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class TurboLinkTestTarget : TargetRules
|
||||
{
|
||||
public TurboLinkTestTarget( TargetInfo Target) : base(Target)
|
||||
{
|
||||
Type = TargetType.Game;
|
||||
DefaultBuildSettings = BuildSettingsVersion.V2;
|
||||
ExtraModuleNames.AddRange( new string[] { "TurboLinkTest" } );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "TimeTestDSWidget.h"
|
||||
#include "TurboLinkTestController.h"
|
||||
|
||||
#include "Components/Button.h"
|
||||
#include "Components/EditableText.h"
|
||||
#include "Components/TextBlock.h"
|
||||
|
||||
#include "TurboLinkGrpcManager.h"
|
||||
#include "TurboLinkGrpcUtilities.h"
|
||||
#include "TurboLinkGrpcConfig.h"
|
||||
|
||||
void UTimeTestDSWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
Button_ConnectTimeService->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnConnectServiceButtonClicked);
|
||||
Button_ShutdownTimeService->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnShutdownServiceButtonClicked);
|
||||
|
||||
Button_CreateTimeClient->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnCreateClientButtonClicked);
|
||||
Button_ShutdownTimeClient->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnShutdownClientButtonClicked);
|
||||
|
||||
Button_Now->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnNowButtonClicked);
|
||||
Button_Now_Cancel->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnNowCancelButtonClicked);
|
||||
|
||||
Button_Ticktok->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnTicktokButtonClicked);
|
||||
Button_Ticktok_Cancel->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnTicktokCancelButtonClicked);
|
||||
|
||||
Button_Watch->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnWatchButtonClicked);
|
||||
Button_Watch_Send->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnWatchSendButtonClicked);
|
||||
Button_Watch_Cancel->OnClicked.AddDynamic(this, &UTimeTestDSWidget::OnWatchCancelButtonClicked);
|
||||
|
||||
FString timeServiceEndPoint = UTurboLinkGrpcUtilities::GetTurboLinkGrpcConfig()->GetServiceEndPoint(TEXT("TimeService"));
|
||||
TimeServiceAddress->SetText(FText::FromString(*timeServiceEndPoint));
|
||||
TimeServiceAddress->SetIsReadOnly(true);
|
||||
|
||||
PC = Cast<ATurboLinkTestController>(GetWorld()->GetFirstPlayerController());
|
||||
if (PC) {
|
||||
PC->ClientWidget = this;
|
||||
}
|
||||
|
||||
UpdateControlState();
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::UpdateControlState()
|
||||
{
|
||||
if (!PC) return;
|
||||
|
||||
bool serviceConnected = (PC->GetTimeServiceState() == EGrpcServiceState::Ready || PC->GetTimeServiceState()== EGrpcServiceState::Idle);
|
||||
bool clientCreated = PC->IsClientCreated();
|
||||
|
||||
Button_ConnectTimeService->SetIsEnabled(!serviceConnected);
|
||||
Button_ShutdownTimeService->SetIsEnabled(serviceConnected || PC->GetTimeServiceState()== EGrpcServiceState::TransientFailure);
|
||||
|
||||
Button_CreateTimeClient->SetIsEnabled(serviceConnected && !clientCreated);
|
||||
Button_ShutdownTimeClient->SetIsEnabled(clientCreated);
|
||||
|
||||
Button_Now->SetIsEnabled(serviceConnected && clientCreated && PC->GetCtxNowState() == EGrpcContextState::Done);
|
||||
Button_Now_Cancel->SetIsEnabled(serviceConnected && clientCreated && (PC->GetCtxNowState() == EGrpcContextState::Initialing || PC->GetCtxNowState() == EGrpcContextState::Busy));
|
||||
|
||||
Button_Ticktok->SetIsEnabled(serviceConnected && clientCreated && PC->GetCtxTicktokState() == EGrpcContextState::Done);
|
||||
Button_Ticktok_Cancel->SetIsEnabled(serviceConnected && clientCreated && (PC->GetCtxTicktokState() == EGrpcContextState::Initialing || PC->GetCtxTicktokState() == EGrpcContextState::Busy));
|
||||
|
||||
Button_Watch->SetIsEnabled(serviceConnected && clientCreated && PC->GetCtxWatchState() == EGrpcContextState::Done);
|
||||
Button_Watch_Send->SetIsEnabled(serviceConnected && clientCreated && PC->GetCtxWatchState() == EGrpcContextState::Busy);
|
||||
Button_Watch_Cancel->SetIsEnabled(serviceConnected && clientCreated && (PC->GetCtxWatchState() == EGrpcContextState::Initialing || PC->GetCtxWatchState() == EGrpcContextState::Busy));
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnConnectServiceButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
|
||||
bool serviceConnected = (PC->GetTimeServiceState() == EGrpcServiceState::Ready);
|
||||
if (serviceConnected) return;
|
||||
|
||||
PC->ConnectToTimeService();
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnShutdownServiceButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
|
||||
bool serviceConnected = (PC->GetTimeServiceState() == EGrpcServiceState::Ready);
|
||||
if (serviceConnected || PC->GetTimeServiceState() == EGrpcServiceState::TransientFailure)
|
||||
{
|
||||
PC->ShutdownTimeService();
|
||||
}
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnCreateClientButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
if (PC->IsClientCreated()) return;
|
||||
|
||||
PC->CreateTimeClient();
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnShutdownClientButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
if (!(PC->IsClientCreated())) return;
|
||||
|
||||
PC->ShutdownTimeClient();
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnNowButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
if (!(PC->IsClientCreated())) return;
|
||||
if (PC->GetCtxNowState() != EGrpcContextState::Done) return;
|
||||
|
||||
PC->CallTimeNow();
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnNowCancelButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
if (!(PC->IsClientCreated())) return;
|
||||
if (PC->GetCtxNowState() == EGrpcContextState::Done) return;
|
||||
|
||||
PC->CancelTimeNow();
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnTicktokButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
if (!(PC->IsClientCreated())) return;
|
||||
if (PC->GetCtxTicktokState() != EGrpcContextState::Done) return;
|
||||
|
||||
int32 counts = FCString::Atoi(*(TicktokCounts->GetText().ToString()));
|
||||
PC->CallTimeTicktok(counts);
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnTicktokCancelButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
if (!(PC->IsClientCreated())) return;
|
||||
if (PC->GetCtxTicktokState() == EGrpcContextState::Done) return;
|
||||
|
||||
PC->CancelTimeTicktok();
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnWatchButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
if (!(PC->IsClientCreated())) return;
|
||||
if (PC->GetCtxWatchState() != EGrpcContextState::Done) return;
|
||||
|
||||
PC->InitTimeWatch();
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnWatchSendButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
if (!(PC->IsClientCreated())) return;
|
||||
if (PC->GetCtxWatchState() != EGrpcContextState::Busy) return;
|
||||
|
||||
PC->CallTimeWatch();
|
||||
}
|
||||
|
||||
void UTimeTestDSWidget::OnWatchCancelButtonClicked()
|
||||
{
|
||||
if (!PC) return;
|
||||
if (!(PC->IsClientCreated())) return;
|
||||
if (PC->GetCtxWatchState() == EGrpcContextState::Done) return;
|
||||
|
||||
PC->CancelTimeWatch();
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "SGreeter/GreeterService.h"
|
||||
#include "TimeTestDSWidget.generated.h"
|
||||
|
||||
class ATurboLinkTestController;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class TURBOLINKTEST_API UTimeTestDSWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
public:
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UEditableText* TimeServiceAddress;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UTextBlock* TimeServiceStatus;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_ConnectTimeService;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_ShutdownTimeService;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_CreateTimeClient;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_ShutdownTimeClient;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Now;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UTextBlock* TextResultNow;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Now_Cancel;
|
||||
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Ticktok;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UEditableText* TicktokCounts;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UTextBlock* TextResultTicktok;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Ticktok_Cancel;
|
||||
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Watch;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Watch_Send;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UTextBlock* TextResultWatch;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Watch_Cancel;
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
void OnConnectServiceButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnShutdownServiceButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnCreateClientButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnShutdownClientButtonClicked();
|
||||
|
||||
|
||||
UFUNCTION()
|
||||
void OnNowButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnNowCancelButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnTicktokButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnTicktokCancelButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnWatchButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnWatchSendButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnWatchCancelButtonClicked();
|
||||
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadOnly)
|
||||
ATurboLinkTestController* PC;
|
||||
|
||||
public:
|
||||
void UpdateControlState();
|
||||
};
|
||||
@@ -0,0 +1,270 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "TimeTestWidget.h"
|
||||
|
||||
#include "Components/Button.h"
|
||||
#include "Components/EditableText.h"
|
||||
#include "Components/TextBlock.h"
|
||||
|
||||
#include "TurboLinkGrpcManager.h"
|
||||
#include "TurboLinkGrpcUtilities.h"
|
||||
#include "TurboLinkGrpcConfig.h"
|
||||
|
||||
void UTimeTestWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
Button_ConnectTimeService->OnClicked.AddDynamic(this, &UTimeTestWidget::OnConnectServiceButtonClicked);
|
||||
Button_ShutdownTimeService->OnClicked.AddDynamic(this, &UTimeTestWidget::OnShutdownServiceButtonClicked);
|
||||
|
||||
Button_CreateTimeClient->OnClicked.AddDynamic(this, &UTimeTestWidget::OnCreateClientButtonClicked);
|
||||
Button_ShutdownTimeClient->OnClicked.AddDynamic(this, &UTimeTestWidget::OnShutdownClientButtonClicked);
|
||||
|
||||
Button_Now->OnClicked.AddDynamic(this, &UTimeTestWidget::OnNowButtonClicked);
|
||||
Button_Now_Cancel->OnClicked.AddDynamic(this, &UTimeTestWidget::OnNowCancelButtonClicked);
|
||||
|
||||
Button_Ticktok->OnClicked.AddDynamic(this, &UTimeTestWidget::OnTicktokButtonClicked);
|
||||
Button_Ticktok_Cancel->OnClicked.AddDynamic(this, &UTimeTestWidget::OnTicktokCancelButtonClicked);
|
||||
|
||||
Button_Watch->OnClicked.AddDynamic(this, &UTimeTestWidget::OnWatchButtonClicked);
|
||||
Button_Watch_Send->OnClicked.AddDynamic(this, &UTimeTestWidget::OnWatchSendButtonClicked);
|
||||
Button_Watch_Cancel->OnClicked.AddDynamic(this, &UTimeTestWidget::OnWatchCancelButtonClicked);
|
||||
|
||||
FString timeServiceEndPoint = UTurboLinkGrpcUtilities::GetTurboLinkGrpcConfig()->GetServiceEndPoint(TEXT("TimeService"));
|
||||
TimeServiceAddress->SetText(FText::FromString(*timeServiceEndPoint));
|
||||
TimeServiceAddress->SetIsReadOnly(true);
|
||||
|
||||
UpdateControlState();
|
||||
}
|
||||
|
||||
void UTimeTestWidget::UpdateControlState()
|
||||
{
|
||||
bool serviceConnected = (TimeService!=nullptr && (TimeService->GetServiceState()==EGrpcServiceState::Ready || TimeService->GetServiceState() == EGrpcServiceState::Idle));
|
||||
bool clientCreated = (TimeServiceClient != nullptr);
|
||||
|
||||
Button_ConnectTimeService->SetIsEnabled(TimeService == nullptr);
|
||||
Button_ShutdownTimeService->SetIsEnabled(serviceConnected || (TimeService != nullptr && TimeService->GetServiceState() == EGrpcServiceState::TransientFailure));
|
||||
|
||||
Button_CreateTimeClient->SetIsEnabled(serviceConnected && !clientCreated);
|
||||
Button_ShutdownTimeClient->SetIsEnabled(clientCreated);
|
||||
|
||||
Button_Now->SetIsEnabled(serviceConnected && clientCreated && TimeServiceClient->GetContextState(CtxNow) == EGrpcContextState::Done);
|
||||
Button_Now_Cancel->SetIsEnabled(serviceConnected && clientCreated&& (TimeServiceClient->GetContextState(CtxNow) == EGrpcContextState::Initialing || TimeServiceClient->GetContextState(CtxNow) == EGrpcContextState::Busy));
|
||||
|
||||
Button_Ticktok->SetIsEnabled(serviceConnected && clientCreated && TimeServiceClient->GetContextState(CtxTicktok) == EGrpcContextState::Done);
|
||||
Button_Ticktok_Cancel->SetIsEnabled(serviceConnected && clientCreated && (TimeServiceClient->GetContextState(CtxTicktok) == EGrpcContextState::Initialing || TimeServiceClient->GetContextState(CtxTicktok) == EGrpcContextState::Busy));
|
||||
|
||||
Button_Watch->SetIsEnabled(serviceConnected && clientCreated && TimeServiceClient->GetContextState(CtxWatch) == EGrpcContextState::Done);
|
||||
Button_Watch_Send->SetIsEnabled(serviceConnected && clientCreated && TimeServiceClient->GetContextState(CtxWatch) == EGrpcContextState::Busy);
|
||||
Button_Watch_Cancel->SetIsEnabled(serviceConnected && clientCreated && (TimeServiceClient->GetContextState(CtxWatch) == EGrpcContextState::Initialing || TimeServiceClient->GetContextState(CtxWatch) == EGrpcContextState::Busy));
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnConnectServiceButtonClicked()
|
||||
{
|
||||
if (TimeService != nullptr) return;
|
||||
UTurboLinkGrpcManager* turboLinkManager = UTurboLinkGrpcUtilities::GetTurboLinkGrpcManager();
|
||||
|
||||
//create service adapter
|
||||
TimeService = Cast<UTimeService>(turboLinkManager->MakeService("TimeService"));
|
||||
if (TimeService==nullptr)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("Can't find time service!"));
|
||||
return;
|
||||
}
|
||||
TimeService->OnServiceStateChanged.AddUniqueDynamic(this, &UTimeTestWidget::OnTimeServiceStateChanged);
|
||||
TimeService->Connect();
|
||||
|
||||
UpdateControlState();
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnShutdownServiceButtonClicked()
|
||||
{
|
||||
if (TimeService != nullptr)
|
||||
{
|
||||
if (TimeServiceClient!=nullptr)
|
||||
{
|
||||
TimeServiceClient->Shutdown();
|
||||
TimeServiceClient = nullptr;
|
||||
}
|
||||
|
||||
TimeService->Shutdown();
|
||||
TimeService = nullptr;
|
||||
|
||||
UpdateControlState();
|
||||
}
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnCreateClientButtonClicked()
|
||||
{
|
||||
if (TimeService != nullptr && TimeService->GetServiceState() == EGrpcServiceState::Ready)
|
||||
{
|
||||
if (TimeServiceClient != nullptr) return;
|
||||
|
||||
//create client
|
||||
TimeServiceClient = TimeService->MakeClient();
|
||||
TimeServiceClient->OnContextStateChange.AddUniqueDynamic(this, &UTimeTestWidget::OnContextStateChange);
|
||||
TimeServiceClient->OnNowResponse.AddUniqueDynamic(this, &UTimeTestWidget::OnTimeNowResponse);
|
||||
TimeServiceClient->OnTicktokResponse.AddUniqueDynamic(this, &UTimeTestWidget::OnTimeTicktokResponse);
|
||||
TimeServiceClient->OnWatchResponse.AddUniqueDynamic(this, &UTimeTestWidget::OnTimeWatchResponse);
|
||||
|
||||
UpdateControlState();
|
||||
}
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnShutdownClientButtonClicked()
|
||||
{
|
||||
if (TimeServiceClient != nullptr)
|
||||
{
|
||||
TimeServiceClient->Shutdown();
|
||||
TimeServiceClient = nullptr;
|
||||
|
||||
UpdateControlState();
|
||||
}
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnTimeServiceStateChanged(EGrpcServiceState NewState)
|
||||
{
|
||||
int preFixLen = FString(TEXT("EGrpcServiceState::")).Len();
|
||||
TimeServiceStatus->SetText(FText::FromString(UEnum::GetValueAsString(NewState).RightChop(preFixLen)));
|
||||
|
||||
UpdateControlState();
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnContextStateChange(FGrpcContextHandle Handle, EGrpcContextState State)
|
||||
{
|
||||
UpdateControlState();
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnNowButtonClicked()
|
||||
{
|
||||
if (TimeService == nullptr ||
|
||||
(TimeService->GetServiceState() != EGrpcServiceState::Ready && TimeService->GetServiceState()!= EGrpcServiceState::Idle) ||
|
||||
TimeServiceClient==nullptr)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Connect to time service first!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (TimeServiceClient->GetContextState(CtxNow) != EGrpcContextState::Done)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Busy!"));
|
||||
return;
|
||||
}
|
||||
|
||||
CtxNow = TimeServiceClient->InitNow();
|
||||
TimeServiceClient->Now(CtxNow, {});
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnNowCancelButtonClicked()
|
||||
{
|
||||
if (TimeServiceClient && TimeServiceClient->GetContextState(CtxNow) != EGrpcContextState::Done)
|
||||
{
|
||||
TimeServiceClient->TryCancelContext(CtxNow);
|
||||
}
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnTimeNowResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response)
|
||||
{
|
||||
if (Result.Code == EGrpcResultCode::Ok)
|
||||
{
|
||||
FString value = FString::Printf(TEXT("%lld"), Response.Now);
|
||||
TextResultNow->SetText(FText::FromString(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
TextResultNow->SetText(FText::FromString(Result.GetCodeString()));
|
||||
}
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnTicktokButtonClicked()
|
||||
{
|
||||
if (TimeService == nullptr ||
|
||||
(TimeService->GetServiceState() != EGrpcServiceState::Ready && TimeService->GetServiceState() != EGrpcServiceState::Idle) ||
|
||||
TimeServiceClient == nullptr)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Connect to time service first!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (TimeServiceClient->GetContextState(CtxTicktok) != EGrpcContextState::Done)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Busy!"));
|
||||
return;
|
||||
}
|
||||
|
||||
CtxTicktok = TimeServiceClient->InitTicktok();
|
||||
|
||||
FGrpcGreeterTicktokRequest request;
|
||||
request.Counts = FCString::Atoi(*(TicktokCounts->GetText().ToString()));
|
||||
TimeServiceClient->Ticktok(CtxTicktok, request);
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnTimeTicktokResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response)
|
||||
{
|
||||
if (Result.Code == EGrpcResultCode::Ok)
|
||||
{
|
||||
FString value = FString::Printf(TEXT("%lld/%d"), Response.Now, Response.Counts);
|
||||
TextResultTicktok->SetText(FText::FromString(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
TextResultTicktok->SetText(FText::FromString(Result.GetCodeString()));
|
||||
}
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnTicktokCancelButtonClicked()
|
||||
{
|
||||
if (TimeServiceClient && TimeServiceClient->GetContextState(CtxTicktok) != EGrpcContextState::Done)
|
||||
{
|
||||
TimeServiceClient->TryCancelContext(CtxTicktok);
|
||||
}
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnWatchButtonClicked()
|
||||
{
|
||||
if (TimeService == nullptr ||
|
||||
(TimeService->GetServiceState() != EGrpcServiceState::Ready && TimeService->GetServiceState() != EGrpcServiceState::Idle) ||
|
||||
TimeServiceClient == nullptr)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Connect to time service first!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (TimeServiceClient->GetContextState(CtxWatch) != EGrpcContextState::Done)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("Busy!"));
|
||||
return;
|
||||
}
|
||||
|
||||
CtxWatch = TimeServiceClient->InitWatch();
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnWatchSendButtonClicked()
|
||||
{
|
||||
if (TimeServiceClient && TimeServiceClient->GetContextState(CtxWatch) == EGrpcContextState::Busy)
|
||||
{
|
||||
TimeServiceClient->Watch(CtxWatch, {});
|
||||
}
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnWatchCancelButtonClicked()
|
||||
{
|
||||
if (TimeServiceClient && TimeServiceClient->GetContextState(CtxWatch) != EGrpcContextState::Done)
|
||||
{
|
||||
TimeServiceClient->TryCancel(CtxWatch);
|
||||
}
|
||||
}
|
||||
|
||||
void UTimeTestWidget::OnTimeWatchResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response)
|
||||
{
|
||||
if (Result.Code == EGrpcResultCode::Ok)
|
||||
{
|
||||
FString value = FString::Printf(TEXT("%lld"), Response.Now);
|
||||
TextResultWatch->SetText(FText::FromString(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
TextResultWatch->SetText(FText::FromString(Result.GetCodeString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "SGreeter/GreeterService.h"
|
||||
#include "TimeTestWidget.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class TURBOLINKTEST_API UTimeTestWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UEditableText* TimeServiceAddress;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UTextBlock* TimeServiceStatus;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_ConnectTimeService;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_ShutdownTimeService;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_CreateTimeClient;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_ShutdownTimeClient;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Now;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UTextBlock* TextResultNow;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Now_Cancel;
|
||||
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Ticktok;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UEditableText* TicktokCounts;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UTextBlock* TextResultTicktok;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Ticktok_Cancel;
|
||||
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Watch;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Watch_Send;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UTextBlock* TextResultWatch;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
|
||||
class UButton* Button_Watch_Cancel;
|
||||
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadOnly)
|
||||
UTimeService* TimeService;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly)
|
||||
UTimeServiceClient* TimeServiceClient;
|
||||
|
||||
FGrpcContextHandle CtxNow;
|
||||
|
||||
UFUNCTION()
|
||||
void OnTimeNowResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response);
|
||||
|
||||
FGrpcContextHandle CtxTicktok;
|
||||
|
||||
UFUNCTION()
|
||||
void OnTimeTicktokResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response);
|
||||
|
||||
FGrpcContextHandle CtxWatch;
|
||||
|
||||
UFUNCTION()
|
||||
void OnTimeWatchResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response);
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
void OnTimeServiceStateChanged(EGrpcServiceState NewState);
|
||||
|
||||
UFUNCTION()
|
||||
void OnContextStateChange(FGrpcContextHandle Handle, EGrpcContextState State);
|
||||
|
||||
|
||||
UFUNCTION()
|
||||
void OnConnectServiceButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnShutdownServiceButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnCreateClientButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnShutdownClientButtonClicked();
|
||||
|
||||
|
||||
UFUNCTION()
|
||||
void OnNowButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnNowCancelButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnTicktokButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnTicktokCancelButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnWatchButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnWatchSendButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void OnWatchCancelButtonClicked();
|
||||
|
||||
protected:
|
||||
void UpdateControlState();
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class TurboLinkTest : ModuleRules
|
||||
{
|
||||
public TurboLinkTest(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] {
|
||||
"Core",
|
||||
"CoreUObject",
|
||||
"Engine",
|
||||
"InputCore"
|
||||
});
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] {
|
||||
"TurboLinkGrpc"
|
||||
});
|
||||
|
||||
// Uncomment if you are using Slate UI
|
||||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
||||
|
||||
// Uncomment if you are using online features
|
||||
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
|
||||
|
||||
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "TurboLinkTest.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, TurboLinkTest, "TurboLinkTest" );
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "TurboLinkTestController.h"
|
||||
#include "TurboLinkGrpcManager.h"
|
||||
#include "TurboLinkGrpcUtilities.h"
|
||||
#include "TimeTestDSWidget.h"
|
||||
|
||||
#include "Net/UnrealNetwork.h"
|
||||
#include "Components/TextBlock.h"
|
||||
|
||||
void ATurboLinkTestController::GetLifetimeReplicatedProps(TArray <FLifetimeProperty>& OutLifetimeProps) const
|
||||
{
|
||||
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||||
|
||||
//Replicate current health.
|
||||
DOREPLIFETIME(ATurboLinkTestController, TimeServiceState);
|
||||
DOREPLIFETIME(ATurboLinkTestController, bIsClientCreated);
|
||||
|
||||
DOREPLIFETIME(ATurboLinkTestController, CtxNowState);
|
||||
DOREPLIFETIME(ATurboLinkTestController, NowResult);
|
||||
|
||||
DOREPLIFETIME(ATurboLinkTestController, CtxTicktokState);
|
||||
DOREPLIFETIME(ATurboLinkTestController, TicktokResult);
|
||||
|
||||
DOREPLIFETIME(ATurboLinkTestController, CtxWatchState);
|
||||
DOREPLIFETIME(ATurboLinkTestController, WatchResult);
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::ConnectToTimeService_Implementation()
|
||||
{
|
||||
if (TimeService != nullptr) return;
|
||||
UTurboLinkGrpcManager* turboLinkManager = UTurboLinkGrpcUtilities::GetTurboLinkGrpcManager();
|
||||
|
||||
//create service adapter
|
||||
TimeService = Cast<UTimeService>(turboLinkManager->MakeService("TimeService"));
|
||||
if (TimeService == nullptr)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("Can't find time service!"));
|
||||
return;
|
||||
}
|
||||
TimeService->OnServiceStateChanged.AddUniqueDynamic(this, &ATurboLinkTestController::OnTimeServiceStateChanged);
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS]Connect to time service"));
|
||||
TimeService->Connect();
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::ShutdownTimeService_Implementation()
|
||||
{
|
||||
if (TimeService != nullptr)
|
||||
{
|
||||
if (TimeServiceClient != nullptr)
|
||||
{
|
||||
TimeServiceClient->Shutdown();
|
||||
TimeServiceClient = nullptr;
|
||||
}
|
||||
|
||||
TimeService->Shutdown();
|
||||
TimeService = nullptr;
|
||||
|
||||
bIsClientCreated = false;
|
||||
TimeServiceState = EGrpcServiceState::Shutdown;
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::CreateTimeClient_Implementation()
|
||||
{
|
||||
if (TimeService != nullptr && TimeService->GetServiceState() == EGrpcServiceState::Ready)
|
||||
{
|
||||
if (TimeServiceClient != nullptr) return;
|
||||
|
||||
//create client
|
||||
TimeServiceClient = TimeService->MakeClient();
|
||||
TimeServiceClient->OnContextStateChange.AddUniqueDynamic(this, &ATurboLinkTestController::OnContextStateChange);
|
||||
TimeServiceClient->OnNowResponse.AddUniqueDynamic(this, &ATurboLinkTestController::OnTimeNowResponse);
|
||||
TimeServiceClient->OnTicktokResponse.AddUniqueDynamic(this, &ATurboLinkTestController::OnTimeTicktokResponse);
|
||||
TimeServiceClient->OnWatchResponse.AddUniqueDynamic(this, &ATurboLinkTestController::OnTimeWatchResponse);
|
||||
|
||||
bIsClientCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::ShutdownTimeClient_Implementation()
|
||||
{
|
||||
if (TimeServiceClient != nullptr)
|
||||
{
|
||||
TimeServiceClient->Shutdown();
|
||||
TimeServiceClient = nullptr;
|
||||
|
||||
bIsClientCreated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnTimeServiceStateChanged(EGrpcServiceState NewState)
|
||||
{
|
||||
TimeServiceState = NewState;
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnRep_TimeServiceState()
|
||||
{
|
||||
int preFixLen = FString(TEXT("EGrpcServiceState::")).Len();
|
||||
FString timeServiceStateString = UEnum::GetValueAsString(TimeServiceState).RightChop(preFixLen);
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("[Client]Time service state:%s"), *timeServiceStateString);
|
||||
if (ClientWidget && ClientWidget->TimeServiceStatus)
|
||||
{
|
||||
ClientWidget->TimeServiceStatus->SetText(FText::FromString(timeServiceStateString));
|
||||
ClientWidget->UpdateControlState();
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnRep_ClientCreated()
|
||||
{
|
||||
if (ClientWidget)
|
||||
{
|
||||
ClientWidget->UpdateControlState();
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::CallTimeNow_Implementation()
|
||||
{
|
||||
if (TimeService == nullptr ||
|
||||
(TimeService->GetServiceState() != EGrpcServiceState::Ready && TimeService->GetServiceState() != EGrpcServiceState::Idle) ||
|
||||
TimeServiceClient == nullptr)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("[DS]Connect to time service first!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (TimeServiceClient->GetContextState(CtxNow) != EGrpcContextState::Done)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("[DS] Busy!"));
|
||||
return;
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS] Call Time Now!"));
|
||||
CtxNow = TimeServiceClient->InitNow();
|
||||
TimeServiceClient->Now(CtxNow, {});
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::CancelTimeNow_Implementation()
|
||||
{
|
||||
if (TimeServiceClient && TimeServiceClient->GetContextState(CtxNow) != EGrpcContextState::Done)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS] Cancel Time Now!"));
|
||||
TimeServiceClient->TryCancelContext(CtxNow);
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::CallTimeTicktok_Implementation(int32 Counts)
|
||||
{
|
||||
if (TimeService == nullptr ||
|
||||
(TimeService->GetServiceState() != EGrpcServiceState::Ready && TimeService->GetServiceState() != EGrpcServiceState::Idle) ||
|
||||
TimeServiceClient == nullptr)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("[DS]Connect to time service first!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (TimeServiceClient->GetContextState(CtxTicktok) != EGrpcContextState::Done)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("[DS] Busy!"));
|
||||
return;
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS] Call Time Clock(%d)!"), Counts);
|
||||
|
||||
CtxTicktok = TimeServiceClient->InitTicktok();
|
||||
|
||||
FGrpcGreeterTicktokRequest request;
|
||||
request.Counts = Counts;
|
||||
TimeServiceClient->Ticktok(CtxTicktok, request);
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::CancelTimeTicktok_Implementation()
|
||||
{
|
||||
if (TimeServiceClient && TimeServiceClient->GetContextState(CtxTicktok) != EGrpcContextState::Done)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS] Cancel Time Clock!"));
|
||||
TimeServiceClient->TryCancelContext(CtxTicktok);
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::InitTimeWatch_Implementation()
|
||||
{
|
||||
if (TimeService == nullptr ||
|
||||
(TimeService->GetServiceState() != EGrpcServiceState::Ready && TimeService->GetServiceState() != EGrpcServiceState::Idle) ||
|
||||
TimeServiceClient == nullptr)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("[DS]Connect to time service first!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (TimeServiceClient->GetContextState(CtxWatch) != EGrpcContextState::Done)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("[DS] Busy!"));
|
||||
return;
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS] Init Time Watch!"));
|
||||
CtxWatch = TimeServiceClient->InitWatch();
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::CallTimeWatch_Implementation()
|
||||
{
|
||||
if (TimeServiceClient && TimeServiceClient->GetContextState(CtxWatch) == EGrpcContextState::Busy)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS] Send Time Watch!"));
|
||||
TimeServiceClient->Watch(CtxWatch, {});
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::CancelTimeWatch_Implementation()
|
||||
{
|
||||
if (TimeServiceClient && TimeServiceClient->GetContextState(CtxWatch) != EGrpcContextState::Done)
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS] Cancel Time Watch!"));
|
||||
TimeServiceClient->TryCancel(CtxWatch);
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnContextStateChange(FGrpcContextHandle Handle, EGrpcContextState State)
|
||||
{
|
||||
CtxNowState = TimeServiceClient->GetContextState(CtxNow);
|
||||
CtxTicktokState = TimeServiceClient->GetContextState(CtxTicktok);
|
||||
CtxWatchState = TimeServiceClient->GetContextState(CtxWatch);
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnRep_TimeContextState()
|
||||
{
|
||||
if (ClientWidget)
|
||||
{
|
||||
ClientWidget->UpdateControlState();
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnTimeNowResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response)
|
||||
{
|
||||
if (Result.Code == EGrpcResultCode::Ok)
|
||||
{
|
||||
NowResult = FString::Printf(TEXT("%lld"), Response.Now);
|
||||
}
|
||||
else
|
||||
{
|
||||
NowResult = Result.GetCodeString();
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS] On Time Now Response: %s"), *NowResult);
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnRep_TimeNowResult()
|
||||
{
|
||||
if (ClientWidget && ClientWidget->TextResultNow)
|
||||
{
|
||||
ClientWidget->TextResultNow->SetText(FText::FromString(NowResult));
|
||||
ClientWidget->UpdateControlState();
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnTimeTicktokResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response)
|
||||
{
|
||||
if (Result.Code == EGrpcResultCode::Ok)
|
||||
{
|
||||
TicktokResult = FString::Printf(TEXT("%lld/%d"), Response.Now, Response.Counts);
|
||||
}
|
||||
else
|
||||
{
|
||||
TicktokResult = Result.GetCodeString();
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS] On Time Clock Response: %s"), *TicktokResult);
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnRep_TimeTicktokResult()
|
||||
{
|
||||
if (ClientWidget && ClientWidget->TextResultTicktok)
|
||||
{
|
||||
ClientWidget->TextResultTicktok->SetText(FText::FromString(TicktokResult));
|
||||
ClientWidget->UpdateControlState();
|
||||
}
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnTimeWatchResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response)
|
||||
{
|
||||
if (Result.Code == EGrpcResultCode::Ok)
|
||||
{
|
||||
WatchResult = FString::Printf(TEXT("%lld"), Response.Now);
|
||||
}
|
||||
else
|
||||
{
|
||||
WatchResult = Result.GetCodeString();
|
||||
}
|
||||
|
||||
UE_LOG(LogTemp, Warning, TEXT("[DS] On Time Watch Response: %s"), *WatchResult);
|
||||
}
|
||||
|
||||
void ATurboLinkTestController::OnRep_TimeWatchResult()
|
||||
{
|
||||
if (ClientWidget && ClientWidget->TextResultWatch)
|
||||
{
|
||||
ClientWidget->TextResultWatch->SetText(FText::FromString(WatchResult));
|
||||
ClientWidget->UpdateControlState();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "SGreeter/GreeterService.h"
|
||||
#include "TurboLinkTestController.generated.h"
|
||||
|
||||
class UTimeTestDSWidget;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class TURBOLINKTEST_API ATurboLinkTestController : public APlayerController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void ConnectToTimeService();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void ShutdownTimeService();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void CreateTimeClient();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void ShutdownTimeClient();
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void CallTimeNow();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void CancelTimeNow();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void CallTimeTicktok(int32 Counts);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void CancelTimeTicktok();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void InitTimeWatch();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void CallTimeWatch();
|
||||
|
||||
UFUNCTION(BlueprintCallable, Server, Reliable)
|
||||
void CancelTimeWatch();
|
||||
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadOnly)
|
||||
UTimeService* TimeService;
|
||||
|
||||
UFUNCTION()
|
||||
void OnTimeServiceStateChanged(EGrpcServiceState NewState);
|
||||
|
||||
UPROPERTY(BlueprintReadOnly)
|
||||
UTimeServiceClient* TimeServiceClient;
|
||||
|
||||
UFUNCTION()
|
||||
void OnContextStateChange(FGrpcContextHandle Handle, EGrpcContextState State);
|
||||
|
||||
FGrpcContextHandle CtxNow;
|
||||
|
||||
UFUNCTION()
|
||||
void OnTimeNowResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response);
|
||||
|
||||
FGrpcContextHandle CtxTicktok;
|
||||
|
||||
UFUNCTION()
|
||||
void OnTimeTicktokResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response);
|
||||
|
||||
FGrpcContextHandle CtxWatch;
|
||||
|
||||
UFUNCTION()
|
||||
void OnTimeWatchResponse(FGrpcContextHandle Handle, const FGrpcResult& Result, const FGrpcGreeterNowResponse& Response);
|
||||
|
||||
public:
|
||||
EGrpcServiceState GetTimeServiceState() const {
|
||||
return TimeServiceState;
|
||||
}
|
||||
|
||||
bool IsClientCreated() const {
|
||||
return bIsClientCreated;
|
||||
}
|
||||
|
||||
EGrpcContextState GetCtxNowState() const {
|
||||
return CtxNowState;
|
||||
}
|
||||
|
||||
EGrpcContextState GetCtxTicktokState() const {
|
||||
return CtxTicktokState;
|
||||
}
|
||||
|
||||
EGrpcContextState GetCtxWatchState() const {
|
||||
return CtxWatchState;
|
||||
}
|
||||
|
||||
UPROPERTY(BlueprintReadOnly)
|
||||
UTimeTestDSWidget* ClientWidget;
|
||||
|
||||
protected:
|
||||
UPROPERTY(ReplicatedUsing = OnRep_TimeServiceState)
|
||||
EGrpcServiceState TimeServiceState;
|
||||
|
||||
UFUNCTION()
|
||||
void OnRep_TimeServiceState();
|
||||
|
||||
UPROPERTY(ReplicatedUsing = OnRep_ClientCreated)
|
||||
bool bIsClientCreated = false;
|
||||
|
||||
UFUNCTION()
|
||||
void OnRep_ClientCreated();
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
void OnRep_TimeContextState();
|
||||
|
||||
UPROPERTY(ReplicatedUsing = OnRep_TimeContextState)
|
||||
EGrpcContextState CtxNowState = EGrpcContextState::Done;
|
||||
|
||||
UPROPERTY(ReplicatedUsing = OnRep_TimeContextState)
|
||||
EGrpcContextState CtxTicktokState = EGrpcContextState::Done;
|
||||
|
||||
UPROPERTY(ReplicatedUsing = OnRep_TimeContextState)
|
||||
EGrpcContextState CtxWatchState = EGrpcContextState::Done;
|
||||
|
||||
UPROPERTY(ReplicatedUsing = OnRep_TimeNowResult)
|
||||
FString NowResult;
|
||||
|
||||
UFUNCTION()
|
||||
void OnRep_TimeNowResult();
|
||||
|
||||
UPROPERTY(ReplicatedUsing = OnRep_TimeTicktokResult)
|
||||
FString TicktokResult;
|
||||
|
||||
UFUNCTION()
|
||||
void OnRep_TimeTicktokResult();
|
||||
|
||||
UPROPERTY(ReplicatedUsing = OnRep_TimeWatchResult)
|
||||
FString WatchResult;
|
||||
|
||||
UFUNCTION()
|
||||
void OnRep_TimeWatchResult();
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "TurboLinkTestGameInstance.h"
|
||||
#include "TurboLinkGrpcManager.h"
|
||||
#include "TurboLinkGrpcUtilities.h"
|
||||
|
||||
void UTurboLinkTestGameInstance::Init()
|
||||
{
|
||||
Super::Init();
|
||||
|
||||
TurboLinkManager = UTurboLinkGrpcUtilities::GetTurboLinkGrpcManager();
|
||||
TurboLinkManager->InitManager();
|
||||
}
|
||||
|
||||
void UTurboLinkTestGameInstance::Shutdown()
|
||||
{
|
||||
// Unregister ticker delegate
|
||||
TurboLinkManager->Shutdown();
|
||||
TurboLinkManager = nullptr;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Engine/GameInstance.h"
|
||||
#include "TurboLinkTestGameInstance.generated.h"
|
||||
|
||||
class UTurboLinkGrpcManager;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class TURBOLINKTEST_API UTurboLinkTestGameInstance : public UGameInstance
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
void Init() override;
|
||||
void Shutdown() override;
|
||||
|
||||
protected:
|
||||
UPROPERTY()
|
||||
UTurboLinkGrpcManager* TurboLinkManager;
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
|
||||
#include "TurboLinkTestGameModeBase.h"
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "TurboLinkTestGameModeBase.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class TURBOLINKTEST_API ATurboLinkTestGameModeBase : public AGameModeBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "TurboLinkTestPawn.h"
|
||||
|
||||
// Sets default values
|
||||
ATurboLinkTestPawn::ATurboLinkTestPawn()
|
||||
{
|
||||
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ATurboLinkTestPawn::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void ATurboLinkTestPawn::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
}
|
||||
|
||||
// Called to bind functionality to input
|
||||
void ATurboLinkTestPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Pawn.h"
|
||||
#include "TurboLinkTestPawn.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class TURBOLINKTEST_API ATurboLinkTestPawn : public APawn
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this pawn's properties
|
||||
ATurboLinkTestPawn();
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
// Called to bind functionality to input
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class TurboLinkTestEditorTarget : TargetRules
|
||||
{
|
||||
public TurboLinkTestEditorTarget( TargetInfo Target) : base(Target)
|
||||
{
|
||||
Type = TargetType.Editor;
|
||||
DefaultBuildSettings = BuildSettingsVersion.V2;
|
||||
ExtraModuleNames.AddRange( new string[] { "TurboLinkTest" } );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
using UnrealBuildTool;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[SupportedPlatforms(UnrealPlatformClass.Server)]
|
||||
public class TurboLinkTestServerTarget : TargetRules
|
||||
{
|
||||
public TurboLinkTestServerTarget( TargetInfo Target) : base(Target)
|
||||
{
|
||||
Type = TargetType.Server;
|
||||
|
||||
ExtraModuleNames.AddRange( new string[] { "TurboLinkTest" } );
|
||||
|
||||
//These configurations are invalid for a Linux server build.
|
||||
DisablePlugins.Add("WMFMediaPlayer");
|
||||
DisablePlugins.Add("AsyncLoadingScreen"); //if you are using this plugin
|
||||
DisablePlugins.Add("WindowsMoviePlayer");
|
||||
DisablePlugins.Add("MediaFoundationMediaPlayer");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user