Libpointing
An open-source cross-platform library to get raw events from pointing devices and master transfer functions.
 All Classes Functions Variables Typedefs Enumerator Pages
osxHIDPointingDevice.h
1 /* -*- mode: c++ -*-
2  *
3  * pointing/input/osx/osxHIDPointingDevice.h --
4  *
5  * Initial software
6  * Authors: Nicolas Roussel
7  * Copyright © Inria
8  *
9  * http://libpointing.org/
10  *
11  * This software may be used and distributed according to the terms of
12  * the GNU General Public License version 2 or any later version.
13  *
14  */
15 
16 #ifndef osxHIDPointingDevice_h
17 #define osxHIDPointingDevice_h
18 
19 #include <pointing/input/osx/osxHIDInputDevice.h>
20 #include <pointing/input/PointingDevice.h>
21 #include <pointing/utils/URI.h>
22 #include <pointing/utils/TimeStamp.h>
23 
24 #include <mach/mach_time.h>
25 
26 namespace pointing {
27 
29 
30  struct PointingReport {
31  TimeStamp::inttime t ;
32  int32_t dx, dy ;
33  uint32_t btns ;
34 
35  PointingReport(void) ;
36  PointingReport& operator = (PointingReport& src) ;
37  void clear(void) ; // preserves btns
38  bool isOlderThan(TimeStamp::inttime t) const ;
39  bool setButton(uint32_t index, uint32_t value) ;
40  std::string toString(void) const ;
41  } ;
42 
43  TimeStamp::inttime epoch ;
44  TimeStamp::inttime epoch_mach ;
45  mach_timebase_info_data_t mach_timebaseinfo ;
46 
47  int vendorID, productID ;
48  int primaryUsagePage, primaryUsage ;
49 
50  osxHIDInputDevice *hiddev ;
51  PointingCallback callback ;
52  void *callback_context ;
53  bool use_report_callback ;
54  bool use_queue_callback ;
55  PointingReport qreport ;
56 
57  double forced_cpi, forced_hz ;
58 
59  bool isUSB(void) ;
60  bool isBluetooth(void) ;
61 
62 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
63  static void hidReportCallback(void *context, IOReturn result, void *sender,
64  IOHIDReportType type, uint32_t reportID,
65  uint8_t *report, CFIndex reportLength,
66  uint64_t timeStamp) ;
67 #else
68  static void hidReportCallback(void *context, IOReturn result, void *sender,
69  IOHIDReportType type, uint32_t reportID,
70  uint8_t *report, CFIndex reportLength) ;
71 #endif
72 
73  static void hidQueueCallback(void *context, IOReturn result, void *sender) ;
74 
75  void report(osxHIDPointingDevice::PointingReport &r) ;
76 
77  public:
78 
79  osxHIDPointingDevice(URI uri) ;
80 
81  bool isActive(void) const ;
82 
83  int getVendorID(void) const ;
84  std::string getVendor(void) const ;
85  int getProductID(void) const ;
86  std::string getProduct(void) const ;
87  double getResolution(double *defval=0) const ;
88  double getUpdateFrequency(double *defval=0) const ;
89 
90  URI getURI(bool expanded=false, bool crossplatform=false) const ;
91 
92  void setPointingCallback(PointingCallback callback, void *context=0) ;
93 
94  void setDebugLevel(int level) ;
95 
96  ~osxHIDPointingDevice(void) ;
97 
98  } ;
99 
100 }
101 
102 #endif
std::string getProduct(void) const
Readable product name.
Definition: osxHIDPointingDevice.cpp:166
double getResolution(double *defval=0) const
Resolution of the mouse in CPI (counts per inch).
Definition: osxHIDPointingDevice.cpp:175
void(* PointingCallback)(void *context, TimeStamp::inttime timestamp, int dx, int dy, int buttons)
Definition: PointingDevice.h:74
The PointingDevice class is used to represent Pointing Devices connected to the computer or pseudo-de...
Definition: PointingDevice.h:36
void setDebugLevel(int level)
Sets the level of information for debugging purposes (default = 0).
Definition: osxHIDPointingDevice.cpp:207
bool isActive(void) const
Indicates whether the current device is active.
Definition: osxHIDPointingDevice.cpp:96
double getUpdateFrequency(double *defval=0) const
Update frequency of the mouse in Hz.
Definition: osxHIDPointingDevice.cpp:188
URI getURI(bool expanded=false, bool crossplatform=false) const
Constructs the URI according to the parameters of the device.
Definition: osxHIDPointingDevice.cpp:101
std::string getVendor(void) const
Readable vendor name.
Definition: osxHIDPointingDevice.cpp:152
int getVendorID(void) const
Vendor identifier number.
Definition: osxHIDPointingDevice.cpp:145
int getProductID(void) const
Product identifier number.
Definition: osxHIDPointingDevice.cpp:159
Definition: osxHIDPointingDevice.h:28
void setPointingCallback(PointingCallback callback, void *context=0)
Sets the callback function which is called when device events occur.
Definition: osxHIDPointingDevice.cpp:212