Treehopper C++ API
ConnectionService.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Treehopper.h"
4 #include "TreehopperUsb.h"
5 #include "UsbConnection.h"
6 
7 #ifdef __APPLE__
8 #include <IOKit/IOKitLib.h>
9 #include <IOKit/IOTypes.h>
10 #include <CoreFoundation/CFRunLoop.h>
11 #endif
12 #ifdef __linux__
13 #include "libusb-1.0/libusb.h"
14 #endif
15 
16 #include <vector>
17 
18 namespace Treehopper {
21  public:
23 
25 
28  static ConnectionService instance;
29  return instance;
30  }
31 
33  TreehopperUsb& getFirstDevice();
34 
36  vector<TreehopperUsb> boards;
37  private:
38  void scan();
39 
40 #ifdef __linux__
41  libusb_context *context;
42 #endif
43 
44 #ifdef __APPLE__
45  CFRunLoopRef gRunLoop;
46  static void DeviceAdded(void *refCon, io_iterator_t iterator);
47  static void DeviceRemoved(void *refCon, io_service_t service, natural_t messageType, void *messageArgument);
48  static std::mutex boardCollectionMutex;
49  static std::condition_variable boardCollectionCondition;
50  static std::thread deviceListenerThread;
51  static IONotificationPortRef gNotifyPort;
52 #endif
53  };
54 }
55 
vector< TreehopperUsb > boards
Gets the collection of TreehopperUsb boards connected to the computer.
Definition: ConnectionService.h:36
Provides TreehopperUsb discovery and factory duties.
Definition: ConnectionService.h:20
The core class for communicating with Treehopper USB boards.
Definition: TreehopperUsb.h:59
static ConnectionService & instance()
Gets the ConnectionService instance to use for TreehopperUsb discovery.
Definition: ConnectionService.h:27
Definition: AdcPin.h:3
#define TREEHOPPER_API
Definition: Treehopper.h:17