oculus1
view libovr/Src/linux/OVR_Linux_DeviceManager.h @ 24:8419d8a13cee
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 04 Oct 2013 14:50:26 +0300 |
parents | |
children |
line source
1 /************************************************************************************
3 Filename : OVR_Linux_DeviceManager.h
4 Content : Linux-specific DeviceManager header.
5 Created :
6 Authors :
8 Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
10 Use of this software is subject to the terms of the Oculus license
11 agreement provided at the time of installation or download, or which
12 otherwise accompanies this software in either electronic or hard copy form.
14 *************************************************************************************/
16 #ifndef OVR_Linux_DeviceManager_h
17 #define OVR_Linux_DeviceManager_h
19 #include "OVR_DeviceImpl.h"
21 #include <unistd.h>
22 #include <sys/poll.h>
25 namespace OVR { namespace Linux {
27 class DeviceManagerThread;
29 //-------------------------------------------------------------------------------------
30 // ***** Linux DeviceManager
32 class DeviceManager : public DeviceManagerImpl
33 {
34 public:
35 DeviceManager();
36 ~DeviceManager();
38 // Initialize/Shutdowncreate and shutdown manger thread.
39 virtual bool Initialize(DeviceBase* parent);
40 virtual void Shutdown();
42 virtual ThreadCommandQueue* GetThreadQueue();
43 virtual ThreadId GetThreadId() const;
45 virtual DeviceEnumerator<> EnumerateDevicesEx(const DeviceEnumerationArgs& args);
47 virtual bool GetDeviceInfo(DeviceInfo* info) const;
49 Ptr<DeviceManagerThread> pThread;
50 };
52 //-------------------------------------------------------------------------------------
53 // ***** Device Manager Background Thread
55 class DeviceManagerThread : public Thread, public ThreadCommandQueue
56 {
57 friend class DeviceManager;
58 enum { ThreadStackSize = 64 * 1024 };
59 public:
60 DeviceManagerThread();
61 ~DeviceManagerThread();
63 virtual int Run();
65 // ThreadCommandQueue notifications for CommandEvent handling.
66 virtual void OnPushNonEmpty_Locked() { write(CommandFd[1], this, 1); }
67 virtual void OnPopEmpty_Locked() { }
69 class Notifier
70 {
71 public:
72 // Called when I/O is received
73 virtual void OnEvent(int i, int fd) = 0;
75 // Called when timing ticks are updated.
76 // Returns the largest number of microseconds this function can
77 // wait till next call.
78 virtual UInt64 OnTicks(UInt64 ticksMks)
79 {
80 OVR_UNUSED1(ticksMks);
81 return Timer::MksPerSecond * 1000;
82 }
83 };
85 // Add I/O notifier
86 bool AddSelectFd(Notifier* notify, int fd);
87 bool RemoveSelectFd(Notifier* notify, int fd);
89 // Add notifier that will be called at regular intervals.
90 bool AddTicksNotifier(Notifier* notify);
91 bool RemoveTicksNotifier(Notifier* notify);
93 private:
95 bool threadInitialized() { return CommandFd[0] != 0; }
97 // pipe used to signal commands
98 int CommandFd[2];
100 Array<struct pollfd> PollFds;
101 Array<Notifier*> FdNotifiers;
103 Event StartupEvent;
105 // Ticks notifiers - used for time-dependent events such as keep-alive.
106 Array<Notifier*> TicksNotifiers;
107 };
109 }} // namespace Linux::OVR
111 #endif // OVR_Linux_DeviceManager_h