1 /*---------------------------------------------------------------------------* 2 Project: RevolutionDWC public include file 3 File: ./gdb/dwc_gdb.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 15 #ifndef DWC_GDB_H_ 16 #define DWC_GDB_H_ 17 18 #ifdef __cplusplus 19 extern "C" 20 { 21 #endif 22 23 #include <dwc.h> 24 #include <nonport/dwc_nonport.h> 25 26 /* ------------------------------------------------------------------------- 27 Define 28 ------------------------------------------------------------------------- */ 29 30 31 32 /* ------------------------------------------------------------------------- 33 enum 34 ------------------------------------------------------------------------- */ 35 36 //* Enumerator type that shows the field type. 37 typedef enum { 38 DWC_GDB_FIELD_TYPE_BYTE, ///< 1-byte unsigned integer. 39 DWC_GDB_FIELD_TYPE_SHORT, ///< 2-byte signed integer. 40 DWC_GDB_FIELD_TYPE_INT, ///< 4-byte signed integer. 41 DWC_GDB_FIELD_TYPE_FLOAT, ///< 8-byte floating-point number. 42 DWC_GDB_FIELD_TYPE_ASCII_STRING, ///< Character string with 1-byte characters. 43 DWC_GDB_FIELD_TYPE_UNICODE_STRING, ///< Character string with 2-byte characters. 44 DWC_GDB_FIELD_TYPE_BOOLEAN, ///< Boolean value. 45 DWC_GDB_FIELD_TYPE_DATE_AND_TIME, ///< Time given by UnixTime. 46 DWC_GDB_FIELD_TYPE_BINARY_DATA, ///< Binary data. 47 DWC_GDB_FIELD_TYPE_NUM_FIELD_TYPES 48 } DWCGdbFieldType; 49 50 //* Enumerator type that shows an error. 51 typedef enum { 52 DWC_GDB_ERROR_NONE = 0, ///< Completed successfully. 53 DWC_GDB_ERROR_OUT_OF_MEMORY = 1, ///< Memory could not be allocated from the allocator given in DWC_Init. 54 DWC_GDB_ERROR_NOT_AVAILABLE = 2, ///< 55 DWC_GDB_ERROR_CORE_SHUTDOWN = 3, ///< 56 DWC_GDB_ERROR_NOT_LOGIN = 4, ///< Not properly logged into Nintendo WiFi Connection. 57 DWC_GDB_ERROR_NOT_AUTHENTICATED = 5, ///< Not properly logged into Nintendo WiFi Connection. 58 DWC_GDB_ERROR_BAD_INPUT = 6, ///< 59 DWC_GDB_ERROR_BAD_TABLENAME = 7, ///< 60 DWC_GDB_ERROR_BAD_FIELDS = 8, ///< 61 DWC_GDB_ERROR_BAD_NUM_FIELDS = 9, ///< 62 DWC_GDB_ERROR_BAD_FIELD_NAME = 10, ///< 63 DWC_GDB_ERROR_BAD_FIELD_TYPE = 11, ///< 64 DWC_GDB_ERROR_BAD_FIELD_VALUE = 12, ///< 65 DWC_GDB_ERROR_BAD_OFFSET = 13, ///< 66 DWC_GDB_ERROR_BAD_MAX = 14, ///< 67 DWC_GDB_ERROR_BAD_RECORDIDS = 15, ///< 68 DWC_GDB_ERROR_BAD_NUM_RECORDIDS = 16, ///< 69 DWC_GDB_ERROR_UNKNOWN = 17, ///< 70 DWC_GDB_ERROR_ALREADY_INITIALIZED = 18, ///< Already initialized. 71 DWC_GDB_ERROR_NOT_INITIALIZED = 19, ///< Not initialized. 72 DWC_GDB_ERROR_IN_ASYNC_PROCESS = 20, ///< Asynchronous processing in progress. 73 DWC_GDB_ERROR_GHTTP = 21, ///< GHTTP error occurred. 74 DWC_GDB_ERROR_IN_DWC_ERROR = 22 ///< DWC error has occurred. Perform error handling. 75 } DWCGdbError; 76 77 //* Enumerator type that shows the result of asynchronous processing. 78 typedef enum { 79 DWC_GDB_ASYNC_RESULT_NONE = 0, ///< Asynchronous processing has not finished yet. 80 DWC_GDB_ASYNC_RESULT_SUCCESS = 1, ///< Succeeded. 81 DWC_GDB_ASYNC_RESULT_SECRET_KEY_INVALID = 2, 82 DWC_GDB_ASYNC_RESULT_SERVICE_DISABLED = 3, 83 DWC_GDB_ASYNC_RESULT_CONNECTION_TIMEOUT = 4, 84 DWC_GDB_ASYNC_RESULT_CONNECTION_ERROR = 5, 85 DWC_GDB_ASYNC_RESULT_MALFORMED_RESPONSE = 6, 86 DWC_GDB_ASYNC_RESULT_OUT_OF_MEMORY = 7, 87 DWC_GDB_ASYNC_RESULT_DATABASE_UNAVAILABLE = 8, 88 DWC_GDB_ASYNC_RESULT_LOGIN_TICKET_INVALID = 9, 89 DWC_GDB_ASYNC_RESULT_LOGIN_TICKET_EXPIRED = 10, 90 DWC_GDB_ASYNC_RESULT_TABLE_NOT_FOUND = 11, 91 DWC_GDB_ASYNC_RESULT_RECORD_NOT_FOUND = 12, 92 DWC_GDB_ASYNC_RESULT_FIELD_NOT_FOUND = 13, 93 DWC_GDB_ASYNC_RESULT_FIELD_TYPE_INVALID = 14, 94 DWC_GDB_ASYNC_RESULT_NO_PERMISSION = 15, 95 DWC_GDB_ASYNC_RESULT_RECORD_LIMIT_REACHED = 16, 96 DWC_GDB_ASYNC_RESULT_ALREADY_RATED = 17, 97 DWC_GDB_ASYNC_RESULT_NOT_RATEABLE = 18, 98 DWC_GDB_ASYNC_RESULT_NOT_OWNED = 19, 99 DWC_GDB_ASYNC_RESULT_FILTER_INVALID = 20, 100 DWC_GDB_ASYNC_RESULT_SORT_INVALID = 21, 101 DWC_GDB_ASYNC_RESULT_UNKNOWN_ERROR = 22, 102 DWC_GDB_ASYNC_RESULT_BAD_HTTP_METHOD = 23, 103 DWC_GDB_ASYNC_RESULT_BAD_FILE_COUNT = 24, 104 DWC_GDB_ASYNC_RESULT_MISSING_PARAMETER = 25, 105 DWC_GDB_ASYNC_RESULT_FILE_NOT_FOUND = 26, 106 DWC_GDB_ASYNC_RESULT_FILE_TOO_LARGE = 27, 107 DWC_GDB_ASYNC_RESULT_FILE_UNKNOWN_ERROR = 28, 108 DWC_GDB_ASYNC_RESULT_GHTTP_ERROR = 29, ///< GHTTP error occurred. 109 DWC_GDB_ASYNC_RESULT_TARGET_FILTER_INVALID = 30, 110 DWC_GDB_ASYNC_RESULT_SERVER_ERROR = 31 111 } DWCGdbAsyncResult; 112 113 //* Enumerator type that shows the state of the DWCGdb library. 114 typedef enum { 115 DWC_GDB_STATE_UNINITIALIZED, ///< Uninitialized state 116 DWC_GDB_STATE_IDLE, ///< State in which initialization has finished and there is no asynchronous processing 117 DWC_GDB_STATE_IN_ASYNC_PROCESS, ///< State in which there is asynchronous processing 118 DWC_GDB_STATE_ERROR_OCCURED ///< State in which an error occurred 119 } DWCGdbState; 120 121 122 /* ------------------------------------------------------------------------- 123 struct 124 ------------------------------------------------------------------------- */ 125 126 /// A value of a binary data type. 127 typedef struct 128 { 129 u8* data; ///< Content of the data. This region is deallocated when leaving a callback. 130 s32 size; ///< Data size. 131 } 132 DWCGdbBinaryData; 133 134 /// Shows the field value. 135 typedef union { 136 u8 int_u8; ///< 1-byte unsigned integer. 137 s16 int_s16; ///< 2-byte signed integer. 138 s32 int_s32; ///< 4-byte signed integer. 139 f32 float_f64; ///< 8-byte floating-point number. 140 char* ascii_string; ///< Character string with 1-byte characters. 141 u16* wide_string; ///< Character string with 2-byte characters. 142 int boolean; ///< Boolean value. 143 DWCTick datetime; ///< Time given by UnixTime. 144 DWCGdbBinaryData binary_data; ///< Binary data. 145 } DWCGdbValue; 146 147 /// Shows the field. 148 typedef struct 149 { 150 char* name; ///< Field name. 151 DWCGdbFieldType type; ///< Field type. 152 DWCGdbValue value; ///< Field value. 153 } 154 DWCGdbField; 155 156 /// Shows the search conditions. 157 typedef struct 158 { 159 char* filter; ///< Performs the same action as the SQL 'WHERE' statement. This will be unspecified if it is set to NULL. 160 char* sort; ///< Performs the same action as the SQL 'ORDER BY' statement. This will be unspecified if it is set to NULL. 161 int offset; ///< Specifies the number of the search result from which to begin acquisition. 162 int max; ///< Specifies the maximum number of search results to obtain. 163 char* target_filter; ///< In order to obtain surrounding records using surrounding_num, this filter must be configured to search for a single record only. 164 ///< When unused, NULL can be given. 165 int surrounding_num; ///< Used in combination with target_filter. When a value of 1 or greater is specified, the search results will be obtained along with the specified number of records both above and below. 166 int* ownerids; ///< Specifies an array of profile IDs for the authors of the records that will be searched. NULL can be given if ownerid_num is set to zero. 167 int ownerid_num; ///< Specifies the length of the array specified by ownerids. Enter zero if unused. 168 BOOL cache_flag; ///< Indicates if search results will be cached on the server. 169 } 170 DWCGdbSearchCond; 171 172 /* ------------------------------------------------------------------------- 173 typedef - callback 174 ------------------------------------------------------------------------- */ 175 176 /** 177 * Callback function when asynchronous processing results and records are obtained. 178 * 179 * Fields passed as arguments are released when the callback exits, so copy necessary data inside the callback. 180 * 181 * 182 * Param: record_num Record count. 183 * Param: records Record array. 184 * Param: user_param Parameters passed to the asynchronous process when it is run. 185 */ 186 typedef void (*DWCGdbGetRecordsCallback)(int record_num, DWCGdbField** records, void* user_param); 187 188 /** 189 * Callback function when asynchronous processing results and files are obtained. 190 * 191 * When TRUE is given as the clear_buf argument to DWC_GdbDownloadFileAsync, the region given as the data argument is dealocated when the callback exists. 192 * It will not be deallocated when FALSE is given, so use DWC_Free to deallocate it at the appropriate time. 193 * 194 * Param: data Retrieved data. 195 * Param: size Retrieved data size. 196 * Param: user_param Parameters passed to the asynchronous process when it is run. 197 */ 198 typedef void (*DWCGdbDownloadFileCallback)(const void* data, int size, void* user_param); 199 200 201 /* ------------------------------------------------------------------------- 202 Function - external 203 ------------------------------------------------------------------------- */ 204 205 //--- Auto Function Prototype --- Don't comment here. 206 extern DWCGdbError DWC_GdbInitialize(int game_id, const DWCUserData* userdata, BOOL use_ssl); 207 extern DWCGdbError DWC_GdbShutdown(); 208 extern void DWC_GdbProcess(); 209 extern DWCGdbState DWC_GdbGetState(); 210 extern DWCGdbAsyncResult DWC_GdbGetAsyncResult(); 211 extern DWCGdbField* DWC_GdbGetFieldByName(const char* field_name, DWCGdbField* fields, int field_num); 212 extern DWCGdbError DWC_GdbCreateRecordAsync(const char* table_name, DWCGdbField* fields, int field_num, int* record_id); 213 extern DWCGdbError DWC_GdbDeleteRecordAsync(const char* table_name, int record_id); 214 extern DWCGdbError DWC_GdbUpdateRecordAsync(const char* table_name, int record_id, DWCGdbField* fields, int field_num); 215 extern DWCGdbError DWC_GdbDownloadFileAsync(int file_id, int buf_size, BOOL clear_buf, DWCGdbDownloadFileCallback callback, void* user_param); 216 extern DWCGdbError DWC_GdbUploadFileAsync(const void* data, int size, const char* file_name, int* file_id); 217 extern DWCGdbError DWC_GdbGetMyRecordsAsync(const char* table_name, const char** field_names, int field_num, DWCGdbGetRecordsCallback callback, void* user_param); 218 extern DWCGdbError DWC_GdbGetRecordLimitAsync(const char* table_name, int* limit_num, int* owned_num); 219 extern DWCGdbError DWC_GdbGetRecordsAsync(const char* table_name, const int* record_ids, int record_num, const char** field_names, int field_num, DWCGdbGetRecordsCallback callback, void* user_param); 220 extern DWCGdbError DWC_GdbRateRecordAsync(const char* table_name, int record_id, u8 rating); 221 extern DWCGdbError DWC_GdbSearchRecordsAsync(const char* table_name, const char** field_names, int field_num, const DWCGdbSearchCond* search_cond, DWCGdbGetRecordsCallback callback, void* user_param); 222 extern DWCGdbError DWC_GdbGetRandomRecordAsync(const char* table_name, const char** field_names, int field_num, const char* filter, DWCGdbGetRecordsCallback callback, void* user_param); 223 extern DWCGdbError DWC_GdbGetRecordCountAsync(const char* table_name, const char* filter, BOOL cache_flag, int* count); 224 //--- End of Auto Function Prototype 225 226 227 #ifdef __cplusplus 228 } 229 #endif 230 231 #endif // DWC_GDB_H_ 232