You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScannerPool.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SNF4CGP/ScannerPool.cpp
  2. // Copyright (C) 2009 ARM Research Labs, LLC.
  3. // See www.armresearch.com for more information.
  4. #include "ScannerPool.hpp"
  5. #include "../SNFMulti/SNFMulti.hpp"
  6. #include "../CodeDweller/threading.hpp"
  7. #include "../CodeDweller/faults.hpp"
  8. using namespace std;
  9. //// Scanner ///////////////////////////////////////////////////////////////////
  10. Scanner::Scanner(snf_RulebaseHandler& Rulebase) : // When constructed allocates an engine.
  11. Rulebase_(Rulebase), // At it's core is a Rulebase handle.
  12. Engine_(new snf_EngineHandler()) { // It contains it's own scan engine.
  13. Engine_->open(&Rulebase); // The scan engine is initialized.
  14. }
  15. Scanner::~Scanner() { // When destructed destroys the engine.
  16. try { // Destructors don't throw.
  17. if(Engine_) { // Safely destroy the engine.
  18. Engine_->close();
  19. Engine_=0;
  20. }
  21. }
  22. catch(...) {}
  23. }
  24. snf_RulebaseHandler& Scanner::Rulebase() { // Provide access to the Rulebase
  25. return Rulebase_;
  26. }
  27. RuntimeCheck CheckScannerEngineIsValid("Scanner::Engine() Check(0 != Engine_)");
  28. snf_EngineHandler& Scanner::Engine() { // Provide access to the Engine.
  29. CheckScannerEngineIsValid(0 != Engine_);
  30. return (*Engine_);
  31. }
  32. //// ScannerPool ///////////////////////////////////////////////////////////////
  33. ScannerPool::ScannerPool() : // Constructed simply.
  34. Rulebase_(0),
  35. ScannerCount(0) {
  36. }
  37. ScannerPool::~ScannerPool() { // Cleanup on the way out.
  38. try { stop(); }
  39. catch(...) {}
  40. }
  41. void ScannerPool::init(string Configuration) { // Get ready to provide scanners.
  42. }
  43. void ScannerPool::stop() { // Shutdown and clean up.
  44. }
  45. Scanner* ScannerPool::makeScanner() { // Create and count a scanner.
  46. }
  47. Scanner& ScannerPool::grab() { // Provides a Scanner from the pool.
  48. }
  49. void ScannerPool::killScannerFromPool() { // Destroy and count a pooled scanner.
  50. }
  51. void ScannerPool::drop(Scanner& S) { // Returns a Scanner to the pool.
  52. }
  53. //// ScopeScanner //////////////////////////////////////////////////////////////
  54. ScopeScanner::ScopeScanner(ScannerPool& P) : // Constructed with the pool.
  55. ScannerPool_(P),
  56. Scanner_(P.grab()) { // Grabs a Scanner on the way up.
  57. }
  58. ScopeScanner::~ScopeScanner() { // When destroyed drops the scanner.
  59. try { ScannerPool_.drop(Scanner_); }
  60. catch(...) {}
  61. }
  62. snf_RulebaseHandler& ScopeScanner::Rulebase() { // Provides access to the Rulebase.
  63. return Scanner_.Rulebase();
  64. }
  65. snf_EngineHandler& ScopeScanner::Engine() { // Provides access to a scan engine.
  66. return Scanner_.Engine();
  67. }