[hac] Add native Result class.

This commit is contained in:
jakcron 2018-09-10 22:10:15 +08:00
parent c6847808a8
commit dd1a97aec2
4 changed files with 109 additions and 0 deletions

View file

@ -0,0 +1,39 @@
#pragma once
#include <fnd/types.h>
namespace nn
{
namespace hac
{
class Result
{
public:
Result();
Result(uint32_t result);
Result(uint32_t module_num, uint32_t desc, uint32_t sub_desc);
void operator=(const Result& other);
bool operator==(const Result& other) const;
bool operator!=(const Result& other) const;
bool isSuccess() const;
bool isFailure() const;
uint32_t getInnerValue() const;
uint32_t getModuleNum() const;
uint32_t getDescription() const;
uint32_t getSubDescription() const;
private:
static const uint32_t kModuleNumBitWidth = 9;
static const uint32_t kModuleNumBitPos = 0;
static const uint32_t kDescriptionBitWidth = 13;
static const uint32_t kDescriptionBitPos = 9;
static const uint32_t kSubDescriptionBitWidth = 10;
static const uint32_t kSubDescriptionBitPos = 22;
inline uint32_t bitWidthToMask(uint32_t bit_width) const { return _BIT(bit_width) - 1; }
uint32_t mResult;
};
}
}

View file

@ -68,6 +68,7 @@
<ClInclude Include="include\nn\hac\NsoHeader.h" />
<ClInclude Include="include\nn\hac\pfs.h" />
<ClInclude Include="include\nn\hac\PfsHeader.h" />
<ClInclude Include="include\nn\hac\Result.h" />
<ClInclude Include="include\nn\hac\romfs.h" />
<ClInclude Include="include\nn\hac\ServiceAccessControlBinary.h" />
<ClInclude Include="include\nn\hac\ServiceAccessControlEntry.h" />
@ -110,6 +111,7 @@
<ClCompile Include="source\NroHeader.cpp" />
<ClCompile Include="source\NsoHeader.cpp" />
<ClCompile Include="source\PfsHeader.cpp" />
<ClCompile Include="source\Result.cpp" />
<ClCompile Include="source\ServiceAccessControlBinary.cpp" />
<ClCompile Include="source\ServiceAccessControlEntry.cpp" />
<ClCompile Include="source\SystemCallEntry.cpp" />

View file

@ -186,6 +186,9 @@
<ClInclude Include="include\nn\hac\IdConverter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\nn\hac\Result.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\AccessControlInfoBinary.cpp">
@ -302,5 +305,8 @@
<ClCompile Include="source\IdConverter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\Result.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -0,0 +1,62 @@
#include <nn/hac/Result.h>
nn::hac::Result::Result() :
mResult(0)
{}
nn::hac::Result::Result(uint32_t result) :
mResult(result)
{}
nn::hac::Result::Result(uint32_t module_num, uint32_t desc, uint32_t sub_desc) :
mResult(0)
{
mResult |= (module_num & bitWidthToMask(kModuleNumBitWidth)) << kModuleNumBitPos;
mResult |= (desc & bitWidthToMask(kDescriptionBitWidth)) << kDescriptionBitPos;
mResult |= (sub_desc & bitWidthToMask(kSubDescriptionBitWidth)) << kSubDescriptionBitPos;
}
void nn::hac::Result::operator=(const Result & other)
{
mResult = other.mResult;
}
bool nn::hac::Result::operator==(const Result & other) const
{
return mResult == other.mResult;
}
bool nn::hac::Result::operator!=(const Result & other) const
{
return !(*this == other);
}
bool nn::hac::Result::isSuccess() const
{
return mResult == 0;
}
bool nn::hac::Result::isFailure() const
{
return !isSuccess();
}
uint32_t nn::hac::Result::getInnerValue() const
{
return mResult;
}
uint32_t nn::hac::Result::getModuleNum() const
{
return (mResult >> kModuleNumBitPos) & bitWidthToMask(kModuleNumBitWidth);
}
uint32_t nn::hac::Result::getDescription() const
{
return (mResult >> kDescriptionBitPos) & bitWidthToMask(kDescriptionBitWidth);
}
uint32_t nn::hac::Result::getSubDescription() const
{
return (mResult >> kSubDescriptionBitPos) & bitWidthToMask(kSubDescriptionBitWidth);
}