/*---------------------------------------------------------------------------* Project: Wii Connect 24 API demos File: MsgList.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: MsgList.c,v $ Revision 1.2 2007/12/12 01:40:12 hirose_kazuki Fixed variable to set as third argument of NWC24GetMsgIdList(). Revision 1.1 2006/09/27 08:56:17 torigoe_nobutaka Moved from nwc24demo/src. Revision 1.7 2006/09/21 02:35:13 hirose_kazuki Changes due to re-arrangement of message types. Revision 1.6 2006/09/13 08:14:22 yosizaki Changed to call VFInit(). Revision 1.5 2006/09/10 09:20:56 hirose_kazuki Changed to use NWC24OpenLib/NWC24CloseLib instead of obsolete functions. Revision 1.4 2006/08/29 13:11:43 hirose_kazuki Corrected message type handling. Revision 1.3 2006/08/14 14:39:50 yasu Suppressed return value ignored warnings Revision 1.2 2006/07/13 12:51:58 hirose_kazuki Updated due to the API spec change. Revision 1.1 2006/06/29 12:46:21 hirose_kazuki Moved from another repository. Revision 1.1 2006/06/12 07:37:18 hirose Initial check in. *---------------------------------------------------------------------------*/ #include #include #include #include #include #include /*---------------------------------------------------------------------------* Listing content stored in both message boxes. *---------------------------------------------------------------------------*/ void ListMessageBox( NWC24MsgBoxId mBoxId ); void Print16Digits( u64 num ); /*---------------------------------------------------------------------------*/ 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(" MessageBox List demo\n"); OSReport("*******************************************************\n"); libWorkMem = MEMAllocFromAllocator(&Allocator, NWC24_WORK_MEM_SIZE); err = NWC24OpenLib(libWorkMem); if ( err != NWC24_OK ) { OSReport("NWC24OpenLib(): Error %d\n", err); OSHalt("Failed.\n"); } // Lists content inside the send box. OSReport("\n [Send Box]\n"); OSReport("-------------------------------------------------------\n"); ListMessageBox(NWC24_SEND_BOX); // Lists content inside the receive box. OSReport("\n [Receive Box]\n"); OSReport("-------------------------------------------------------\n"); ListMessageBox(NWC24_RECV_BOX); err = NWC24CloseLib(); if ( err != NWC24_OK ) { OSReport("NWC24CloseLib(): Error %d\n", err); OSHalt("Failed.\n"); } MEMFreeToAllocator(&Allocator, libWorkMem); OSHalt("\nCompleted.\n"); return 0; } /*---------------------------------------------------------------------------* Listing *---------------------------------------------------------------------------*/ void ListMessageBox( NWC24MsgBoxId mBoxId ) { u32 numMsgs; u32 bufSize; u32* idListBuf; NWC24Err err; int i; err = NWC24GetNumMsgs(mBoxId, &numMsgs); if ( err != NWC24_OK ) { OSReport("NWC24GetNumMsgs(): error %d\n", err); return; } if ( numMsgs == 0 ) { OSReport("(No message.)\n"); return; } bufSize = OSRoundUp32B(numMsgs * sizeof(u32)); idListBuf = (u32*)MEMAllocFromAllocator(&Allocator, bufSize); err = NWC24GetMsgIdList(mBoxId, idListBuf, numMsgs); if ( err != NWC24_OK ) { OSReport("NWC24GetNumMsgList(): error %d\n", err); return; } for ( i = 0 ; i < numMsgs ; ++i ) { NWC24MsgObj msgObj; NWC24MsgType type; OSReport(" [%08d] ", idListBuf[i]); err = NWC24GetMsgObj(&msgObj, mBoxId, idListBuf[i]); if ( err != NWC24_OK ) { OSReport("NWC24GetMsgObj(): error %d\n", err); return; } (void)NWC24GetMsgType(&msgObj, &type); switch (type) { case NWC24_MSGTYPE_WII_MENU_SHARED: case NWC24_MSGTYPE_WII_APP: case NWC24_MSGTYPE_WII_MENU: case NWC24_MSGTYPE_WII_APP_HIDDEN: { // Message from/to other Wii console(s). NWC24UserId uid; if ( mBoxId == NWC24_SEND_BOX ) { u32 numTo; u32 j; (void)NWC24GetMsgNumTo(&msgObj, &numTo); OSReport("To:"); for ( j = 0 ; j < numTo ; ++j ) { (void)NWC24ReadMsgToId(&msgObj, j, &uid); Print16Digits(uid); } OSReport("\n"); } else { (void)NWC24GetMsgFromId(&msgObj, &uid); OSReport("From:"); Print16Digits(uid); OSReport("\n"); } } break; case NWC24_MSGTYPE_PUBLIC: { // Message from/to public e-mail address. if ( mBoxId == NWC24_SEND_BOX ) { OSReport("To: Public e-mail address.\n"); } else { OSReport("From: Public e-mail address.\n"); } } break; default: break; } } MEMFreeToAllocator(&Allocator, idListBuf); return; } /*---------------------------------------------------------------------------* Function for printing 16-digits. *---------------------------------------------------------------------------*/ void Print16Digits( u64 num ) { char buf[20]; u32 i; u64 tmp = num; for ( i = 0 ; i < 16 ; ++i ) { buf[15-i] = (char)((tmp % 10) + 0x30); tmp /= 10; } buf[16] = '\0'; OSReport(" %s", buf); }