18 #include <nn/pia/pia_Platform.h>
19 #include <nn/pia/pia_Types.h>
23 #define PIA_DEFINE_RESULT(name, handling, viewer, description) \
24 typedef ::nn::pia::ResultConst<(handling), (viewer), (description)> name
28 #if NN_PIA_NINTENDOSDK
103 static const uint32_t ValueSuccess = 0;
105 static const int32_t SizeDescription = 10;
106 static const int32_t SizeViewer = 3;
107 static const int32_t SizeHandling = 5;
109 static const int32_t ShiftsDescription = 0;
110 static const int32_t ShiftsViewer = ShiftsDescription + SizeDescription;
111 static const int32_t ShiftsHandling = ShiftsViewer + SizeViewer;
113 #define NN_RESULT_H_MAKE_MASK(size, shift) (((~0u) >> (32 - (size))) << (shift))
114 #define NN_RESULT_H_MAKE_MASK_HELPER(c) \
115 static const uint32_t Mask##c = NN_RESULT_H_MAKE_MASK(Size##c, Shifts##c)
117 NN_RESULT_H_MAKE_MASK_HELPER(Viewer);
118 NN_RESULT_H_MAKE_MASK_HELPER(Handling);
119 #undef NN_RESULT_H_MAKE_MASK_HELPER
120 #undef NN_RESULT_H_MAKE_MASK
122 #define NN_RESULT_H_MAKE_MAX(size) ((~0u) >> (32 - (size)))
123 #define NN_RESULT_H_MAKE_MAX_HELPER(c) \
124 static const int32_t Max##c = NN_RESULT_H_MAKE_MAX(Size##c)
126 NN_RESULT_H_MAKE_MAX_HELPER(Viewer);
127 NN_RESULT_H_MAKE_MAX_HELPER(Handling);
128 #undef NN_RESULT_H_MAKE_MAX_HELPER
129 #undef NN_RESULT_H_MAKE_MAX
201 Description_ConnectionFailed,
202 Description_CreateStationFailed,
205 Description_TableIsFull,
231 Description_MeshConnectionIsLost,
260 Description_DuplicateLogin,
261 Description_OnlinePlayLicenseNotAvailable,
262 Description_OnlinePlayLicenseError
266 static const uint32_t PiaErrorCodeBase = 180000;
268 static const uint32_t PiaErrorCodeBase = 180000;
270 static const uint32_t PiaErrorCodeBase = 1180000;
271 #elif NN_PIA_NINTENDOSDK
272 static const uint32_t PiaErrorCodeBase = 26180000;
274 static const uint32_t PiaErrorCodeBase = 26180000;
276 static const uint32_t PiaErrorCodeBase = 26180000;
278 #error "invalid platform"
288 #if NN_PIA_NINTENDOSDK
289 static void SetNexNetworkErrorCode(
const nn::err::ErrorCode& code);
291 static void SetNexNetworkErrorCode(uint32_t code);
299 static void ClearNexNetworkErrorCode(
void);
309 static void SetSdkErrorCode(uint32_t code)
311 s_SdkErrorCode = code;
320 static void ClearSdkErrorCode(
void)
327 #if NN_PIA_NINTENDOSDK
328 static nn::err::ErrorCode s_NexNetworkErrorCode;
330 static uint32_t s_NexNetworkErrorCode;
332 static uint32_t s_SdkErrorCode;
335 explicit Result(uint32_t code)
342 : m_Code(ValueSuccess)
346 Result(
const Result& r)
352 : m_Code(static_cast<uint32_t>(
353 ((static_cast<uint32_t>(handling) << ShiftsHandling) & MaskHandling) |
354 ((static_cast<uint32_t>(viewer) << ShiftsViewer) & MaskViewer) |
355 ((static_cast<uint32_t>(description) << ShiftsDescription) & MaskDescription)))
376 return m_Code == ValueSuccess;
389 return static_cast<enum
Description>(GetCodeBits(MaskDescription, ShiftsDescription));
392 uint32_t GetValue()
const
409 return this->m_Code == rhs.m_Code;
420 return this->m_Code != rhs.m_Code;
436 return static_cast<enum
HandlingType>(GetCodeBits(MaskHandling, ShiftsHandling));
470 return static_cast<enum
ViewerType>(GetCodeBits(MaskViewer, ShiftsViewer));
473 #if !NN_PIA_NINTENDOSDK
508 #if NN_PIA_NINTENDOSDK
544 uint32_t GetCodeBits(uint32_t mask, int32_t shift)
const
546 return ((m_Code & mask) >> shift);
555 struct AssertableResultAll
561 static void EnableAssert()
563 s_IsAssertEnabled =
true;
569 static void DisableAssert()
571 s_IsAssertEnabled =
false;
578 static bool IsAssertEnabled()
580 return s_IsAssertEnabled;
584 static bool s_IsAssertEnabled;
594 template <Result::HandlingType THandling, Result::ViewerType TViewer, Result::Description TDescription>
595 struct ResultConst :
public Result
597 static const uint32_t Value =
598 static_cast<uint32_t
>(
599 ((
static_cast<uint32_t
>(THandling) << ShiftsHandling) & MaskHandling) |
600 ((static_cast<uint32_t>(TViewer) << ShiftsViewer) & MaskViewer) |
601 ((
static_cast<uint32_t
>(TDescription) << ShiftsDescription) & MaskDescription));
611 static void EnableAssert()
613 s_IsAssertEnabled =
true;
619 static void DisableAssert()
621 s_IsAssertEnabled =
false;
628 static bool IsAssertEnabled()
630 return (s_IsAssertEnabled || AssertableResultAll::IsAssertEnabled());
634 static bool s_IsAssertEnabled;
639 template <Result::HandlingType THandling, Result::ViewerType TViewer, Result::Description TDescription>
640 bool ResultConst<THandling, TViewer, TDescription>::s_IsAssertEnabled =
false;
649 ResultAllocationFailed,
659 ResultAlreadyInitialized,
669 ResultBufferShortage,
699 ResultNetworkConnectionIsLost,
709 ResultInvalidArgument,
750 ResultNotImplemented,
761 ResultNotInitialized,
801 ResultContainerIsFull,
811 ResultTemporaryUnavailable,
854 ResultNegligibleFault,
868 ResultInvalidConnection,
889 ResultNetworkIsNotFound,
910 ResultLocalLowerVersion,
920 ResultLocalHigherVersion,
950 ResultWirelessControllerCountLimitation,
962 ResultConnectionFailed,
965 Result::Description_ConnectionFailed);
975 ResultCreateStationFailed,
978 Result::Description_CreateStationFailed);
986 ResultIncompatibleFormat,
996 ResultNotInCommunication,
1011 Result::Description_TableIsFull);
1023 ResultDataIsNotArrivedYet,
1045 ResultNatCheckFailed,
1059 Result::Description_InUsed);
1079 ResultNexInternalError,
1090 ResultJoinRequestDenied,
1101 ResultStationConnectionFailed,
1123 ResultInvalidSystemMessage,
1133 ResultStationConnectionNatTraversalFailedUnknown,
1143 ResultNatTraversalFailedBothEim,
1153 ResultNatTraversalFailedLocalEimRemoteEdm,
1163 ResultNatTraversalFailedLocalEdmRemoteEim,
1173 ResultNatTraversalFailedBothEdm,
1184 ResultRelayFailedNoCandidate,
1194 ResultRelayFailedRttLimit,
1203 ResultRelayFailedRelayNumLimit,
1212 ResultRelayFailedUnknown,
1222 ResultNatTraversalRequestTimeout,
1232 ResultSessionIsNotFound,
1242 ResultMatchmakeSessionIsFull,
1252 ResultDeniedByParticipants,
1262 ResultParticipantInBlockList,
1272 ResultGameServerMaintenance,
1282 ResultSessionUserPasswordUnmatch,
1292 ResultSessionSystemPasswordUnmatch,
1303 ResultMeshConnectionIsLost,
1306 Result::Description_MeshConnectionIsLost);
1314 ResultSessionIsClosed,
1324 ResultCompanionStationIsOffline,
1334 ResultHostIsNotFriend,
1345 ResultSessionConnectionIsLost,
1355 ResultCompanionStationIsLeft,
1365 ResultSessionMigrationFailed,
1375 ResultGameServerProcessAborted,
1385 ResultSessionWrongState,
1395 ResultCreateCommunityFailedUpperLimit,
1405 ResultJoinCommunityFailedUpperLimit,
1415 ResultCommunityIsFull,
1425 ResultCommunityIsNotFound,
1435 ResultCommunityIsClosed,
1445 ResultCommunityUserPasswordUnmatch,
1455 ResultAlreadyJoinedCommunity,
1465 ResultUserAccountNotExisted,
1475 ResultNatTraversalFailedBothEimSamePublicAddress,
1485 ResultNatTraversalFailedBothEdmSamePublicAddress,
1495 ResultNatTraversalFailedLocalEimRemoteEdmSamePublicAddress,
1505 ResultNatTraversalFailedLocalEdmRemoteEimSamePublicAddress,
1525 ResultSdkViewerErrorCodeError,
1537 ResultSdkViewerResultError,
1549 ResultCancelledByUser,
1559 ResultLanLowerVersion,
1569 ResultLanHigherVersion,
1581 ResultNetworkConnectionIsLostByDuplicateLogin,
1584 Result::Description_DuplicateLogin);
1593 ResultOnlinePlayLicenseNotAvailable,
1596 Result::Description_OnlinePlayLicenseNotAvailable);
1605 ResultOnlinePlayLicenseError,
1608 Result::Description_OnlinePlayLicenseError);
1621 #define PIA_RETURN_RESULT(result) \
1623 PIA_ASSERTMSG(result::IsAssertEnabled() == false, "Result:" #result); \