1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: os_Event.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: 47812 $
14 *---------------------------------------------------------------------------*/
15
16 /* Please see man pages for details
17
18
19
20 */
21
22 #ifndef NN_OS_OS_EVENT_H_
23 #define NN_OS_OS_EVENT_H_
24
25 #include <nn/types.h>
26 #include <nn/Handle.h>
27 #include <nn/Result.h>
28 #include <nn/os/os_Synchronization.h>
29
30 #include <nn/util/util_Result.h>
31 #include <nn/os/os_ErrorHandlerSelect.h>
32
33 #ifdef __cplusplus
34
35 namespace nn{ namespace os {
36
37 /* Please see man pages for details
38
39
40
41 */
42 class EventBase : public InterruptEvent
43 {
44 protected:
45 explicit EventBase(ResetType resetType);
EventBase()46 EventBase() {}
~EventBase()47 ~EventBase() {}
48
49 void Initialize(ResetType resetType);
50 nn::Result TryInitialize(ResetType resetType);
51 void Finalize();
52 void Signal();
53 void ClearSignal();
54
55 private:
56 Result TryInitializeImpl(ResetType resetType);
57 };
58
59 // In-line implementation
60
TryInitializeImpl(ResetType resetType)61 inline Result EventBase::TryInitializeImpl(ResetType resetType)
62 {
63 Handle handle;
64 NN_UTIL_RETURN_IF_FAILED(nn::svc::CreateEvent(&handle, resetType));
65 this->SetHandle(handle);
66 return ResultSuccess();
67 }
68
Initialize(ResetType resetType)69 inline void EventBase::Initialize(ResetType resetType)
70 {
71 NN_OS_ERROR_IF_FAILED(TryInitializeImpl(resetType));
72 }
73
TryInitialize(ResetType resetType)74 inline nn::Result EventBase::TryInitialize(ResetType resetType)
75 {
76 Result result = TryInitializeImpl(resetType);
77 if (result.GetSummary() == Result::SUMMARY_OUT_OF_RESOURCE)
78 {
79 return result;
80 }
81 NN_OS_ERROR_IF_FAILED(result);
82 return result;
83 }
84
Finalize()85 inline void EventBase::Finalize()
86 {
87 InterruptEvent::Finalize();
88 }
89
EventBase(ResetType resetType)90 inline EventBase::EventBase(ResetType resetType)
91 {
92 Initialize(resetType);
93 }
94
Signal()95 inline void EventBase::Signal()
96 {
97 NN_OS_ERROR_IF_FAILED(nn::svc::SignalEvent(GetHandle()));
98 }
99
ClearSignal()100 inline void EventBase::ClearSignal()
101 {
102 NN_OS_ERROR_IF_FAILED(nn::svc::ClearEvent(GetHandle()));
103 }
104
105
106 /* Please see man pages for details
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133 */
134 class Event : public EventBase
135 {
136 public:
137
138 /* Please see man pages for details
139
140
141
142 */
Event(bool manualReset)143 explicit Event(bool manualReset) : EventBase(manualReset ? RESET_TYPE_STICKY: RESET_TYPE_ONESHOT) {}
144
145 /* Please see man pages for details
146
147
148 */
Event()149 Event() {}
150
151 /* Please see man pages for details
152
153
154
155 */
Initialize(bool manualReset)156 void Initialize(bool manualReset) { EventBase::Initialize(manualReset ? RESET_TYPE_STICKY: RESET_TYPE_ONESHOT); }
Initialize(ResetType resetType)157 void Initialize(ResetType resetType) { EventBase::Initialize(resetType); }
158
TryInitialize(bool manualReset)159 nn::Result TryInitialize(bool manualReset) { return EventBase::TryInitialize(manualReset ? RESET_TYPE_STICKY: RESET_TYPE_ONESHOT); }
160
161 /* Please see man pages for details
162
163
164
165
166 */
Finalize()167 void Finalize() { EventBase::Finalize(); }
168
169 /* Please see man pages for details
170
171 */
~Event()172 ~Event() {}
173
174 /* Please see man pages for details
175
176
177
178 */
Signal()179 void Signal() { EventBase::Signal(); }
180
181 /* Please see man pages for details
182
183
184
185 */
Wait()186 void Wait() { EventBase::WaitOne(); }
187
188 /* Please see man pages for details
189
190
191
192
193
194
195
196
197
198
199 */
Wait(nn::fnd::TimeSpan timeout)200 bool Wait(nn::fnd::TimeSpan timeout) { return EventBase::WaitOne(timeout); }
201
202 /* Please see man pages for details
203
204
205
206 */
ClearSignal()207 void ClearSignal() { EventBase::ClearSignal(); }
208
209 //----------------------------------------------------------------------
210 //
211 //
212 //
213 //
214 //
215 //
216 //
217 //
218 //----------------------------------------------------------------------
219 static s32 GetCurrentCount();
220
221 //----------------------------------------------------------------------
222 //
223 //
224 //
225 //----------------------------------------------------------------------
226 static s32 GetMaxCount();
227 };
228
229 }} // namespace nn::os
230
231 #endif // __cplusplus
232
233 // Below is the C declaration
234
235 #include <nn/util/detail/util_CLibImpl.h>
236
237 /* Please see man pages for details
238
239
240
241
242
243
244
245
246 */
247
248 /* Please see man pages for details
249
250
251
252 */
253 NN_UTIL_DETAIL_CLIBIMPL_DEFINE_BUFFER_CLASS(nnosEvent, nn::os::Event, 4, u32);
254 NN_UTIL_DETAIL_CLIBIMPL_DECLARE_CONVERSION(nnosEventToWaitObject, nnosEvent, nnosWaitObject);
255 NN_UTIL_DETAIL_CLIBIMPL_DECLARE_CONVERSION(nnosWaitObjectToEvent, nnosWaitObject, nnosEvent);
256
257 /* Please see man pages for details
258
259 */
260 NN_EXTERN_C void nnosEventInitialize(nnosEvent* this_, bool manualReset);
261
262 /* Please see man pages for details
263
264 */
265 NN_EXTERN_C bool nnosEventTryInitialize(nnosEvent* this_, bool manualReset);
266
267 /* Please see man pages for details
268
269 */
270 NN_EXTERN_C void nnosEventSignal(nnosEvent* this_);
271
272 /* Please see man pages for details
273
274 */
275 NN_EXTERN_C void nnosEventWaitSignal(nnosEvent* this_);
276
277 /* Please see man pages for details
278
279 */
280 NN_EXTERN_C bool nnosEventTryWaitSignal(nnosEvent* this_, s64 nanoSecondsTimeout);
281
282 /* Please see man pages for details
283
284 */
285 NN_EXTERN_C void nnosEventClearSignal(nnosEvent* this_);
286
287 /* Please see man pages for details
288
289 */
290 NN_EXTERN_C void nnosEventFinalize(nnosEvent* this_);
291
292 /*
293
294
295
296 */
297
298 #endif
299
300