1
2 #include <revolution.h>
3
4 #include <revolution/nand.h>
5 #include <revolution/vf.h>
6 #include <revolution/mem.h>
7
8 #include <revolution/nwc24.h>
9
10 #include <stdio.h>
11 #include <string.h>
12
13 /*---------------------------------------------------------------------------*
14 template data
15 *---------------------------------------------------------------------------*/
16 extern u8 my_letter_arc_begin[];
17 extern u8 my_letter_arc_end[];
18
19 /*---------------------------------------------------------------------------*
20 A simple demo to post a message.
21 *---------------------------------------------------------------------------*/
22 void PostTestMsg( void );
23
24 MEMHeapHandle HeapHndl;
25 MEMAllocator Allocator;
26
main(void)27 int main(void)
28 {
29 NWC24Err err;
30 s32 result;
31 void* arenaLo;
32 void* arenaHi;
33 char* libWorkMem;
34
35 // Memory allocator initialization
36 arenaLo = OSGetMEM1ArenaLo();
37 arenaHi = OSGetMEM1ArenaHi();
38 HeapHndl = MEMCreateExpHeap(arenaLo, (u32)arenaHi - (u32)arenaLo);
39 OSSetMEM1ArenaLo(arenaHi);
40 MEMInitAllocatorForExpHeap(&Allocator, HeapHndl, 32);
41
42 result = NANDInit();
43 if ( result != NAND_RESULT_OK )
44 {
45 OSHalt("NANDInit() failed.\n");
46 }
47
48 VFInit();
49
50 OSReport("*******************************************************\n");
51 OSReport(" NWC24 Letter demo\n");
52 OSReport("*******************************************************\n");
53
54 libWorkMem = MEMAllocFromAllocator(&Allocator, NWC24_WORK_MEM_SIZE);
55
56 err = NWC24OpenLib(libWorkMem);
57 if ( err != NWC24_OK )
58 {
59 OSReport("NWC24OpenLib(): Error %d\n", err);
60 OSHalt("Failed.\n");
61 }
62
63 // Post a message.
64 PostTestMsg();
65
66 err = NWC24CloseLib();
67 if ( err != NWC24_OK )
68 {
69 OSReport("NWC24CloseLib(): Error %d\n", err);
70 OSHalt("Failed.\n");
71 }
72
73 MEMFreeToAllocator(&Allocator, libWorkMem);
74
75 OSHalt("\nCompleted.\n");
76 return 0;
77 }
78
79 /*---------------------------------------------------------------------------*
80 Data for this test.
81 "TestMsgText" and "TestAltName" are sent in the UTF_16BE charset.
82 *---------------------------------------------------------------------------*/
83 static char* TestSubject = "Test Message";
84 static wchar_t TestMsgText[] =
85 L"Hello WiiConnect24 World!!\x0d\x0a"
86 L"This is a test mail with an original template.\x0d\x0a"
87 L"Thank you.\x0d\x0a"
88 L"\x0d\x0a"
89 L"AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEEEEEEEEE\x0d\x0a";
90 static wchar_t TestAltName[] =
91 L"Wii Game";
92
PostTestMsg(void)93 void PostTestMsg(void)
94 {
95 NWC24Err err;
96 NWC24MsgObj msgObj;
97 NWC24UserId testIdTo;
98
99 // Initializes the object, specifies Wii-to-Wii message.
100 err = NWC24InitMsgObj(&msgObj, NWC24_MSGTYPE_WII_MENU);
101 if ( err != NWC24_OK )
102 {
103 OSReport("NWC24InitMsgObj(): error %d\n", err);
104 return;
105 }
106
107 // To address (by user id)
108 err = NWC24GetMyUserId(&testIdTo);
109 if( err != NWC24_OK )
110 {
111 OSReport("NWC24GetMyUserId(): error %d\n", err);
112 return;
113 }
114
115 err = NWC24SetMsgToId(&msgObj, testIdTo);
116 if ( err != NWC24_OK )
117 {
118 OSReport("NWC24SetMsgToId(): error %d\n", err);
119 return;
120 }
121
122 // Subject
123 err = NWC24SetMsgSubject(&msgObj, TestSubject, (u32)strlen(TestSubject));
124 if ( err != NWC24_OK )
125 {
126 OSReport("NWC24SetMsgSubject(): error %d\n", err);
127 return;
128 }
129
130 // Message body (text)
131 err = NWC24SetMsgText(&msgObj, (const char*)TestMsgText, (u32)sizeof(TestMsgText) - 2,
132 NWC24_UTF_16BE, NWC24_ENC_BASE64);
133 if ( err != NWC24_OK )
134 {
135 OSReport("NWC24SetMsgText(): error %d\n", err);
136 return;
137 }
138
139 // Attached template file.
140 err = NWC24SetMsgAttached(&msgObj, (const char*)my_letter_arc_begin,
141 (u32)(my_letter_arc_end - my_letter_arc_begin), NWC24_APP_WII_MSGBOARD);
142 if ( err != NWC24_OK )
143 {
144 OSReport("NWC24SetMsgAttached(): error %d\n", err);
145 return;
146 }
147
148 // Set alternate name.
149 err = NWC24SetMsgAltName(&msgObj, (const u16*)TestAltName, (u32)sizeof(TestAltName) - 2);
150 if ( err != NWC24_OK )
151 {
152 OSReport("NWC24SetMsgAltName(): error %d\n", err);
153 return;
154 }
155
156 // Commit settings and post the message into the send box.
157 err = NWC24CommitMsg(&msgObj);
158 if ( err != NWC24_OK )
159 {
160 OSReport("NWC24CommitMsg: error %d\n", err);
161 return;
162 }
163
164 OSReport("Posted a test message successfully.\n");
165
166 return;
167 }
168