CTR Pia  4.11.3
Game Communication Engine
common_WatermarkManager.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: common_WatermarkManager.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/common/common_definitions.h>
18 
19 #include <pia/common/common_Singleton.h>
20 #include <pia/common/common_Watermark.h>
21 
22 
23 #define NN_PIA_WATERMARK_UPDATE(KEY, VALUE) \
24  \
25 if(nn::pia::common::WatermarkManager::GetInstance()) \
26  \
27 { \
28  nn::pia::common::WatermarkManager::GetInstance()->GetWatermark(KEY)->Update(VALUE); \
29  \
30 }
31 
32 
33 #define NN_PIA_WATERMARK_SETNAME(KEY, NAME) \
34  \
35 if(nn::pia::common::WatermarkManager::GetInstance()) \
36  \
37 { \
38  nn::pia::common::WatermarkManager::GetInstance()->GetWatermark(KEY)->SetName(NAME); \
39  \
40 }
41 
42 
43 #define NN_PIA_WATERMARK_TRACE(KEY, FLAG) \
44  \
45 if(nn::pia::common::WatermarkManager::GetInstance()) \
46  \
47 { \
48  nn::pia::common::WatermarkManager::GetInstance()->GetWatermark(KEY)->Trace(FLAG); \
49  \
50 }
51 
52 
53 namespace nn
54 {
55 namespace pia
56 {
57 namespace common
58 {
59 
60 /*!
61 @brief This class manages a collection of Watermark instances (not supported).
62 @details The <tt>WatermarkManager</tt> class is provided for managing collections of <tt>Watermark</tt> instances.
63 You can use it to get information like the peak buffer usage of the Pia library.
64 @date 2014-09-18 Changed the specifications so that <tt>ResultAlreadyExists</tt> is returned if you call <tt>CreateInstance</tt> when an instance already exists.
65 @date 2013-05-14 Added <tt>KEY_UNRELIABLE_PROTOCOL_RECEIVE_BUFFER_NUM</tt>.
66 @date 2013-04-01 Removed <tt>KEY_PACKETPARSER_BUFFUR_NUM</tt> and <tt>KEY_PACKETCREATOR_BUFFUR_NUM</tt>.
67 @date 2013-03-21 Added keys for <tt>Reliable</tt> send and receive buffers in <tt>SessionProtocol</tt>.
68 @date 2012-05-09 Added keys for <tt>ReliableProtocol</tt> and <tt>StationProtocolReliable</tt> send and receive buffers.
69 @date 2012-04-25 Added documentation.
70 @date 2012-04-04 Initial version.
71 
72 
73 */
75 {
76 public:
77  static const int WATERMARK_INSTANCES = 10; //!< The maximum number of <tt>Watermark</tt> instances managed by the <tt>WatermarkManager</tt> class.
78 
79  // This key is for differentiating watermark instances. It must not be duplicated.
80  static const int KEY_SENDTHREADSTREAM_BUFFER_NUM = 0; //!< This key is for the buffer usage of the send thread.
81  static const int KEY_RECEIVETHREADSTREAM_BUFFER_NUM = 1; //!< This key is for the buffer usage of the receive thread.
82  static const int KEY_INET_RECEIVE_BUFFER_NUM = 2;
83  static const int KEY_RELIABLE_PROTOCOL_SEND_BUFFER_NUM = 3; //!< This key is for the send buffer usage of the <tt>ReliableProtocol</tt> instance.
84  static const int KEY_RELIABLE_PROTOCOL_RECEIVE_BUFFER_NUM = 4; //!< This key is for the receive buffer usage of the <tt>ReliableProtocol</tt> instance.
85  static const int KEY_STATION_PROTOCOL_RELIABLE_SEND_BUFFER_NUM = 5; //!< This key is for the send buffer usage of the <tt>StationProtocolReliable</tt> instance.
86  static const int KEY_STATION_PROTOCOL_RELIABLE_RECEIVE_BUFFER_NUM = 6; //!< This key is for the receive buffer usage of the <tt>StationProtocolReliable</tt> instance.
87  static const int KEY_SESSION_PROTOCOL_RELIABLE_SEND_BUFFER_NUM = 7; //!< This key is for the <tt>Reliable</tt> send buffer usage of the <tt>SessionProtocol</tt> instance.
88  static const int KEY_SESSION_PROTOCOL_RELIABLE_RECEIVE_BUFFER_NUM = 8; //!< This key is for the <tt>Reliable</tt> receive buffer usage of the <tt>SessionProtocol</tt> instance.
89  static const int KEY_UNRELIABLE_PROTOCOL_RECEIVE_BUFFER_NUM = 9; //!< This key is for the receive buffer usage of the <tt>UnreliableProtocol</tt> instance.
90  static const int KEY_MAX = WATERMARK_INSTANCES - 1;
91 
92 
93 /*!
94 @brief Creates the class instance in the <tt>common</tt> module (singleton pattern).
95 @return Returns a <tt>Result</tt> value that indicates success if the instance is created successfully. Your application's implementation must ensure that this function does not return any errors.
96 @retval ResultNotInitialized Indicates that the <tt>common</tt> module is not initialized. Programming error. Fix your program so that this error is not returned.
97 @retval ResultInvalidState Indicates that the timing at which the <tt>CreateInstance</tt> function was called is incorrect. Make this call between the <tt>BeginSetup</tt> and <tt>EndSetup</tt> functions. Programming error. Fix your program so that this error is not returned.
98 @retval ResultAlreadyExists Indicates that an instance has already been created. Programming error. Fix your program so that this error is not returned.
99 
100 */
101  static nn::Result CreateInstance(void);
102 
103 
104 /*!
105 @brief Destroys the class instance in the <tt>common</tt> module (singleton pattern).
106 */
107  static void DestroyInstance(void);
108 
109 
110 /*!
111 @brief Gets the class instance in the <tt>common</tt> module (singleton pattern).
112 @details Returns a <tt>NULL</tt> pointer if the instance has not yet been created using the <tt>@ref CreateInstance</tt> function.
113 @return Returns a pointer to the instance.
114 
115 
116 
117 */
119  {
120  return s_pInstance;
121  }
122 
123 
124 /*!
125 @cond PRIVATE
126 @brief Instantiates the object with default parameters (default constructor).
127 */
128  WatermarkManager(void);
129  //! @endcond
130 
131 
132 /*!
133 @cond PRIVATE
134 @brief Destroys the object.
135 */
136  ~WatermarkManager(void);
137  //! @endcond
138 
139 
140 /*!
141 @brief Gets a <tt>Watermark</tt> instance (non-<tt>const</tt> version).
142 @param[in] key Specifies the key. The following relation must hold: <tt>0 <= key <= KEY_MAX</tt>.
143 The function asserts if a key outside this range is specified.
144 @return On success, returns a pointer to a <tt>Watermark</tt> instance. On failure, returns a <tt>NULL</tt> pointer.
145 
146 */
147  Watermark* GetWatermark(int key);
148 
149 
150 /*!
151 @brief Gets a <tt>Watermark</tt> instance (<tt>const</tt> version).
152 @param[in] key Specifies the key. The following relation must hold: <tt>0 <= key <= KEY_MAX</tt>.
153 The function asserts if a key outside this range is specified.
154 @return On success, returns a pointer to a <tt>Watermark</tt> instance. On failure, returns a <tt>NULL</tt> pointer.
155 
156 */
157  const Watermark* GetWatermark(int key) const;
158 
159 
160 /*!
161 @brief Enables the <tt>Update</tt> feature of all <tt>Watermark</tt> instances managed by the <tt>WatermarkManager</tt> instance.
162 @see DisableAllWatermark
163 
164 */
165  void EnableAllWatermark(void);
166 
167 
168 /*!
169 @brief Disables the <tt>Update</tt> feature of all <tt>Watermark</tt> instances managed by the <tt>WatermarkManager</tt> instance.
170 @see EnableAllWatermark
171 
172 */
173  void DisableAllWatermark(void);
174 
175 
176 /*!
177 @brief Prints information useful for debugging.
178 @param[in] flag Specifies the bitwise OR of trace flags. For more information, see the <tt>@ref TraceFlag</tt> type.
179 
180 */
181  virtual void Trace(u64 flag) const;
182 
183 private:
184  Watermark m_Watermark[WATERMARK_INSTANCES];
185 
186  static WatermarkManager* s_pInstance; // The only instantiation of this class
187 };
188 }
189 }
190 } // end of namespace nn::pia::common
This class manages a collection of Watermark instances (not supported).
Definition: common_WatermarkManager.h:74
static const int KEY_STATION_PROTOCOL_RELIABLE_SEND_BUFFER_NUM
This key is for the send buffer usage of the StationProtocolReliable instance.
Definition: common_WatermarkManager.h:85
static const int KEY_RELIABLE_PROTOCOL_RECEIVE_BUFFER_NUM
This key is for the receive buffer usage of the ReliableProtocol instance.
Definition: common_WatermarkManager.h:84
void DisableAllWatermark(void)
Disables the Update feature of all Watermark instances managed by the WatermarkManager instance...
Definition: assert.h:115
static const int KEY_RECEIVETHREADSTREAM_BUFFER_NUM
This key is for the buffer usage of the receive thread.
Definition: common_WatermarkManager.h:81
static const int KEY_STATION_PROTOCOL_RELIABLE_RECEIVE_BUFFER_NUM
This key is for the receive buffer usage of the StationProtocolReliable instance. ...
Definition: common_WatermarkManager.h:86
void EnableAllWatermark(void)
Enables the Update feature of all Watermark instances managed by the WatermarkManager instance...
static nn::Result CreateInstance(void)
Creates the class instance in the common module (singleton pattern).
static const int KEY_SESSION_PROTOCOL_RELIABLE_RECEIVE_BUFFER_NUM
This key is for the Reliable receive buffer usage of the SessionProtocol instance.
Definition: common_WatermarkManager.h:88
static const int KEY_RELIABLE_PROTOCOL_SEND_BUFFER_NUM
This key is for the send buffer usage of the ReliableProtocol instance.
Definition: common_WatermarkManager.h:83
static const int WATERMARK_INSTANCES
The maximum number of Watermark instances managed by the WatermarkManager class.
Definition: common_WatermarkManager.h:77
static const int KEY_SENDTHREADSTREAM_BUFFER_NUM
This key is for the buffer usage of the send thread.
Definition: common_WatermarkManager.h:80
static const int KEY_SESSION_PROTOCOL_RELIABLE_SEND_BUFFER_NUM
This key is for the Reliable send buffer usage of the SessionProtocol instance.
Definition: common_WatermarkManager.h:87
virtual void Trace(u64 flag) const
Prints information useful for debugging.
Contains member functions for profiling things like peak values in the Pia library&#39;s resource usage (...
Definition: common_Watermark.h:35
Watermark * GetWatermark(int key)
Gets a Watermark instance (non-const version).
static const int KEY_UNRELIABLE_PROTOCOL_RECEIVE_BUFFER_NUM
This key is for the receive buffer usage of the UnreliableProtocol instance.
Definition: common_WatermarkManager.h:89
static WatermarkManager * GetInstance(void)
Gets the class instance in the common module (singleton pattern).
Definition: common_WatermarkManager.h:118
static void DestroyInstance(void)
Destroys the class instance in the common module (singleton pattern).
This is the common base class used inside the Pia library.
Definition: common_RootObject.h:40