1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     hio_SerialChannel.h
4 
5   Copyright (C)2009 Nintendo Co., Ltd.  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   $Rev: 32255 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_HIO_CTR_HIO_SERIALCHANNEL_H_
17 #define NN_HIO_CTR_HIO_SERIALCHANNEL_H_
18 #ifdef  NN_SWITCH_ENABLE_HOST_IO
19 
20 /* Please see man pages for details
21 
22 
23 
24 */
25 
26 #include <nn/types.h>
27 
28 namespace nn {
29 namespace hio {
30 namespace CTR {
31 
32     /* Please see man pages for details
33 
34 
35 
36 
37 
38 
39     */
40     class SerialChannel
41     {
42     public:
43         /* Please see man pages for details
44 
45         */
46         enum Attribute
47         {
48             ATTRIBUTE_NONE      = 0,            //
49             ATTRIBUTE_NO_WAIT   = (1u << 0),    //
50             ATTRIBUTE_IN_PC     = (1u << 1)     //
51         };
52 
53     private:
54         s32     m_Ch;
55 
56     public:
57         /* Please see man pages for details
58 
59         */
SerialChannel()60         SerialChannel() : m_Ch(-1) {}
61 
62         /* Please see man pages for details
63 
64         */
~SerialChannel()65         ~SerialChannel()
66         {
67             if( m_Ch >= 0 )
68             {
69                 Close();
70             }
71         }
72 
73         /* Please see man pages for details
74 
75 
76 
77 
78 
79 
80 
81         */
82         Result Open(s32 ch, void* pWorkMemory);
83 
84 
85         /* Please see man pages for details
86 
87 
88 
89 
90         */
91         Result Close();
92 
93         /* Please see man pages for details
94 
95 
96 
97 
98         */
99         Result Connect();
100 
101 
102         /* Please see man pages for details
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115         */
116         Result WaitHost(bit32 attr=ATTRIBUTE_NONE);
117 
118 
119         /* Please see man pages for details
120 
121 
122 
123 
124         */
125         Result Disconnect();
126 
127         /* Please see man pages for details
128 
129 
130 
131 
132         */
133         Result Flush();
134 
135 
136         /* Please see man pages for details
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147         */
148         Result GetReadableSize(size_t* pSize, bit32 attr=ATTRIBUTE_NONE);
149 
150 
151         /* Please see man pages for details
152 
153 
154 
155 
156 
157 
158 
159 
160 
161 
162 
163 
164         */
165         Result Read(size_t* pReadSize, void* buf, size_t size, bit32 attr=ATTRIBUTE_NONE);
166 
167         /* Please see man pages for details
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179         */
180         s32 Read(void* buf, size_t size, bit32 attr=ATTRIBUTE_NONE)
181         {
182             size_t read;
183             return Read(&read, buf, size, attr).IsFailure() ? -1: static_cast<s32>(read);
184         }
185 
186         /* Please see man pages for details
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197         */
198         Result GetWritableSize(size_t* pSize, bit32 attr=ATTRIBUTE_NONE);
199 
200         /* Please see man pages for details
201 
202 
203 
204 
205 
206 
207 
208 
209 
210 
211 
212 
213         */
214         Result Write(size_t* pWrittenSize, const void* buf, size_t size, bit32 attr=ATTRIBUTE_NONE);
215 
216         /* Please see man pages for details
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228         */
229         s32 Write(const void* buf, size_t size, bit32 attr=ATTRIBUTE_NONE)
230         {
231             size_t written;
232             return Write(&written, buf, size,  attr).IsFailure() ? -1: static_cast<s32>(written);
233         }
234     };
235 
236     /* Please see man pages for details
237 
238 
239     */
240     nn::Result ResultNoConnected();
241 
242     /* Please see man pages for details
243 
244 
245     */
246     nn::Result ResultConnected();
247 
ResultNoConnected()248     inline nn::Result ResultNoConnected()
249     {
250         return nn::Result(nn::Result::LEVEL_SUCCESS, nn::Result::SUMMARY_SUCCESS, nn::Result::MODULE_COMMON, 0);
251     }
252 
ResultConnected()253     inline nn::Result ResultConnected()
254     {
255         return nn::Result(nn::Result::LEVEL_SUCCESS, nn::Result::SUMMARY_SUCCESS, nn::Result::MODULE_COMMON, 1);
256     }
257 
258 }
259 }
260 }
261 
262 
263 #endif  // ifdef NN_SWITCH_ENABLE_HOST_IO
264 #endif  // ifndef NN_HIO_CTR_HIO_SERIALCHANNEL_H_
265