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