Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(void)startNextRouteTask {
- if(nil == self.currentBuilding){
- NSLog(@"ERROR: building not loaded!");
- return;
- }
- static BOOL isBusy = NO;
- static dispatch_queue_t backgroundQueue = nil;
- if(nil == backgroundQueue){
- backgroundQueue = dispatch_queue_create("com.messe.abindooradkmanager.route", 0);
- }
- NSArray *waitObservers = [self.routingQueue allKeys];
- if(NO == isBusy && waitObservers.count > 0){
- isBusy = YES;
- NSValue *observerValue = waitObservers.firstObject;
- NSMutableArray *tasks = [self.routingQueue objectForKey:observerValue];
- ABPair *routeTask = tasks.firstObject;
- self.currentRouteTaskObserver = observerValue.nonretainedObjectValue;
- NSValue* start = routeTask.a;
- NSValue* end = routeTask.b;
- IDSFloor *floor = [self.currentBuilding floorAtLevel:0];
- static CGPoint startP;
- static CGPoint endP;
- startP = start.CGPointValue;
- endP = end.CGPointValue;
- //convert to indor coords
- startP = [self indoorCoordsForGeoLocation:CLLocationCoordinate2DMake(startP.x, startP.y) inBuilding:self.currentBuilding andFloor:floor];
- endP = [self indoorCoordsForGeoLocation:CLLocationCoordinate2DMake(endP.x, endP.y) inBuilding:self.currentBuilding andFloor:floor];
- [tasks removeObject:routeTask];
- if(0 == tasks.count){
- [self.routingQueue removeObjectForKey:observerValue];
- }
- dispatch_async(backgroundQueue, ^{
- NSLog(@"%@",NSStringFromCGPoint(startP));
- NSLog(@"%@",NSStringFromCGPoint(endP));
- IDSCoordinate* startC = [[IDSCoordinate alloc] initWithX:startP.x andY:startP.y andFloorLevel:0] ;
- IDSCoordinate* endC = [[IDSCoordinate alloc] initWithX:endP.x andY:endP.y andFloorLevel:0] ;
- @try {
- NSLog(@"-START-");
- [[Indoors instance] routeFromLocation:startC toLocation:endC delegate:self];
- NSLog(@"-END-");
- }
- @catch (NSException *exception) {
- NSLog(@"-ERROR- %@", exception);
- }
- @finally {
- }
- [startC release];
- [endC release];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- isBusy = NO;
- [self performSelectorOnMainThread:@selector(startNextRouteTask) withObject:nil waitUntilDone:NO];
- });
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement