Files
Plugin/Source/SenseGloveCore/Private/SGCore/SGDeviceModel.cpp
T

201 lines
6.8 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2023 SenseGlove
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @section DESCRIPTION
*
*
*/
#include "SGCore/SGDeviceModel.h"
#include "Runtime/Launch/Resources/Version.h"
#include "SGCoreImpl/SGExportedFunctions.h"
#include "SGInterop/SGIC_FSGDeviceModelImpl.h"
#include "SGInterop/SGIC_FString.h"
#include "SGInterop/SGIC_TArray_bool.h"
struct USGDeviceModel::FImpl
{
/************************
* Member variables
************************/
FSGDeviceModelImpl DeviceModelImpl;
/************************
* Owner object
************************/
USGDeviceModel* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(USGDeviceModel* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
USGDeviceModel* USGDeviceModel::NewDeviceModel(UObject* Outer, const FSGDeviceModelImpl& DeviceModelImpl)
{
USGDeviceModel* Instance = NewObject<USGDeviceModel>(Outer);
Instance->SetDeviceModelImpl(DeviceModelImpl);
return Instance;
}
USGDeviceModel* USGDeviceModel::NewDeviceModel(UObject* Outer)
{
FSGIC_FSGDeviceModelImpl OutDeviceModelImplContainer;
SGCoreImpl_FSGDeviceModelImpl_ctor(&OutDeviceModelImplContainer);
return NewDeviceModel(Outer, MoveTemp(OutDeviceModelImplContainer.DeviceModelImpl));
}
USGDeviceModel* USGDeviceModel::NewDeviceModel(
UObject* Outer,
const FString& Id, const FString& HardwareVersion, const int32 FirmwareVersion, const int32 SubFirmwareVersion)
{
FSGIC_FSGDeviceModelImpl OutDeviceModelImplContainer;
FSGIC_FString IdContainer{Id};
FSGIC_FString HardwareVersionContainer{HardwareVersion};
SGCoreImpl_FSGDeviceModelImpl_ctor_Id_HardwareVersion_FirmwareVersion_SubFirmwareVersion(
&OutDeviceModelImplContainer, &IdContainer, &HardwareVersionContainer, FirmwareVersion, SubFirmwareVersion);
return NewDeviceModel(Outer, MoveTemp(OutDeviceModelImplContainer.DeviceModelImpl));
}
TArray<bool> USGDeviceModel::ParseFunctions(const int32 Value, const int32 Size)
{
FSGIC_TArray_bool OutParseFunctionsContainer;
SGCoreImpl_FSGDeviceModelImpl_ParseFunctions(&OutParseFunctionsContainer, Value, Size);
return MoveTemp(OutParseFunctionsContainer.Array);
}
void USGDeviceModel::ParseFirmware(const FString& RawFirmware, int32& OutMainVersion, int32& OutSubVersion)
{
FSGIC_FString RawFirmwareContainer{RawFirmware};
SGCoreImpl_FSGDeviceModelImpl_ParseFirmware(&RawFirmwareContainer, &OutMainVersion, &OutSubVersion);
}
USGDeviceModel::USGDeviceModel()
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
FSGIC_FSGDeviceModelImpl OutDeviceModelImplContainer;
SGCoreImpl_FSGDeviceModelImpl_ctor(&OutDeviceModelImplContainer);
Pimpl->DeviceModelImpl = MoveTemp(OutDeviceModelImplContainer.DeviceModelImpl);
}
USGDeviceModel::USGDeviceModel(const FString& Id, const FString& HardwareVersion,
const int32 FirmwareVersion, const int32 SubFirmwareVersion)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
FSGIC_FSGDeviceModelImpl OutDeviceModelImplContainer;
FSGIC_FString IdContainer{Id};
FSGIC_FString HardwareVersionContainer{HardwareVersion};
SGCoreImpl_FSGDeviceModelImpl_ctor_Id_HardwareVersion_FirmwareVersion_SubFirmwareVersion(
&OutDeviceModelImplContainer, &IdContainer, &HardwareVersionContainer, FirmwareVersion, SubFirmwareVersion);
Pimpl->DeviceModelImpl = MoveTemp(OutDeviceModelImplContainer.DeviceModelImpl);
}
USGDeviceModel::USGDeviceModel(const FSGDeviceModelImpl& DeviceModelImpl)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
SetDeviceModelImpl(DeviceModelImpl);
}
USGDeviceModel::~USGDeviceModel() = default;
void USGDeviceModel::SetDeviceModelImpl(const FSGDeviceModelImpl& DeviceModelImpl)
{
FSGIC_FSGDeviceModelImpl OutDeviceModelContainer;
FSGIC_FSGDeviceModelImpl RhsContainer{DeviceModelImpl};
SGCoreImpl_FSGDeviceModelImpl_ctor_copy(&OutDeviceModelContainer, &RhsContainer);
Pimpl->DeviceModelImpl = MoveTemp(OutDeviceModelContainer.DeviceModelImpl);
}
const FSGDeviceModelImpl& USGDeviceModel::ToDeviceModelImpl() const
{
return Pimpl->DeviceModelImpl;
}
FSGDeviceModelImpl& USGDeviceModel::ToDeviceModelImpl()
{
return Pimpl->DeviceModelImpl;
}
FString USGDeviceModel::GetDeviceId() const
{
FSGIC_FSGDeviceModelImpl InstanceContainer{ToDeviceModelImpl()};
FSGIC_FString OutIdContainer;
SGCoreImpl_FSGDeviceModelImpl_GetDeviceId(&InstanceContainer, &OutIdContainer);
return MoveTemp(OutIdContainer.String);
}
FString USGDeviceModel::GetHardwareVersion() const
{
FSGIC_FSGDeviceModelImpl InstanceContainer{ToDeviceModelImpl()};
FSGIC_FString OutVersionContainer;
SGCoreImpl_FSGDeviceModelImpl_GetHardwareVersion(&InstanceContainer, &OutVersionContainer);
return MoveTemp(OutVersionContainer.String);
}
int32 USGDeviceModel::GetFirmwareVersion() const
{
FSGIC_FSGDeviceModelImpl InstanceContainer{ToDeviceModelImpl()};
return SGCoreImpl_FSGDeviceModelImpl_GetFirmwareVersion(&InstanceContainer);
}
int32 USGDeviceModel::GetSubFirmwareVersion() const
{
FSGIC_FSGDeviceModelImpl InstanceContainer{ToDeviceModelImpl()};
return SGCoreImpl_FSGDeviceModelImpl_GetSubFirmwareVersion(&InstanceContainer);
}
USGDeviceModel::FImpl::FImpl(USGDeviceModel* InOwner)
: Owner(InOwner)
{
}
USGDeviceModel::FImpl::~FImpl() = default;
void USGDeviceModel::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}