1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     os_LightEvent.h
4 
5   Copyright (C)2009-2012 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: 47236 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_OS_OS_LIGHTEVENT_H_
17 #define NN_OS_OS_LIGHTEVENT_H_
18 
19 #ifdef __cplusplus
20 
21 #include <nn/os/os_WaitableCounter.h>
22 #include <nn/os/os_SimpleLock.h>
23 #include <nn/assert.h>
24 #include <nn/WithInitialize.h>
25 #include <nn/util/detail/util_ScopedLockImpl.h>
26 #include <nn/util/util_NonCopyable.h>
27 
28 namespace nn { namespace os {
29 
30 /* Please see man pages for details
31 
32 
33 
34 
35 */
36 
37 /*
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51  */
52 class LightEvent : private nn::util::NonCopyable<LightEvent>
53 {
54 private:
55     static const s32 SIGNALED_MANUAL        = 1;
56     static const s32 SIGNALED_AUTO          = 0;
57     static const s32 NOT_SIGNALED_AUTO      = -1;
58     static const s32 NOT_SIGNALED_MANUAL    = -2;
59 
60 private:
61     WaitableCounter     m_Counter;
62     SimpleLock          m_Lock;
63 
64 public:
65     //----------------------------------------
66     //
67     //
68 
69     /*
70 
71 
72 
73 
74 
75 
76 
77 
78      */
LightEvent()79     LightEvent(){}
80 
81     /*
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103      */
LightEvent(bool isManualReset)104     explicit LightEvent(bool isManualReset)
105     {
106         Initialize(isManualReset);
107     }
108 
109     /*
110 
111 
112 
113 
114 
115 
116 
117      */
118     void Initialize(bool isManualReset);
119 
120     /*
121 
122 
123 
124 
125      */
Finalize()126     void Finalize() {}
127 
128     //
129 
130     //----------------------------------------
131     //
132     //
133 
134     /*
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147      */
IsSignaled()148     bool IsSignaled() const { return *m_Counter >= 0; }
149 
150     /*
151 
152 
153 
154 
155 
156      */
IsManualReset()157     bool IsManualReset() const
158     {
159         const s32 c = *m_Counter;
160         return (c == SIGNALED_MANUAL) || (c == NOT_SIGNALED_MANUAL);
161     }
162 
163     //
164 
165     //----------------------------------------
166     //
167     //
168 
169     /*
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180      */
181     bool TryWait();
182 
183     /*
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198      */
199     bool TryWait(fnd::TimeSpan timeout);
200 
201     /*
202 
203 
204 
205 
206 
207 
208 
209      */
210     void Wait();
211 
212     /*
213 
214 
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231      */
232     void Signal();
233 
234     /*
235 
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247 
248      */
249     void Pulse();
250 
251     /*
252 
253 
254 
255 
256      */
257     void ClearSignal();
258 
259     //
260 };
261 
262 
263 }} // namespace nn::os
264 
265 #endif // __cplusplus
266 
267 // Below is the C declaration
268 
269 #include <nn/util/detail/util_CLibImpl.h>
270 
271 /* Please see man pages for details
272 
273 
274 
275 
276 
277 
278 
279 
280 */
281 
282 /* Please see man pages for details
283 
284 
285 
286 */
287 NN_UTIL_DETAIL_CLIBIMPL_DEFINE_BUFFER_CLASS(nnosLightEvent, nn::os::LightEvent, 8, u32);
288 
289 /* Please see man pages for details
290 
291 */
292 NN_EXTERN_C void nnosLightEventInitialize(nnosLightEvent* this_, bool isManualReset);
293 
294 /* Please see man pages for details
295 
296 */
297 NN_EXTERN_C bool nnosLightEventIsSignaled(nnosLightEvent* this_);
298 
299 /* Please see man pages for details
300 
301 */
302 NN_EXTERN_C bool nnosLightEventIsManualReset(nnosLightEvent* this_);
303 
304 /* Please see man pages for details
305 
306 */
307 NN_EXTERN_C bool nnosLightEventTryWait(nnosLightEvent* this_);
308 
309 /* Please see man pages for details
310 
311 */
312 NN_EXTERN_C void nnosLightEventWait(nnosLightEvent* this_);
313 
314 /* Please see man pages for details
315 
316 */
317 NN_EXTERN_C void nnosLightEventSignal(nnosLightEvent* this_);
318 
319 /* Please see man pages for details
320 
321 */
322 NN_EXTERN_C void nnosLightEventPulse(nnosLightEvent* this_);
323 
324 /* Please see man pages for details
325 
326 */
327 NN_EXTERN_C void nnosLightEventClearSignal(nnosLightEvent* this_);
328 
329 /* Please see man pages for details
330 
331 */
332 NN_EXTERN_C void nnosLightEventFinalize(nnosLightEvent* this_);
333 
334 /*
335 
336 
337 
338 */
339 
340 
341 
342 #endif  // ifndef NN_OS_OS_LIGHTEVENT_H_
343