Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CAPI_GlobalState.cpp
Go to the documentation of this file.
1 /************************************************************************************
2 
3 Filename : CAPI_GlobalState.cpp
4 Content : Maintains global state of the CAPI
5 Created : January 24, 2014
6 Authors : Michael Antonov
7 
8 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
9 
10 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
12 which is provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
14 
15 You may obtain a copy of the License at
16 
17 http://www.oculusvr.com/licenses/LICENSE-3.1
18 
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
24 
25 ************************************************************************************/
26 
27 #include "CAPI_GlobalState.h"
28 
29 namespace OVR { namespace CAPI {
30 
31 
32 //-------------------------------------------------------------------------------------
33 // Open Questions / Notes
34 
35 // 2. Detect HMDs.
36 // Challenge: If we do everything through polling, it would imply we want all the devices
37 // initialized. However, there may be multiple rifts, extra sensors, etc,
38 // which shouldn't be allocated.
39 //
40 
41 // How do you reset orientation Quaternion?
42 // Can you change IPD?
43 
44 
45 
46 //-------------------------------------------------------------------------------------
47 // ***** OVRGlobalState
48 
49 // Global instance
50 GlobalState* GlobalState::pInstance = 0;
51 
52 
54 {
56  // Handle the DeviceManager's messages
57  pManager->AddMessageHandler( this );
59 
60  // PhoneSensors::Init();
61 }
62 
64 {
66  OVR_ASSERT(HMDs.IsEmpty());
67 }
68 
70 {
71  // Need to use separate lock for device enumeration, as pManager->GetHandlerLock()
72  // would produce deadlocks here.
74 
75  EnumeratedDevices.Clear();
76 
77  DeviceEnumerator<HMDDevice> e = pManager->EnumerateDevices<HMDDevice>();
78  while(e.IsAvailable())
79  {
80  EnumeratedDevices.PushBack(DeviceHandle(e));
81  e.Next();
82  }
83 
84  return (int)EnumeratedDevices.GetSize();
85 }
86 
87 
89 {
91 
92  if (index >= (int)EnumeratedDevices.GetSize())
93  return 0;
94  return EnumeratedDevices[index].CreateDeviceTyped<HMDDevice>();
95 }
96 
97 
99 {
100  Lock::Locker lock(pManager->GetHandlerLock());
101  HMDs.PushBack(hmd);
102 }
104 {
105  Lock::Locker lock(pManager->GetHandlerLock());
106  hmd->RemoveNode();
107 }
108 
110 {
111  Lock::Locker lock(pManager->GetHandlerLock());
112  for(HMDState* hmd = HMDs.GetFirst(); !HMDs.IsNull(hmd); hmd = hmd->pNext)
113  hmd->NotifyAddDevice(deviceType);
114 }
115 
117 {
118  if (msg.Type == Message_DeviceAdded || msg.Type == Message_DeviceRemoved)
119  {
120  if (msg.pDevice == pManager)
121  {
122  const MessageDeviceStatus& statusMsg =
123  static_cast<const MessageDeviceStatus&>(msg);
124 
125  if (msg.Type == Message_DeviceAdded)
126  {
127  //LogText("OnMessage DeviceAdded.\n");
128 
129  // We may have added a sensor/other device; notify any HMDs that might
130  // need it to check for it later.
131  NotifyHMDs_AddDevice(statusMsg.Handle.GetType());
132  }
133  else
134  {
135  //LogText("OnMessage DeviceRemoved.\n");
136  }
137  }
138  }
139 }
140 
141 
142 }} // namespace OVR::CAPI
void OnMessage(const Message &msg)
Ptr< DeviceManager > pManager
DeviceType GetType() const
MessageType Type
void AddHMD(HMDState *hmd)
enum _deviceType deviceType
void RemoveHMD(HMDState *hmd)
void RemoveNode()
Definition: OVR_List.h:58
void NotifyHMDs_AddDevice(DeviceType deviceType)
#define OVR_ASSERT(p)
List< HMDState > HMDs
DeviceBase * pDevice
static DeviceManager * Create()
bool IsAvailable() const
HMDDevice * CreateDevice(int index)
int char * index(const char *__s, int __c) __THROW __attribute_pure__ __nonnull((1))
static GlobalState * pInstance
Array< DeviceHandle > EnumeratedDevices