-
-
Save 0xc010d/2044858 to your computer and use it in GitHub Desktop.
TVRemote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface TVRemote : NSObject | |
@property (nonatomic, retain) TVRemoteAbstract *currentRemote; | |
- (void)createSocketRemote; | |
@end | |
@implementation TVRemote | |
- (void)createSocketRemote { | |
self.currentRemote = [[TVRemoteSocket alloc] init]; | |
} | |
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector | |
{ | |
NSMethodSignature *signature = [super methodSignatureForSelector:aSelector]; | |
if(!signature) { | |
if ([self.currentRemote respondsToSelector:aSelector]) { | |
return [self.currentRemote methodSignatureForSelector:aSelector]; | |
} | |
signature = [NSMethodSignature signatureWithObjCTypes: "@^v^c"]; | |
} | |
return signature; | |
} | |
- (void)forwardInvocation:(NSInvocation *)anInvocation | |
{ | |
if ([self.currentRemote respondsToSelector:[anInvocation selector]]) { | |
[anInvocation invokeWithTarget:self.currentRemote]; | |
} | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@protocol TVRemoteAbstract <NSObject> | |
@property (nonatomic, assign) BOOL isTCP; | |
@property (nonatomic, assign) BOOL isHTTP; | |
@property (nonatomic, assign) BOOL isJSON; | |
@property (nonatomic, assign) BOOL requiresPersistantConnection; | |
@property (nonatomic, copy) NSString *host; | |
@property (nonatomic, assign) NSUInteger port; | |
@property (nonatomic, readonly) BOOL isConnected; | |
@property (nonatomic, readonly) BOOL finishedSending; | |
- (void)connect; | |
- (void)connectToHost:(NSString *)host port:(NSUInteger)port; | |
- (void)disconnect; | |
- (void)disconnectNow:(BOOL)now; | |
- (void)authorize; | |
- (void)sendNextProgram; | |
- (void)sendPreviousProgram; | |
- (void)sendVolumeUp; | |
- (void)sendVolumeDown; | |
- (void)sendOK; | |
- (void)selectProgramNumber:(NSUInteger)programNumber; | |
@end | |
@interface TVRemoteAbstract : NSObject <TVRemoteAbstract> | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface TVRemoteSocket : TVRemoteAbstract | |
@end | |
@implementation TVRemoteSocket | |
static const NSTimeInterval kPacketSendingTimerInterval = 0.250; | |
- (id)init | |
{ | |
self = [super init]; | |
if (self) { | |
self.packetsToSend = [NSMutableArray array]; | |
_socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; | |
//[_socket synchronouslySetDelegate:self]; | |
//[_socket setAutoDisconnectOnClosedReadStream:NO]; | |
} | |
return self; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)testAuthorizeAndVolumeUp | |
{ | |
TVRemote<TVRemoteAbstract> *remote = [[TVRemote alloc] init]; | |
[remote createSocketRemote]; | |
[remote connectToHost:@"10.10.10.87" port:55000]; | |
[remote authorize]; | |
/* | |
[remote sendVolumeUp]; | |
[remote sendVolumeUp]; | |
[remote sendVolumeUp]; | |
[remote sendVolumeUp]; | |
*/ | |
[remote selectProgramNumber:1]; | |
[remote sendVolumeUp]; | |
[remote sendVolumeUp]; | |
[remote sendVolumeUp]; | |
[remote sendVolumeDown]; | |
[remote sendVolumeDown]; | |
/* | |
[remote sendPreviousProgram]; | |
*/ | |
//[remote selectProgramNumber:21]; | |
while (remote.finishedSending) { | |
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]]; | |
NSLog(@"Polling..."); | |
} | |
[remote disconnect]; | |
while (remote.isConnected) { | |
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]]; | |
NSLog(@"Disconnecting..."); | |
} | |
//[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:3.0]]; | |
//NSLog(@"Done..?"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment