OVR_Win32_DeviceStatus.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   OVR_Win32_DeviceStatus.h
00004 Content     :   Win32-specific DeviceStatus header.
00005 Created     :   January 24, 2013
00006 Authors     :   Lee Cooper
00007 
00008 Copyright   :   Copyright 2013 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_Win32_DeviceStatus_h
00017 #define OVR_Win32_DeviceStatus_h
00018 
00019 #include <windows.h>
00020 #include "Kernel/OVR_String.h"
00021 #include "Kernel/OVR_RefCount.h"
00022 #include "Kernel/OVR_Array.h"
00023 
00024 namespace OVR { namespace Win32 {
00025 
00026 //-------------------------------------------------------------------------------------
00027 // ***** DeviceStatus
00028 //
00029 // DeviceStatus abstracts the handling of windows messages of interest for
00030 // example the WM_DEVICECHANGED message which occurs when a device is plugged/unplugged.
00031 // The device manager thread creates an instance of this class and passes its pointer
00032 // in the constructor. That thread is also responsible for periodically calling 'ProcessMessages'
00033 // to process queued windows messages. The client is notified via the 'OnMessage' method
00034 // declared in the 'DeviceMessages::Notifier' interface.
00035 class DeviceStatus : public RefCountBase<DeviceStatus>
00036 {
00037 public:
00038 
00039         // Notifier used for device messages.
00040         class Notifier  
00041         {
00042         public:
00043                 enum MessageType
00044                 {
00045                         DeviceAdded     = 0,
00046                         DeviceRemoved   = 1,
00047                 };
00048 
00049                 virtual bool OnMessage(MessageType type, const String& devicePath) 
00050         { OVR_UNUSED2(type, devicePath); return true; }
00051         };
00052 
00053         DeviceStatus(Notifier* const pClient);
00054         ~DeviceStatus();
00055 
00056         void operator = (const DeviceStatus&);  // No assignment implementation.
00057 
00058         bool Initialize();
00059         void ShutDown();
00060 
00061         void ProcessMessages();
00062 
00063 private:        
00064     enum 
00065     { 
00066         MaxUSBRecoveryAttempts  = 20,
00067         USBRecoveryTimeInterval = 500   // ms
00068     };
00069     struct RecoveryTimerDesc
00070     {
00071         UINT_PTR    TimerId;
00072         String      DevicePath;
00073         unsigned    NumAttempts;
00074     };
00075 
00076         static LRESULT CALLBACK WindowsMessageCallback( HWND hwnd, 
00077                                                     UINT message, 
00078                                                     WPARAM wParam, 
00079                                                     LPARAM lParam);
00080 
00081         bool MessageCallback(WORD messageType, const String& devicePath);
00082 
00083     void CleanupRecoveryTimer(UPInt index);
00084     RecoveryTimerDesc* FindRecoveryTimer(UINT_PTR timerId, UPInt* pindex);
00085     void FindAndCleanupRecoveryTimer(const String& devicePath);
00086 
00087 private: // data
00088     Notifier* const     pNotificationClient;    // Don't reference count a back-pointer.
00089 
00090     HWND                hMessageWindow;
00091     HDEVNOTIFY          hDeviceNotify;
00092 
00093     UINT_PTR            LastTimerId;
00094     Array<RecoveryTimerDesc> RecoveryTimers;
00095 
00096     GUID                HidGuid;
00097 };
00098 
00099 }} // namespace OVR::Win32
00100 
00101 #endif // OVR_Win32_DeviceStatus_h


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