diff --git a/plugin-dev/Source/Sentry/Private/SentryBreadcrumb.cpp b/plugin-dev/Source/Sentry/Private/SentryBreadcrumb.cpp index f7ddb3fbf..ea8466f89 100644 --- a/plugin-dev/Source/Sentry/Private/SentryBreadcrumb.cpp +++ b/plugin-dev/Source/Sentry/Private/SentryBreadcrumb.cpp @@ -4,12 +4,11 @@ #include "HAL/PlatformSentryBreadcrumb.h" -void USentryBreadcrumb::Initialize() +FSentryBreadcrumb::FSentryBreadcrumb() : NativeImpl(CreateSharedSentryBreadcrumb()) { - NativeImpl = CreateSharedSentryBreadcrumb(); } -void USentryBreadcrumb::SetMessage(const FString &Message) +void FSentryBreadcrumb::SetMessage(const FString &Message) { if (!NativeImpl) return; @@ -17,7 +16,7 @@ void USentryBreadcrumb::SetMessage(const FString &Message) NativeImpl->SetMessage(Message); } -FString USentryBreadcrumb::GetMessage() const +FString FSentryBreadcrumb::GetMessage() const { if(!NativeImpl) return FString(); @@ -25,7 +24,7 @@ FString USentryBreadcrumb::GetMessage() const return NativeImpl->GetMessage(); } -void USentryBreadcrumb::SetType(const FString& Type) +void FSentryBreadcrumb::SetType(const FString& Type) { if (!NativeImpl) return; @@ -33,7 +32,7 @@ void USentryBreadcrumb::SetType(const FString& Type) NativeImpl->SetType(Type); } -FString USentryBreadcrumb::GetType() const +FString FSentryBreadcrumb::GetType() const { if(!NativeImpl) return FString(); @@ -41,7 +40,7 @@ FString USentryBreadcrumb::GetType() const return NativeImpl->GetType(); } -void USentryBreadcrumb::SetCategory(const FString& Category) +void FSentryBreadcrumb::SetCategory(const FString& Category) { if (!NativeImpl) return; @@ -49,7 +48,7 @@ void USentryBreadcrumb::SetCategory(const FString& Category) NativeImpl->SetCategory(Category); } -FString USentryBreadcrumb::GetCategory() const +FString FSentryBreadcrumb::GetCategory() const { if(!NativeImpl) return FString(); @@ -57,7 +56,7 @@ FString USentryBreadcrumb::GetCategory() const return NativeImpl->GetCategory(); } -void USentryBreadcrumb::SetData(const TMap& Data) +void FSentryBreadcrumb::SetData(const TMap& Data) { if (!NativeImpl) return; @@ -65,7 +64,7 @@ void USentryBreadcrumb::SetData(const TMap& Data) NativeImpl->SetData(Data); } -TMap USentryBreadcrumb::GetData() const +TMap FSentryBreadcrumb::GetData() const { if(!NativeImpl) return TMap(); @@ -73,7 +72,7 @@ TMap USentryBreadcrumb::GetData() const return NativeImpl->GetData(); } -void USentryBreadcrumb::SetLevel(ESentryLevel Level) +void FSentryBreadcrumb::SetLevel(ESentryLevel Level) { if (!NativeImpl) return; @@ -81,10 +80,60 @@ void USentryBreadcrumb::SetLevel(ESentryLevel Level) NativeImpl->SetLevel(Level); } -ESentryLevel USentryBreadcrumb::GetLevel() const +ESentryLevel FSentryBreadcrumb::GetLevel() const { if(!NativeImpl) return ESentryLevel::Debug; return NativeImpl->GetLevel(); } + +void USentryBreadcrumbLibrary::SetMessage(FSentryBreadcrumb& Breadcrumb, const FString& Message) +{ + Breadcrumb.SetMessage(Message); +} + +FString USentryBreadcrumbLibrary::GetMessage(const FSentryBreadcrumb& Breadcrumb) +{ + return Breadcrumb.GetMessage(); +} + +void USentryBreadcrumbLibrary::SetType(FSentryBreadcrumb& Breadcrumb, const FString& Type) +{ + Breadcrumb.SetType(Type); +} + +FString USentryBreadcrumbLibrary::GetType(const FSentryBreadcrumb& Breadcrumb) +{ + return Breadcrumb.GetType(); +} + +void USentryBreadcrumbLibrary::SetCategory(FSentryBreadcrumb& Breadcrumb, const FString& Category) +{ + Breadcrumb.SetCategory(Category); +} + +FString USentryBreadcrumbLibrary::GetCategory(const FSentryBreadcrumb& Breadcrumb) +{ + return Breadcrumb.GetCategory(); +} + +void USentryBreadcrumbLibrary::SetData(FSentryBreadcrumb& Breadcrumb, const TMap& Data) +{ + Breadcrumb.SetData(Data); +} + +TMap USentryBreadcrumbLibrary::GetData(const FSentryBreadcrumb& Breadcrumb) +{ + return Breadcrumb.GetData(); +} + +void USentryBreadcrumbLibrary::SetLevel(FSentryBreadcrumb& Breadcrumb, ESentryLevel Level) +{ + Breadcrumb.SetLevel(Level); +} + +ESentryLevel USentryBreadcrumbLibrary::GetLevel(const FSentryBreadcrumb& Breadcrumb) +{ + return Breadcrumb.GetLevel(); +} diff --git a/plugin-dev/Source/Sentry/Private/SentryLibrary.cpp b/plugin-dev/Source/Sentry/Private/SentryLibrary.cpp index d495d85cc..7ff76d8a3 100644 --- a/plugin-dev/Source/Sentry/Private/SentryLibrary.cpp +++ b/plugin-dev/Source/Sentry/Private/SentryLibrary.cpp @@ -60,16 +60,16 @@ USentryUserFeedback* USentryLibrary::CreateSentryUserFeedback(const FString& Eve return UserFeedback; } -USentryBreadcrumb* USentryLibrary::CreateSentryBreadcrumb(const FString& Message, const FString& Type, const FString& Category, +FSentryBreadcrumb USentryLibrary::CreateSentryBreadcrumb(const FString& Message, const FString& Type, const FString& Category, const TMap& Data, ESentryLevel Level) { - USentryBreadcrumb* Breadcrumb = USentryBreadcrumb::Create(CreateSharedSentryBreadcrumb()); + FSentryBreadcrumb Breadcrumb; - Breadcrumb->SetMessage(Message); - Breadcrumb->SetCategory(Category); - Breadcrumb->SetType(Type); - Breadcrumb->SetData(Data); - Breadcrumb->SetLevel(Level); + Breadcrumb.SetMessage(Message); + Breadcrumb.SetCategory(Category); + Breadcrumb.SetType(Type); + Breadcrumb.SetData(Data); + Breadcrumb.SetLevel(Level); return Breadcrumb; } diff --git a/plugin-dev/Source/Sentry/Private/SentryScope.cpp b/plugin-dev/Source/Sentry/Private/SentryScope.cpp index ea9c71791..a1b181b59 100644 --- a/plugin-dev/Source/Sentry/Private/SentryScope.cpp +++ b/plugin-dev/Source/Sentry/Private/SentryScope.cpp @@ -11,12 +11,12 @@ void USentryScope::Initialize() NativeImpl = CreateSharedSentryScope(); } -void USentryScope::AddBreadcrumb(USentryBreadcrumb* Breadcrumb) +void USentryScope::AddBreadcrumb(const FSentryBreadcrumb& Breadcrumb) { if (!NativeImpl) return; - NativeImpl->AddBreadcrumb(Breadcrumb->GetNativeObject()); + NativeImpl->AddBreadcrumb(Breadcrumb.GetNativeObject()); } void USentryScope::ClearBreadcrumbs() diff --git a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp index 2055eaae1..dc639155e 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp @@ -196,17 +196,16 @@ ESentryCrashedLastRun USentrySubsystem::IsCrashedLastRun() const return SubsystemNativeImpl->IsCrashedLastRun(); } -void USentrySubsystem::AddBreadcrumb(USentryBreadcrumb* Breadcrumb) +void USentrySubsystem::AddBreadcrumb(const FSentryBreadcrumb& Breadcrumb) { check(SubsystemNativeImpl); - check(Breadcrumb); if (!SubsystemNativeImpl || !SubsystemNativeImpl->IsEnabled()) { return; } - SubsystemNativeImpl->AddBreadcrumb(Breadcrumb->GetNativeObject()); + SubsystemNativeImpl->AddBreadcrumb(Breadcrumb.GetNativeObject()); } void USentrySubsystem::AddBreadcrumbWithParams(const FString& Message, const FString& Category, const FString& Type, const TMap& Data, ESentryLevel Level) diff --git a/plugin-dev/Source/Sentry/Private/Tests/SentryBreadcrumb.spec.cpp b/plugin-dev/Source/Sentry/Private/Tests/SentryBreadcrumb.spec.cpp index 6a359ea5e..40c883c09 100644 --- a/plugin-dev/Source/Sentry/Private/Tests/SentryBreadcrumb.spec.cpp +++ b/plugin-dev/Source/Sentry/Private/Tests/SentryBreadcrumb.spec.cpp @@ -10,14 +10,14 @@ #if WITH_AUTOMATION_TESTS BEGIN_DEFINE_SPEC(SentryBreadcrumbSpec, "Sentry.SentryBreadcrumb", EAutomationTestFlags::ProductFilter | SentryApplicationContextMask) - USentryBreadcrumb* SentryBreadcrumb; + FSentryBreadcrumb SentryBreadcrumb; END_DEFINE_SPEC(SentryBreadcrumbSpec) void SentryBreadcrumbSpec::Define() { BeforeEach([this]() { - SentryBreadcrumb = USentryBreadcrumb::Create(CreateSharedSentryBreadcrumb()); + SentryBreadcrumb = FSentryBreadcrumb(); }); Describe("Breadcrumb params", [this]() @@ -32,18 +32,18 @@ void SentryBreadcrumbSpec::Define() TestData.Add(TEXT("Key1"), TEXT("Val1")); TestData.Add(TEXT("Key2"), TEXT("Val2")); - SentryBreadcrumb->SetLevel(ESentryLevel::Fatal); - SentryBreadcrumb->SetMessage(TestMessage); - SentryBreadcrumb->SetType(TestType); - SentryBreadcrumb->SetCategory(TestCategory); - SentryBreadcrumb->SetData(TestData); + SentryBreadcrumb.SetLevel(ESentryLevel::Fatal); + SentryBreadcrumb.SetMessage(TestMessage); + SentryBreadcrumb.SetType(TestType); + SentryBreadcrumb.SetCategory(TestCategory); + SentryBreadcrumb.SetData(TestData); - TestEqual("Breadcrumb level", SentryBreadcrumb->GetLevel(), ESentryLevel::Fatal); - TestEqual("Breadcrumb message", SentryBreadcrumb->GetMessage(), TestMessage); - TestEqual("Breadcrumb type", SentryBreadcrumb->GetType(), TestType); - TestEqual("Breadcrumb category", SentryBreadcrumb->GetCategory(), TestCategory); + TestEqual("Breadcrumb level", SentryBreadcrumb.GetLevel(), ESentryLevel::Fatal); + TestEqual("Breadcrumb message", SentryBreadcrumb.GetMessage(), TestMessage); + TestEqual("Breadcrumb type", SentryBreadcrumb.GetType(), TestType); + TestEqual("Breadcrumb category", SentryBreadcrumb.GetCategory(), TestCategory); - TMap ReceivedData = SentryBreadcrumb->GetData(); + TMap ReceivedData = SentryBreadcrumb.GetData(); TestEqual("Data 1", ReceivedData[TEXT("Key1")], TestData[TEXT("Key1")]); TestEqual("Data 2", ReceivedData[TEXT("Key2")], TestData[TEXT("Key2")]); }); diff --git a/plugin-dev/Source/Sentry/Public/SentryBreadcrumb.h b/plugin-dev/Source/Sentry/Public/SentryBreadcrumb.h index 7485861be..7ea1ff0d0 100644 --- a/plugin-dev/Source/Sentry/Public/SentryBreadcrumb.h +++ b/plugin-dev/Source/Sentry/Public/SentryBreadcrumb.h @@ -5,6 +5,8 @@ #include "SentryDataTypes.h" #include "SentryImplWrapper.h" +#include "Kismet/BlueprintFunctionLibrary.h" + #include "SentryBreadcrumb.generated.h" class ISentryBreadcrumb; @@ -12,53 +14,81 @@ class ISentryBreadcrumb; /** * Information to create a trail of events that happened prior to an issue. */ -UCLASS(BlueprintType, NotBlueprintable, HideDropdown) -class SENTRY_API USentryBreadcrumb : public UObject, public TSentryImplWrapper +USTRUCT(BlueprintType) +struct SENTRY_API FSentryBreadcrumb { GENERATED_BODY() -public: - /** Initializes the breadcrumb. */ - UFUNCTION(BlueprintCallable, Category = "Sentry") - void Initialize(); + FSentryBreadcrumb(); + + void SetMessage(const FString& Message); + FString GetMessage() const; + + void SetType(const FString& Type); + FString GetType() const; + + void SetCategory(const FString& Category); + FString GetCategory() const; + + void SetData(const TMap& Data); + TMap GetData() const; + + void SetLevel(ESentryLevel Level); + ESentryLevel GetLevel() const; + + /** Retrieves the underlying native implementation. */ + TSharedPtr GetNativeObject() const { return NativeImpl; } +private: + TSharedPtr NativeImpl; +}; + +/** + * Utility blueprint functions for Sentry breadcrumb. + */ +UCLASS() +class SENTRY_API USentryBreadcrumbLibrary : public UBlueprintFunctionLibrary +{ + GENERATED_BODY() + +public: /** Sets message of the breadcrumb. */ UFUNCTION(BlueprintCallable, Category = "Sentry") - void SetMessage(const FString& Message); + static void SetMessage(UPARAM(ref) FSentryBreadcrumb& Breadcrumb, const FString& Message); /** Gets message of the breadcrumb. */ UFUNCTION(BlueprintPure, Category = "Sentry") - FString GetMessage() const; + static FString GetMessage(const FSentryBreadcrumb& Breadcrumb); /** Sets type of the breadcrumb. */ UFUNCTION(BlueprintCallable, Category = "Sentry") - void SetType(const FString& Type); + static void SetType(UPARAM(ref) FSentryBreadcrumb& Breadcrumb, const FString& Type); /** Gets type of the breadcrumb. */ UFUNCTION(BlueprintPure, Category = "Sentry") - FString GetType() const; + static FString GetType(const FSentryBreadcrumb& Breadcrumb); /** Sets category of the breadcrumb. */ UFUNCTION(BlueprintCallable, Category = "Sentry") - void SetCategory(const FString& Category); + static void SetCategory(UPARAM(ref) FSentryBreadcrumb& Breadcrumb, const FString& Category); /** Gets category of the breadcrumb. */ UFUNCTION(BlueprintPure, Category = "Sentry") - FString GetCategory() const; + static FString GetCategory(const FSentryBreadcrumb& Breadcrumb); /** Sets data associated with the breadcrumb. */ UFUNCTION(BlueprintCallable, Category = "Sentry") - void SetData(const TMap& Data); + static void SetData(UPARAM(ref) FSentryBreadcrumb& Breadcrumb, const TMap& Data); /** Gets data associated with the breadcrumb. */ UFUNCTION(BlueprintPure, Category = "Sentry") - TMap GetData() const; + static TMap GetData(const FSentryBreadcrumb& Breadcrumb); /** Sets the level of the breadcrumb. */ UFUNCTION(BlueprintCallable, Category = "Sentry") - void SetLevel(ESentryLevel Level); + static void SetLevel(UPARAM(ref) FSentryBreadcrumb& Breadcrumb, ESentryLevel Level); /** Gets the level of the breadcrumb. */ UFUNCTION(BlueprintPure, Category = "Sentry") - ESentryLevel GetLevel() const; + static ESentryLevel GetLevel(const FSentryBreadcrumb& Breadcrumb); }; diff --git a/plugin-dev/Source/Sentry/Public/SentryLibrary.h b/plugin-dev/Source/Sentry/Public/SentryLibrary.h index c0f5fafa6..208820d0e 100644 --- a/plugin-dev/Source/Sentry/Public/SentryLibrary.h +++ b/plugin-dev/Source/Sentry/Public/SentryLibrary.h @@ -67,7 +67,7 @@ class SENTRY_API USentryLibrary : public UBlueprintFunctionLibrary * @param Level Level of the breadcrumb. */ UFUNCTION(BlueprintCallable, Category = "Sentry", Meta = (AutoCreateRefTerm = "Data")) - static USentryBreadcrumb* CreateSentryBreadcrumb(const FString& Message, const FString& Type, const FString& Category, + static FSentryBreadcrumb CreateSentryBreadcrumb(const FString& Message, const FString& Type, const FString& Category, const TMap& Data, ESentryLevel Level = ESentryLevel::Info); /** diff --git a/plugin-dev/Source/Sentry/Public/SentryScope.h b/plugin-dev/Source/Sentry/Public/SentryScope.h index 86607359f..aca86bc7a 100644 --- a/plugin-dev/Source/Sentry/Public/SentryScope.h +++ b/plugin-dev/Source/Sentry/Public/SentryScope.h @@ -26,7 +26,7 @@ class SENTRY_API USentryScope : public UObject, public TSentryImplWrapper