Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_Linux_DeviceManager.h
Go to the documentation of this file.
1 /************************************************************************************
2 
3 Filename : OVR_Linux_DeviceManager.h
4 Content : Linux-specific DeviceManager header.
5 Created :
6 Authors :
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 #ifndef OVR_Linux_DeviceManager_h
28 #define OVR_Linux_DeviceManager_h
29 
30 #include "OVR_DeviceImpl.h"
31 
32 #include <unistd.h>
33 #include <sys/poll.h>
34 
35 
36 namespace OVR { namespace Linux {
37 
38 class DeviceManagerThread;
39 
40 //-------------------------------------------------------------------------------------
41 // ***** Linux DeviceManager
42 
44 {
45 public:
46  DeviceManager();
48 
49  // Initialize/Shutdowncreate and shutdown manger thread.
50  virtual bool Initialize(DeviceBase* parent);
51  virtual void Shutdown();
52 
54  virtual ThreadId GetThreadId() const;
55 
57 
58  virtual bool GetDeviceInfo(DeviceInfo* info) const;
59 
61 };
62 
63 //-------------------------------------------------------------------------------------
64 // ***** Device Manager Background Thread
65 
67 {
68  friend class DeviceManager;
69  enum { ThreadStackSize = 64 * 1024 };
70 public:
73 
74  virtual int Run();
75 
76  // ThreadCommandQueue notifications for CommandEvent handling.
77  virtual void OnPushNonEmpty_Locked() { write(CommandFd[1], this, 1); }
78  virtual void OnPopEmpty_Locked() { }
79 
80  class Notifier
81  {
82  public:
83  // Called when I/O is received
84  virtual void OnEvent(int i, int fd) = 0;
85 
86  // Called when timing ticks are updated.
87  // Returns the largest number of seconds this function can
88  // wait till next call.
89  virtual double OnTicks(double tickSeconds)
90  {
91  OVR_UNUSED1(tickSeconds);
92  return 1000.0;
93  }
94  };
95 
96  // Add I/O notifier
97  bool AddSelectFd(Notifier* notify, int fd);
98  bool RemoveSelectFd(Notifier* notify, int fd);
99 
100  // Add notifier that will be called at regular intervals.
101  bool AddTicksNotifier(Notifier* notify);
102  bool RemoveTicksNotifier(Notifier* notify);
103 
104 private:
105 
106  bool threadInitialized() { return CommandFd[0] != 0; }
107 
108  // pipe used to signal commands
109  int CommandFd[2];
110 
113 
115 
116  // Ticks notifiers - used for time-dependent events such as keep-alive.
118 };
119 
120 }} // namespace Linux::OVR
121 
122 #endif // OVR_Linux_DeviceManager_h
bool RemoveSelectFd(Notifier *notify, int fd)
virtual ThreadCommandQueue * GetThreadQueue()
Ptr< DeviceManagerThread > pThread
virtual bool GetDeviceInfo(DeviceInfo *info) const
#define OVR_UNUSED1(a1)
bool AddSelectFd(Notifier *notify, int fd)
virtual bool Initialize(DeviceBase *parent)
void * ThreadId
Definition: OVR_Threads.h:180
virtual ThreadId GetThreadId() const
virtual DeviceEnumerator EnumerateDevicesEx(const DeviceEnumerationArgs &args)
virtual double OnTicks(double tickSeconds)
virtual void OnEvent(int i, int fd)=0