Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOAIStateMachineVerifierStage Class Reference

#include <OOAIStateMachineVerifierStage.h>

+ Inheritance diagram for OOAIStateMachineVerifierStage:
+ Collaboration diagram for OOAIStateMachineVerifierStage:

Instance Methods

(void) - stateMachineNamed:usedByShip:
 
(void) - dealloc [implementation]
 
(NSString *) - name [implementation]
 
(BOOL) - shouldRun [implementation]
 
(void) - run [implementation]
 
(void) - validateAI: [implementation]
 
- Instance Methods inherited from OOFileHandlingVerifierStage
(NSSet *) - dependencies [implementation]
 
(NSSet *) - dependents [implementation]
 
- Instance Methods inherited from OOOXPVerifierStage
(OOOXPVerifier *) - verifier
 
(BOOL) - completed
 
(id) - init [implementation]
 
(id) - description [implementation]
 
(void) - setVerifier: [implementation]
 
(BOOL) - isDependentOf: [implementation]
 
(void) - registerDependency: [implementation]
 
(void) - dependencyRegistrationComplete [implementation]
 
(BOOL) - canRun [implementation]
 
(void) - performRun [implementation]
 
(void) - noteSkipped [implementation]
 
(NSSet *) - resolvedDependencies [implementation]
 
(NSSet *) - resolvedDependents [implementation]
 
(void) - registerDepedent: [implementation]
 
(void) - dependencyCompleted: [implementation]
 

Class Methods

(NSString *) + nameForReverseDependencyForVerifier:
 

Private Attributes

NSSet * _whitelist
 
NSMutableSet * _usedAIs
 

Detailed Description

Definition at line 32 of file OOAIStateMachineVerifierStage.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Reimplemented from OOOXPVerifierStage.

Definition at line 34 of file OOAIStateMachineVerifierStage.m.

47{
48 [_whitelist release];
49 [_usedAIs release];
50
51 [super dealloc];
52}

◆ name

- (NSString *) name
implementation

Reimplemented from OOOXPVerifierStage.

Definition at line 34 of file OOAIStateMachineVerifierStage.m.

56{
57 return kStageName;
58}
static NSString *const kStageName

◆ nameForReverseDependencyForVerifier:

+ (NSString *) nameForReverseDependencyForVerifier: (OOOXPVerifier *) verifier

Definition at line 34 of file OOAIStateMachineVerifierStage.m.

94{
95 return kStageName;
96}
OOOXPVerifier * verifier()

◆ run

- (void) run
implementation

Reimplemented from OOOXPVerifierStage.

Definition at line 34 of file OOAIStateMachineVerifierStage.m.

