Lookin_PTUSBHub.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifdef SHOULD_COMPILE_LOOKIN_SERVER
  2. #include <dispatch/dispatch.h>
  3. #import <Foundation/Foundation.h>
  4. // Lookin_PTUSBDeviceDidAttachNotification
  5. // Posted when a device has been attached. Also posted for each device that is
  6. // already attached when the Lookin_PTUSBHub starts listening.
  7. //
  8. // .userInfo = {
  9. // DeviceID = 3;
  10. // MessageType = Attached;
  11. // Properties = {
  12. // ConnectionSpeed = 480000000;
  13. // ConnectionType = USB;
  14. // DeviceID = 3;
  15. // LocationID = 1234567890;
  16. // ProductID = 1234;
  17. // SerialNumber = 0123456789abcdef0123456789abcdef01234567;
  18. // };
  19. // }
  20. //
  21. FOUNDATION_EXPORT NSString * const Lookin_PTUSBDeviceDidAttachNotification;
  22. // Lookin_PTUSBDeviceDidDetachNotification
  23. // Posted when a device has been detached.
  24. //
  25. // .userInfo = {
  26. // DeviceID = 3;
  27. // MessageType = Detached;
  28. // }
  29. //
  30. FOUNDATION_EXPORT NSString * const Lookin_PTUSBDeviceDidDetachNotification;
  31. // NSError domain
  32. FOUNDATION_EXPORT NSString * const Lookin_PTUSBHubErrorDomain;
  33. // Error codes returned with NSError.code for NSError domain Lookin_PTUSBHubErrorDomain
  34. typedef enum {
  35. PTUSBHubErrorBadDevice = 2,
  36. PTUSBHubErrorConnectionRefused = 3,
  37. } PTUSBHubError;
  38. @interface Lookin_PTUSBHub : NSObject
  39. // Shared, implicitly opened hub.
  40. + (Lookin_PTUSBHub*)sharedHub;
  41. // Connect to a TCP *port* on a device, while the actual transport is over USB.
  42. // Upon success, *error* is nil and *channel* is a duplex I/O channel.
  43. // You can retrieve the underlying file descriptor using
  44. // dispatch_io_get_descriptor(channel). The dispatch_io_t channel behaves just
  45. // like any stream type dispatch_io_t, making it possible to use the same logic
  46. // for both USB bridged connections and e.g. ethernet-based connections.
  47. //
  48. // *onStart* is called either when a connection failed, in which case the error
  49. // argument is non-nil, or when the connection was successfully established (the
  50. // error argument is nil). Must not be NULL.
  51. //
  52. // *onEnd* is called when a connection was open and just did close. If the error
  53. // argument is non-nil, the channel closed because of an error. Pass NULL for no
  54. // callback.
  55. //
  56. - (void)connectToDevice:(NSNumber*)deviceID
  57. port:(int)port
  58. onStart:(void(^)(NSError *error, dispatch_io_t channel))onStart
  59. onEnd:(void(^)(NSError *error))onEnd;
  60. // Start listening for devices. You only need to invoke this method on custom
  61. // instances to start receiving notifications. The shared instance returned from
  62. // +sharedHub is always in listening mode.
  63. //
  64. // *onStart* is called either when the system failed to start listening, in
  65. // which case the error argument is non-nil, or when the receiver is listening.
  66. // Pass NULL for no callback.
  67. //
  68. // *onEnd* is called when listening stopped. If the error argument is non-nil,
  69. // listening stopped because of an error. Pass NULL for no callback.
  70. //
  71. - (void)listenOnQueue:(dispatch_queue_t)queue
  72. onStart:(void(^)(NSError*))onStart
  73. onEnd:(void(^)(NSError*))onEnd;
  74. @end
  75. #endif /* SHOULD_COMPILE_LOOKIN_SERVER */