Files
EventCenterPlugin/Source/EventCenterPlugin/Private/EventSourceActor.cpp
T
2021-02-16 00:26:55 -05:00

103 lines
2.6 KiB
C++

#include "EventSourceActor.h"
#include "UObject/Object.h"
DEFINE_LOG_CATEGORY(EventSourceLog);
AEventSourceActor::AEventSourceActor() :
redis(nullptr)
{
UE_LOG(EventSourceLog, Log, TEXT("CTOR()"));
// Set this actor to call Tick() every frame.
// You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
//redis = NewObject<URedisObject>(this, TEXT("RedisObject"));
//redis = CreateDefaultSubobject<URedisObject>(TEXT("RedisObject"));
//RootComponent = redis;
}
AEventSourceActor::~AEventSourceActor()
{
// TODO: Memory leak (somehow placing a BP derivation into the editor causes the below lines to segfault)
//delete redis;
//redis = nullptr;
/*if (redis != nullptr) {
delete redis;
redis = nullptr;
}*/
}
void AEventSourceActor::BeginPlay()
{
Super::BeginPlay();
UE_LOG(EventSourceLog, Log, TEXT("BeginPlay()"));
if (redis == nullptr) {
UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Creating redis instance"));
redis = NewObject<URedisObject>(this, TEXT("RedisObject"));
}
UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis is null? ? %d"), redis == nullptr);
//UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis host: %s"), redisHost);
UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis port: %d"), redisPort);
//UE_LOG(EventSourceLog, Log, TEXT("BeginPlay(): Redis password (no secrets): %s"), redisPassword);
}
void AEventSourceActor::BeginDestroy()
{
Super::BeginDestroy();
}
void AEventSourceActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// NB: Handled by RedisObject internal delegate
//redis->Tick(DeltaTime);
}
void AEventSourceActor::ConstructClient()
{
if (redis != nullptr) {
UE_LOG(EventSourceLog, Log, TEXT("Construct2(): Redis is NOT null"));
return;
}
UE_LOG(EventSourceLog, Log, TEXT("construct2(): redis = new Redis()"));
redis = NewObject<URedisObject>(this, TEXT("RedisObject"));
}
void AEventSourceActor::Init()
{
if (redis == nullptr) {
UE_LOG(EventSourceLog, Log, TEXT("Init2(): Redis is null"));
return;
}
//UE_LOG(EventSourceLog, Log, TEXT("construct(): redis = new Redis()"));
//redis = NewObject<URedisObject>(this, TEXT("RedisObject"));
UE_LOG(EventSourceLog, Log, TEXT("Init2(): redis->Init()"));
redis->Init(redisHost, redisPort, redisPassword);
}
void AEventSourceActor::Subscribe(const FString& Channel)
{
if (redis == nullptr) {
UE_LOG(EventSourceLog, Log, TEXT("Subscribe2(): Redis is null"));
return;
}
UE_LOG(EventSourceLog, Log, TEXT("Subscribe2(): redis->Subscribe()"));
redis->Subscribe(Channel);
}
void AEventSourceActor::Unsubscribe(const FString& Channel)
{
redis->Unsubscribe(Channel);
}