/** * @file * * @author Mamadou Babaei * * @section LICENSE * * (The MIT License) * * Copyright (c) 2020 - 2022 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 "SGCoreImpl/SGBetaDeviceImpl.h" #include "Containers/StringConv.h" #include "Misc/AssertionMacros.h" #include "Runtime/Launch/Resources/Version.h" #include "SGBuildHacks/SGInclude_Core_BetaDevice.h" #include "SGBuildHacks/SGInclude_Core_SGDevice.h" #include "SGCoreImpl/SGCoreEnumCast.h" struct FSGBetaDeviceImpl::FImpl { /************************ * Owner object ************************/ FSGBetaDeviceImpl* Owner; /************************ * Constructor / Destructor ************************/ explicit FImpl(FSGBetaDeviceImpl* InOwner); ~FImpl(); /************************ * Default copy constructor & copy assignment operator ************************/ FImpl(const FImpl& Rhs) = default; FImpl& operator=(const FImpl& Rhs) = default; }; TSharedRef FSGBetaDeviceImpl::Parse(const FString& String) { FSGDevicePtrType SGDevicePtr{FBetaDeviceType::Parse(TCHAR_TO_UTF8(*String))}; ensureAlwaysMsgf(SGDevicePtr, TEXT("Invalid SGDevice!")); TSharedRef BetaDeviceImpl{MakeShared( std::dynamic_pointer_cast(MoveTemp(SGDevicePtr)))}; return MoveTemp(BetaDeviceImpl); } FSGBetaDeviceImpl::FSGBetaDeviceImpl() : FSGDeviceImpl(), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { } FSGBetaDeviceImpl::FSGBetaDeviceImpl(const FString& ConstantsString, const FString& DeviceId, const FString& HardwareVersion, int32 FirmwareVersion, int32 SubFirmwareVersion) : FSGDeviceImpl(std::make_shared( TCHAR_TO_UTF8(*ConstantsString), TCHAR_TO_UTF8(*DeviceId), TCHAR_TO_UTF8(*HardwareVersion), FirmwareVersion, SubFirmwareVersion)), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { } FSGBetaDeviceImpl::FSGBetaDeviceImpl(const FBetaDeviceType BetaDevice) : FSGDeviceImpl(std::make_shared(BetaDevice)), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { } FSGBetaDeviceImpl::FSGBetaDeviceImpl(const FBetaDevicePtrType BetaDevice) : FSGDeviceImpl(BetaDevice), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { } FSGBetaDeviceImpl::FSGBetaDeviceImpl(const FSGBetaDeviceImpl& Rhs) : FSGDeviceImpl(Rhs), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{*Rhs.Pimpl}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{*Rhs.Pimpl})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { Pimpl->Owner = this; } FSGBetaDeviceImpl::FSGBetaDeviceImpl(FSGBetaDeviceImpl&& Rhs) noexcept = default; FSGBetaDeviceImpl::~FSGBetaDeviceImpl() = default; FSGBetaDeviceImpl& FSGBetaDeviceImpl::operator=(const FSGBetaDeviceImpl& Rhs) { FSGDeviceImpl::operator=(Rhs); *Pimpl = *Rhs.Pimpl; Pimpl->Owner = this; return *this; } FSGBetaDeviceImpl& FSGBetaDeviceImpl::operator=(FSGBetaDeviceImpl&& Rhs) noexcept = default; FSGBetaDeviceImpl::FBetaDeviceType FSGBetaDeviceImpl::ToBetaDevice() const { return *ToBetaDevicePtr(); } FSGBetaDeviceImpl::FBetaDevicePtrType FSGBetaDeviceImpl::ToBetaDevicePtr() const { return std::dynamic_pointer_cast(ToSGDevicePtr()); } FSGBetaDeviceImpl::FBetaDevicePtrType FSGBetaDeviceImpl::ToBetaDevicePtrChecked() const { FBetaDevicePtrType BetaDevice = std::dynamic_pointer_cast(ToSGDevicePtr()); ensureAlwaysMsgf(BetaDevice.get(), TEXT("Invalid BetaDevice")); return BetaDevice; } ESGDeviceType FSGBetaDeviceImpl::GetDeviceType() const { return FSGCoreEnumCast::ToESGDeviceType(ToBetaDevicePtrChecked()->GetDeviceType()); } FString FSGBetaDeviceImpl::GetDeviceId() const { FString Id{UTF8_TO_TCHAR(ToBetaDevicePtrChecked()->GetDeviceId().c_str())}; return MoveTemp(Id); } FString FSGBetaDeviceImpl::GetHardwareVersion() const { FString Version{UTF8_TO_TCHAR(ToBetaDevicePtrChecked()->GetHardwareVersion().c_str())}; return MoveTemp(Version); } int32 FSGBetaDeviceImpl::GetFirmwareVersion() const { return ToBetaDevicePtrChecked()->GetFirmwareVersion(); } int32 FSGBetaDeviceImpl::GetSubFirmwareVersion() const { return ToBetaDevicePtrChecked()->GetSubFirmwareVersion(); } FString FSGBetaDeviceImpl::GetConstantsString() const { FString String{UTF8_TO_TCHAR(ToBetaDevicePtrChecked()->GetConstantsString().c_str())}; return MoveTemp(String); } FString FSGBetaDeviceImpl::GetSensorData() const { FString Data{UTF8_TO_TCHAR(ToBetaDevicePtrChecked()->GetSensorData().c_str())}; return MoveTemp(Data); } FString FSGBetaDeviceImpl::GetLastCommand() const { FString Command{UTF8_TO_TCHAR(ToBetaDevicePtrChecked()->GetLastCommand().c_str())}; return MoveTemp(Command); } bool FSGBetaDeviceImpl::SendHaptics(const FString& Command) const { return ToBetaDevicePtrChecked()->SendHaptics(TCHAR_TO_UTF8(*Command)); } FString FSGBetaDeviceImpl::ToString() const { return FSGDeviceImpl::ToString(); } FSGBetaDeviceImpl::FImpl::FImpl(FSGBetaDeviceImpl* InOwner) : Owner(InOwner) { } FSGBetaDeviceImpl::FImpl::~FImpl() = default; void FSGBetaDeviceImpl::FImplDeleter::operator()(const FImpl* P) const { delete P; }