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