Skip to content

Commit 759c839

Browse files
authored
Add conversion to FString for SentryId (#161)
* Add string conversion for Sentry ID on desctom, iOS and Android * Update changelog
1 parent 7eaff60 commit 759c839

File tree

10 files changed

+45
-1
lines changed

10 files changed

+45
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features
66

77
- Add debug symbols upload settings ([#94](https://github.com/getsentry/sentry-unreal/pull/94))
8+
- Add conversion to FString for SentryId ([#161](https://github.com/getsentry/sentry-unreal/pull/161))
89
- Add editor menu for automatic CRC configuration ([#152](https://github.com/getsentry/sentry-unreal/pull/152))
910

1011
### Fixes

plugin-dev/Source/Sentry/Private/Android/SentryIdAndroid.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "SentryIdAndroid.h"
44

5+
#include "Infrastructure/SentryMethodCallAndroid.h"
6+
57
SentryIdAndroid::SentryIdAndroid()
68
{
79
JNIEnv* Env = FAndroidApplication::GetJavaEnv();
@@ -26,4 +28,9 @@ SentryIdAndroid::~SentryIdAndroid()
2628
jobject SentryIdAndroid::GetNativeObject()
2729
{
2830
return IdAndroid;
31+
}
32+
33+
FString SentryIdAndroid::ToString() const
34+
{
35+
return SentryMethodCallAndroid::CallStringMethod(IdAndroid, "toString", "()Ljava/lang/String;");
2936
}

plugin-dev/Source/Sentry/Private/Android/SentryIdAndroid.h

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class SentryIdAndroid : public ISentryId
1515

1616
jobject GetNativeObject();
1717

18+
virtual FString ToString() const override;
19+
1820
private:
1921
jobject IdAndroid;
2022
};

plugin-dev/Source/Sentry/Private/Desktop/SentryIdDesktop.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ sentry_uuid_t SentryIdDesktop::GetNativeObject()
2121
{
2222
return IdDesktop;
2323
}
24+
25+
FString SentryIdDesktop::ToString() const
26+
{
27+
char IdString[37];
28+
sentry_uuid_as_string(&IdDesktop, IdString);
29+
return FString(IdString);
30+
}

plugin-dev/Source/Sentry/Private/Desktop/SentryIdDesktop.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class SentryIdDesktop : public ISentryId
1515

1616
sentry_uuid_t GetNativeObject();
1717

18+
virtual FString ToString() const override;
19+
1820
private:
1921
sentry_uuid_t IdDesktop;
20-
};
22+
};

plugin-dev/Source/Sentry/Private/IOS/SentryIdIOS.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ SentryId* SentryIdIOS::GetNativeObject()
2424
{
2525
return IdIOS;
2626
}
27+
28+
FString SentryIdIOS::ToString() const
29+
{
30+
return FString(IdIOS.sentryIdString);
31+
}

plugin-dev/Source/Sentry/Private/IOS/SentryIdIOS.h

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class SentryIdIOS : public ISentryId
1515

1616
SentryId* GetNativeObject();
1717

18+
virtual FString ToString() const override;
19+
1820
private:
1921
SentryId* IdIOS;
2022
};

plugin-dev/Source/Sentry/Private/Interface/SentryIdInterface.h

+2
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ class ISentryId
88
{
99
public:
1010
virtual ~ISentryId() = default;
11+
12+
virtual FString ToString() const = 0;
1113
};

plugin-dev/Source/Sentry/Private/SentryId.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "Android/SentryIdAndroid.h"
99
#elif PLATFORM_IOS
1010
#include "IOS/SentryIdIOS.h"
11+
#elif PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX
12+
#include "Desktop/SentryIdDesktop.h"
1113
#endif
1214

1315
USentryId::USentryId()
@@ -18,10 +20,20 @@ USentryId::USentryId()
1820
SentryIdNativeImpl = MakeShareable(new SentryIdAndroid());
1921
#elif PLATFORM_IOS
2022
SentryIdNativeImpl = MakeShareable(new SentryIdIOS());
23+
#elif PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX
24+
SentryIdNativeImpl = MakeShareable(new SentryIdDesktop());
2125
#endif
2226
}
2327
}
2428

29+
FString USentryId::ToString() const
30+
{
31+
if(!SentryIdNativeImpl)
32+
return FString();
33+
34+
return SentryIdNativeImpl->ToString();
35+
}
36+
2537
void USentryId::InitWithNativeImpl(TSharedPtr<ISentryId> idImpl)
2638
{
2739
SentryIdNativeImpl = idImpl;

plugin-dev/Source/Sentry/Public/SentryId.h

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class SENTRY_API USentryId : public UObject
1717
public:
1818
USentryId();
1919

20+
/** Gets string representation of the event ID. */
21+
UFUNCTION(BlueprintPure, Category = "Sentry")
22+
FString ToString() const;
23+
2024
void InitWithNativeImpl(TSharedPtr<ISentryId> idImpl);
2125
TSharedPtr<ISentryId> GetNativeImpl();
2226

0 commit comments

Comments
 (0)