Libpointing
An open-source cross-platform library to get raw events from pointing devices and master transfer functions.
DisplayDeviceManager.h
1 /* -*- mode: c++ -*-
2  *
3  * pointing/output/DisplayDeviceManager.h --
4  *
5  * Initial software
6  * Authors: Izzat Mukhanov
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 #include <set>
17 #include <string>
18 
19 #ifndef DISPLAYDEVICEMANAGER_H
20 #define DISPLAYDEVICEMANAGER_H
21 
22 namespace pointing
23 {
25  {
26  std::string devURI;
27  std::string name;
28 
29  int width; // In pixels
30  int height;
31 
32  DisplayDeviceDescriptor(std::string devURI = "", std::string name = "")
33  :devURI(devURI),name(name),width(-1),height(-1)
34  { }
35 
36  bool operator < (const DisplayDeviceDescriptor& rhs) const;
37  };
38 
39  typedef std::set<DisplayDeviceDescriptor> DisplayDescriptorSet;
40  typedef DisplayDescriptorSet::iterator DisplayDescriptorIterator;
41  typedef DisplayDescriptorSet::const_iterator DisplayDescriptorConstIterator;
42 
44  {
45  typedef void (*DeviceUpdateCallback)(void *context, const DisplayDeviceDescriptor &descriptor, bool wasAdded);
46 
47  struct CallbackInfo
48  {
49  DeviceUpdateCallback callbackFunc;
50  void *context;
51  CallbackInfo(DeviceUpdateCallback callbackFunc, void *context)
52  :callbackFunc(callbackFunc),context(context) { }
53 
54  bool operator < (const CallbackInfo& rhs) const
55  {
56  if (context < rhs.context) return true;
57  if (context > rhs.context) return false;
58 
59  return callbackFunc < rhs.callbackFunc;
60  }
61  };
62 
63  protected:
64  DisplayDeviceManager():callback(NULL) {}
65  DeviceUpdateCallback callback;
66 
67  virtual ~DisplayDeviceManager(void) {}
68  static DisplayDeviceManager *singleManager;
69 
70  DisplayDescriptorSet descriptors;
71 
72  std::set<CallbackInfo> callbackInfos;
73  typedef std::set<CallbackInfo>::iterator CallbackInfoIterator;
74 
75  void callCallbackFunctions(DisplayDeviceDescriptor &descriptor, bool wasAdded);
76 
77  public:
78 
83  void addDeviceUpdateCallback(DeviceUpdateCallback callback, void *context);
84 
89  void removeDeviceUpdateCallback(DeviceUpdateCallback callback, void *context);
90 
95  static DisplayDeviceManager *get();
96 
101  size_t size() const { return descriptors.size(); }
102 
103  //static void destroy();
104 
105  /*
106  * Delegate the iteration to the inner set of the descriptors
107  */
109  DisplayDescriptorIterator begin() { return descriptors.begin(); }
110  DisplayDescriptorIterator end() { return descriptors.end(); }
112 
113  protected:
114  void addDevice(DisplayDeviceDescriptor &descriptor);
115  void removeDevice(DisplayDeviceDescriptor &descriptor);
116  };
117 }
118 
119 #endif // DISPLAYDEVICEMANAGER_H
Definition: DummyPointingDevice.cpp:23
void addDeviceUpdateCallback(DeviceUpdateCallback callback, void *context)
Adds the callback function which is called when a device was added or removed.
Definition: DisplayDeviceManager.cpp:93
void removeDeviceUpdateCallback(DeviceUpdateCallback callback, void *context)
Removes the callback function which is called when a device was added or removed. ...
Definition: DisplayDeviceManager.cpp:99
size_t size() const
size
Definition: DisplayDeviceManager.h:101
Definition: DisplayDeviceManager.h:24
Definition: DisplayDeviceManager.h:43