MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
AppleRemote.h
Go to the documentation of this file.
1 #ifndef APPLEREMOTE
2 #define APPLEREMOTE
3 
4 // C++ headers
5 #include <string>
6 #include <vector>
7 #include <map>
8 
9 // MythTV headers
10 #include "mthread.h"
11 
12 #include <QTimer>
13 
14 #include <IOKit/IOKitLib.h>
15 #include <IOKit/IOCFPlugIn.h>
16 #include <IOKit/hid/IOHIDLib.h>
17 #include <IOKit/hid/IOHIDKeys.h>
18 #include <CoreFoundation/CoreFoundation.h>
19 
20 class AppleRemote : public QObject, public MThread
21 {
22  Q_OBJECT
23 public:
24  enum Event
25  { // label/meaning on White ... and Aluminium remote
26  Up = 0, // VolumePlus Up
27  Down, // VolumeMinus Down
29  Select, // Play Select
35  PlayHold, // was PlaySleep
37  PlayPause, // Play or Pause
38  Undefined // Used to handle the Apple TV > v2.3
39  };
40 
41  class Listener
42  {
43  public:
44  virtual ~Listener();
45  virtual void appleRemoteButton(Event button, bool pressedDown) = 0;
46  };
47 
48  static AppleRemote * Get();
49  ~AppleRemote();
50 
51  bool isListeningToRemote();
53  Listener* listener() { return _listener; }
56  void startListening();
57  void stopListening();
58  void run();
59 
60 protected:
61  AppleRemote(); // will be a singleton class
62 
64 
65 
66 private:
68  IOHIDDeviceInterface** hidDeviceInterface;
69  IOHIDQueueInterface** queue;
70  std::vector<int> cookies;
71  std::map< std::string, Event > cookieToButtonMapping;
72  int remoteId;
74 
78  bool mKeyIsDown;
79  QTimer* mCallbackTimer;
80 
81  void _initCookieMap();
82  bool _initCookies();
83  bool _createDeviceInterface(io_object_t hidDevice);
84  bool _openDevice();
85 
86  static void QueueCallbackFunction(void* target, IOReturn result,
87  void* refcon, void* sender);
88  void _queueCallbackFunction(IOReturn result,
89  void* refcon, void* sender);
90  void _queueCallbackATV23(IOReturn result);
91  void _handleEventWithCookieString(std::string cookieString,
92  SInt32 sumOfValues);
93  void _handleEventATV23(std::string cookieString, SInt32 sumOfValues);
94 
95 private slots:
96  // Key up event handling on the ATV v2.3 and above
97  void TimeoutHandler();
98 };
99 
100 #endif // APPLEREMOTE