Bladeren bron

Sketched in ScannerPool.cpp

Successfully compiled & linked skeleton app :-)


git-svn-id: https://svn.microneil.com/svn/SNF4CGP/trunk@18 59e8e3e7-56fa-483b-b4b4-fa6ab0af3dfc
master
madscientist 15 jaren geleden
bovenliggende
commit
e9131c36d5
3 gewijzigde bestanden met toevoegingen van 92 en 13 verwijderingen
  1. 0
    11
      SNF4CGP/ExecutiveProcess.cpp
  2. 87
    0
      SNF4CGP/ScannerPool.cpp
  3. 5
    2
      SNF4CGP/ScannerPool.hpp

+ 0
- 11
SNF4CGP/ExecutiveProcess.cpp Bestand weergeven

@@ -10,17 +10,6 @@
using namespace std;
/**** this is wrong
***** Creating the ExecutiveProcess will create the raw JobPool, WorkerPool, Input, and Output modules
***** in an uninitialized state. They will then be initialized by these processes. This prevents the
***** chicken-and-egg problem that happens when one two objects need to know about each other in order
***** to operate properly. This means that each of these objects must have an init() and stop() method.
****/
RuntimeCheck CheckJobPoolNotNull("ExecutiveProcess::initializeOutput() Check(0 != Jobs)");
RuntimeCheck CheckOutputProccessorWasConstructed("ExecutiveProcess::initializeOutput() Check(0 != Output)");
RuntimeCheck CheckOutputProcessorWasStarted("ExecutiveProcess::initializeOutput() Check(Output->isRunning())");
void ExecutiveProcess::initializeOutput() {
Output.init(Jobs);
}

+ 87
- 0
SNF4CGP/ScannerPool.cpp Bestand weergeven

@@ -1,3 +1,90 @@
// SNF4CGP/ScannerPool.cpp
// Copyright (C) 2009 ARM Research Labs, LLC.
// See www.armresearch.com for more information.
#include "ScannerPool.hpp"
#include "../SNFMulti/SNFMulti.hpp"
#include "../CodeDweller/threading.hpp"
#include "../CodeDweller/faults.hpp"
using namespace std;
//// Scanner ///////////////////////////////////////////////////////////////////
Scanner::Scanner(snf_RulebaseHandler& Rulebase) : // When constructed allocates an engine.
Rulebase_(Rulebase), // At it's core is a Rulebase handle.
Engine_(new snf_EngineHandler()) { // It contains it's own scan engine.
Engine_->open(&Rulebase); // The scan engine is initialized.
}
Scanner::~Scanner() { // When destructed destroys the engine.
try { // Destructors don't throw.
if(Engine_) { // Safely destroy the engine.
Engine_->close();
Engine_=0;
}
}
catch(...) {}
}
snf_RulebaseHandler& Scanner::Rulebase() { // Provide access to the Rulebase
return Rulebase_;
}
RuntimeCheck CheckScannerEngineIsValid("Scanner::Engine() Check(0 != Engine_)");
snf_EngineHandler& Scanner::Engine() { // Provide access to the Engine.
CheckScannerEngineIsValid(0 != Engine_);
return (*Engine_);
}
//// ScannerPool ///////////////////////////////////////////////////////////////
ScannerPool::ScannerPool() : // Constructed simply.
Rulebase_(0),
ScannerCount(0) {
}
ScannerPool::~ScannerPool() { // Cleanup on the way out.
try { stop(); }
catch(...) {}
}
void ScannerPool::init(string Configuration) { // Get ready to provide scanners.
}
void ScannerPool::stop() { // Shutdown and clean up.
}
Scanner* ScannerPool::makeScanner() { // Create and count a scanner.
}
Scanner& ScannerPool::grab() { // Provides a Scanner from the pool.
}
void ScannerPool::killScannerFromPool() { // Destroy and count a pooled scanner.
}
void ScannerPool::drop(Scanner& S) { // Returns a Scanner to the pool.
}
//// ScopeScanner //////////////////////////////////////////////////////////////
ScopeScanner::ScopeScanner(ScannerPool& P) : // Constructed with the pool.
ScannerPool_(P),
Scanner_(P.grab()) { // Grabs a Scanner on the way up.
}
ScopeScanner::~ScopeScanner() { // When destroyed drops the scanner.
try { ScannerPool_.drop(Scanner_); }
catch(...) {}
}
snf_RulebaseHandler& ScopeScanner::Rulebase() { // Provides access to the Rulebase.
return Scanner_.Rulebase();
}
snf_EngineHandler& ScopeScanner::Engine() { // Provides access to a scan engine.
return Scanner_.Engine();
}

+ 5
- 2
SNF4CGP/ScannerPool.hpp Bestand weergeven

@@ -39,8 +39,11 @@ class ScannerPool {
unsigned int ScannerCount; // Allocates and counts scanners.
ProductionQueue<Scanner*> PooledScanners; // Pool of ready-to-go scanners.
Scanner* makeScanner(); // Make and count a scanner.
void killScannerFromPool(); // Kill and count a pooled scanner.
public:
ScannerPool(); // Constructed with Rulebase config.
ScannerPool(); // Constructed simply.
~ScannerPool(); // Cleans up when destroyed.
void init(string Configuration); // Get ready to provide scanners.
void stop(); // Shutdown and clean up.
@@ -57,7 +60,7 @@ class ScannerPool {
class ScopeScanner { // Temporary handle for a Scanner.
private:
ScannerPool& ScannerPool_; // Knows the scanner pool.
Scanner* Scanner_; // Holds a pointer to a scanner.
Scanner& Scanner_; // Holds a pointer to a scanner.
public:

Laden…
Annuleren
Opslaan