Lookin_PTUSBHub.h 2.9 KB

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