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

Remove UObject-derived classes references from native SDKs wrappers #662

Merged
merged 15 commits into from
Nov 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,33 @@

#include "SentryScopeCallbackAndroid.h"

USentryScopeCallbackAndroid::USentryScopeCallbackAndroid()
#include "HAL/CriticalSection.h"

int64 SentryScopeCallbackAndroid::NextDelegateID;
TMap<int64, FSentryScopeDelegate> SentryScopeCallbackAndroid::ScopeDelegates;

FCriticalSection CriticalSection;

int64 SentryScopeCallbackAndroid::SaveDelegate(const FSentryScopeDelegate& onConfigure)
{
if (USentryScope::StaticClass()->GetDefaultObject() != this)
{
AddToRoot();
}
FScopeLock Lock(&CriticalSection);

int64 delegateId = NextDelegateID++;
ScopeDelegates.Add(delegateId, onConfigure);

return delegateId;
}

void USentryScopeCallbackAndroid::BindDelegate(const FConfigureScopeNativeDelegate& OnConfigure)
void SentryScopeCallbackAndroid::RemoveDelegate(int64 delegateId)
{
OnConfigureDelegate = OnConfigure;
FScopeLock Lock(&CriticalSection);

ScopeDelegates.Remove(delegateId);
}

void USentryScopeCallbackAndroid::ExecuteDelegate(USentryScope* Scope)
FSentryScopeDelegate* SentryScopeCallbackAndroid::GetDelegateById(int64 delegateId)
{
OnConfigureDelegate.ExecuteIfBound(Scope);
RemoveFromRoot();
FScopeLock Lock(&CriticalSection);

return ScopeDelegates.Find(delegateId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@

#include "CoreMinimal.h"

#include "SentryScope.h"
#include "Android/SentrySubsystemAndroid.h"

#include "SentryScopeCallbackAndroid.generated.h"

UCLASS()
class USentryScopeCallbackAndroid : public UObject
class SentryScopeCallbackAndroid
{
GENERATED_BODY()

public:
USentryScopeCallbackAndroid();

void BindDelegate(const FConfigureScopeNativeDelegate& OnConfigure);
void ExecuteDelegate(USentryScope* Scope);
static int64 SaveDelegate(const FSentryScopeDelegate& onConfigure);
static void RemoveDelegate(int64 delegateId);
static FSentryScopeDelegate* GetDelegateById(int64 delegateId);

private:
FConfigureScopeNativeDelegate OnConfigureDelegate;
static int64 NextDelegateID;
static TMap<int64, FSentryScopeDelegate> ScopeDelegates;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@
#include "SentryJavaObjectWrapper.h"
#include "SentryJavaClasses.h"

#include "SentryScope.h"
#include "SentryId.h"
#include "SentryTransaction.h"
#include "SentrySpan.h"
#include "SentryTransactionContext.h"
#include "SentryDefines.h"

#include "Android/SentryScopeAndroid.h"
#include "Android/SentryIdAndroid.h"
#include "Android/SentryTransactionAndroid.h"
#include "Android/SentrySpanAndroid.h"
#include "Android/SentryTransactionContextAndroid.h"

#include "Android/AndroidApplication.h"
#include "Android/AndroidJavaEnv.h"

Expand Down Expand Up @@ -139,46 +128,6 @@ ESentryLevel SentryConvertorsAndroid::SentryLevelToUnreal(jobject level)
return unrealLevel;
}

USentryScope* SentryConvertorsAndroid::SentryScopeToUnreal(jobject scope)
{
TSharedPtr<SentryScopeAndroid> scopeNativeImpl = MakeShareable(new SentryScopeAndroid(scope));
USentryScope* unrealScope = NewObject<USentryScope>();
unrealScope->InitWithNativeImpl(scopeNativeImpl);
return unrealScope;
}

USentryId* SentryConvertorsAndroid::SentryIdToUnreal(jobject id)
{
TSharedPtr<SentryIdAndroid> idNativeImpl = MakeShareable(new SentryIdAndroid(id));
USentryId* unrealId = NewObject<USentryId>();
unrealId->InitWithNativeImpl(idNativeImpl);
return unrealId;
}

USentryTransaction* SentryConvertorsAndroid::SentryTransactionToUnreal(jobject transaction)
{
TSharedPtr<SentryTransactionAndroid> transactionNativeImpl = MakeShareable(new SentryTransactionAndroid(transaction));
USentryTransaction* unrealTransaction = NewObject<USentryTransaction>();
unrealTransaction->InitWithNativeImpl(transactionNativeImpl);
return unrealTransaction;
}

USentrySpan* SentryConvertorsAndroid::SentrySpanToUnreal(jobject span)
{
TSharedPtr<SentrySpanAndroid> spanNativeImpl = MakeShareable(new SentrySpanAndroid(span));
USentrySpan* unrealSpan = NewObject<USentrySpan>();
unrealSpan->InitWithNativeImpl(spanNativeImpl);
return unrealSpan;
}

USentryTransactionContext* SentryConvertorsAndroid::SentryTransactionContextToUnreal(jobject transactionContext)
{
TSharedPtr<SentryTransactionContextAndroid> transactionContextNativeImpl = MakeShareable(new SentryTransactionContextAndroid(transactionContext));
USentryTransactionContext* unrealTransactionContext = NewObject<USentryTransactionContext>();
unrealTransactionContext->InitWithNativeImpl(transactionContextNativeImpl);
return unrealTransactionContext;
}

TMap<FString, FString> SentryConvertorsAndroid::StringMapToUnreal(jobject map)
{
TMap<FString, FString> result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

#include "Android/AndroidJNI.h"

class USentryScope;
class USentryId;
class USentryTransaction;
class USentrySpan;
class USentryTransactionContext;
class FSentryJavaObjectWrapper;
class FJsonValue;

Expand All @@ -25,11 +20,6 @@ class SentryConvertorsAndroid

/** Conversions from native Java types */
static ESentryLevel SentryLevelToUnreal(jobject level);
static USentryScope* SentryScopeToUnreal(jobject scope);
static USentryId* SentryIdToUnreal(jobject id);
static USentryTransaction* SentryTransactionToUnreal(jobject transaction);
static USentrySpan* SentrySpanToUnreal(jobject span);
static USentryTransactionContext* SentryTransactionContextToUnreal(jobject transactionContext);
static TMap<FString, FString> StringMapToUnreal(jobject stringMap);
static TArray<FString> StringListToUnreal(jobject stringList);
static TArray<uint8> ByteArrayToUnreal(jbyteArray byteArray);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "Android/Callbacks/SentryScopeCallbackAndroid.h"
#include "Android/Infrastructure/SentryConvertorsAndroid.h"
#include "Android/Infrastructure/SentryJavaClasses.h"
#include "Android/SentrySubsystemAndroid.h"
#include "Android/SentryScopeAndroid.h"
#include "Android/SentryEventAndroid.h"
#include "Android/SentryHintAndroid.h"
#include "Android/SentrySamplingContextAndroid.h"
Expand All @@ -16,13 +18,14 @@
#include "SentryTraceSampler.h"
#include "SentrySamplingContext.h"

JNI_METHOD void Java_io_sentry_unreal_SentryBridgeJava_onConfigureScope(JNIEnv* env, jclass clazz, jlong objAddr, jobject scope)
JNI_METHOD void Java_io_sentry_unreal_SentryBridgeJava_onConfigureScope(JNIEnv* env, jclass clazz, jlong callbackId, jobject scope)
{
USentryScopeCallbackAndroid* callback = reinterpret_cast<USentryScopeCallbackAndroid*>(objAddr);
FSentryScopeDelegate* callback = SentryScopeCallbackAndroid::GetDelegateById(callbackId);

if (IsValid(callback))
if (callback != nullptr)
{
callback->ExecuteDelegate(SentryConvertorsAndroid::SentryScopeToUnreal(scope));
callback->Execute(MakeShareable(new SentryScopeAndroid(scope)));
SentryScopeCallbackAndroid::RemoveDelegate(callbackId);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) 2023 Sentry. All Rights Reserved.

#include "SentryHintAndroid.h"

#include "SentryAttachmentAndroid.h"
Expand All @@ -23,8 +25,8 @@ void SentryHintAndroid::SetupClassMethods()
AddAttachmentMethod = GetMethod("addAttachment", "(Lio/sentry/Attachment;)V");
}

void SentryHintAndroid::AddAttachment(USentryAttachment* attachment)
void SentryHintAndroid::AddAttachment(TSharedPtr<ISentryAttachment> attachment)
{
TSharedPtr<SentryAttachmentAndroid> attachmentAndroid = StaticCastSharedPtr<SentryAttachmentAndroid>(attachment->GetNativeImpl());
TSharedPtr<SentryAttachmentAndroid> attachmentAndroid = StaticCastSharedPtr<SentryAttachmentAndroid>(attachment);
CallMethod<void>(AddAttachmentMethod, attachmentAndroid->GetJObject());
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SentryHintAndroid : public ISentryHint, public FSentryJavaObjectWrapper

void SetupClassMethods();

virtual void AddAttachment(USentryAttachment* attachment) override;
virtual void AddAttachment(TSharedPtr<ISentryAttachment> attachment) override;

private:
FSentryJavaMethod AddAttachmentMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (c) 2024 Sentry. All Rights Reserved.

#include "SentrySamplingContextAndroid.h"

#include "SentryTransactionContext.h"
#include "SentryTransactionContextAndroid.h"

#include "Infrastructure/SentryConvertorsAndroid.h"
#include "Infrastructure/SentryJavaClasses.h"
Expand All @@ -19,10 +18,10 @@ void SentrySamplingContextAndroid::SetupClassMethods()
GetCustomSamplingContextMethod = GetMethod("getCustomSamplingContext", "()Lio/sentry/CustomSamplingContext;");
}

USentryTransactionContext* SentrySamplingContextAndroid::GetTransactionContext() const
TSharedPtr<ISentryTransactionContext> SentrySamplingContextAndroid::GetTransactionContext() const
{
auto transactionContext = CallObjectMethod<jobject>(GetTransactionContextMethod);
return SentryConvertorsAndroid::SentryTransactionContextToUnreal(*transactionContext);
return MakeShareable(new SentryTransactionContextAndroid(*transactionContext));
}

TMap<FString, FString> SentrySamplingContextAndroid::GetCustomSamplingContext() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SentrySamplingContextAndroid : public ISentrySamplingContext, public FSent

void SetupClassMethods();

virtual USentryTransactionContext* GetTransactionContext() const override;
virtual TSharedPtr<ISentryTransactionContext> GetTransactionContext() const override;
virtual TMap<FString, FString> GetCustomSamplingContext() const override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "SentryBreadcrumbAndroid.h"
#include "SentryAttachmentAndroid.h"

#include "SentryBreadcrumb.h"
#include "SentryAttachment.h"

#include "Infrastructure/SentryConvertorsAndroid.h"
#include "Infrastructure/SentryJavaClasses.h"

Expand Down Expand Up @@ -45,9 +42,9 @@ void SentryScopeAndroid::SetupClassMethods()
ClearMethod = GetMethod("clear", "()V");
}

void SentryScopeAndroid::AddBreadcrumb(USentryBreadcrumb* breadcrumb)
void SentryScopeAndroid::AddBreadcrumb(TSharedPtr<ISentryBreadcrumb> breadcrumb)
{
TSharedPtr<SentryBreadcrumbAndroid> breadcrumbAndroid = StaticCastSharedPtr<SentryBreadcrumbAndroid>(breadcrumb->GetNativeImpl());
TSharedPtr<SentryBreadcrumbAndroid> breadcrumbAndroid = StaticCastSharedPtr<SentryBreadcrumbAndroid>(breadcrumb);
CallMethod<void>(AddBreadcrumbMethod, breadcrumbAndroid->GetJObject());
}

Expand All @@ -56,9 +53,9 @@ void SentryScopeAndroid::ClearBreadcrumbs()
CallMethod<void>(ClearBreadcrumbsMethod);
}

void SentryScopeAndroid::AddAttachment(USentryAttachment* attachment)
void SentryScopeAndroid::AddAttachment(TSharedPtr<ISentryAttachment> attachment)
{
TSharedPtr<SentryAttachmentAndroid> attachmentAndroid = StaticCastSharedPtr<SentryAttachmentAndroid>(attachment->GetNativeImpl());
TSharedPtr<SentryAttachmentAndroid> attachmentAndroid = StaticCastSharedPtr<SentryAttachmentAndroid>(attachment);
CallMethod<void>(AddAttachmentMethod, attachmentAndroid->GetJObject());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class SentryScopeAndroid : public ISentryScope, public FSentryJavaObjectWrapper

void SetupClassMethods();

virtual void AddBreadcrumb(USentryBreadcrumb* breadcrumb) override;
virtual void AddBreadcrumb(TSharedPtr<ISentryBreadcrumb> breadcrumb) override;
virtual void ClearBreadcrumbs() override;
virtual void AddAttachment(USentryAttachment* attachment) override;
virtual void AddAttachment(TSharedPtr<ISentryAttachment> attachment) override;
virtual void ClearAttachments() override;
virtual void SetTagValue(const FString& key, const FString& value) override;
virtual FString GetTagValue(const FString& key) const override;
Expand Down
Loading
Loading