CTR Pia  4.11.3
Game Communication Engine
util_NetworkErrorCodeConverter.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: util_NetworkErrorCodeConverter.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/util/util_definitions.h>
18 
19 #include <pia/common/common_RootObject.h>
20 
21 
22 namespace nn
23 {
24 namespace pia
25 {
26 namespace util
27 {
28 
29 
30 /*!
31 @cond CTR_DOC
32 @brief This class converts <tt>nn::Result</tt> type errors into network error codes passed to the error/EULA applet.
33 @endcond
34 @cond CAFE_DOC
35 @brief This class converts <tt>nn::Result</tt> type errors into network error codes passed to Error Viewer.
36 @endcond
37 
38 @date 2015-04-16 Fixed a bug where <tt>ResultNexInternalError</tt> objects could not be converted using the <tt>Convert</tt> function after the <tt>Session::Cleanup</tt> function was called, causing the library to stop on an assertion.
39 @date 2014-11-04 Changed the operations of the <tt>Convert</tt> function.
40 @date 2014-08-07 Changed Pia so that it halts on an assertion if something other than a <tt>Result</tt> is passed to the <tt>Convert</tt> function.
41 @date 2012-11-06 Replaced locations that coded non-Pia <tt>Result</tt> values passed to <tt>Convert</tt> as immediate values with symbol names. The actual values passed remain the same.
42 @date 2012-06-21 Initial version.
43 */
45 {
46 public:
47 #if NN_PIA_CTR
48  static const u32 NN_PIA_ERROR_CODE_BASE = 180000; // 018-xxxx has been assigned to CTR Pia.
49 #elif NN_PIA_WIN || NN_PIA_NIN_WIN
50  static const u32 NN_PIA_ERROR_CODE_BASE = 180000; // Although the numbers have been matched to CTR, is the error display applet used in the Windows environment?
51 #elif NN_PIA_CAFE
52  static const u32 NN_PIA_ERROR_CODE_BASE = 1180000; // 118-xxxx has been assigned to Cafe Pia.
53 #else
54 #error "Invalid platform"
55 #endif
56 
57 /*!
58 @cond PRIVATE
59 @brief Instantiates the object with default parameters (default constructor).
60 @endcond
61 */
63 
64 
65 /*!
66 @cond PRIVATE
67 @brief Destroys the object.
68 @endcond
69 */
71 
72 
73 /*!
74 @brief Converts Pia library <tt>Result</tt> values to network error codes.
75 
76 @details Converts the <tt>Result</tt> type value returned by the Pia library to a network error code.
77 @details As an exception, returns a network error code corresponding to the NEX internal error for this <tt>Result</tt> if the <tt>ResultNexInternalError</tt> is passed.
78 There are several types of internal error, so the return value when passed <tt>ResultNexInternalError</tt> can be undefined.
79 @details If <tt> ResultNexInternalError</tt> is passed to this function when the Pia API has not yet returned <tt>ResultNexInternalError</tt>, this function asserts.
80 @if CTR_DOC
81 The converted values can be passed to the Error/EULA applet.
82 @endif
83 @if CAFE_DOC
84 The converted values can be passed to the Error Viewer.
85 @endif
86 If <tt>IsSuccess</tt> is <tt>true</tt> for the argument, <tt>0</tt> is returned. If an argument not defined in the Pia library is passed, Pia raises an assertion. (In release builds, it returns <tt>NN_PIA_ERROR_CODE_BASE</tt>.)
87 This function converts the results defined in the Pia library into unique identification codes, with the exception of <tt>ResultNexInternalError</tt>, but it is not necessary to show all codes as errors to the user.
88 For information about the error codes to show,
89 @if CTR_DOC
90 For more information, see the <i>CTR Guidelines: Internet</i> or the network error code list.
91 @endif
92 @if CAFE_DOC
93 See the chapter about displaying errors in <i>Wii U Guidelines</i>.
94 @endif
95 
96 @param[in] r Specifies the <tt>nn::Result</tt> value to convert to a network error code.
97 @return Returns the corresponding network error code.
98 
99 
100 
101 
102 
103 
104 */
105  static u32 Convert(const nn::Result& r);
106 
107 
108 /*!
109 @cond PRIVATE
110 @brief Sets the network error codes for errors that occur in communication with the game server.
111 
112 @param[in] networkErrorCode Sets the value converted from the NEX's <tt>qResult</tt> into a network error code.
113 @endcond
114 */
115  static void SetNexNetworkErrorCode(u32 code) { s_NexNetworkErrorCode = code; }
116 
117 
118 /*!
119 @cond PRIVATE
120 @brief Clears the network error code set by the <tt>SetNexNetworkErrorCode</tt> function.
121 @endcond
122 */
123  static void ClearNexNetworkErrorCode(void) { s_NexNetworkErrorCode = 0; }
124 
125 
126 /*!
127 @brief Prints information that is useful for debugging.
128 
129 @param[in] flag Specifies the bitwise OR of trace flags. For more information, see the <tt>@ref TraceFlag</tt> type.
130 */
131  void Trace(u64 flag) const;
132 
133 protected:
134 private:
135  static u32 s_NexNetworkErrorCode;
136 };
137 }
138 }
139 } // end of namespace nn::pia::util
Definition: assert.h:115
void Trace(u64 flag) const
Prints information that is useful for debugging.
This class converts nn::Result type errors into network error codes passed to the error/EULA applet...
Definition: util_NetworkErrorCodeConverter.h:44
static u32 Convert(const nn::Result &r)
Converts Pia library Result values to network error codes.
This is the common base class used inside the Pia library.
Definition: common_RootObject.h:40