1 /*---------------------------------------------------------------------------*
2 
3 Copyright (C) 2012 Nintendo. All rights reserved.
4 
5 These coded instructions, statements, and computer programs contain
6 proprietary information of Nintendo of America Inc. and/or Nintendo
7 Company Ltd., and are protected by Federal copyright law.  They may
8 not be disclosed to third parties or copied or duplicated in any form,
9 in whole or in part, without the prior written consent of Nintendo.
10 
11  *---------------------------------------------------------------------------*/
12 
13 #ifndef NN_BOSS_BOSS_TYPES_H_
14 #define NN_BOSS_BOSS_TYPES_H_
15 
16 #include <nn/boss/boss_Const.h>
17 
18 /*=======================================================================*
19 Type Definitions
20  *=======================================================================*/
21 
22 #ifdef __cplusplus
23 
24 namespace nn {
25 namespace boss {
26 
27 /*!
28 @addtogroup nn_boss_api
29   @{
30 */
31 
32 typedef u32     AccountID;//!< Account ID type.
33 
34 typedef char    BossStoragePath[FILEPATH_IN_BOSSSTORAGE_MAX_LENGTH];//!< String that represents the BOSS storage path.
35 typedef char    BossStorageDirectory[BOSSSTORAGE_DIRECTORY_NAME_MAX_LENGTH_WITH_NULL];//!< String that represents the BOSS storage directory name.
36 
37 typedef u64     BossStorageID;//!< BOSS storage ID type.
38 
39 /*!
40 @brief Structure that stores the title ID.
41 */
42 class TitleID
43 {
44 public:
45     /*!
46 @brief        Constructor with no arguments. <tt>0</tt> is stored as the title ID.
47     */
48     TitleID(void);
49 
50     /*!
51 @brief        Constructor that takes a <tt>u64</tt> value as an argument. The argument is stored as the title ID.
52 
53 @param[in]    id   The title ID to set.
54     */
55     TitleID(u64 id);
56 
57     /*!
58 @brief        Copy constructor. The same name as the task ID stored in the <tt>@ref TitleID</tt> argument is stored as the title ID.
59 
60 @param[in]    obj The <tt>@ref TitleID</tt> instance to copy.
61     */
62     TitleID(const TitleID& obj);
63 
64     /*!
65 @brief  Equivalence operator for <tt>@ref TitleID</tt> objects.
66 
67 If it indicates a title that is the same as the stored title ID, it is determined to be equal.
68 
69 @param[in]    obj The <tt>@ref TitleID</tt> instance to compare.
70 @return       Whether the two objects are equal. If equal (meaning that it indicates a title that is the same as the stored title ID), it returns <tt>true</tt>.
71     */
72     bool operator==(const TitleID& obj) const;
73 
74     /*!
75 @brief  Non-equivalence operator for <tt>@ref TitleID</tt> objects.
76 
77 If it is not the same as the stored title ID, it is determined to be not equal.
78 
79 @param[in]    obj The <tt>@ref TitleID</tt> instance to compare.
80 @return       Whether the two objects are not equal. If not equal (meaning that it is not the same as the stored title ID), it returns <tt>true</tt>.
81     */
82     bool operator!=(const TitleID& obj) const;
83 
84     /*!
85 @brief        Determines whether the stored title ID is valid as a title ID.
86 
87 @return       Whether the stored title ID is valid as a title ID. Returns <tt>true</tt> if valid.
88     */
89     bool IsValid( void ) const;
90 
91     /*!
92 @brief        Returns the stored title ID.
93 
94 @return       Stored title ID.
95     */
96     u64 GetValue( void ) const;
97 
98     /*!
99 @brief        Returns the title code (the last 32 bits of the title ID) of the stored title ID.
100 
101 @return       Title code for the stored title ID.
102     */
103     u32 GetTitleCode( void ) const;
104 
105     /*!
106 @brief        Returns the lower 32 bits of the stored title ID. Returns the same value as the <tt>@ref GetTitleCode</tt> function.
107 
108 @return       The lower 32 bits of the stored title ID. Returns the same value as the <tt>@ref GetTitleCode</tt> function.
109     */
110     u32 GetTitleId( void ) const;
111 
112     /*!
113 @brief        Returns the unique ID for the stored title ID.
114 
115 @return       Unique ID for the stored title ID.
116     */
117     u32 GetUniqueId( void ) const;
118 
119 private:
120     u64 value;//!< Buffer that stores the title ID.
121 };
122 
123 /*!
124 @brief Structure that stores the task ID.
125 */
126 struct TaskID
127 {
128     /*!
129 @brief        Constructor with no arguments. An empty string is stored as the task ID.
130     */
131     TaskID(void);
132 
133     /*!
134 @brief        Constructor that takes a string as an argument. The string passed in the parameter is stored as the task ID.
135 
136 @param[in] idStr  The task ID to set.
137     */
138     TaskID(const char* idStr);
139 
140     /*!
141 @brief        Copy constructor. The same name as the task ID stored in the <tt>@ref TitleID</tt> argument is stored as the task ID.
142 
143 @param[in]    obj The <tt>@ref TaskID</tt> instance to copy.
144     */
145     TaskID(const TaskID& obj);
146 
147     /*!
148 @brief  Equivalence operator for <tt>@ref TaskID</tt> objects.
149 
150 If it is the same as the stored task ID, it is determined to be equal.
151 
152 @param[in]    obj The <tt>@ref TaskID</tt> instance to compare.
153 @return       Whether the two objects are equal. Returns <tt>true</tt> if equal. (The ID is the same as the stored task ID.)
154     */
155     bool operator==(const TaskID& obj) const;
156 
157     /*!
158 @brief  Non-equivalence operator for <tt>@ref TaskID</tt> objects.
159 
160 If it is not the same as the stored <tt>TaskID</tt>, it is determined to be not equal.
161 
162 @param[in]    obj The <tt>@ref TaskID</tt> instance to compare.
163 @return       Whether the two objects are not equal. Returns <tt>true</tt> if not equal. (The ID is not the same as the stored task ID.)
164     */
165     bool operator!=(const TaskID& obj) const;
166 
167     /*!
168 @brief        Equal-to operator for strings.
169 
170 If the stored task ID is the same as the string specified by argument, it is determined to be equal.
171 
172 @param[in]    obj The string to compare with.
173 @return       Whether the two objects are equal. Returns <tt>true</tt> if equal. (The specified string matches the stored task ID.)
174     */
175     bool operator==(const char* obj) const;
176 
177     /*!
178 @brief        Not-equal-to operator for strings.
179 
180 If the stored task ID is not the same as the string specified by argument, it is determined to be not equal.
181 
182 @param[in]    obj The string to compare with.
183 @return       Whether the two objects are not equal. Returns <tt>true</tt> if not equal. (The string specified by the argument is not the same as the stored task ID.)
184     */
185     bool operator!=(const char* obj) const;
186 
187     /*!
188 @brief        Operator for casting to <tt>const char*</tt>. Casts to a <tt>const char*</tt> type pointing to the task ID being stored.
189 
190 @return       A <tt>const char*</tt> value pointing to the task ID being stored.
191     */
192     operator const char*() const;
193 
194     /*!
195 @brief        Assignment operator.
196 
197 @param[in] idStr  The string to assign.
198 @return       A reference to the instance of <tt>@ref TaskID</tt> resulting from the assignment.
199     */
200     TaskID& operator=(const char* idStr);
201 
202     char id[TASK_ID_LENGTH_WITH_NULL];//!< Buffer that stores the task ID.
203 };
204 
205 /*!
206 @brief Structure that stores the name of the data in BOSS storage.
207 */
208 struct DataName
209 {
210     /*!
211 @brief        Constructor with no arguments. An empty string is stored for the data name.
212     */
213     DataName(void);
214 
215     /*!
216 @brief        Constructor that takes a string as an argument. The string passed in the argument is stored as the data name.
217 
218 @param[in]    nameStr   The data name to set.
219     */
220     DataName(const char* nameStr);
221 
222     /*!
223 @brief        Copy constructor. The same name as the directory name stored in the <tt>@ref DataName</tt> argument is stored as the directory name.
224 
225 @param[in]    obj The <tt>@ref DataName</tt> instance to copy.
226     */
227     DataName(const DataName& obj);
228 
229     /*!
230 @brief  Equivalence operator for <tt>@ref DataName</tt> objects.
231 
232 If it is the same as the stored data name, it is determined to be equal.
233 
234 @param[in]    obj The <tt>@ref DataName</tt> instance to compare.
235 @return       Whether the two objects are equal. Returns <tt>true</tt> if equal. (The data name is the same as the stored data name.)
236     */
237     bool operator==(const DataName& obj) const;
238 
239     /*!
240 @brief  Non-equivalence operator for <tt>@ref DataName</tt> objects.
241 
242 If it is not the same as the stored data name, it is determined to be not equal.
243 
244 @param[in]    obj The <tt>@ref DataName</tt> instance to compare.
245 @return       Whether the two objects are not equal. Returns <tt>true</tt> if not equal. (The data name is not the same as the stored data name.)
246     */
247     bool operator!=(const DataName& obj) const;
248 
249     /*!
250 @brief        Equal-to operator for strings.
251 
252 If the stored data name is the same as the string specified by argument, it is determined to be equal.
253 
254 @param[in]    obj The string to compare with.
255 @return       Whether the two objects are equal. Returns <tt>true</tt> if equal. (The string specified by the argument is the same as the stored data name.)
256     */
257     bool operator==(const char* obj) const;
258 
259     /*!
260 @brief        Not-equal-to operator for strings.
261 
262 If the stored data name is not the same as the string specified by argument, it is determined to be not equal.
263 
264 @param[in]    obj The string to compare with.
265 @return       Whether the two objects are not equal. Returns <tt>true</tt> if not equal. (The string specified by the argument is not the same as the stored data name.)
266     */
267     bool operator!=(const char* obj) const;
268 
269     /*!
270 @brief        Operator for casting to <tt>const char*</tt>. Casts to a <tt>const char*</tt> type pointing to the data name being stored.
271 
272 @return       A <tt>const char*</tt> value pointing to the data name being stored.
273     */
274     operator const char*() const;
275 
276     /*!
277 @brief        Assignment operator.
278 
279 @param[in]    nameStr The string to assign.
280 @return       A reference to the instance of <tt>@ref DataName</tt> resulting from the assignment.
281     */
282     DataName& operator=(const char* nameStr);
283 
284     char name[NSDATA_NAME_MAX_LENGTH_WITH_NULL];//!< Buffer storing the data name.
285 };
286 
287 /*!
288 @brief Structure that stores the name of the directory in BOSS storage.
289 */
290 struct DirectoryName
291 {
292     /*!
293 @brief        Constructor with no arguments. An empty string is stored for the directory name.
294     */
295     DirectoryName(void);
296 
297     /*!
298 @brief        Constructor that takes a string as an argument. The string passed as the argument is stored as the directory name.
299 
300 @param[in]    nameStr   The directory name to set.
301     */
302     DirectoryName(const char* nameStr);
303 
304     /*!
305 @brief        Copy constructor. The same name as the directory name stored in the <tt>@ref DirectoryName</tt> argument is stored as the directory name.
306 
307 @param[in]    obj The <tt>@ref DirectoryName</tt> instance to copy.
308     */
309     DirectoryName(const DirectoryName& obj);
310 
311     /*!
312 @brief  Equivalence operator for <tt>@ref DirectoryName</tt> objects.
313 
314 If it is the same as the stored directory name, it is determined to be equal.
315 
316 @param[in]    obj The <tt>@ref DirectoryName</tt> instance to compare.
317 @return       Whether the two objects are equal. Returns <tt>true</tt> if equal. (The directory name is the same as the stored directory name.)
318     */
319     bool operator==(const DirectoryName& obj) const;
320 
321     /*!
322 @brief  Non-equivalence operator for <tt>@ref DirectoryName</tt> objects.
323 
324 If it is not the same as the stored directory name, it is determined to be not equal.
325 
326 @param[in]    obj The <tt>@ref DirectoryName</tt> instance to compare.
327 @return       Whether the two objects are not equal. Returns <tt>true</tt> if not equal. (The directory name is not the same as the stored directory name.)
328     */
329     bool operator!=(const DirectoryName& obj) const;
330 
331     /*!
332 @brief        Equal-to operator for strings.
333 
334 If the stored directory name is the same as the string specified by argument, it is determined to be equal.
335 
336 @param[in]    obj The string to compare with.
337 @return       Whether the two objects are equal. Returns <tt>true</tt> if equal. (The directory name is not the same as the stored directory name.)
338     */
339     bool operator==(const char* obj) const;
340 
341     /*!
342 @brief        Not-equal-to operator for strings.
343 
344 If the stored directory name is not the same as the string specified by argument, it is determined to be not equal.
345 
346 @param[in]    obj The string to compare with.
347 @return       Whether the two objects are not equal. Returns <tt>true</tt> if not equal. (The directory name is not the same as the stored directory name.)
348     */
349     bool operator!=(const char* obj) const;
350 
351     /*!
352 @brief        Operator for casting to <tt>const char*</tt>. Casts to a <tt>const char*</tt> type pointing to the directory name being stored.
353 
354 @return       A <tt>const char*</tt> value pointing to the directory name being stored.
355     */
356     operator const char*() const;
357 
358     /*!
359 @brief        Assignment operator.
360 
361 @param[in]    nameStr The string to assign.
362 @return       A reference to the instance of <tt>@ref DataName</tt> resulting from the assignment.
363     */
364     DirectoryName& operator=(const char* nameStr);
365 
366     char name[BOSSSTORAGE_DIRECTORY_NAME_MAX_LENGTH_WITH_NULL];//!< Buffer storing the directory name.
367 };
368 
369 /*!
370 @brief Structure that stores the task execution result.
371 
372 The execution result is set in the <tt>@ref result</tt> element. The type of result value is defined in <tt>@ref TaskResultDefinition</tt>.
373 Depending on the <tt>result</tt> value, additional information may also be set in <tt>@ref subResult</tt>. The type of additional information value is defined in <tt>@ref SubTaskResultDefinition</tt>.
374 */
375 struct TaskResult
376 {
377     /*!
378 @brief        Constructor with no arguments. Creates an instance equivalent to "unknown." (<tt>@ref TR_UNKNOWN</tt> is assigned to <tt>result</tt>, and <tt>@ref STR_NONE</tt> is assigned to <tt>subResult</tt>.)
379     */
380     TaskResult(void);
381 
382     /*!
383 @brief  Constructor that takes an <tt>@ref TaskResultDefinition</tt> value as an argument. <tt>result</tt> is assigned the value of the argument. <tt>subResult</tt> is assigned a value of <tt>@ref STR_NONE</tt>.
384 
385 @param[in]    resultValue           The <tt>@ref TaskResultDefinition</tt> value to assign to the instance.
386     */
387     TaskResult(TaskResultDefinition resultValue);
388 
389     /*!
390 @brief  Constructor that takes <tt>@ref TaskResultDefinition</tt> and <tt>@ref SubTaskResultDefinition</tt> values as an arguments. <tt>result</tt> is assigned <span class="argument">resultValue</span> and <tt>subResult</tt> is assigned <span class="argument">subResultValue</span>.
391 
392 @param[in]    resultValue           The <tt>@ref TaskResultDefinition</tt> value to assign to the instance.
393 @param[in]    subResultValue           The <tt>@ref SubTaskResultDefinition</tt> value to assign to the instance.
394     */
395     TaskResult(TaskResultDefinition resultValue, SubTaskResultDefinition subResultValue);
396 
397     /*!
398 @brief  Constructor that takes an <tt>@ref nn::Result</tt> value as an argument. Creates an instance for the specified <tt>@ref nn::Result</tt> value.
399 
400 If BOSS does not have a <tt>TaskResult</tt> definition equivalent to the specified <tt>@ref nn::Result</tt> value (for example, if it is an <tt>@ref nn::Result</tt> value not used by BOSS), an instance equivalent to "unknown" is created (with <tt>result</tt> assigned a value of <tt>@ref TR_UNKNOWN</tt> and <tt>subResult</tt> assigned a value of <tt>@ref STR_NONE</tt>).
401 @param[in]    argResult           The <tt>@ref nn::Result</tt> instance to map to <tt>result</tt> and <tt>subResult</tt>.
402     */
403     TaskResult(Result argResult);
404 
405     /*!
406 @brief        Assignment operator.
407 
408 @param[in]    obj The <tt>@ref TaskID</tt> instance to assign.
409 @return       A reference to the instance of <tt>@ref TaskResult </tt> resulting from the assignment.
410     */
411     TaskResult& operator=(const TaskResult obj);
412 
413     /*!
414 @brief        Equivalence operator used with other <tt>@ref TaskResultDefinition</tt> values.
415 
416 If <tt>result</tt> is the same as the <tt>@ref TaskResultDefinition</tt> value being compared, the execution results are considered to be identical.
417 @param[in]    resultDef   The <tt>@ref TaskResultDefinition</tt> value to compare with.
418 @return       Whether the two objects are equal. Returns <tt>true</tt> if <tt>@ref TaskResultDefinition</tt> is determined to represent the same task execution result.
419     */
420     bool operator==(TaskResultDefinition resultDef) const;
421 
422     /*!
423 @brief        Non-equivalence operator used with other <tt>@ref TaskResultDefinition</tt> values.
424 
425 If <tt>result</tt> differs from the <tt>@ref TaskResultDefinition</tt> value being compared, the execution result is determined to be different.
426 @param[in]    resultDef   The <tt>@ref TaskResultDefinition</tt> value to compare with.
427 @return       Whether the two objects are not equal. Returns <tt>true</tt> if <tt>@ref TaskResultDefinition</tt> is determined to represent a different task execution result.
428     */
429     bool operator!=(TaskResultDefinition resultDef) const;
430 
431     /*!
432 @brief        Equivalence operator used with other <tt>@ref TaskResult</tt> instances.
433 
434 If both the <tt>result</tt> and <tt>subResult</tt> elements match the instance of <tt>@ref TaskResult</tt> being compared, the execution result is determined to match.
435 @param[in]    obj         The <tt>@ref TaskResult</tt> value to compare with.
436 @return       Whether the two objects are equal. Returns <tt>true</tt> if <tt>@ref TaskResult</tt> is determined to represent the same task execution result.
437     */
438     bool operator==(const TaskResult& obj) const;
439 
440     /*!
441 @brief         Non-equivalence operator used with other <tt>@ref TaskResult</tt> instances.
442 
443 If either the <tt>result</tt> or <tt>subResult</tt> element does not match the instance of <tt>@ref TaskResult</tt> being compared, the execution result is determined to be different.
444 @param[in]    obj         The <tt>@ref TaskResult</tt> value to compare with.
445 @return       Whether the two objects are not equal. Returns <tt>true</tt> if <tt>@ref TaskResult</tt> is determined to represent a different task execution result.
446     */
447     bool operator!=(const TaskResult& obj) const;
448 
449     /*!
450 @brief        Returns whether the result indicates execution succeeded.
451 
452 Execution is determined to have succeeded if <tt>result</tt> has a value of <tt>@ref TR_SUCCESS</tt>.
453 @return       A result value indicating whether execution succeeded (<tt>true</tt> if execution succeeded).
454     */
455     bool IsSuccess( void ) const;
456 
457     /*!
458 @brief        Returns whether the result indicates execution failed.
459 
460 Execution is determined to have failed if <tt>result</tt> is neither <tt>@ref TR_SUCCESS</tt> nor <tt>@ref TR_UNKNOWN</tt>.
461 @return       A result value indicating whether execution failed (<tt>true</tt> if execution failed).
462     */
463     bool IsFailure( void ) const;
464 
465     /*!
466 @brief        Returns whether the execution result is unknown.
467 
468 The execution result is determined unknown if <tt>result</tt> has a value of <tt>@ref TR_UNKNOWN</tt>.
469 @return       A result value indicating whether the result of execution is unknown (<tt>true</tt> if it is unknown).
470     */
471     bool IsUnknown( void ) const;
472 
473     /*!
474 @brief        Returns a <tt>u64</tt> value formed by concatenating <tt>result</tt> and <tt>subResult</tt>.
475 
476 @return        Returns a <tt>u64</tt> value formed by concatenating <tt>result</tt> and <tt>subResult</tt>. (<tt>result</tt> is stored in the first 32 bits and <tt>subResult</tt> is stored in the last 32 bits.)
477     */
478     u64  GetValue(void) const;
479 
480     /*!
481 @brief        Returns a <tt>u32</tt> value formed by concatenating <tt>result</tt> and <tt>subResult</tt>.
482 
483 @return        Returns a <tt>u32</tt> value formed by concatenating <tt>result</tt> and <tt>subResult</tt>. (<tt>result</tt> is stored in the first 16 bits and <tt>subResult</tt> is stored in the last 16 bits.)
484     */
485     u32  GetResultValue(void) const;
486 
487     /*!
488 @brief        Returns a <tt>TaskResult</tt> instance indicating success.
489 
490 @return       An instance of <tt>TaskResult</tt> indicating that execution succeeded.
491     */
492     static TaskResult Success(void);
493 
494     /*!
495 @brief        Returns the error code for the executed result.
496 
497 @return       The error code. (Returns <tt>0</tt> when the executed result is either <tt>Unknown</tt> or <tt>Success</tt>.)
498     */
499     u32 ErrorCode( void ) const;
500 
501     u16 result;     //!< Result value. The value type is defined in <tt>@ref TaskResultDefinition</tt>.
502     u16 subResult;  //!< A value that indicates supplementary information about the result. The value type is defined in <tt>@ref SubTaskResultDefinition</tt>.
503 };
504 
505 //! @}
506 
507 } // end of namespace boss
508 } // end of namespace nn
509 
510 
511 #endif /*__cplusplus*/
512 
513 #endif /* NN_BOSS_BOSS_TYPES_H_ */
514