oculus1

view libovr/Src/osx/OVR_OSX_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_OSX_DeviceManager.h
4 Content : OSX specific DeviceManager header.
5 Created : March 14, 2013
6 Authors : Lee Cooper
8 Copyright : Copyright 2013 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_OSX_DeviceManager_h
17 #define OVR_OSX_DeviceManager_h
19 #include "OVR_DeviceImpl.h"
21 #include "Kernel/OVR_Timer.h"
23 #include <IOKit/hid/IOHIDManager.h>
24 #include <CoreGraphics/CGDirectDisplay.h>
25 #include <CoreGraphics/CGDisplayConfiguration.h>
28 namespace OVR { namespace OSX {
30 class DeviceManagerThread;
32 //-------------------------------------------------------------------------------------
33 // ***** OSX DeviceManager
35 class DeviceManager : public DeviceManagerImpl
36 {
37 public:
38 DeviceManager();
39 ~DeviceManager();
41 // Initialize/Shutdown manager thread.
42 virtual bool Initialize(DeviceBase* parent);
43 virtual void Shutdown();
45 virtual ThreadCommandQueue* GetThreadQueue();
46 virtual ThreadId GetThreadId() const;
48 virtual DeviceEnumerator<> EnumerateDevicesEx(const DeviceEnumerationArgs& args);
50 virtual bool GetDeviceInfo(DeviceInfo* info) const;
52 protected:
53 static void displayReconfigurationCallBack (CGDirectDisplayID display,
54 CGDisplayChangeSummaryFlags flags,
55 void *userInfo);
57 public: // data
58 Ptr<DeviceManagerThread> pThread;
59 };
61 //-------------------------------------------------------------------------------------
62 // ***** Device Manager Background Thread
64 class DeviceManagerThread : public Thread, public ThreadCommandQueue
65 {
66 friend class DeviceManager;
67 enum { ThreadStackSize = 32 * 1024 };
68 public:
69 DeviceManagerThread();
70 ~DeviceManagerThread();
72 virtual int Run();
74 // ThreadCommandQueue notifications for CommandEvent handling.
75 virtual void OnPushNonEmpty_Locked()
76 {
77 CFRunLoopSourceSignal(CommandQueueSource);
78 CFRunLoopWakeUp(RunLoop);
79 }
81 virtual void OnPopEmpty_Locked() {}
84 // Notifier used for different updates (EVENT or regular timing or messages).
85 class Notifier
86 {
87 public:
89 // Called when timing ticks are updated. // Returns the largest number of microseconds
90 // this function can wait till next call.
91 virtual UInt64 OnTicks(UInt64 ticksMks)
92 { OVR_UNUSED1(ticksMks); return Timer::MksPerSecond * 1000; }
93 };
95 // Add notifier that will be called at regular intervals.
96 bool AddTicksNotifier(Notifier* notify);
97 bool RemoveTicksNotifier(Notifier* notify);
99 CFRunLoopRef GetRunLoop()
100 { return RunLoop; }
102 void Shutdown();
103 private:
104 CFRunLoopRef RunLoop;
106 CFRunLoopSourceRef CommandQueueSource;
108 static void staticCommandQueueSourceCallback(void* pContext);
109 void commandQueueSourceCallback();
111 Event StartupEvent;
113 // Ticks notifiers. Used for time-dependent events such as keep-alive.
114 Array<Notifier*> TicksNotifiers;
115 };
117 }} // namespace OSX::OVR
119 #endif // OVR_OSX_DeviceManager_h