oculus1
diff libovr/Src/linux/OVR_Linux_DeviceManager.h @ 1:e2f9e4603129
added LibOVR and started a simple vr wrapper.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 Sep 2013 16:14:59 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libovr/Src/linux/OVR_Linux_DeviceManager.h Sat Sep 14 16:14:59 2013 +0300 1.3 @@ -0,0 +1,111 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +Filename : OVR_Linux_DeviceManager.h 1.7 +Content : Linux-specific DeviceManager header. 1.8 +Created : 1.9 +Authors : 1.10 + 1.11 +Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved. 1.12 + 1.13 +Use of this software is subject to the terms of the Oculus license 1.14 +agreement provided at the time of installation or download, or which 1.15 +otherwise accompanies this software in either electronic or hard copy form. 1.16 + 1.17 +*************************************************************************************/ 1.18 + 1.19 +#ifndef OVR_Linux_DeviceManager_h 1.20 +#define OVR_Linux_DeviceManager_h 1.21 + 1.22 +#include "OVR_DeviceImpl.h" 1.23 + 1.24 +#include <unistd.h> 1.25 +#include <sys/poll.h> 1.26 + 1.27 + 1.28 +namespace OVR { namespace Linux { 1.29 + 1.30 +class DeviceManagerThread; 1.31 + 1.32 +//------------------------------------------------------------------------------------- 1.33 +// ***** Linux DeviceManager 1.34 + 1.35 +class DeviceManager : public DeviceManagerImpl 1.36 +{ 1.37 +public: 1.38 + DeviceManager(); 1.39 + ~DeviceManager(); 1.40 + 1.41 + // Initialize/Shutdowncreate and shutdown manger thread. 1.42 + virtual bool Initialize(DeviceBase* parent); 1.43 + virtual void Shutdown(); 1.44 + 1.45 + virtual ThreadCommandQueue* GetThreadQueue(); 1.46 + virtual ThreadId GetThreadId() const; 1.47 + 1.48 + virtual DeviceEnumerator<> EnumerateDevicesEx(const DeviceEnumerationArgs& args); 1.49 + 1.50 + virtual bool GetDeviceInfo(DeviceInfo* info) const; 1.51 + 1.52 + Ptr<DeviceManagerThread> pThread; 1.53 +}; 1.54 + 1.55 +//------------------------------------------------------------------------------------- 1.56 +// ***** Device Manager Background Thread 1.57 + 1.58 +class DeviceManagerThread : public Thread, public ThreadCommandQueue 1.59 +{ 1.60 + friend class DeviceManager; 1.61 + enum { ThreadStackSize = 64 * 1024 }; 1.62 +public: 1.63 + DeviceManagerThread(); 1.64 + ~DeviceManagerThread(); 1.65 + 1.66 + virtual int Run(); 1.67 + 1.68 + // ThreadCommandQueue notifications for CommandEvent handling. 1.69 + virtual void OnPushNonEmpty_Locked() { write(CommandFd[1], this, 1); } 1.70 + virtual void OnPopEmpty_Locked() { } 1.71 + 1.72 + class Notifier 1.73 + { 1.74 + public: 1.75 + // Called when I/O is received 1.76 + virtual void OnEvent(int i, int fd) = 0; 1.77 + 1.78 + // Called when timing ticks are updated. 1.79 + // Returns the largest number of microseconds this function can 1.80 + // wait till next call. 1.81 + virtual UInt64 OnTicks(UInt64 ticksMks) 1.82 + { 1.83 + OVR_UNUSED1(ticksMks); 1.84 + return Timer::MksPerSecond * 1000; 1.85 + } 1.86 + }; 1.87 + 1.88 + // Add I/O notifier 1.89 + bool AddSelectFd(Notifier* notify, int fd); 1.90 + bool RemoveSelectFd(Notifier* notify, int fd); 1.91 + 1.92 + // Add notifier that will be called at regular intervals. 1.93 + bool AddTicksNotifier(Notifier* notify); 1.94 + bool RemoveTicksNotifier(Notifier* notify); 1.95 + 1.96 +private: 1.97 + 1.98 + bool threadInitialized() { return CommandFd[0] != 0; } 1.99 + 1.100 + // pipe used to signal commands 1.101 + int CommandFd[2]; 1.102 + 1.103 + Array<struct pollfd> PollFds; 1.104 + Array<Notifier*> FdNotifiers; 1.105 + 1.106 + Event StartupEvent; 1.107 + 1.108 + // Ticks notifiers - used for time-dependent events such as keep-alive. 1.109 + Array<Notifier*> TicksNotifiers; 1.110 +}; 1.111 + 1.112 +}} // namespace Linux::OVR 1.113 + 1.114 +#endif // OVR_Linux_DeviceManager_h