Files
Plugin/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGDeviceModelImpl.cpp
T

223 lines
6.2 KiB
C++
Raw Normal View History

2022-11-02 22:43:14 +01:00
/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @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/SGDeviceModelImpl.h"
#include <string>
#include <vector>
#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<bool> FSGDeviceModelImpl::ParseFunctions(int32 Value, int32 Size)
{
/// NOTE
/// std::vector<bool> is a non conforming container. Since it packs bools to be stored in one bit,
/// it cannot provide a bool reference. Thus FSGArrayUtils::FromStdVector<bool>() cannot be used.
static TArray<bool> ParsedFunctionsArray;
std::vector<bool> 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()
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
}
FSGDeviceModelImpl::FSGDeviceModelImpl(
const FString& Id, const FString& HardwareVersion, const int32 FirmwareVersion, const int32 SubFirmwareVersion)
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
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)
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
Pimpl->DeviceModel = DeviceModel;
}
FSGDeviceModelImpl::FSGDeviceModelImpl(const FSGDeviceModelImpl& Rhs)
:
#if SG_CPP17
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}))
#endif /* SG_CPP17 */
2022-11-02 22:43:14 +01:00
{
Pimpl->Owner = this;
}
FSGDeviceModelImpl::FSGDeviceModelImpl(FSGDeviceModelImpl&& Rhs)
#if SG_CPP17
noexcept
#endif /* SG_CPP17 */
= default;
2022-11-02 22:43:14 +01:00
FSGDeviceModelImpl::~FSGDeviceModelImpl() = default;
FSGDeviceModelImpl& FSGDeviceModelImpl::operator=(const FSGDeviceModelImpl& Rhs)
{
*Pimpl = *Rhs.Pimpl;
Pimpl->Owner = this;
return *this;
}
FSGDeviceModelImpl& FSGDeviceModelImpl::operator=(FSGDeviceModelImpl&& Rhs)
#if SG_CPP17
noexcept
#endif /* SG_CPP17 */
= default;
2022-11-02 22:43:14 +01:00
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);
}
void FSGDeviceModelImpl::SetDeviceId(const FString& Id) const
{
Pimpl->DeviceModel.SetDeviceId(TCHAR_TO_UTF8(*Id));
}
FString FSGDeviceModelImpl::GetHardwareVersion() const
{
FString HardwareVersion(UTF8_TO_TCHAR(Pimpl->DeviceModel.GetHardwareVersion().c_str()));
return MoveTemp(HardwareVersion);
}
void FSGDeviceModelImpl::SetHardwareVersion(const FString& Version) const
{
Pimpl->DeviceModel.SetHardwareVersion(TCHAR_TO_UTF8(*Version));
}
int32 FSGDeviceModelImpl::GetFirmwareVersion() const
{
return Pimpl->DeviceModel.GetFirmwareVersion();
}
void FSGDeviceModelImpl::SetFirmwareVersion(const int32 Version) const
{
Pimpl->DeviceModel.SetFirmwareVersion(Version);
}
int32 FSGDeviceModelImpl::GetSubFirmwareVersion() const
{
return Pimpl->DeviceModel.GetSubFirmwareVersion();
}
void FSGDeviceModelImpl::SetSubFirmwareVersion(const int32 Version) const
{
Pimpl->DeviceModel.SetSubFirmwareVersion(Version);
}
FSGDeviceModelImpl::FImpl::FImpl(FSGDeviceModelImpl* InOwner)
: Owner(InOwner)
{
}
FSGDeviceModelImpl::FImpl::~FImpl() = default;
void FSGDeviceModelImpl::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}