/** * @file * * @author Mamadou Babaei * * @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 "SGCoreImpl/SGDeviceModelImpl.h" #include #include #include "Containers/StringConv.h" #include "Runtime/Launch/Resources/Version.h" #include "SGBuildHacks/SGInclude_Core_DeviceModel.h" struct FSGDeviceModelImpl::FImpl { /************************ * Member variables ************************/ FDeviceModelType DeviceModel; /************************ * Owner object ************************/ FSGDeviceModelImpl* Owner; /************************ * Constructor / Destructor ************************/ explicit FImpl(FSGDeviceModelImpl* InOwner); ~FImpl(); /************************ * Default copy constructor & copy assignment operator ************************/ FImpl(const FImpl& Rhs) = default; FImpl& operator=(const FImpl& Rhs) = default; }; TArray FSGDeviceModelImpl::ParseFunctions(int32 Value, int32 Size) { /// NOTE /// std::vector is a non conforming container. Since it packs bools to be stored in one bit, /// it cannot provide a bool reference. Thus FSGArrayUtils::FromStdVector() cannot be used. static TArray ParsedFunctionsArray; std::vector ParsedFunctionsVector{FDeviceModelType::ParseFunctions(Value, Size)}; for (const bool bValue: ParsedFunctionsVector) { ParsedFunctionsArray.Add(bValue); } return ParsedFunctionsArray; } void FSGDeviceModelImpl::ParseFirmware(const FString& RawFirmware, int32& OutMainVersion, int32& OutSubVersion) { std::string RawFirmwareString(TCHAR_TO_UTF8(*RawFirmware)); FDeviceModelType::ParseFirmware(MoveTemp(RawFirmwareString), OutMainVersion, OutSubVersion); } FSGDeviceModelImpl::FSGDeviceModelImpl() : Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) { } FSGDeviceModelImpl::FSGDeviceModelImpl( const FString& Id, const FString& HardwareVersion, const int32 FirmwareVersion, const int32 SubFirmwareVersion) : Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) { std::string IdString(TCHAR_TO_UTF8(*Id)); std::string HardwareVersionString(TCHAR_TO_UTF8(*HardwareVersion)); Pimpl->DeviceModel = FDeviceModelType(MoveTemp(IdString), MoveTemp(HardwareVersionString), FirmwareVersion, SubFirmwareVersion); } FSGDeviceModelImpl::FSGDeviceModelImpl(const FDeviceModelType& DeviceModel) : Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) { Pimpl->DeviceModel = DeviceModel; } FSGDeviceModelImpl::FSGDeviceModelImpl(const FSGDeviceModelImpl& Rhs) : Pimpl(TUniquePtr(new FImpl{*Rhs.Pimpl}, PimplDeleter)) { Pimpl->Owner = this; } FSGDeviceModelImpl::FSGDeviceModelImpl(FSGDeviceModelImpl&& Rhs) SG_NOEXCEPT = default; FSGDeviceModelImpl::~FSGDeviceModelImpl() = default; FSGDeviceModelImpl& FSGDeviceModelImpl::operator=(const FSGDeviceModelImpl& Rhs) { *Pimpl = *Rhs.Pimpl; Pimpl->Owner = this; return *this; } FSGDeviceModelImpl& FSGDeviceModelImpl::operator=(FSGDeviceModelImpl&& Rhs) SG_NOEXCEPT = default; const FSGDeviceModelImpl::FDeviceModelType& FSGDeviceModelImpl::ToDeviceModel() const { return Pimpl->DeviceModel; } FString FSGDeviceModelImpl::GetDeviceId() const { FString DeviceId(UTF8_TO_TCHAR(Pimpl->DeviceModel.GetDeviceId().c_str())); return MoveTemp(DeviceId); } FString FSGDeviceModelImpl::GetHardwareVersion() const { FString HardwareVersion(UTF8_TO_TCHAR(Pimpl->DeviceModel.GetHardwareVersion().c_str())); return MoveTemp(HardwareVersion); } int32 FSGDeviceModelImpl::GetFirmwareVersion() const { return Pimpl->DeviceModel.GetFirmwareVersion(); } int32 FSGDeviceModelImpl::GetSubFirmwareVersion() const { return Pimpl->DeviceModel.GetSubFirmwareVersion(); } FSGDeviceModelImpl::FImpl::FImpl(FSGDeviceModelImpl* InOwner) : Owner(InOwner) { } FSGDeviceModelImpl::FImpl::~FImpl() = default; void FSGDeviceModelImpl::FImplDeleter::operator()(const FImpl* P) const { delete P; }