Advertisement
jnis

Untitled

Sep 23rd, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. -(void)startNextRouteTask {
  2. if(nil == self.currentBuilding){
  3. NSLog(@"ERROR: building not loaded!");
  4. return;
  5. }
  6.  
  7. static BOOL isBusy = NO;
  8. static dispatch_queue_t backgroundQueue = nil;
  9. if(nil == backgroundQueue){
  10. backgroundQueue = dispatch_queue_create("com.messe.abindooradkmanager.route", 0);
  11. }
  12.  
  13. NSArray *waitObservers = [self.routingQueue allKeys];
  14. if(NO == isBusy && waitObservers.count > 0){
  15. isBusy = YES;
  16.  
  17. NSValue *observerValue = waitObservers.firstObject;
  18. NSMutableArray *tasks = [self.routingQueue objectForKey:observerValue];
  19. ABPair *routeTask = tasks.firstObject;
  20.  
  21. self.currentRouteTaskObserver = observerValue.nonretainedObjectValue;
  22. NSValue* start = routeTask.a;
  23. NSValue* end = routeTask.b;
  24.  
  25. IDSFloor *floor = [self.currentBuilding floorAtLevel:0];
  26.  
  27. static CGPoint startP;
  28. static CGPoint endP;
  29. startP = start.CGPointValue;
  30. endP = end.CGPointValue;
  31. //convert to indor coords
  32. startP = [self indoorCoordsForGeoLocation:CLLocationCoordinate2DMake(startP.x, startP.y) inBuilding:self.currentBuilding andFloor:floor];
  33. endP = [self indoorCoordsForGeoLocation:CLLocationCoordinate2DMake(endP.x, endP.y) inBuilding:self.currentBuilding andFloor:floor];
  34.  
  35. [tasks removeObject:routeTask];
  36. if(0 == tasks.count){
  37. [self.routingQueue removeObjectForKey:observerValue];
  38. }
  39.  
  40. dispatch_async(backgroundQueue, ^{
  41. NSLog(@"%@",NSStringFromCGPoint(startP));
  42. NSLog(@"%@",NSStringFromCGPoint(endP));
  43. IDSCoordinate* startC = [[IDSCoordinate alloc] initWithX:startP.x andY:startP.y andFloorLevel:0] ;
  44. IDSCoordinate* endC = [[IDSCoordinate alloc] initWithX:endP.x andY:endP.y andFloorLevel:0] ;
  45.  
  46. @try {
  47. NSLog(@"-START-");
  48. [[Indoors instance] routeFromLocation:startC toLocation:endC delegate:self];
  49. NSLog(@"-END-");
  50. }
  51. @catch (NSException *exception) {
  52. NSLog(@"-ERROR- %@", exception);
  53. }
  54. @finally {
  55.  
  56. }
  57.  
  58. [startC release];
  59. [endC release];
  60.  
  61. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  62. isBusy = NO;
  63. [self performSelectorOnMainThread:@selector(startNextRouteTask) withObject:nil waitUntilDone:NO];
  64. });
  65. });
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement