summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorSiqi LIU <me@siqi.fr>2013-08-13 23:51:28 +0800
committerSiqi LIU <me@siqi.fr>2013-08-15 13:26:10 +0800
commit03b7dde22c147b62cf285a4752646562119905ad (patch)
tree8b14403e3682d2afb895b778a6f9c3b11ba36e0f /ios
parent9a1483c41ebf5bc32776b084d47576d0c2a374a2 (diff)
seperate state handling for connection and searching
Change-Id: I1bbffb94127905f48672ce8e7baf28fa2a07189d
Diffstat (limited to 'ios')
-rw-r--r--ios/iosremote/iosremote/Communication/CommunicationManager.h8
-rw-r--r--ios/iosremote/iosremote/Communication/CommunicationManager.m1
-rw-r--r--ios/iosremote/iosremote/serverList_vc.m23
3 files changed, 19 insertions, 13 deletions
diff --git a/ios/iosremote/iosremote/Communication/CommunicationManager.h b/ios/iosremote/iosremote/Communication/CommunicationManager.h
index a0997d5e2572..76c719e6dceb 100644
--- a/ios/iosremote/iosremote/Communication/CommunicationManager.h
+++ b/ios/iosremote/iosremote/Communication/CommunicationManager.h
@@ -54,11 +54,16 @@
typedef enum ConnectionState : NSInteger ConnectionState;
+typedef enum SearchState : NSInteger SearchState;
enum ConnectionState : NSInteger {
DISCONNECTED,
CONNECTING,
- CONNECTED,
+ CONNECTED
+};
+
+enum SearchState : NSInteger {
+ WAITING,
SEARCHING
};
@@ -72,6 +77,7 @@ enum ConnectionState : NSInteger {
- (void) removeServerAtIndex:(NSUInteger)index;
@property ConnectionState state;
+@property SearchState searchState;
@property (nonatomic, strong) id delegate;
@property (atomic, strong) NSMutableArray* servers;
@property (atomic, strong) NSMutableArray* autoDiscoveryServers;
diff --git a/ios/iosremote/iosremote/Communication/CommunicationManager.m b/ios/iosremote/iosremote/Communication/CommunicationManager.m
index cfa4a39fa921..a920f3f2fb88 100644
--- a/ios/iosremote/iosremote/Communication/CommunicationManager.m
+++ b/ios/iosremote/iosremote/Communication/CommunicationManager.m
@@ -107,6 +107,7 @@
{
self = [super init];
self.state = DISCONNECTED;
+ self.searchState = WAITING;
self.interpreter = [[CommandInterpreter alloc] init];
self.servers = [[NSMutableArray alloc] init];
diff --git a/ios/iosremote/iosremote/serverList_vc.m b/ios/iosremote/iosremote/serverList_vc.m
index 824c19adc5fa..63214e24f3bb 100644
--- a/ios/iosremote/iosremote/serverList_vc.m
+++ b/ios/iosremote/iosremote/serverList_vc.m
@@ -107,7 +107,7 @@
-(void) netServiceBrowserWillSearch:(NSNetServiceBrowser *)aNetServiceBrowser
{
NSLog(@"Will search");
- self.comManager.state = SEARCHING;
+ self.comManager.searchState = SEARCHING;
self.searchStateText = NSLocalizedString(@"Searching", nil);
[self.searchLabelTimer invalidate];
[self.searchTimeoutTimer invalidate];
@@ -130,8 +130,7 @@
-(void) netServiceBrowserDidStopSearch:(NSNetServiceBrowser *)aNetServiceBrowser
{
NSLog(@"End search");
- if (self.comManager.state == SEARCHING)
- self.comManager.state = DISCONNECTED;
+ self.comManager.searchState = WAITING;
[self.searchLabelTimer invalidate];
[self.searchTimeoutTimer invalidate];
self.searchStateText = NSLocalizedString(@"Click to refresh", nil);
@@ -141,7 +140,7 @@
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict
{
NSLog(@"search error");
- [self.serviceBrowser searchForServicesOfType:@"_impressRemote._tcp" inDomain:@"local"];
+// [self.serviceBrowser searchForServicesOfType:@"_impressRemote._tcp" inDomain:@"local"];
}
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser
@@ -297,9 +296,15 @@
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
- // Return when browser is still searching...
- if ([self.comManager.autoDiscoveryServers count] == 0 && indexPath.section == 0 && self.comManager.state == SEARCHING)
+ if ([self.comManager.autoDiscoveryServers count] == 0 && indexPath.section == 0){
+ // No discovered server and not searching => in a "click to refresh" state, so we restart searching process
+ if (self.comManager.searchState == WAITING){
+ [self.serviceBrowser searchForServicesOfType:@"_impressremote._tcp" inDomain:@"local"];
+ [self.serviceBrowser scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+ }
+ // Return when browser is still searching...
return;
+ }
// Return when nothing should be done
if (self.comManager.state == CONNECTING)
@@ -317,12 +322,6 @@
NSLog(@"Connecting to %@:%@", [[self.comManager.servers objectAtIndex:indexPath.row] serverName], [[self.comManager.servers objectAtIndex:indexPath.row] serverAddress]);
[self.comManager connectToServer:[self.comManager.servers objectAtIndex:indexPath.row]];
} else if (indexPath.section == 0){
- // No discovered server and not searching => in a click to refresh state, so we restart searching process
- if ([self.comManager.autoDiscoveryServers count] == 0) {
- [self.serviceBrowser searchForServicesOfType:@"_impressremote._tcp" inDomain:@"local"];
- [self.serviceBrowser scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
- return;
- }
NSLog(@"Connecting to %@", [[self.comManager.autoDiscoveryServers objectAtIndex:indexPath.row] name]);
[[self.comManager.autoDiscoveryServers objectAtIndex:indexPath.row] resolveWithTimeout:0.0];
}