The ScoutSecure Wi-Fi Security & Monitoring Framework
by Michael Larson

Listing One

/*******  Result  ********/
class ResultBase
{
public:
   /* Constructor and Destructor */
   ResultBase(TestType type) : result_time_(0) {;}
   virtual ~ResultBase() {;}
   /* cloning operation */
   virtual ResultBase*
   clone() const = 0;
   void
   set_result_time(unsigned long time) {result_time_ = time;}
   unsigned long
   get_result_time() const {return result_time_;}
private:
   unsigned long result_time_;
};
/******* Test ***********/
class Test
{
public:
public:
   /* Constructor and Destructor */
   Test(TestType type) : test_type_(type), target_(0) {;}
   ~Test();
   /* Copy Constructor */
   Test(const Test &test); //copy constructor
   /* Assignment operator */
   Test& operator=(const Test &test); //assignment operator
   /* Returns target host */
   unsigned long
   get_target() const {return target_;}
   /* Sets target host */
   void
   set_target(unsigned long target) {target_ = target;}
   /* */
   TestType
   get_test() const {return test_type_;}
   void
   set_result(const ResultBase *result);
   ResultBase*
private:
   TestType test_type_;    //type of test to perform
   unsigned long target_;  //target address, 0 means all
   ResultBase *result_;    //result to be returned to action
};


Listing Two

void
ToolManager::run()
{
   ToolBase *tool_base;
   cout << "ToolManager::StartTask::run(), starting..." << endl;
   while (true)
   {
      Test *test(get());
      if (test != NULL)
      {
         //find tool for test type
         tool_base = getTool(test->get_test());
         if (tool_base != NULL)
         {
            //dispatch to tool for processing
            tool_base->put(test);
         }
         else
         {
            //not found. delete.
            delete test;
         }
      }
      else
      {
         cout << "event is null..." << endl;
      }
   }
}

Listing Three

/** Dispatch support class. Definition/implementation for Test distribution */
class Dispatch : public unary_function < Test, void >
{
public:
   //constructor
   Dispatch(Test *test) : test_(test) {;}
   void operator() (ActionBase *action)
   {
      //put copy of test into each registered action
      action->put(new Test(*test_));
   }
private:
   Test *test_; //pointer of test to distribute
};
/** ActionManager::run(). Manager test dispatching thread **/
void
ActionManager::run()
{
  while (true)
   {
    GUARD(&mutex_);
    //block until new test and result are received
    auto_ptr<Test> test(get());
    if (test.get() != NULL)
     {
     //dispatches copy of results to each registered action
     for_each(action_coll_.begin(), action_coll_.end(), Dispatch(test.get()));
    }
  }
}





1