68{
69 NSArray *aiNames = nil;
70 NSEnumerator *aiEnum = nil;
71 NSString *aiName = nil;
72 NSMutableSet *whitelist = nil;
73
74 // Build whitelist. Note that we merge in aliases since the distinction doesn't matter when just validating.
75 whitelist = [[NSMutableSet alloc] init];
76 [whitelist addObjectsFromArray:[[ResourceManager whitelistDictionary] oo_arrayForKey:@"ai_methods"]];
77 [whitelist addObjectsFromArray:[[ResourceManager whitelistDictionary] oo_arrayForKey:@"ai_and_action_methods"]];
78 [whitelist addObjectsFromArray:[[[ResourceManager whitelistDictionary] oo_dictionaryForKey:@"ai_method_aliases"] allKeys]];
79 _whitelist = [whitelist copy];
80 [whitelist release];
81
82 aiNames = [[_usedAIs allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
83 for (aiEnum = [aiNames objectEnumerator]; (aiName = [aiEnum nextObject]); )
84 {
85 [self validateAI:aiName];
86 }
87
88 [_whitelist release];
90}
return nil
NSDictionary * whitelistDictionary()

◆ shouldRun

- (BOOL) shouldRun
implementation

Reimplemented from OOOXPVerifierStage.

Definition at line 34 of file OOAIStateMachineVerifierStage.m.

62{
63 return [_usedAIs count] != 0;
64}

◆ stateMachineNamed:usedByShip:

- (void) stateMachineNamed: (NSString *) name
usedByShip: (NSString *) shipName 

Definition at line 34 of file OOAIStateMachineVerifierStage.m.

99 :(NSString *)name usedByShip:(NSString *)shipName
100{
101 OOFileScannerVerifierStage *fileScanner = nil;
102
103 if (name == nil) return;
104 if ([_usedAIs containsObject:name]) return;
105 if (_usedAIs == nil) _usedAIs = [[NSMutableSet alloc] init];
106 [_usedAIs addObject:name];
107
108 fileScanner = [[self verifier] fileScannerStage];
109 if (![fileScanner fileExists:name
110 inFolder:@"AIs"
111 referencedFrom:[NSString stringWithFormat:@"shipdata.plist entry \"%@\"", shipName]
112 checkBuiltIn:YES])
113 {
114 OOLog(@"verifyOXP.validateAI.notFound", @"----- WARNING: AI state machine \"%@\" referenced in shipdata.plist entry \"%@\" could not be found in %@ or in Oolite.", name, shipName, [[self verifier] oxpDisplayName]);
115 }
116}
#define OOLog(class, format,...)
Definition OOLogging.h:88

◆ validateAI:

- (void) validateAI: (NSString *) aiName
implementation

Provided by category OOAIStateMachineVerifierStage(Private).

Definition at line 34 of file OOAIStateMachineVerifierStage.m.

123 :(NSString *)aiName
124{
125 NSString *path = nil;
126 NSDictionary *aiStateMachine = nil;
127 NSEnumerator *stateEnum = nil;
128 NSString *stateKey = nil;
129 NSDictionary *stateHandlers = nil;
130 NSEnumerator *handlerEnum = nil;
131 NSString *handlerKey = nil;
132 NSArray *handlerActions = nil;
133 NSEnumerator *actionEnum = nil;
134 NSString *action = nil;
135 NSRange spaceRange;
136 NSString *selector = nil;
137 NSMutableSet *badSelectors = nil;
138 NSString *badSelectorDesc = nil;
139 NSUInteger index = 0;
140
141 OOLog(@"verifyOXP.verbose.validateAI", @"- Validating AI \"%@\".", aiName);
142 OOLogIndentIf(@"verifyOXP.verbose.validateAI");
143
144 // Attempt to load AI.
145 path = [[[self verifier] fileScannerStage] pathForFile:aiName inFolder:@"AIs" referencedFrom:@"AI list" checkBuiltIn:NO];
146 if (path == nil) return;
147
148 badSelectors = [NSMutableSet set];
149
150 aiStateMachine = OODictionaryFromFile(path);
151 if (aiStateMachine == nil)
152 {
153 OOLog(@"verifyOXP.validateAI.failed.notDictPlist", @"***** ERROR: could not interpret \"%@\" as a dictionary.", path);
154 return;
155 }
156
157 // Validate each state.
158 for (stateEnum = [aiStateMachine keyEnumerator]; (stateKey = [stateEnum nextObject]); )
159 {
160 stateHandlers = [aiStateMachine objectForKey:stateKey];
161 if (![stateHandlers isKindOfClass:[NSDictionary class]])
162 {
163 OOLog(@"verifyOXP.validateAI.failed.invalidFormat.state", @"***** ERROR: state \"%@\" in AI \"%@\" is not a dictionary.", stateKey, aiName);
164 continue;
165 }
166
167 // Verify handlers for this state.
168 for (handlerEnum = [stateHandlers keyEnumerator]; (handlerKey = [handlerEnum nextObject]); )
169 {
170 handlerActions = [stateHandlers objectForKey:handlerKey];
171 if (![handlerActions isKindOfClass:[NSArray class]])
172 {
173 OOLog(@"verifyOXP.validateAI.failed.invalidFormat.handler", @"***** ERROR: handler \"%@\" for state \"%@\" in AI \"%@\" is not an array, ignoring.", handlerKey, stateKey, aiName);
174 continue;
175 }
176
177 // Verify commands for this handler.
178 index = 0;
179 for (actionEnum = [handlerActions objectEnumerator]; (action = [actionEnum nextObject]); )
180 {
181 index++;
182 if (![action isKindOfClass:[NSString class]])
183 {
184 OOLog(@"verifyOXP.validateAI.failed.invalidFormat.action", @"***** ERROR: action %lu in handler \"%@\" for state \"%@\" in AI \"%@\" is not a string, ignoring.", index - 1, handlerKey, stateKey, aiName);
185 continue;
186 }
187
188 // Trim spaces from beginning and end.
189 action = [action stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
190
191 // Cut off parameters.
192 spaceRange = [action rangeOfString:@" "];
193 if (spaceRange.location == NSNotFound) selector = action;
194 else selector = [action substringToIndex:spaceRange.location];
195
196 // Check against whitelist.
197 if (![_whitelist containsObject:selector])
198 {
199 [badSelectors addObject:selector];
200 }
201 }
202 }
203 }
204
205 if ([badSelectors count] != 0)
206 {
207 badSelectorDesc = [[[badSelectors allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] componentsJoinedByString:@", "];
208 OOLog(@"verifyOXP.validateAI.failed.badSelector", @"***** ERROR: the AI \"%@\" uses %lu unpermitted method%s: %@", aiName, [badSelectors count], ([badSelectors count] == 1) ? "" : "s", badSelectorDesc);
209 }
210
211 OOLogOutdentIf(@"verifyOXP.verbose.validateAI");
212}
#define OOLogOutdentIf(class)
Definition OOLogging.h:102
#define OOLogIndentIf(class)
Definition OOLogging.h:101
NSDictionary * OODictionaryFromFile(NSString *path)
unsigned count

Member Data Documentation

◆ _usedAIs

- (NSMutableSet*) _usedAIs
private

Definition at line 36 of file OOAIStateMachineVerifierStage.h.

◆ _whitelist

- (NSSet*) _whitelist
private

Definition at line 35 of file OOAIStateMachineVerifierStage.h.


The documentation for this class was generated from the following files: