├── BKServiceController ├── BKServiceController_Internal.h ├── BKService.h ├── _BKServiceTreeNode.h ├── BKServiceRegistrar.h ├── BKServiceRegistrar_Internal.h ├── BKServiceController.h ├── _BKServiceTreeNode.m ├── BKServiceRegistrar.m └── BKServiceController.m ├── LICENSE ├── BKServiceController.podspec ├── README.md ├── .gitignore └── BKServiceController.xcodeproj └── project.pbxproj /BKServiceController/BKServiceController_Internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014-present 650 Industries. All rights reserved. 2 | 3 | #import "BKServiceController.h" 4 | 5 | @interface BKServiceController () 6 | 7 | @property (nonatomic, strong, readonly) NSMapTable *services;; 8 | 9 | @end 10 | -------------------------------------------------------------------------------- /BKServiceController/BKService.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014-present 650 Industries. All rights reserved. 2 | 3 | @import Foundation; 4 | 5 | @protocol BKService; 6 | 7 | typedef void (^service_load_callback_t)(id service, BOOL loaded, NSError *error); 8 | 9 | @protocol BKService 10 | 11 | - (void)loadServiceWithCallback:(service_load_callback_t)callback; 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /BKServiceController/_BKServiceTreeNode.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014-present 650 Industries. All rights reserved. 2 | 3 | @import Foundation; 4 | 5 | #import "BKService.h" 6 | 7 | @interface _BKServiceTreeNode : NSObject 8 | @property (nonatomic, assign) BOOL running; 9 | 10 | @property (nonatomic, copy, readonly) NSString *key; 11 | @property (nonatomic, strong, readonly) id service; 12 | @property (nonatomic, copy, readonly) NSArray *dependencies; 13 | 14 | - (instancetype)initWithService:(id)service key:(NSString *)key dependencies:(NSArray *)dependencies; 15 | @end 16 | -------------------------------------------------------------------------------- /BKServiceController/BKServiceRegistrar.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014-present 650 Industries. All rights reserved. 2 | 3 | @import Foundation; 4 | 5 | @protocol BKService; 6 | 7 | @interface BKServiceRegistrar : NSObject 8 | 9 | - (BOOL)registerBlock:(void (^)())block forKey:(NSString *)key; 10 | - (BOOL)registerBlock:(void (^)())block forKey:(NSString *)key dependencies:(NSArray *)dependencies; 11 | - (BOOL)registerService:(id)service forKey:(NSString *)key; 12 | - (BOOL)registerService:(id)service forKey:(NSString *)key dependencies:(NSArray *)dependencies; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /BKServiceController/BKServiceRegistrar_Internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014-present 650 Industries. All rights reserved. 2 | 3 | #import "BKServiceRegistrar.h" 4 | 5 | #import "BKService.h" 6 | 7 | @class BKServiceController; 8 | 9 | @interface BKServiceRegistrar () 10 | 11 | @property (nonatomic, strong, readonly) NSMapTable *addedServices; 12 | 13 | - (instancetype)initWithController:(BKServiceController *)controller; 14 | 15 | @end 16 | 17 | @interface BKBlockService : NSObject 18 | @property (nonatomic, copy, readonly) void (^block)(); 19 | 20 | - (instancetype)initWithBlock:(void (^)())block; 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /BKServiceController/BKServiceController.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014-present 650 Industries. All rights reserved. 2 | 3 | @import Foundation; 4 | 5 | @class BKServiceController; 6 | @class BKServiceRegistrar; 7 | @protocol BKService; 8 | 9 | typedef void (^service_registration_block_t)(BKServiceController *controller, BKServiceRegistrar *registrar); 10 | 11 | @interface BKServiceController : NSObject 12 | 13 | + (instancetype)sharedInstance; 14 | - (id)serviceForKey:(NSString *)key; 15 | - (NSArray *)serviceKeys; 16 | 17 | - (void)registerServices:(service_registration_block_t)registrationBlock; 18 | - (void)registerServicesImmediately:(service_registration_block_t)registrationBlock; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /BKServiceController/_BKServiceTreeNode.m: -------------------------------------------------------------------------------- 1 | // Copyright 2014-present 650 Industries. All rights reserved. 2 | 3 | #import "_BKServiceTreeNode.h" 4 | 5 | @implementation _BKServiceTreeNode 6 | - (instancetype)initWithService:(id)service key:(NSString *)key dependencies:(NSArray *)dependencies 7 | { 8 | if (self = [super init]) { 9 | _service = service; 10 | _key = [key copy]; 11 | _dependencies = [dependencies copy]; 12 | } 13 | return self; 14 | } 15 | 16 | - (NSString *)description 17 | { 18 | return [NSString stringWithFormat:@"[%@] => running=%d <%@: %p> dependencies: %@", _key, _running, NSStringFromClass([_service class]), _service, _dependencies]; 19 | } 20 | @end 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 650 Industries, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /BKServiceController.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "BKServiceController" 3 | s.version = "0.0.1" 4 | s.summary = "A concurrent dependency-resolving code launcher intended for use at application startup." 5 | s.description = <<-DESC 6 | Application startup often requires several things to be executed as a precondition to making the app interactable. This is often done sequentially in the app delegate on the main thread; while this is very predictable, modern iOS devices have more than one core and benefit greatly from intelligent use of queues. 7 | 8 | This framework aims to make service declaration and dependency resolution straightforward, and to accelerate startup times by maximizing use of multi-core devices. 9 | DESC 10 | s.homepage = "https://github.com/Basket/BKServiceController" 11 | s.license = 'MIT' 12 | s.author = { "Andrew Toulouse" => "andrew@atoulou.se" } 13 | s.source = { :git => "https://github.com/Basket/BKServiceController.git", :tag => s.version.to_s } 14 | 15 | s.platform = :ios, '7.0' 16 | s.requires_arc = true 17 | 18 | s.source_files = 'BKServiceController/*.{h,m}' 19 | s.public_header_files = 'BKServiceController/BKService.h', 20 | 'BKServiceController/BKServiceController.h', 21 | 'BKServiceController/BKServiceRegistrar.h' 22 | s.frameworks = 'UIKit' 23 | end 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BKServiceController 2 | 3 | A concurrent dependency-resolving code launcher intended for use at application startup. Currently beta quality. 4 | 5 | ## Installation 6 | 7 | 1. Add BKServiceController to your Podfile. 8 | 2. In your terminal, run `pod install`. 9 | 10 | ## Usage 11 | 12 | 1. Add `#import ` and `#import ` to your application delegate class. Add `#import ` as needed in implementing classes. 13 | 2. Write your services to conform to `BKService`: implement the `loadServiceWithCallback:` method, and use the supplied `service_load_callback_t` callback to notify the service controller of your service's successful (or failed) loading. This method is (currently) callable from arbitrary queues. 14 | 3. Add calls to the service controller (documented below), typically in `application:willFinishLaunchingWithOptions:` or `application:didFinishLaunchingWithOptions:`, to your application delegate. 15 | 16 | ## FAQ 17 | 18 | **Q:** Why should I use this? 19 | **A:** A couple of reasons: 20 | 21 | * The faster you can start up, the more your users will like your app. Even better, avoid the main thread when doing so. 22 | * Utilizing iOS devices' cores to the maximum extent possible in the shortest period of time is A Good Thing™ for power savings, since it can ramp down the CPU earlier. Even if there's slightly more total work, if the time to quiescence is faster, the hardware can potentially drop to a low-power state sooner, for less overall consumption. 23 | * Rather than a gargantuan app delegate that has to change a lot every time you want to add something new at startup, you can keep stuff neatly organized. 24 | * Simple dependency management for launching services, so you only ever start service C if service A and service B are available. **Services are uniquely identified by the key they are registered with.** 25 | 26 | **Q:** Why register with some `BKServiceRegistrar` object? 27 | **A:** This forces the addition of multiple potentially interdependent services to be done atomically, allowing dependency resolution to happen immediately after the registration block executes. IMO, it makes for a simpler, more predictable, and more debuggable API. 28 | 29 | **Q:** `registerServicesImmediately:forKey:` doesn't work right with dependencies! 30 | **A:** Right now, it's a straight-up sequential start. Resolving them into a linearized DAG is possible, but has not yet been done. 31 | 32 | **Q:** Why does `BKServiceController` load services in waves, rather than as each node in the tree satisfying a service's dependency completes? 33 | **A:** At the time it was being written, it wasn't clear that an atomic, tree-based registration mechanism that dispatched out to background queues was going to work out. After a small amount of usage, it's proven to be pretty useful! The design doesn't prevent this; and it would definitely be an improvement. 34 | 35 | ## Documentation 36 | 37 | This project is a work in progress; the interface may not remain totally stable (though it's unlikely to change very much at all). Documentation will come after some more iteration. -------------------------------------------------------------------------------- /BKServiceController/BKServiceRegistrar.m: -------------------------------------------------------------------------------- 1 | // Copyright 2014-present 650 Industries. All rights reserved. 2 | 3 | #import "BKServiceRegistrar.h" 4 | #import "BKServiceRegistrar_Internal.h" 5 | 6 | #import "BKServiceController.h" 7 | #import "BKServiceController_Internal.h" 8 | #import "_BKServiceTreeNode.h" 9 | 10 | @implementation BKServiceRegistrar { 11 | __weak BKServiceController *_serviceController; 12 | } 13 | 14 | - (instancetype)initWithController:(BKServiceController *)controller 15 | { 16 | if (self = [super init]) { 17 | _serviceController = controller; 18 | _addedServices = [NSMapTable strongToStrongObjectsMapTable]; 19 | } 20 | return self; 21 | } 22 | 23 | - (BOOL)_shouldRegisterService:(id)service forKey:(NSString *)key 24 | { 25 | if ([_serviceController.services objectForKey:key]) { 26 | NSLog(@"ERROR: Service already registered in the Service Controller"); 27 | return NO; 28 | } 29 | NSEnumerator *serviceEnumerator = [_addedServices objectEnumerator]; 30 | _BKServiceTreeNode *node; 31 | while (node = [serviceEnumerator nextObject]) { 32 | if (node.service == service) { 33 | NSLog(@"ERROR: This service is already added to the current service registrar"); 34 | return NO; 35 | } else if ([node.key isEqualToString:key]) { 36 | NSLog(@"ERROR: A service with an identical key is already added to the current service registrar: %@", [node.service description]); 37 | return NO; 38 | } 39 | } 40 | return YES; 41 | } 42 | 43 | - (BOOL)registerBlock:(void (^)())block forKey:(NSString *)key 44 | { 45 | return [self registerBlock:block forKey:key dependencies:nil]; 46 | } 47 | 48 | - (BOOL)registerBlock:(void (^)())block forKey:(NSString *)key dependencies:(NSArray *)dependencies 49 | { 50 | BKBlockService *blockService = [[BKBlockService alloc] initWithBlock:block]; 51 | return [self registerService:blockService forKey:key dependencies:dependencies]; 52 | } 53 | 54 | - (BOOL)registerService:(id)service forKey:(NSString *)key 55 | { 56 | return [self registerService:service forKey:key dependencies:nil]; 57 | } 58 | 59 | - (BOOL)registerService:(id)service forKey:(NSString *)key dependencies:(NSArray *)dependencies 60 | { 61 | if (![self _shouldRegisterService:service forKey:key]) { 62 | return NO; 63 | } 64 | 65 | NSMutableArray *dependencyNodes; 66 | if (dependencies.count) { 67 | dependencyNodes = [NSMutableArray array]; 68 | for (NSString *dependencyKey in dependencies) { 69 | _BKServiceTreeNode *dependencyNode = [_addedServices objectForKey:dependencyKey]; 70 | if (!dependencyNode) { 71 | dependencyNode = [_serviceController.services objectForKey:dependencyKey]; 72 | } 73 | NSAssert(dependencyNode != nil, @"Expected non-nil value"); 74 | [dependencyNodes addObject:dependencyNode]; 75 | } 76 | } else { 77 | dependencyNodes = nil; 78 | } 79 | 80 | _BKServiceTreeNode *node = [[_BKServiceTreeNode alloc] initWithService:service key:key dependencies:dependencyNodes]; 81 | [_addedServices setObject:node forKey:key]; 82 | return YES; 83 | } 84 | 85 | @end 86 | 87 | 88 | @implementation BKBlockService 89 | 90 | - (instancetype)initWithBlock:(void (^)())block 91 | { 92 | if (self = [super init]) { 93 | _block = [block copy]; 94 | } 95 | return self; 96 | } 97 | 98 | - (void)loadServiceWithCallback:(service_load_callback_t)callback 99 | { 100 | _block(); 101 | callback(self, YES, nil); 102 | } 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ######################### 2 | # .gitignore file for Xcode4 / OS X Source projects 3 | # 4 | # Version 2.0 5 | # For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects 6 | # 7 | # 2013 updates: 8 | # - fixed the broken "save personal Schemes" 9 | # 10 | # NB: if you are storing "built" products, this WILL NOT WORK, 11 | # and you should use a different .gitignore (or none at all) 12 | # This file is for SOURCE projects, where there are many extra 13 | # files that we want to exclude 14 | # 15 | ######################### 16 | 17 | ##### 18 | # OS X temporary files that should never be committed 19 | 20 | .DS_Store 21 | *.swp 22 | *.lock 23 | profile 24 | 25 | 26 | #### 27 | # Xcode temporary files that should never be committed 28 | # 29 | # NB: NIB/XIB files still exist even on Storyboard projects, so we want this... 30 | 31 | *~.nib 32 | 33 | 34 | #### 35 | # Xcode build files - 36 | # 37 | # NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData" 38 | 39 | DerivedData/ 40 | 41 | # NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build" 42 | 43 | build/ 44 | 45 | 46 | ##### 47 | # Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups) 48 | # 49 | # This is complicated: 50 | # 51 | # SOMETIMES you need to put this file in version control. 52 | # Apple designed it poorly - if you use "custom executables", they are 53 | # saved in this file. 54 | # 99% of projects do NOT use those, so they do NOT want to version control this file. 55 | # ..but if you're in the 1%, comment out the line "*.pbxuser" 56 | 57 | *.pbxuser 58 | *.mode1v3 59 | *.mode2v3 60 | *.perspectivev3 61 | # NB: also, whitelist the default ones, some projects need to use these 62 | !default.pbxuser 63 | !default.mode1v3 64 | !default.mode2v3 65 | !default.perspectivev3 66 | 67 | 68 | #### 69 | # Xcode 4 - semi-personal settings 70 | # 71 | # 72 | # OPTION 1: --------------------------------- 73 | # throw away ALL personal settings (including custom schemes! 74 | # - unless they are "shared") 75 | # 76 | # NB: this is exclusive with OPTION 2 below 77 | xcuserdata 78 | 79 | # OPTION 2: --------------------------------- 80 | # get rid of ALL personal settings, but KEEP SOME OF THEM 81 | # - NB: you must manually uncomment the bits you want to keep 82 | # 83 | # NB: this is exclusive with OPTION 1 above 84 | # 85 | #xcuserdata/**/* 86 | 87 | # (requires option 2 above): Personal Schemes 88 | # 89 | #!xcuserdata/**/xcschemes/* 90 | 91 | #### 92 | # XCode 4 workspaces - more detailed 93 | # 94 | # Workspaces are important! They are a core feature of Xcode - don't exclude them :) 95 | # 96 | # Workspace layout is quite spammy. For reference: 97 | # 98 | # /(root)/ 99 | # /(project-name).xcodeproj/ 100 | # project.pbxproj 101 | # /project.xcworkspace/ 102 | # contents.xcworkspacedata 103 | # /xcuserdata/ 104 | # /(your name)/xcuserdatad/ 105 | # UserInterfaceState.xcuserstate 106 | # /xcsshareddata/ 107 | # /xcschemes/ 108 | # (shared scheme name).xcscheme 109 | # /xcuserdata/ 110 | # /(your name)/xcuserdatad/ 111 | # (private scheme).xcscheme 112 | # xcschememanagement.plist 113 | # 114 | # 115 | 116 | #### 117 | # Xcode 4 - Deprecated classes 118 | # 119 | # Allegedly, if you manually "deprecate" your classes, they get moved here. 120 | # 121 | # We're using source-control, so this is a "feature" that we do not want! 122 | 123 | *.moved-aside 124 | 125 | 126 | #### 127 | # UNKNOWN: recommended by others, but I can't discover what these files are 128 | # 129 | # ...none. Everything is now explained. -------------------------------------------------------------------------------- /BKServiceController/BKServiceController.m: -------------------------------------------------------------------------------- 1 | // Copyright 2014-present 650 Industries. All rights reserved. 2 | 3 | #import "BKServiceController.h" 4 | #import "BKServiceController_Internal.h" 5 | 6 | #import "BKService.h" 7 | #import "BKServiceRegistrar.h" 8 | #import "BKServiceRegistrar_Internal.h" 9 | #import "_BKServiceTreeNode.h" 10 | 11 | @implementation BKServiceController { 12 | dispatch_queue_t _serviceQueue; 13 | } 14 | 15 | + (instancetype)sharedInstance 16 | { 17 | static dispatch_once_t pred; 18 | static BKServiceController *shared = nil; 19 | 20 | dispatch_once(&pred, ^{ 21 | shared = [[BKServiceController alloc] init]; 22 | }); 23 | return shared; 24 | } 25 | 26 | - (instancetype)init 27 | { 28 | self = [super init]; 29 | if (self = [super init]) { 30 | _services = [NSMapTable strongToStrongObjectsMapTable]; 31 | _serviceQueue = dispatch_queue_create("basket.services", DISPATCH_QUEUE_CONCURRENT); 32 | dispatch_set_target_queue(_serviceQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)); 33 | } 34 | return self; 35 | } 36 | 37 | - (id)serviceForKey:(NSString *)key 38 | { 39 | _BKServiceTreeNode *node = [_services objectForKey:key]; 40 | if (!node) { 41 | return nil; 42 | } 43 | 44 | return node.service; 45 | } 46 | 47 | - (NSArray *)serviceKeys 48 | { 49 | return [[_services dictionaryRepresentation] allKeys]; 50 | } 51 | 52 | - (void)registerServicesImmediately:(service_registration_block_t)registrationBlock 53 | { 54 | BKServiceRegistrar *registrar = [[BKServiceRegistrar alloc] initWithController:self]; 55 | registrationBlock(self, registrar); 56 | for (NSString *key in registrar.addedServices) { 57 | NSAssert([_services objectForKey:key] == nil, @"Expected nil"); 58 | id node = [registrar.addedServices objectForKey:key]; 59 | [_services setObject:node forKey:key]; 60 | } 61 | 62 | for (NSString *key in registrar.addedServices) { 63 | _BKServiceTreeNode *node = [registrar.addedServices objectForKey:key]; 64 | 65 | // FIXME TODO: linearize the DAG. 66 | for (_BKServiceTreeNode *dependencyNode in node.dependencies) { 67 | if (!dependencyNode.running) { 68 | // TODO: error reporting here? 69 | NSAssert(NO, @"A needed dependency is not running!"); 70 | } 71 | } 72 | 73 | [node.service loadServiceWithCallback:^(id service, BOOL loaded, NSError *error) { 74 | node.running = loaded; 75 | NSAssert(loaded, @"Failed to load service: %@ with error: %@", service, error); 76 | }]; 77 | node.running = YES; 78 | } 79 | } 80 | 81 | - (void)registerServices:(service_registration_block_t)registrationBlock 82 | { 83 | BKServiceRegistrar *registrar = [[BKServiceRegistrar alloc] initWithController:self]; 84 | registrationBlock(self, registrar); 85 | for (NSString *key in registrar.addedServices) { 86 | NSAssert([_services objectForKey:key] == nil, @"Expected nil"); 87 | id service = [registrar.addedServices objectForKey:key]; 88 | [_services setObject:service forKey:key]; 89 | } 90 | 91 | [self _recursiveLoad]; 92 | } 93 | 94 | - (void)_recursiveLoad 95 | { 96 | NSArray *servicesToLoad = [self _calculateNextServicesToLoad]; 97 | if (!servicesToLoad.count) { 98 | return; 99 | } 100 | 101 | dispatch_group_t group = dispatch_group_create(); 102 | for (_BKServiceTreeNode *node in servicesToLoad) { 103 | dispatch_group_enter(group); 104 | dispatch_async(_serviceQueue, ^{ 105 | [node.service loadServiceWithCallback:^(id service, BOOL loaded, NSError *error) { 106 | node.running = loaded; 107 | dispatch_group_leave(group); 108 | NSAssert(loaded, @"Failed to load service: %@ with error: %@", service, error); 109 | }]; 110 | }); 111 | } 112 | 113 | [self _blockThenContinueWithGroup:group]; 114 | } 115 | 116 | - (void)_blockThenContinueWithGroup:(dispatch_group_t)group 117 | { 118 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ 119 | long result = dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC)); 120 | if (result != 0) { // Dispatch group didn't finish 121 | NSLog(@"ERROR: Timeout reached while launching services!"); 122 | [self _blockThenContinueWithGroup:group]; 123 | } else { // Dispatch group did finish 124 | dispatch_async(dispatch_get_main_queue(), ^{ 125 | [self _recursiveLoad]; 126 | }); 127 | } 128 | }); 129 | } 130 | 131 | - (NSArray *)_calculateNextServicesToLoad 132 | { 133 | NSMutableArray *servicesToLoad = [NSMutableArray array]; 134 | 135 | // Select non-running nodes whose dependencies are all running (no dependencies == all running). 136 | NSEnumerator *serviceEnumerator = [_services objectEnumerator]; 137 | _BKServiceTreeNode *currentNode; 138 | while (currentNode = [serviceEnumerator nextObject]) { 139 | if (currentNode.running) { 140 | continue; 141 | } 142 | 143 | NSIndexSet *runningDependencies = [currentNode.dependencies indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { 144 | return ((_BKServiceTreeNode *)obj).running; 145 | }]; 146 | if (runningDependencies.count == currentNode.dependencies.count) { 147 | [servicesToLoad addObject:currentNode]; 148 | } 149 | } 150 | 151 | return [servicesToLoad copy]; 152 | } 153 | 154 | @end 155 | 156 | 157 | -------------------------------------------------------------------------------- /BKServiceController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6BEE0A61198715AE00D73B41 /* BKServiceController.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 6BEE0A60198715AE00D73B41 /* BKServiceController.h */; }; 11 | 6BEE0A63198715AE00D73B41 /* BKServiceController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BEE0A62198715AE00D73B41 /* BKServiceController.m */; }; 12 | 6BEE0A7E198715FD00D73B41 /* _BKServiceTreeNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BEE0A78198715FD00D73B41 /* _BKServiceTreeNode.m */; }; 13 | 6BEE0A7F198715FD00D73B41 /* BKServiceRegistrar.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BEE0A7C198715FD00D73B41 /* BKServiceRegistrar.m */; }; 14 | 6BEE0A80198716AB00D73B41 /* BKService.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 6BEE0A7D198715FD00D73B41 /* BKService.h */; }; 15 | 6BEE0A81198716AB00D73B41 /* BKServiceRegistrar.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 6BEE0A7B198715FD00D73B41 /* BKServiceRegistrar.h */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXCopyFilesBuildPhase section */ 19 | 6BEE0A5B198715AE00D73B41 /* CopyFiles */ = { 20 | isa = PBXCopyFilesBuildPhase; 21 | buildActionMask = 2147483647; 22 | dstPath = "include/$(PRODUCT_NAME)"; 23 | dstSubfolderSpec = 16; 24 | files = ( 25 | 6BEE0A80198716AB00D73B41 /* BKService.h in CopyFiles */, 26 | 6BEE0A61198715AE00D73B41 /* BKServiceController.h in CopyFiles */, 27 | 6BEE0A81198716AB00D73B41 /* BKServiceRegistrar.h in CopyFiles */, 28 | ); 29 | runOnlyForDeploymentPostprocessing = 0; 30 | }; 31 | /* End PBXCopyFilesBuildPhase section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 6BEE0A5D198715AE00D73B41 /* libBKServiceController.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBKServiceController.a; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | 6BEE0A60198715AE00D73B41 /* BKServiceController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BKServiceController.h; sourceTree = ""; }; 36 | 6BEE0A62198715AE00D73B41 /* BKServiceController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BKServiceController.m; sourceTree = ""; }; 37 | 6BEE0A77198715FD00D73B41 /* _BKServiceTreeNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _BKServiceTreeNode.h; sourceTree = ""; }; 38 | 6BEE0A78198715FD00D73B41 /* _BKServiceTreeNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _BKServiceTreeNode.m; sourceTree = ""; }; 39 | 6BEE0A79198715FD00D73B41 /* BKServiceController_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BKServiceController_Internal.h; sourceTree = ""; }; 40 | 6BEE0A7A198715FD00D73B41 /* BKServiceRegistrar_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BKServiceRegistrar_Internal.h; sourceTree = ""; }; 41 | 6BEE0A7B198715FD00D73B41 /* BKServiceRegistrar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BKServiceRegistrar.h; sourceTree = ""; }; 42 | 6BEE0A7C198715FD00D73B41 /* BKServiceRegistrar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BKServiceRegistrar.m; sourceTree = ""; }; 43 | 6BEE0A7D198715FD00D73B41 /* BKService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BKService.h; sourceTree = ""; }; 44 | /* End PBXFileReference section */ 45 | 46 | /* Begin PBXFrameworksBuildPhase section */ 47 | 6BEE0A5A198715AE00D73B41 /* Frameworks */ = { 48 | isa = PBXFrameworksBuildPhase; 49 | buildActionMask = 2147483647; 50 | files = ( 51 | ); 52 | runOnlyForDeploymentPostprocessing = 0; 53 | }; 54 | /* End PBXFrameworksBuildPhase section */ 55 | 56 | /* Begin PBXGroup section */ 57 | 6BEE0A54198715AE00D73B41 = { 58 | isa = PBXGroup; 59 | children = ( 60 | 6BEE0A5F198715AE00D73B41 /* BKServiceController */, 61 | 6BEE0A5E198715AE00D73B41 /* Products */, 62 | ); 63 | sourceTree = ""; 64 | }; 65 | 6BEE0A5E198715AE00D73B41 /* Products */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 6BEE0A5D198715AE00D73B41 /* libBKServiceController.a */, 69 | ); 70 | name = Products; 71 | sourceTree = ""; 72 | }; 73 | 6BEE0A5F198715AE00D73B41 /* BKServiceController */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 6BEE0A77198715FD00D73B41 /* _BKServiceTreeNode.h */, 77 | 6BEE0A78198715FD00D73B41 /* _BKServiceTreeNode.m */, 78 | 6BEE0A7D198715FD00D73B41 /* BKService.h */, 79 | 6BEE0A60198715AE00D73B41 /* BKServiceController.h */, 80 | 6BEE0A62198715AE00D73B41 /* BKServiceController.m */, 81 | 6BEE0A79198715FD00D73B41 /* BKServiceController_Internal.h */, 82 | 6BEE0A7B198715FD00D73B41 /* BKServiceRegistrar.h */, 83 | 6BEE0A7C198715FD00D73B41 /* BKServiceRegistrar.m */, 84 | 6BEE0A7A198715FD00D73B41 /* BKServiceRegistrar_Internal.h */, 85 | ); 86 | path = BKServiceController; 87 | sourceTree = ""; 88 | }; 89 | /* End PBXGroup section */ 90 | 91 | /* Begin PBXNativeTarget section */ 92 | 6BEE0A5C198715AE00D73B41 /* BKServiceController */ = { 93 | isa = PBXNativeTarget; 94 | buildConfigurationList = 6BEE0A71198715AE00D73B41 /* Build configuration list for PBXNativeTarget "BKServiceController" */; 95 | buildPhases = ( 96 | 6BEE0A59198715AE00D73B41 /* Sources */, 97 | 6BEE0A5A198715AE00D73B41 /* Frameworks */, 98 | 6BEE0A5B198715AE00D73B41 /* CopyFiles */, 99 | ); 100 | buildRules = ( 101 | ); 102 | dependencies = ( 103 | ); 104 | name = BKServiceController; 105 | productName = BKServiceController; 106 | productReference = 6BEE0A5D198715AE00D73B41 /* libBKServiceController.a */; 107 | productType = "com.apple.product-type.library.static"; 108 | }; 109 | /* End PBXNativeTarget section */ 110 | 111 | /* Begin PBXProject section */ 112 | 6BEE0A55198715AE00D73B41 /* Project object */ = { 113 | isa = PBXProject; 114 | attributes = { 115 | LastUpgradeCheck = 0600; 116 | ORGANIZATIONNAME = "650 Industries, Inc."; 117 | TargetAttributes = { 118 | 6BEE0A5C198715AE00D73B41 = { 119 | CreatedOnToolsVersion = 6.0; 120 | }; 121 | }; 122 | }; 123 | buildConfigurationList = 6BEE0A58198715AE00D73B41 /* Build configuration list for PBXProject "BKServiceController" */; 124 | compatibilityVersion = "Xcode 3.2"; 125 | developmentRegion = English; 126 | hasScannedForEncodings = 0; 127 | knownRegions = ( 128 | en, 129 | ); 130 | mainGroup = 6BEE0A54198715AE00D73B41; 131 | productRefGroup = 6BEE0A5E198715AE00D73B41 /* Products */; 132 | projectDirPath = ""; 133 | projectRoot = ""; 134 | targets = ( 135 | 6BEE0A5C198715AE00D73B41 /* BKServiceController */, 136 | ); 137 | }; 138 | /* End PBXProject section */ 139 | 140 | /* Begin PBXSourcesBuildPhase section */ 141 | 6BEE0A59198715AE00D73B41 /* Sources */ = { 142 | isa = PBXSourcesBuildPhase; 143 | buildActionMask = 2147483647; 144 | files = ( 145 | 6BEE0A7E198715FD00D73B41 /* _BKServiceTreeNode.m in Sources */, 146 | 6BEE0A63198715AE00D73B41 /* BKServiceController.m in Sources */, 147 | 6BEE0A7F198715FD00D73B41 /* BKServiceRegistrar.m in Sources */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXSourcesBuildPhase section */ 152 | 153 | /* Begin XCBuildConfiguration section */ 154 | 6BEE0A6F198715AE00D73B41 /* Debug */ = { 155 | isa = XCBuildConfiguration; 156 | buildSettings = { 157 | ALWAYS_SEARCH_USER_PATHS = NO; 158 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 159 | CLANG_CXX_LIBRARY = "libc++"; 160 | CLANG_ENABLE_MODULES = YES; 161 | CLANG_ENABLE_OBJC_ARC = YES; 162 | CLANG_WARN_BOOL_CONVERSION = YES; 163 | CLANG_WARN_CONSTANT_CONVERSION = YES; 164 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 165 | CLANG_WARN_EMPTY_BODY = YES; 166 | CLANG_WARN_ENUM_CONVERSION = YES; 167 | CLANG_WARN_INT_CONVERSION = YES; 168 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 169 | CLANG_WARN_UNREACHABLE_CODE = YES; 170 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 171 | COPY_PHASE_STRIP = NO; 172 | ENABLE_STRICT_OBJC_MSGSEND = YES; 173 | GCC_C_LANGUAGE_STANDARD = gnu99; 174 | GCC_DYNAMIC_NO_PIC = NO; 175 | GCC_OPTIMIZATION_LEVEL = 0; 176 | GCC_PREPROCESSOR_DEFINITIONS = ( 177 | "DEBUG=1", 178 | "$(inherited)", 179 | ); 180 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 181 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 182 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 183 | GCC_WARN_UNDECLARED_SELECTOR = YES; 184 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 185 | GCC_WARN_UNUSED_FUNCTION = YES; 186 | GCC_WARN_UNUSED_VARIABLE = YES; 187 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 188 | MTL_ENABLE_DEBUG_INFO = YES; 189 | ONLY_ACTIVE_ARCH = YES; 190 | SDKROOT = iphoneos; 191 | }; 192 | name = Debug; 193 | }; 194 | 6BEE0A70198715AE00D73B41 /* Release */ = { 195 | isa = XCBuildConfiguration; 196 | buildSettings = { 197 | ALWAYS_SEARCH_USER_PATHS = NO; 198 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 199 | CLANG_CXX_LIBRARY = "libc++"; 200 | CLANG_ENABLE_MODULES = YES; 201 | CLANG_ENABLE_OBJC_ARC = YES; 202 | CLANG_WARN_BOOL_CONVERSION = YES; 203 | CLANG_WARN_CONSTANT_CONVERSION = YES; 204 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 205 | CLANG_WARN_EMPTY_BODY = YES; 206 | CLANG_WARN_ENUM_CONVERSION = YES; 207 | CLANG_WARN_INT_CONVERSION = YES; 208 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 209 | CLANG_WARN_UNREACHABLE_CODE = YES; 210 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 211 | COPY_PHASE_STRIP = YES; 212 | ENABLE_NS_ASSERTIONS = NO; 213 | ENABLE_STRICT_OBJC_MSGSEND = YES; 214 | GCC_C_LANGUAGE_STANDARD = gnu99; 215 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 216 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 217 | GCC_WARN_UNDECLARED_SELECTOR = YES; 218 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 219 | GCC_WARN_UNUSED_FUNCTION = YES; 220 | GCC_WARN_UNUSED_VARIABLE = YES; 221 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 222 | MTL_ENABLE_DEBUG_INFO = NO; 223 | SDKROOT = iphoneos; 224 | VALIDATE_PRODUCT = YES; 225 | }; 226 | name = Release; 227 | }; 228 | 6BEE0A72198715AE00D73B41 /* Debug */ = { 229 | isa = XCBuildConfiguration; 230 | buildSettings = { 231 | OTHER_LDFLAGS = "-ObjC"; 232 | PRODUCT_NAME = "$(TARGET_NAME)"; 233 | SKIP_INSTALL = YES; 234 | }; 235 | name = Debug; 236 | }; 237 | 6BEE0A73198715AE00D73B41 /* Release */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | OTHER_LDFLAGS = "-ObjC"; 241 | PRODUCT_NAME = "$(TARGET_NAME)"; 242 | SKIP_INSTALL = YES; 243 | }; 244 | name = Release; 245 | }; 246 | /* End XCBuildConfiguration section */ 247 | 248 | /* Begin XCConfigurationList section */ 249 | 6BEE0A58198715AE00D73B41 /* Build configuration list for PBXProject "BKServiceController" */ = { 250 | isa = XCConfigurationList; 251 | buildConfigurations = ( 252 | 6BEE0A6F198715AE00D73B41 /* Debug */, 253 | 6BEE0A70198715AE00D73B41 /* Release */, 254 | ); 255 | defaultConfigurationIsVisible = 0; 256 | defaultConfigurationName = Release; 257 | }; 258 | 6BEE0A71198715AE00D73B41 /* Build configuration list for PBXNativeTarget "BKServiceController" */ = { 259 | isa = XCConfigurationList; 260 | buildConfigurations = ( 261 | 6BEE0A72198715AE00D73B41 /* Debug */, 262 | 6BEE0A73198715AE00D73B41 /* Release */, 263 | ); 264 | defaultConfigurationIsVisible = 0; 265 | defaultConfigurationName = Release; 266 | }; 267 | /* End XCConfigurationList section */ 268 | }; 269 | rootObject = 6BEE0A55198715AE00D73B41 /* Project object */; 270 | } 271 | --------------------------------------------------------------------------------