OVR_Linux_DeviceManager.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   OVR_Linux_DeviceManager.h
00004 Content     :   Linux-specific DeviceManager header.
00005 Created     :   
00006 Authors     :   
00007 
00008 Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
00009 
00010 Use of this software is subject to the terms of the Oculus license
00011 agreement provided at the time of installation or download, or which
00012 otherwise accompanies this software in either electronic or hard copy form.
00013 
00014 *************************************************************************************/
00015 
00016 #ifndef OVR_Linux_DeviceManager_h
00017 #define OVR_Linux_DeviceManager_h
00018 
00019 #include "OVR_DeviceImpl.h"
00020 
00021 #include <unistd.h>
00022 #include <sys/poll.h>
00023 
00024 
00025 namespace OVR { namespace Linux {
00026 
00027 class DeviceManagerThread;
00028 
00029 //-------------------------------------------------------------------------------------
00030 // ***** Linux DeviceManager
00031 
00032 class DeviceManager : public DeviceManagerImpl
00033 {
00034 public:
00035     DeviceManager();
00036     ~DeviceManager();
00037 
00038     // Initialize/Shutdowncreate and shutdown manger thread.
00039     virtual bool Initialize(DeviceBase* parent);
00040     virtual void Shutdown();
00041 
00042     virtual ThreadCommandQueue* GetThreadQueue();
00043     virtual ThreadId GetThreadId() const;
00044 
00045     virtual DeviceEnumerator<> EnumerateDevicesEx(const DeviceEnumerationArgs& args);    
00046 
00047     virtual bool  GetDeviceInfo(DeviceInfo* info) const;
00048 
00049     Ptr<DeviceManagerThread> pThread;
00050 };
00051 
00052 //-------------------------------------------------------------------------------------
00053 // ***** Device Manager Background Thread
00054 
00055 class DeviceManagerThread : public Thread, public ThreadCommandQueue
00056 {
00057     friend class DeviceManager;
00058     enum { ThreadStackSize = 64 * 1024 };
00059 public:
00060     DeviceManagerThread();
00061     ~DeviceManagerThread();
00062 
00063     virtual int Run();
00064 
00065     // ThreadCommandQueue notifications for CommandEvent handling.
00066     virtual void OnPushNonEmpty_Locked() { write(CommandFd[1], this, 1); }
00067     virtual void OnPopEmpty_Locked()     { }
00068 
00069     class Notifier
00070     {
00071     public:
00072         // Called when I/O is received
00073         virtual void OnEvent(int i, int fd) = 0;
00074 
00075         // Called when timing ticks are updated.
00076         // Returns the largest number of microseconds this function can
00077         // wait till next call.
00078         virtual UInt64  OnTicks(UInt64 ticksMks)
00079         {
00080             OVR_UNUSED1(ticksMks);
00081             return Timer::MksPerSecond * 1000;
00082         }
00083     };
00084 
00085     // Add I/O notifier
00086     bool AddSelectFd(Notifier* notify, int fd);
00087     bool RemoveSelectFd(Notifier* notify, int fd);
00088 
00089     // Add notifier that will be called at regular intervals.
00090     bool AddTicksNotifier(Notifier* notify);
00091     bool RemoveTicksNotifier(Notifier* notify);
00092 
00093 private:
00094     
00095     bool threadInitialized() { return CommandFd[0] != 0; }
00096 
00097     // pipe used to signal commands
00098     int CommandFd[2];
00099 
00100     Array<struct pollfd>    PollFds;
00101     Array<Notifier*>        FdNotifiers;
00102 
00103     Event                   StartupEvent;
00104 
00105     // Ticks notifiers - used for time-dependent events such as keep-alive.
00106     Array<Notifier*>        TicksNotifiers;
00107 };
00108 
00109 }} // namespace Linux::OVR
00110 
00111 #endif // OVR_Linux_DeviceManager_h


oculus_sdk
Author(s):
autogenerated on Mon Oct 6 2014 03:01:18