Skip to content
Browse files

error domain and PTDeviceChannel.deviceID is of type id instead of NS…

…Number (less specific)
  • Loading branch information...
1 parent 5bd1229 commit 1ed33eab82039830d7cb4fc6e407d2a7d5b2d957 @rsms committed Mar 30, 2012
Showing with 17 additions and 5 deletions.
  1. +10 −3 rusbhub/PTChannel.h
  2. +3 −0 rusbhub/PTProtocol.h
  3. +4 −2 rusbhub/PTProtocol.m
View
13 rusbhub/PTChannel.h
@@ -29,9 +29,11 @@
@property (copy) void(^onAccept)(PTChannel *serverChannel, PTChannel *channel);
@property (copy) void(^onEnd)(PTChannel *channel, NSError *error);
-// Create a new channel initialized with delegate=*delegate*.
+// Create a new channel using the shared PTProtocol for the current dispatch
+// queue, with *delegate*.
+ (PTChannel*)channelWithDelegate:(id<PTChannelDelegate>)delegate;
+
// Initialize a new frame channel, configuring it to use the calling queue's
// protocol instance (as returned by [PTProtocol sharedProtocolForQueue:
// dispatch_get_current_queue()])
@@ -40,7 +42,9 @@
// Initialize a new frame channel with a specific protocol.
- (id)initWithProtocol:(PTProtocol*)protocol;
-- (BOOL)startReadingFromConnectedChannel:(dispatch_io_t)channel error:(__autoreleasing NSError**)error;
+// Initialize a new frame channel with a specific protocol and delegate.
+- (id)initWithProtocol:(PTProtocol*)protocol delegate:(id<PTChannelDelegate>)delegate;
+
// Connect to a TCP port on a device connected over USB
- (void)connectToPort:(int)port overUSBHub:(PTUSBHub*)usbHub deviceID:(NSNumber*)deviceID callback:(void(^)(NSError *error))callback;
@@ -59,6 +63,9 @@
// or when the frame (and payload, if any) has been completely sent.
- (void)sendFrameOfType:(uint32_t)frameType tag:(uint32_t)tag withPayload:(dispatch_data_t)payload callback:(void(^)(NSError *error))callback;
+// Lower-level method to assign a connected dispatch IO channel to this channel
+- (BOOL)startReadingFromConnectedChannel:(dispatch_io_t)channel error:(__autoreleasing NSError**)error;
+
// Close the channel, preventing further reading and writing. Any ongoing and
// queued reads and writes will be aborted.
- (void)close;
@@ -73,7 +80,7 @@
// A simple subclass used for device-specific channels that contains a device
// identifier
@interface PTDeviceChannel : PTChannel
-@property (strong) NSNumber *deviceID;
+@property (strong) id deviceID;
@end
View
3 rusbhub/PTProtocol.h
@@ -21,6 +21,9 @@ static const uint32_t PTFrameNoTag = 0;
// Special frame type that signifies that the stream has ended.
static const uint32_t PTFrameTypeEndOfStream = 0;
+// NSError domain
+NSString *PTProtocolErrorDomain;
+
@interface PTProtocol : NSObject
View
6 rusbhub/PTProtocol.m
@@ -2,6 +2,8 @@
static const uint32_t PTProtocolVersion1 = 1;
+NSString *PTProtocolErrorDomain = @"PTProtocolError";
+
// This is what we send as the header for each frame.
typedef struct _PTFrame {
// The version of the frame and protocol.
@@ -183,7 +185,7 @@ - (void)readFrameOverChannel:(dispatch_io_t)channel callback:(void(^)(NSError *e
if (!allData || dispatch_data_get_size(allData) < sizeof(PTFrame)) {
if (allData) dispatch_release(allData);
- callback([[NSError alloc] initWithDomain:@"PTProtocolError" code:0 userInfo:nil], 0, 0, 0);
+ callback([[NSError alloc] initWithDomain:PTProtocolErrorDomain code:0 userInfo:nil], 0, 0, 0);
return;
}
@@ -199,7 +201,7 @@ - (void)readFrameOverChannel:(dispatch_io_t)channel callback:(void(^)(NSError *e
frame->version = ntohl(frame->version);
if (frame->version != PTProtocolVersion1) {
- callback([[NSError alloc] initWithDomain:@"PTProtocolError" code:0 userInfo:nil], 0, 0, 0);
+ callback([[NSError alloc] initWithDomain:PTProtocolErrorDomain code:0 userInfo:nil], 0, 0, 0);
} else {
frame->type = ntohl(frame->type);
frame->tag = ntohl(frame->tag);

0 comments on commit 1ed33ea

Please sign in to comment.
Something went wrong with that request. Please try again.