CTR-Pia  5.4.3
Game Communication Engine
 全て クラス ネームスペース 関数 変数 型定義 列挙型 列挙型の値 ページ
common_CachedPrint.h
1 /*--------------------------------------------------------------------------------*
2  Copyright (C)Nintendo All rights reserved.
3 
4  These coded instructions, statements, and computer programs contain proprietary
5  information of Nintendo and/or its licensed developers and are protected by
6  national and international copyright laws. They may not be disclosed to third
7  parties or copied or duplicated in any form, in whole or in part, without the
8  prior written consent of Nintendo.
9 
10  The content herein is highly confidential and should be handled accordingly.
11  *--------------------------------------------------------------------------------*/
12 
13 
14 #pragma once
15 
16 #include <nn/pia/common/common_Definitions.h>
17 #include <nn/pia/common/common_CriticalSection.h>
18 
19 
20 // @addtogroup pia_common_debug_macro Pia の提供するデバッグ用マクロ定義
21 // @brief Pia の提供するデバッグ用マクロです。
22 //! @{
23 //! @name ログ出力
24 //! @{
25 
26 /*!
27 @def PIA_BASIC_PRINT
28 @brief コンソール出力をキャッシュします。 CachedPrint インスタンスが生成されていない場合は普通にコンソール出力します。
29 
30 @param[in] ... 標準ライブラリの printf の引数と同様です。
31  */
32 #if NN_PIA_UNDER_DEVELOP
33 #if NN_PIA_ENABLE_CACHEDPRINT
34 #define PIA_BASIC_PRINT(...) \
35  if (::nn::pia::common::CachedPrint::GetInstance() != NULL) \
36  { \
37  ::nn::pia::common::CachedPrint::GetInstance()->Printf(__VA_ARGS__); \
38  } \
39  else \
40  { \
41  ::nn::pia::common::Printf(__VA_ARGS__); \
42  }
43 #else
44 #define PIA_BASIC_PRINT(...) ::nn::pia::common::Printf(__VA_ARGS__)
45 #endif
46 #else
47 #define PIA_BASIC_PRINT(...) \
48  { \
49  }
50 #endif
51 
52 
53 /*!
54 @def PIA_BASIC_VPRINT
55 @brief コンソール出力をキャッシュします。 CachedPrint インスタンスが生成されていない場合は普通にコンソール出力します。
56 
57 @param[in] format 出力書式文字列(フォーマット文字列)を指定します。
58 @param[in] varg 可変引数リストを指定します。
59  */
60 #if NN_PIA_UNDER_DEVELOP
61 #if NN_PIA_ENABLE_CACHEDPRINT
62 #define PIA_BASIC_VPRINT(format, varg) \
63  if (::nn::pia::common::CachedPrint::GetInstance() != NULL) \
64  { \
65  ::nn::pia::common::CachedPrint::GetInstance()->VPrintf((format), (varg)); \
66  } \
67  else \
68  { \
69  ::nn::pia::common::VPrintf((format), (varg)); \
70  }
71 #else
72 #define PIA_BASIC_VPRINT(...) ::nn::pia::common::VPrintf(__VA_ARGS__)
73 #endif
74 #else
75 #define PIA_BASIC_VPRINT(format, varg) \
76  { \
77  (void)(format); \
78  (void)(varg); \
79  }
80 #endif
81 
82 //! @}
83 //! @}
84 
85 
86 namespace nn
87 {
88 namespace pia
89 {
90 namespace common
91 {
92 #if NN_PIA_ENABLE_CACHEDPRINT
93 /*!
94  @brief コンソール出力をキャッシュします。
95  このクラスはデバッグ用です。製品には組み込んではいけません。
96 
97  */
99 {
100 public:
101  /*!
102  @brief インスタンスを作成します(シングルトンパターン)。
103 
104  @details このAPIは、 nn::pia::common::BeginSetup() を呼び出してから、
105  nn::pia::common::EndSetup() を呼び出すまでの間に呼び出す必要があります。
106 
107  @param[in] bufferSize キャッシュするバッファのサイズ(バイト)を指定します。512以上の値を指定する必要があります。
108 
109  @return インスタンスの作成に成功すれば、成功の Result が返されます。この関数がエラーを返さないようにアプリケーションを実装する必要があります。
110 
111  @retval ResultAlreadyExists 既にインスタンスは作成されています。プログラミングエラーです。このエラーが返らないようにソースコードを修正してください。
112  @retval ResultNotInitialized commonモジュールが初期化されていません。プログラミングエラーです。このエラーが返らないようにソースコードを修正してください。
113  @retval ResultInvalidState BeginSetup() ~ EndSetup() 間で呼び出されていません。プログラミングエラーです。このエラーが返らないようにソースコードを修正してください。
114  @retval ResultInvalidArgument 引数の指定が不正です。プログラミングエラーです。このエラーが返らないようにソースコードを修正してください。
115  */
116  static Result CreateInstance(uint32_t bufferSize);
117 
118 
119  /*!
120  @brief インスタンスを破棄します(シングルトンパターン)。
121 
122  @details インスタンスが作成されていないときにこの関数が呼び出された場合は、
123  何も実行せずに関数から返ります。
124  */
125  static void DestroyInstance();
126 
127 
128  /*!
129  @brief CachedPrint インスタンスへのポインタを取得します(シングルトンパターン)。
130 
131  @return インスタンスが作成されていないときは、 NULL ポインタが返ります。
132  */
134  {
135  return s_pInstance;
136  }
137 
138 
139  /*!
140  @brief デバッグに有用な情報をプリントします。
141 
142  @param[in] flag トレースフラグの論理和。詳細は @ref TraceFlag 型を参照してください。
143  */
144  void Trace(uint64_t flag) const;
145 
146 
147  /*!
148  @cond PRIVATE
149  @brief キャッシュに文字列を書き込みます。
150 
151  @param[in] cpFormat フォーマット文字列です。
152  @param[in] varg 引数リストです。
153  */
154  void VPrintf(const char* cpFormat, va_list varg);
155  //! @endcond
156 
157 
158  /*!
159  @cond PRIVATE
160  @brief キャッシュに文字列を書き込みます。
161 
162  @param[in] cpFormat フォーマット文字列です。
163  @param[in] ... 可変長引数です。
164  */
165  void Printf(const char* cpFormat, ...);
166  //! @endcond
167 
168 
169  /*!
170  @brief キャッシュされている文字列をクリアします。
171  */
172  void Clear();
173 
174 
175  /*!
176  @brief キャッシュされている文字列をコンソールに出力してクリアします。
177  */
178  void Flush();
179 
180 
181  /*!
182  @cond PRIVATE
183  @brief キャッシュされている文字列を取得します。文字列は NULL 終端されます。(未検証なのでまだ使ってはいけません。)
184 
185  @param[out] pBuffer 文字列を取得するバッファです。
186  @param[out] pLength 取得した文字列の長さです。
187  @param[in] bufferSize バッファのサイズ(バイト)です。
188 
189  @return 成功すれば、IsSuccess()がtrueを返すResultが返ります。
190 
191  @retval ResultInvalidArgument 引数が不正です。プログラミングエラーです。このエラーが返らないようにソースコードを修正してください。
192  @retval ResultNoData キャッシュされている文字列はありません。この場合も与えられたバッファには NULL 終端が書き込まれます。アプリケーションで適切にハンドリングしてください。
193  */
194  Result Read(char* pBuffer, uint32_t* pLength, uint32_t bufferSize);
195  //! @endcond
196 
197 
198 private:
199  // 実装しません
200  CachedPrint();
201  CachedPrint(const CachedPrint& rhs);
202  bool operator==(const CachedPrint& rhs) const;
203  bool operator!=(const CachedPrint& rhs) const;
204  CachedPrint& operator=(const CachedPrint& rhs);
205 
206  explicit CachedPrint(uint32_t bufferSize);
207  ~CachedPrint();
208 
209  static CachedPrint* s_pInstance;
210 
211  char* m_pBuffer;
212  uint32_t m_Size;
213 
214  uint32_t m_Top;
215  uint32_t m_Next;
216  uint32_t m_Repeat;
217 
218  CriticalSection m_CriticalSection;
219 };
220 #endif // NN_PIA_ENABLE_CACHEDPRINT
221 }
222 }
223 } // end of namespace nn::pia::common