1 /*---------------------------------------------------------------------------*
2   Project:  RevolutionDWC public include file
3   File:     ./nd/dwc_nd.h
4 
5   Copyright 2005-2008 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 #ifndef DWC_ND_H_
15 #define DWC_ND_H_
16 
17 #ifdef __cplusplus
18 extern "C"
19 {
20 #endif
21 
22     /* -------------------------------------------------------------------------
23             Define
24        ------------------------------------------------------------------------- */
25 
26 /// Maximum string length of the file name specified when obtaining a file
27 #define DWC_ND_FILENAME_LEN                 32
28 
29 /// Maximum string length of the attribute specified before obtaining a file
30 #define DWC_ND_FILEATTR_LEN                 10
31 
32 /// Maximum string length of the description, in UTF16BE, specified for the file
33 #define DWC_ND_FILEEXPLSIN_LEN              50
34 
35 /// The thread priority used internally by the download library
36 #define DWC_ND_THREAD_PRIORITY              17
37 
38 /// Byte length of a DL game code (gamecd)
39 #define DWC_ND_LENGTH_GAMECODE				4
40 
41 /// Byte length of the password (passwd)
42 #define DWC_ND_LENGTH_PASSWORD				16
43 
44     /* -------------------------------------------------------------------------
45             enum
46        ------------------------------------------------------------------------- */
47 
48     /**
49      * Download library state
50      *
51      * Enumerator type showing the state of the download library.
52      *
53      * See also:  DWC_NdProcess
54      */
55     typedef enum {
56         DWC_ND_STATE_NOTINITIALIZED,    ///< The download library is uninitialized
57         DWC_ND_STATE_READY,             ///< State in which initialization is complete, and other download library functions can be called
58         DWC_ND_STATE_BUSY,              ///< Asynchronous processing in progress
59         DWC_ND_STATE_COMPLETE,          ///< Asynchronous processing completed successfully
60         DWC_ND_STATE_ERROR,             ///< An error occurred during asynchronous processing, and the process ended
61         DWC_ND_STATE_MAX
62     } DWCNdState;
63 
64 
65     /* -------------------------------------------------------------------------
66             struct
67        ------------------------------------------------------------------------- */
68     /**
69      * This is a structure that stores the file data acquired by the download library.
70      *
71      * See also:  DWC_NdGetFileListAsync
72      * See also:  DWC_NdGetFileAsync
73      */
74     typedef struct
75     {
76         char            name[DWC_ND_FILENAME_LEN+1];		    ///< File name expressed as a NULL-terminated ASCII string of up to 32 characters
77         short           explain[DWC_ND_FILEEXPLSIN_LEN+1];      ///< File description expressed as a NULL-terminated UTF16BE string of up to 50 characters
78         char            param1[DWC_ND_FILEATTR_LEN+1];		    ///< Attribute string 1, expressed as a NULL-terminated ASCII string of up to 10 characters
79         char            param2[DWC_ND_FILEATTR_LEN+1];		    ///< Attribute string 2, expressed as a NULL-terminated ASCII string of up to 10 characters
80         char            param3[DWC_ND_FILEATTR_LEN+1];		    ///< Attribute string 3, expressed as a NULL-terminated ASCII string of up to 10 characters
81         unsigned int    size;						            ///< File size
82     }
83     DWCNdFileInfo;
84 
85     /**
86      * Enumerator for download library errors
87      *
88      * Enumerator type that shows errors generated by the download library.
89      *
90      * See also:  DWCNdCallback
91      *
92      * Version:  1.4.15: Created the initial version.
93      */
94     typedef enum {
95         DWC_ND_ERROR_NONE,     ///< Processing in progress has completed
96         DWC_ND_ERROR_ALLOC,    ///< Failed to allocate memory
97         DWC_ND_ERROR_STATE,    ///< A function was called from a state in which it originally could not be called
98         DWC_ND_ERROR_HTTP,     ///< An error occurred during HTTP communications
99         DWC_ND_ERROR_BUFFULL,  ///< (internal error) Insufficient download buffer
100         DWC_ND_ERROR_PARAM,	   ///< An error occurred due to invalid parameters
101         DWC_ND_ERROR_CANCELED, ///< Finished cancelling a process
102         DWC_ND_ERROR_DLSERVER, ///< The server returned an error code
103         DWC_ND_ERROR_FATAL,	   ///< An undefined fatal error occurred
104         DWC_ND_ERROR_MAX
105     } DWCNdError;
106 
107     /**
108      * Enumerator for download library progress
109      *
110      * This enumerated type indicates the type of process that was running when a notification callback function was called by the download library.
111      *
112      *
113      * See also:  DWCNdCallback
114      *
115      * Version:  1.4.15: Created the initial version.
116      */
117     typedef enum {
118         DWC_ND_CBREASON_INITIALIZE,		///< The notification callback was invoked while initializing the download library
119         DWC_ND_CBREASON_GETFILELISTNUM, ///< The notification callback was invoked while downloading the total number of downloadable files
120         DWC_ND_CBREASON_GETFILELIST,    ///< The notification callback was invoked while downloading a file information list
121         DWC_ND_CBREASON_GETFILE,        ///< The notification callback was invoked while downloading a file
122         DWC_ND_CBREASON_CLEANUP,        ///< Invoked when cleanup has completed
123         DWC_ND_CBREASON_MAX
124     } DWCNdCallbackReason;
125 
126 
127     /**
128      * Type of a notification callback function that is invoked by the download library.
129      *
130      * Type of a notification callback function that is invoked by the download library. Communicates the result of asynchronous processing. @n
131      * Process errors using either the error parameter of this callback or the return value of the DWC_NdProcess function, whichever is more convenient. @n
132      * The error parameter of this callback will be DWC_ND_ERROR_NONE when the return value of the DWC_NdProcess function is DWC_ND_STATE_COMPLETE. @n
133      * The error parameter of this callback will not be DWC_ND_ERROR_NONE when the return value of the DWC_NdProcess function is DWC_ND_STATE_ERROR.
134      * At this time, get the error information with the DWC_GetLastErrorEx function, display the error code along with the error message in accordance with the type of error processing, and shut down the library.
135      *
136      *
137      * Download library functions can also be called from within this callback.
138      *
139      * Param:    reason:      Value showing what kind of process was running when the notification callback function was called.
140      * Param:    error:       Value showing the error that occurred when the notification callback function was called.
141      * Param:    servererror: Error code communicated by the server. @n
142      *                        This will be -1 when error is not DWC_ND_ERROR_DLSERVER.
143      *
144      * See also:  DWC_NdInitAsync
145      * See also:  DWC_NdCleanupAsync
146      *
147      * Version:  1.4.15: Created the initial version.
148      */
149     typedef void (*DWCNdCallback)( DWCNdCallbackReason reason, DWCNdError error, int servererror );
150 
151     /* -------------------------------------------------------------------------
152             Function - external
153        ------------------------------------------------------------------------- */
154 
155     BOOL        DWC_NdInitAsync             (DWCNdCallback callback, const char *gamecd, const char *passwd);
156     DWCNdState  DWC_NdProcess               (void);
157     BOOL        DWC_NdCleanupAsync          (void);
158     BOOL        DWC_NdSetAttr               (const char* attr1, const char* attr2, const char* attr3);
159     BOOL        DWC_NdGetFileListNumAsync   (int* entrynum);
160     BOOL        DWC_NdGetFileListAsync      (DWCNdFileInfo* filelist, unsigned int offset, unsigned int num);
161     BOOL        DWC_NdGetFileAsync          (DWCNdFileInfo* fileinfo, char* buf, unsigned int size);
162     BOOL        DWC_NdCancelAsync           (void);
163     BOOL        DWC_NdGetProgress           (u32* received, u32* contentlen);
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif // DWC_ND_H_
170