1 /*---------------------------------------------------------------------------*
2   Project:  Wii Connect24 API demos
3   File:     PostTestMsg.c
4 
5   Copyright 2006 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   $Log: PostTestMsg.c,v $
14   Revision 1.1  2006/09/27 08:56:17  torigoe_nobutaka
15   Moved from nwc24demo/src.
16 
17   Revision 1.1  2006/08/25 06:17:59  torigoe_nobutaka
18   Initial check in.
19 
20 
21   $NoKeywords: $
22  *---------------------------------------------------------------------------*/
23 #include <revolution.h>
24 #include <revolution/nwc24.h>
25 
26 #include <string.h>
27 
28 #include "PostTestMsg.h"
29 
30 /*---------------------------------------------------------------------------*
31    Static constants
32  *---------------------------------------------------------------------------*/
33 #define NUM_TEST_MSGS   4
34 
35 static const NWC24UserId    TEST_TO_ID                      = 1234567890ULL;
36 
37 static const NWC24MsgType   TEST_MSG_TYPE[NUM_TEST_MSGS]    =
38 {
39     NWC24_MSGTYPE_WII,
40     NWC24_MSGTYPE_WII_APP_ONLY,
41     NWC24_MSGTYPE_WII_MENU_ONLY,
42     NWC24_MSGTYPE_WII
43 };
44 
45 static const char*          STR_TEST_SUBJECT[NUM_TEST_MSGS] =
46 {
47     "Test Message /1",
48     "Test Message /2",
49     "Test Message /3",
50     "Test Message /4"
51 };
52 
53 static const char*          STR_TEST_MSG_TEXT               =
54     "Hello WiiConnect24 World!!\x0d\x0a"
55     "This is a test mail.\x0d\x0a"
56     "Thank you.\x0d\x0a";
57 
58 /*---------------------------------------------------------------------------*
59    Creates and posts test messages.
60  *---------------------------------------------------------------------------*/
PostTestMsg(void)61 void PostTestMsg( void )
62 {
63     NWC24Err        err;
64     NWC24MsgObj     msgObj;
65     u8              iObj;
66     NWC24UserId     uidTo;
67 
68     /* Initializes the message object. */
69     for ( iObj = 0; iObj < NUM_TEST_MSGS; ++iObj )
70     {
71         err = NWC24InitMsgObj( &msgObj, TEST_MSG_TYPE[iObj] );
72         if ( err != NWC24_OK )
73         {
74             OSReport( "NWC24InitMsgObj(): Error %d\n", err );
75             return;
76         }
77 
78         /* To address (by user ID) */
79         if ( iObj == NUM_TEST_MSGS - 1 )
80         {
81             err = NWC24GetMyUserId( &uidTo );
82             if ( err != NWC24_OK )
83             {
84                 OSReport( "NWC24GetMyUserId(): Error %d\n", err );
85                 return;
86             }
87         }
88         else
89         {
90             uidTo = TEST_TO_ID;
91         }
92         err = NWC24SetMsgToId( &msgObj, uidTo );
93         if ( err != NWC24_OK )
94         {
95             OSReport( "NWC24SetMsgToId(): Error %d\n", err );
96             return;
97         }
98 
99         /* Subject */
100         err = NWC24SetMsgSubject( &msgObj, STR_TEST_SUBJECT[iObj],
101                                   (u32)strlen( STR_TEST_SUBJECT[iObj] ) );
102         if ( err != NWC24_OK )
103         {
104             OSReport( "NWC24SetMsgSubject(): Error %d\n", err );
105             return;
106         }
107 
108         /* Message body (text) */
109         err = NWC24SetMsgText( &msgObj, STR_TEST_MSG_TEXT,
110                                (u32)strlen( STR_TEST_MSG_TEXT ),
111                                NWC24_US_ASCII, NWC24_ENC_7BIT );
112         if ( err != NWC24_OK )
113         {
114             OSReport( "NWC24SetMsgText(): Error %d\n", err );
115             return;
116         }
117 
118         /* Commit settings and post the message into the send box. */
119         err = NWC24CommitMsg( &msgObj );
120         if ( err != NWC24_OK )
121         {
122             OSReport( "NWC24CommitMsg(): Error %d\n", err );
123             return;
124         }
125     }
126     OSReport( "Posted %d test messages successfully.\n", NUM_TEST_MSGS );
127     return;
128 }
129 
130 /*======== End of PostTestMsg.c ========*/
131