From 57454c768a962f2baccd7242bfb6db535e5f2859 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 16 Feb 2021 02:01:48 -0500 Subject: [PATCH] Internal dispatch works! --- .../Private/EventSourceActor.cpp | 31 +++++++++++++++---- .../Public/EventSourceActor.h | 5 +++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Source/EventCenterPlugin/Private/EventSourceActor.cpp b/Source/EventCenterPlugin/Private/EventSourceActor.cpp index 1edf81d..d834dc3 100644 --- a/Source/EventCenterPlugin/Private/EventSourceActor.cpp +++ b/Source/EventCenterPlugin/Private/EventSourceActor.cpp @@ -63,11 +63,11 @@ void AEventSourceActor::Tick(float DeltaTime) void AEventSourceActor::ConstructClient() { if (redis != nullptr) { - UE_LOG(EventSourceLog, Log, TEXT("Construct2(): Redis is NOT null")); + UE_LOG(EventSourceLog, Log, TEXT("Construct(): Redis is NOT null")); return; } - UE_LOG(EventSourceLog, Log, TEXT("construct2(): redis = new Redis()")); + UE_LOG(EventSourceLog, Log, TEXT("construct(): redis = new Redis()")); redis = NewObject(this, TEXT("RedisObject")); } @@ -75,28 +75,47 @@ void AEventSourceActor::ConstructClient() void AEventSourceActor::Init() { if (redis == nullptr) { - UE_LOG(EventSourceLog, Log, TEXT("Init2(): Redis is null")); + UE_LOG(EventSourceLog, Log, TEXT("Init(): Redis is null")); return; } //UE_LOG(EventSourceLog, Log, TEXT("construct(): redis = new Redis()")); //redis = NewObject(this, TEXT("RedisObject")); - UE_LOG(EventSourceLog, Log, TEXT("Init2(): redis->Init()")); + UE_LOG(EventSourceLog, Log, TEXT("Init(): 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")); + UE_LOG(EventSourceLog, Log, TEXT("Subscribe(): Redis is null")); return; } - UE_LOG(EventSourceLog, Log, TEXT("Subscribe2(): redis->Subscribe()")); + UE_LOG(EventSourceLog, Log, TEXT("Subscribe(): redis->Subscribe()")); redis->Subscribe(Channel); + + if (!redis->SubscribeReply.IsBound()) { + UE_LOG(EventSourceLog, Log, TEXT("Subscribe(): binding event")); + //redis->SubscribeReply.AddDynamic(this, "AEventSourceActor::SubscribeCallback(FString Channel, FString Message)"); + redis->SubscribeReply.AddDynamic(this, &AEventSourceActor::SubscribeCallback); + } } void AEventSourceActor::Unsubscribe(const FString& Channel) { + if (redis == nullptr) { + UE_LOG(EventSourceLog, Log, TEXT("Unsubscribe(): Redis is null")); + return; + } + + UE_LOG(EventSourceLog, Log, TEXT("Unsubscribe(): redis->Unsubscribe()")); redis->Unsubscribe(Channel); } + +void AEventSourceActor::SubscribeCallback(FString Channel, FString Message) +{ + //UE_LOG(EventSourceLog, Log, TEXT("SubscribeCallback(): %s %s"), Channel, Message); + UE_LOG(EventSourceLog, Log, TEXT("SubscribeCallback(): called")); +} + diff --git a/Source/EventCenterPlugin/Public/EventSourceActor.h b/Source/EventCenterPlugin/Public/EventSourceActor.h index a4d1ecc..6d5ee1d 100644 --- a/Source/EventCenterPlugin/Public/EventSourceActor.h +++ b/Source/EventCenterPlugin/Public/EventSourceActor.h @@ -71,6 +71,11 @@ protected: private: URedisObject* redis; + // Handle callbacks. + // NB(bt): Declared 'UFUNCTION()' so reflection enables as a delegate callback. + UFUNCTION() + void SubscribeCallback(FString Channel, FString Message); + public: // Called every frame virtual void Tick(float DeltaTime) override;