1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: hid_HidBase.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: 12449 $
14 *---------------------------------------------------------------------------*/
15
16 /*! @file
17 @brief HidBase クラス を定義します。
18
19 */
20
21 #ifndef NN_HID_CTR_HID_HIDBASE_H_
22 #define NN_HID_CTR_HID_HIDBASE_H_
23
24 #include <nn/Handle.h>
25 #include <nn/Result.h>
26 #include <nn/types.h>
27 #include <nn/fnd/fnd_Timespan.h>
28 #include <nn/os/os_Synchronization.h>
29 #include <nn/os/os_Event.h>
30 #include <nn/os/os_Mutex.h>
31
32 namespace nn {
33 namespace hid {
34 namespace CTR {
35
36
37 /*!
38 @brief HID の基底 クラスです。
39 */
40 class HidBase : public nn::os::EventBase
41 {
42 protected:
HidBase()43 HidBase() : nn::os::EventBase() {}
~HidBase()44 ~HidBase() {}
45
46 private:
47 nn::os::Mutex m_Mutex;
48 uptr m_pResource;
49
50 public:
51 /*!
52 @brief デバイスがサンプリングするのを待ちます。
53 @return なし。
54 */
55 void WaitSampling( );
56
57 /*!
58 @brief デバイスがサンプリングするのをタイムアウトつきで待ちます。
59
60 @param[in] timeout タイムアウト時間を指定します。0 を指定すると即座に処理を返します。
61
62 @return タイムアウト時間までにイベントが発生したかを返します。
63 */
64 bool WaitSampling(nn::fnd::TimeSpan timeout);
65
66 /*!
67 @brief 引数で指定したデバイスのうち一つがサンプリングするのを待ちます。
68
69 @param[in] devices HidBaseの配列を指定します。
70 @param[in] numDevices HidBaseの数を指定します。
71
72 @return 処理の結果を返します。
73 @retval 0以上 サンプリングされたデバイスのインデックスを返します。
74 */
75 static s32 WaitSamplingAny(HidBase* devices[], s32 numDevices);
76
77 /*!
78 @brief 引数で指定したデバイスのうち一つがサンプリングするのをタイムアウトつきで待ちます。
79
80 @param[in] devices HidBaseの配列を指定します。
81 @param[in] numDevices HidBaseの数を指定します。
82
83 @param[in] timeout タイムアウト時間を指定します。
84
85 @return 処理の結果を返します。
86 @retval 0以上 サンプリングされたデバイスのインデックスを返します。
87 @retval 0未満 タイムアウトしたことを意味します。
88 */
89 static s32 WaitSamplingAny(HidBase* devices[], s32 numDevices, nn::fnd::TimeSpan timeout);
90
91 nn::os::Mutex* GetMutex();
92 uptr GetResource();
93 void SetResource(uptr resource);
94 };
95
96
97
98 // inline 定義
WaitSampling()99 inline void HidBase::WaitSampling( )
100 {
101 WaitOne();
102 }
103
WaitSampling(nn::fnd::TimeSpan timeout)104 inline bool HidBase::WaitSampling(nn::fnd::TimeSpan timeout)
105 {
106 return WaitOne(timeout);
107 }
108
109
WaitSamplingAny(HidBase * devices[],s32 numDevices)110 inline s32 HidBase::WaitSamplingAny(HidBase* devices[], s32 numDevices)
111 {
112 return nn::os::WaitObject::WaitAny(reinterpret_cast<nn::os::WaitObject**>(devices), numDevices);
113 }
114
WaitSamplingAny(HidBase * devices[],s32 numDevices,nn::fnd::TimeSpan timeout)115 inline s32 HidBase::WaitSamplingAny(HidBase* devices[], s32 numDevices, nn::fnd::TimeSpan timeout)
116 {
117 return nn::os::WaitObject::WaitAny(reinterpret_cast<nn::os::WaitObject**>(devices), numDevices, timeout);
118 }
119
GetMutex()120 inline nn::os::Mutex* HidBase::GetMutex()
121 {
122 return &m_Mutex;
123 }
124
GetResource()125 inline uptr HidBase::GetResource()
126 {
127 return m_pResource;
128 }
129
SetResource(uptr resource)130 inline void HidBase::SetResource(uptr resource)
131 {
132 m_pResource = resource;
133 }
134
135 } // namespace CTR {
136 } // namespace hid {
137 } // namespace nn {
138
139 #endif // #ifndef NN_HID_CTR_HID_HIDBASE_H_
140