|
|
@@ -22,6 +22,7 @@ Scanner::~Scanner() { |
|
|
|
try { // Destructors don't throw.
|
|
|
|
if(Engine_) { // Safely destroy the engine.
|
|
|
|
Engine_->close();
|
|
|
|
delete Engine_;
|
|
|
|
Engine_=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -42,31 +43,69 @@ snf_EngineHandler& Scanner::Engine() { |
|
|
|
//// ScannerPool ///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
ScannerPool::ScannerPool() : // Constructed simply.
|
|
|
|
Rulebase_(0),
|
|
|
|
ScannerCount(0) {
|
|
|
|
Rulebase_(new snf_RulebaseHandler()),
|
|
|
|
ScannerCount(0),
|
|
|
|
Started(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ScannerPool::~ScannerPool() { // Cleanup on the way out.
|
|
|
|
try { stop(); }
|
|
|
|
try {
|
|
|
|
stop();
|
|
|
|
delete Rulebase_;
|
|
|
|
Rulebase_ = 0;
|
|
|
|
}
|
|
|
|
catch(...) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScannerPool::init(string Configuration) { // Get ready to provide scanners.
|
|
|
|
RuntimeCheck CheckRulebaseExists("ScannerPool::Rulebase() Check(0 != Rulebase_)");
|
|
|
|
|
|
|
|
snf_RulebaseHandler& ScannerPool::Rulebase() { // Safe access to the rulebase.
|
|
|
|
CheckRulebaseExists(0 != Rulebase_);
|
|
|
|
return (*Rulebase_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScannerPool::init(const string Configuration) { // Get ready to provide scanners.
|
|
|
|
Rulebase().open(Configuration.c_str(), "", ""); // Light up the rulebase manager.
|
|
|
|
Scanner* FirstScanner = new Scanner(Rulebase()); // Create our first scanner.
|
|
|
|
PooledScanners.give(FirstScanner); // Drop it into the pool.
|
|
|
|
Started = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScannerPool::killScannerFromPool() { // Destroy and count a pooled scanner.
|
|
|
|
Scanner* ScannerToKill = 0;
|
|
|
|
ScannerToKill = PooledScanners.take();
|
|
|
|
delete ScannerToKill;
|
|
|
|
--ScannerCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScannerPool::stop() { // Shutdown and clean up.
|
|
|
|
ScopeMutex Busy(AllocationControl);
|
|
|
|
while(0 < ScannerCount) killScannerFromPool();
|
|
|
|
Rulebase().close();
|
|
|
|
Started = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Scanner* ScannerPool::makeScanner() { // Create and count a scanner.
|
|
|
|
Scanner* NewScanner = new Scanner(Rulebase());
|
|
|
|
++ScannerCount;
|
|
|
|
return NewScanner;
|
|
|
|
}
|
|
|
|
|
|
|
|
Scanner& ScannerPool::grab() { // Provides a Scanner from the pool.
|
|
|
|
}
|
|
|
|
LogicCheck CheckGrabScannersOnlyWhenStarted("ScannerPool::grab() Check(Started)");
|
|
|
|
RuntimeCheck CheckForValidGrabbedScanner("ScannerPool::grab() Check(0 != GrabbedScanner)");
|
|
|
|
|
|
|
|
void ScannerPool::killScannerFromPool() { // Destroy and count a pooled scanner.
|
|
|
|
Scanner& ScannerPool::grab() { // Provides a Scanner from the pool.
|
|
|
|
ScopeMutex Busy(AllocationControl);
|
|
|
|
CheckGrabScannersOnlyWhenStarted(Started);
|
|
|
|
Scanner* GrabbedScanner = 0;
|
|
|
|
if(0 < PooledScanners.size()) GrabbedScanner = PooledScanners.take(); // Prefer scanners from the pool.
|
|
|
|
else GrabbedScanner = makeScanner(); // Make new ones if needed.
|
|
|
|
CheckForValidGrabbedScanner(0 != GrabbedScanner);
|
|
|
|
return (*GrabbedScanner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScannerPool::drop(Scanner& S) { // Returns a Scanner to the pool.
|
|
|
|
PooledScanners.give(&S);
|
|
|
|
}
|
|
|
|
|
|
|
|
//// ScopeScanner //////////////////////////////////////////////////////////////
|