Oolite
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 44 of file OOAIStateMachineVerifierStage.m.

45{
46 [_whitelist release];
47 [_usedAIs release];
48
49 [super dealloc];
50}

References dealloc, and OOOXPVerifierStage::dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name

- (NSString *) name
implementation

Reimplemented from OOOXPVerifierStage.

Definition at line 52 of file OOAIStateMachineVerifierStage.m.

53{
54 return kStageName;
55}
static NSString *const kStageName

References kStageName, and name.

Referenced by name, and stateMachineNamed:usedByShip:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nameForReverseDependencyForVerifier:

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

Definition at line 85 of file OOAIStateMachineVerifierStage.m.

85 :(OOOXPVerifier*)verifier
86{
87 return kStageName;
88}
OOOXPVerifier * verifier()

References kStageName.

Referenced by OOCheckShipDataPListVerifierStage::dependents, and OOCheckShipDataPListVerifierStage::run.

Here is the caller graph for this function:

◆ run

- (void) run
implementation

Reimplemented from OOOXPVerifierStage.

Definition at line 62 of file OOAIStateMachineVerifierStage.m.

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

References _whitelist, nil, run, validateAI:, and ResourceManager::whitelistDictionary.

Referenced by run.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shouldRun

- (BOOL) shouldRun
implementation

Reimplemented from OOOXPVerifierStage.

Definition at line 57 of file OOAIStateMachineVerifierStage.m.

58{
59 return [_usedAIs count] != 0;
60}

References shouldRun.

Referenced by shouldRun.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stateMachineNamed:usedByShip:

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

Definition at line 90 of file OOAIStateMachineVerifierStage.m.

90 :(NSString*)name usedByShip:(NSString*)shipName
91{
92 OOFileScannerVerifierStage* fileScanner = nil;
93
94 if (name == nil)
95 return;
96 if ([_usedAIs containsObject:name])
97 return;
98 if (_usedAIs == nil)
99 _usedAIs = [[NSMutableSet alloc] init];
100 [_usedAIs addObject:name];
101
102 fileScanner = [[self verifier] fileScannerStage];
103 if (![fileScanner fileExists:name
104 inFolder:@"AIs"
105 referencedFrom:[NSString stringWithFormat:@"shipdata.plist entry \"%@\"", shipName]
106 checkBuiltIn:YES]) {
107 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]);
108 }
109}
#define OOLog(class, format,...)
Definition OOLogging.h:84

References _usedAIs, OOOXPVerifier::fileScannerStage, name, nil, OOLog, and OOOXPVerifierStage::verifier.

Here is the call graph for this function:

◆ validateAI:

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

Provided by category OOAIStateMachineVerifierStage(Private).

Definition at line 115 of file OOAIStateMachineVerifierStage.m.

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

Referenced by run.

Here is the caller graph for this function:

Member Data Documentation

◆ _usedAIs

- (NSMutableSet*) _usedAIs
private

Definition at line 35 of file OOAIStateMachineVerifierStage.h.

Referenced by stateMachineNamed:usedByShip:.

◆ _whitelist

- (NSSet*) _whitelist
private

Definition at line 34 of file OOAIStateMachineVerifierStage.h.

Referenced by run.


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