/*---------------------------------------------------------------------------* Project: Wii Connect 24 API demos File: Check.c Copyright 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: Check.c,v $ Revision 1.5 2007/01/31 09:10:20 hirose_kazuki Rewrote error check sequence after NWC24OpenLib. Revision 1.4 2006/11/01 01:50:59 hirose_kazuki Removed NWC24_ERR_PROTECTED result from NWC24Check() sequence. Revision 1.3 2006/10/26 08:06:40 hirose_kazuki Fixed an easy mistake. Revision 1.2 2006/10/26 02:52:49 hirose_kazuki Added case handling for NWC24_ERR_FATAL on NWC24Check(). Revision 1.1 2006/10/23 04:13:03 hirose_kazuki Initial check in. *---------------------------------------------------------------------------*/ #include #include #include #include #include #include /*---------------------------------------------------------------------------* WiiConnect24 status check sequence sample. *---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ // Error messages (tentative) #define ERRORMSG_FATAL "Fatal error." #define ERRORMSG_FILE "File access problem." #define ERRORMSG_OLD_SYSTEM "System update required." #define ERRORMSG_NOT_AVAILABLE "Service is not activated." #define ERRORMSG_NETWORK "Network problem." #define ERRORMSG_SERVER "Server problem." #define ERRORMSG_SENDBOXFULL "Send box is full." /*---------------------------------------------------------------------------*/ void PrintError( const char* errorMsg ); /*---------------------------------------------------------------------------*/ MEMHeapHandle HeapHndl; MEMAllocator Allocator; /*---------------------------------------------------------------------------* Main *---------------------------------------------------------------------------*/ int main(void) { NWC24Err err; s32 result; void* arenaLo; void* arenaHi; char* libWorkMem; // Memory allocator initialization arenaLo = OSGetMEM1ArenaLo(); arenaHi = OSGetMEM1ArenaHi(); HeapHndl = MEMCreateExpHeap(arenaLo, (u32)arenaHi - (u32)arenaLo); OSSetMEM1ArenaLo(arenaHi); MEMInitAllocatorForExpHeap(&Allocator, HeapHndl, 32); result = NANDInit(); if ( result != NAND_RESULT_OK ) { OSHalt("NANDInit() failed.\n"); } VFInit(); OSReport("*******************************************************\n"); OSReport(" WiiConnect24 status check sequence sample\n"); OSReport("*******************************************************\n"); libWorkMem = MEMAllocFromAllocator(&Allocator, NWC24_WORK_MEM_SIZE); openRetry: /********************************************** * Opens the library and check results * **********************************************/ err = NWC24OpenLib(libWorkMem); if ( err == NWC24_OK ) { } else if ( NWC24_ERR_IS_FATAL(err) ) { /* Fatal errors [NWC24_ERR_FATAL, NWC24_ERR_INTERNAL_IPC] */ PrintError(ERRORMSG_FATAL); goto end; } else if ( NWC24_ERR_IS_FILE(err) ) { /* File access errors [NWC24_ERR_BROKEN, NWC24_ERR_FILE_*, NWC24_ERR_INTERNAL_VF, NWC24_ERR_NAND_CORRUPT] */ PrintError(ERRORMSG_FILE); goto end; } else if ( err == NWC24_ERR_OLD_SYSTEM ) { /* Systemmenu version errors [NWC24_ERR_OLD_SYSTEM] */ PrintError(ERRORMSG_OLD_SYSTEM); goto end; } else if ( NWC24_ERR_IS_RETRIABLE(err) ) { /* Retriable errors [NWC24_ERR_MUTEX, NWC24_ERR_BUSY, NWC24_ERR_INPROGRESS] */ OSReport("NWC24OpenLib() -- Busy(%d). Retrying.\n", err); OSSleepSeconds(2); goto openRetry; } else { /* Other errors (because of programming error) */ OSReport("NWC24OpenLib() -- Programming error (%d).\n", err); goto end; } /********************************************** * Status check by NWC24Check() * **********************************************/ err = NWC24Check(NWC24_USE_MESSAGES); switch ( err ) { case NWC24_OK: break; case NWC24_ERR_FATAL: PrintError(ERRORMSG_FATAL); goto closeLib; case NWC24_ERR_DISABLED: PrintError(ERRORMSG_NOT_AVAILABLE); goto closeLib; case NWC24_ERR_NETWORK: PrintError(ERRORMSG_NETWORK); goto closeLib; case NWC24_ERR_SERVER: PrintError(ERRORMSG_SERVER); goto closeLib; case NWC24_ERR_FULL: PrintError(ERRORMSG_SENDBOXFULL); goto closeLib; default: // Should not reach here. break; } OSReport("All NWC24 status check passed.\n"); closeLib: err = NWC24CloseLib(); if ( err != NWC24_OK ) { OSReport("NWC24CloseLib(): Error %d\n", err); OSHalt("Failed.\n"); } end: MEMFreeToAllocator(&Allocator, libWorkMem); OSHalt("Program finished.\n"); return 0; } /*---------------------------------------------------------------------------* Prints error message and 6-digits error code *---------------------------------------------------------------------------*/ void PrintError( const char* errorMsg ) { s32 errorCode; errorCode = NWC24GetErrorCode(); OSReport("NWC24 status check failed. [%06d]\n", -errorCode); OSReport("%s\n", errorMsg); return; }