implement sgcore ue api functions that are required for the underlying library and sgfakeshm initialization/termination

This commit is contained in:
Mamadou Babaei
2026-07-13 20:14:36 +02:00
parent 18f1d22321
commit f0beaf1f96
10 changed files with 159 additions and 1 deletions
@@ -39,6 +39,27 @@
#include "SGInterop/SGIC_ESGBackendType.h"
#include "SGInterop/SGIC_FString.h"
bool FSGLibrary::IsInitialized()
{
return SGCoreImpl_FSGLibraryImpl_IsInitialized();
}
bool FSGLibrary::Initialize(FString& OutError)
{
FSGIC_FString Container;
const bool bResult = SGCoreImpl_FSGLibraryImpl_Initialize(&Container);
OutError = MoveTemp(Container.String);
return bResult;
}
bool FSGLibrary::Terminate(FString& OutError)
{
FSGIC_FString Container;
const bool bResult = SGCoreImpl_FSGLibraryImpl_Terminate(&Container);
OutError = MoveTemp(Container.String);
return bResult;
}
FString FSGLibrary::GetVersion()
{
FSGIC_FString Container;
@@ -43,8 +43,34 @@
void FSenseGloveCoreModule::StartupModule()
{
SGLOG("Starting up the SenseGloveCore module...");
SGLOG(FString::Printf(TEXT("The Unreal Engine implementation of '%s' has been loaded successfully!"),
SGLOG(FString::Printf(TEXT("Initializing '%s'..."),
*FSGLibrary::GetVersion()));
const bool bInitializedAlready = FSGLibrary::IsInitialized();
if (!ensureAlwaysMsgf(!bInitializedAlready, TEXT("Failed to initialize SGCore!")))
{
SGLOG_FATAL(FString::Printf(TEXT("Failed to initialize '%s': it has already been initialized!"),
*FSGLibrary::GetVersion()));
}
else
{
FString Error;
const bool bInitialized = FSGLibrary::Initialize(Error);
if (bInitialized)
{
SGLOG(FString::Printf(TEXT("'%s' has been initialized successfully!"),
*FSGLibrary::GetVersion()));
SGLOG(FString::Printf(TEXT("The Unreal Engine implementation of '%s' has been loaded successfully!"),
*FSGLibrary::GetVersion()));
}
else
{
SGLOG_FATAL(FString::Printf(TEXT("Failed to initialize '%s'!"),
*FSGLibrary::GetVersion()));
}
}
}
void FSenseGloveCoreModule::PreUnloadCallback()
@@ -60,6 +86,34 @@ void FSenseGloveCoreModule::PostLoadCallback()
void FSenseGloveCoreModule::ShutdownModule()
{
SGLOG("Shutting down the SenseGloveCore module...");
SGLOG(FString::Printf(TEXT("Terminating '%s'..."),
*FSGLibrary::GetVersion()));
const bool bInitialized = FSGLibrary::IsInitialized();
if (!ensureAlwaysMsgf(bInitialized, TEXT("Failed to terminate SGCore!")))
{
SGLOG_FATAL(FString::Printf(TEXT("Failed to terminate '%s': it has not been initialized yet!"),
*FSGLibrary::GetVersion()));
}
else
{
FString Error;
const bool bTerminated = FSGLibrary::Terminate(Error);
if (bTerminated)
{
SGLOG(FString::Printf(TEXT("'%s' has been terminated successfully!"),
*FSGLibrary::GetVersion()));
SGLOG(FString::Printf(TEXT("The Unreal Engine implementation of '%s' has been shutdown successfully!"),
*FSGLibrary::GetVersion()));
}
else
{
SGLOG_FATAL(FString::Printf(TEXT("Failed to terminate '%s'!"),
*FSGLibrary::GetVersion()));
}
}
}
#undef LOCTEXT_NAMESPACE
@@ -51,6 +51,10 @@ struct SENSEGLOVECORE_API FSGLibrary
GENERATED_BODY()
public:
static bool IsInitialized();
static bool Initialize(FString& OutError);
static bool Terminate(FString& OutError);
/**
* The version of this C++ Library in string representation.
*/
@@ -2776,6 +2776,25 @@ bool SGCoreImpl_FSGJointKinematicsImpl_ForwardKinematics_Profile_Finger_JointAng
* SGLibraryImpl.h
******************************************************************************/
bool SGCoreImpl_FSGLibraryImpl_IsInitialized()
{
return FSGLibraryImpl::IsInitialized();
}
bool SGCoreImpl_FSGLibraryImpl_Initialize(
void* OutError)
{
return FSGLibraryImpl::Initialize(
StaticCast<FSGIC_FString*>(OutError)->String);
}
bool SGCoreImpl_FSGLibraryImpl_Terminate(
void* OutError)
{
return FSGLibraryImpl::Terminate(
StaticCast<FSGIC_FString*>(OutError)->String);
}
void SGCoreImpl_FSGLibraryImpl_Version(
void* OutVersion)
{
@@ -35,11 +35,34 @@
#include "SGCoreImpl/SGLibraryImpl.h"
#include <string>
#include "Containers/StringConv.h"
#include "SGBuildHacks/SGInclude_Core_Library.h"
#include "SGCoreImpl/SGCoreEnumCast.h"
bool FSGLibraryImpl::IsInitialized()
{
return FLibraryType::IsInitialized();
}
bool FSGLibraryImpl::Initialize(FString& OutError)
{
std::string Error;
const bool bResult = FLibraryType::Initialize(Error);
OutError = UTF8_TO_TCHAR(Error.c_str());
return bResult;
}
bool FSGLibraryImpl::Terminate(FString& OutError)
{
std::string Error;
const bool bResult = FLibraryType::Terminate(Error);
OutError = UTF8_TO_TCHAR(Error.c_str());
return bResult;
}
FString FSGLibraryImpl::Version()
{
const FString Version(UTF8_TO_TCHAR(FLibraryType::Version().c_str()));
@@ -1409,6 +1409,14 @@ SGCoreImpl_FSGJointKinematicsImpl_ForwardKinematics_Profile_Finger_JointAngles_O
* SGLibraryImpl.h
******************************************************************************/
SENSEGLOVECOREIMPL_PUBLIC_API bool SGCoreImpl_FSGLibraryImpl_IsInitialized();
SENSEGLOVECOREIMPL_PUBLIC_API bool SGCoreImpl_FSGLibraryImpl_Initialize(
void* OutError);
SENSEGLOVECOREIMPL_PUBLIC_API bool SGCoreImpl_FSGLibraryImpl_Terminate(
void* OutError);
SENSEGLOVECOREIMPL_PUBLIC_API void SGCoreImpl_FSGLibraryImpl_Version(
void* OutVersion);
@@ -50,6 +50,10 @@ public:
typedef SGCore::Library FLibraryType;
public:
static bool IsInitialized();
static bool Initialize(FString& OutError);
static bool Terminate(FString& OutError);
static FString Version();
static ESGBackendType GetBackendType();
@@ -37,6 +37,21 @@
#include "SGCore/SGLibrary.h"
bool USGLibraryKismetLibrary::IsInitialized()
{
return FSGLibrary::IsInitialized();
}
bool USGLibraryKismetLibrary::Initialize(FString& OutError)
{
return FSGLibrary::Initialize(OutError);
}
bool USGLibraryKismetLibrary::Terminate(FString& OutError)
{
return FSGLibrary::Terminate(OutError);
}
FString USGLibraryKismetLibrary::GetVersion()
{
return FSGLibrary::GetVersion();
@@ -51,6 +51,15 @@ class SENSEGLOVECOREKISMET_API USGLibraryKismetLibrary final : public USGBluepri
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Library")
static bool IsInitialized();
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Library")
static bool Initialize(FString& OutError);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Core | Library")
static bool Terminate(FString& OutError);
/**
* The version of this C++ Library in string representation.
*/