Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOOXPVerifierStage.m
Go to the documentation of this file.
1/*
2
3OOOXPVerifierStage.m
4
5
6Copyright (C) 2007-2013 Jens Ayton
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25
26*/
27
28#include <assert.h>
29
31
32#if OO_OXP_VERIFIER_ENABLED
33
34@interface OOOXPVerifierStage (OOPrivate)
35
36- (void)registerDepedent:(OOOXPVerifierStage *)dependent;
37- (void)dependencyCompleted:(OOOXPVerifierStage *)dependency;
38
39@end
40
41
42@implementation OOOXPVerifierStage
43
44- (id)init
45{
46 self = [super init];
47
48 if (self != nil)
49 {
50 _dependencies = [[NSMutableSet alloc] init];
51 _incompleteDependencies = [[NSMutableSet alloc] init];
52 _dependents = [[NSMutableSet alloc] init];
53 _canRun = NO;
54 }
55
56 return self;
57}
58
59
60- (void)dealloc
61{
62 [_dependencies release];
63 [_incompleteDependencies release];
64 [_dependents release];
65
66 [super dealloc];
67}
68
69
70- (id)description
71{
72 return [NSString stringWithFormat:@"<%@ %p>{\"%@\"}", [self class], self, [self name]];
73}
74
75
76- (OOOXPVerifier *)verifier
77{
78 return [[_verifier retain] autorelease];
79}
80
81
82- (BOOL)completed
83{
84 return _hasRun;
85}
86
87
88- (NSString *)name
89{
91 return nil;
92}
93
94
95- (NSSet *)dependencies
96{
97 return nil;
98}
99
100
101- (NSSet *)dependents
102{
103 return nil;
104}
105
106
107- (BOOL)shouldRun
108{
109 return YES;
110}
111
112
113- (void)run
114{
116}
117
118@end
119
120
121@implementation OOOXPVerifierStage (OOInternal)
122
123- (void)setVerifier:(OOOXPVerifier *)verifier
124{
125 _verifier = verifier; // Not retained.
126}
127
128
129- (BOOL)isDependentOf:(OOOXPVerifierStage *)stage
130{
131 NSEnumerator *directDepEnum = nil;
132 OOOXPVerifierStage *directDep = nil;
133
134 if (stage == nil) return NO;
135
136 // Direct dependency check.
137 if ([_dependencies containsObject:stage]) return YES;
138
139 // Recursive dependency check.
140 for (directDepEnum = [_dependencies objectEnumerator]; (directDep = [directDepEnum nextObject]); )
141 {
142 if ([directDep isDependentOf:stage]) return YES;
143 }
144
145 return NO;
146}
147
148
149- (void)registerDependency:(OOOXPVerifierStage *)dependency
150{
151 [_dependencies addObject:dependency];
152 [_incompleteDependencies addObject:dependency];
153
154 [dependency registerDepedent:self];
155}
156
157
158- (BOOL)canRun
159{
160 return _canRun;
161}
162
163
164- (void)performRun
165{
166 assert(_canRun && !_hasRun);
167
169 @try
170 {
171 [self run];
172 }
173 @catch (NSException *exception)
174 {
175 OOLog(@"verifyOXP.exception", @"***** Exception while running verification stage \"%@\": %@", [self name], exception);
176 }
178
179 _hasRun = YES;
180 _canRun = NO;
181 [_dependents makeObjectsPerformSelector:@selector(dependencyCompleted:) withObject:self];
182}
183
184
185- (void)noteSkipped
186{
187 assert(_canRun && !_hasRun);
188
189 _hasRun = YES;
190 _canRun = NO;
191 [_dependents makeObjectsPerformSelector:@selector(dependencyCompleted:) withObject:self];
192}
193
194
195- (void)dependencyRegistrationComplete
196{
197 _canRun = [_incompleteDependencies count] == 0;
198}
199
200
201- (NSSet *)resolvedDependencies
202{
203 return _dependencies;
204}
205
206
207- (NSSet *)resolvedDependents
208{
209 return _dependents;
210}
211
212@end
213
214
215@implementation OOOXPVerifierStage (OOPrivate)
216
217- (void)registerDepedent:(OOOXPVerifierStage *)dependent
218{
219 assert(![self isDependentOf:dependent]);
220
221 [_dependents addObject:dependent];
222}
223
224
225- (void)dependencyCompleted:(OOOXPVerifierStage *)dependency
226{
227 [_incompleteDependencies removeObject:dependency];
228 if ([_incompleteDependencies count] == 0) _canRun = YES;
229}
230
231@end
232
233#endif //OO_OXP_VERIFIER_ENABLED
void OOLogPushIndent(void)
Definition OOLogging.m:316
void OOLogPopIndent(void)
Definition OOLogging.m:340
#define OOLogGenericSubclassResponsibility()
Definition OOLogging.h:129
#define OOLog(class, format,...)
Definition OOLogging.h:88
unsigned count
return nil
void registerDepedent:(OOOXPVerifierStage *dependent)