Przeglądaj źródła

Minor tweaks to remove warnings. Adjusted script runner algorythm to hold down the trigger until after the guard time expires.

git-svn-id: https://svn.microneil.com/svn/SNFMulti/trunk@16 dc71a809-1921-45c4-985c-09c81d0142d9
wx
madscientist 15 lat temu
rodzic
commit
4b288dc970
2 zmienionych plików z 37 dodań i 28 usunięć
  1. 32
    26
      SNFMulti.cpp
  2. 5
    2
      SNFMulti.hpp

+ 32
- 26
SNFMulti.cpp Wyświetl plik



//// Version Info //// Version Info


const char* SNF_ENGINE_VERSION = "SNFMulti Engine Version 3.0.5 Build: " __DATE__ " " __TIME__;
const char* SNF_ENGINE_VERSION = "SNFMulti Engine Version 3.0.6 Build: " __DATE__ " " __TIME__;


//// Script Caller Methods //// Script Caller Methods


Thread(ScriptCaller::Type, S), // Set up the thread type and name. Thread(ScriptCaller::Type, S), // Set up the thread type and name.
GuardTimer(ScriptGuardDefault), // Initialize the guard time. GuardTimer(ScriptGuardDefault), // Initialize the guard time.
GoFlag(false), // Not ready to go yet. GoFlag(false), // Not ready to go yet.
DieFlag(false) { // Not ready to die yet.
DieFlag(false), // Not ready to die yet.
myLastResult(0) { // No last result yet.
run(); // Launch the thread. run(); // Launch the thread.
} }


GoFlag = true; // Set the flag. GoFlag = true; // Set the flag.
} }


int ScriptCaller::LastResult() { // Return the result code from
return myLastResult; // the last system() call.
}

void ScriptCaller::myTask() { // Safely call system() when triggered. void ScriptCaller::myTask() { // Safely call system() when triggered.
Sleeper WaitATic(1000); // One second sleeper. Sleeper WaitATic(1000); // One second sleeper.
while(false == DieFlag) { // While it's not time to die: while(false == DieFlag) { // While it's not time to die:
if(true == GoFlag) { // If GoFlag is triggered and if(true == GoFlag) { // If GoFlag is triggered and
if(hasGuardExpired()) { // Guard time is expired: if(hasGuardExpired()) { // Guard time is expired:
CurrentThreadState(CallingSystem); // Publish our state. CurrentThreadState(CallingSystem); // Publish our state.
system(ScriptThisRound.c_str()); // Make the system call.
myLastResult = system(ScriptThisRound.c_str()); // Make the system call.
GoFlag = false; // Done with that trigger. GoFlag = false; // Done with that trigger.
GuardTimer.restart(); // Restart our Guard Time. GuardTimer.restart(); // Restart our Guard Time.
} else { // If we're waiting for Guard Time: } else { // If we're waiting for Guard Time:
CurrentThreadState(PendingGuardTime); // publish that state.
CurrentThreadState(PendingGuardTime); // publish that state and hold down
GoFlag = false; // the trigger signal (no stale go).
} }
} else { // If nothing is triggered yet then } else { // If nothing is triggered yet then
CurrentThreadState(StandingBy); // we are standing by. CurrentThreadState(StandingBy); // we are standing by.


snf_Reloader::snf_Reloader(snf_RulebaseHandler& R) : // When we are created, we snf_Reloader::snf_Reloader(snf_RulebaseHandler& R) : // When we are created, we
Thread(snf_Reloader::Type, "Reloader"), // brand and name our thread. Thread(snf_Reloader::Type, "Reloader"), // brand and name our thread.
MyRulebase(R), // Capture the rulebase handler.
TimeToStop(false), // It's not time to stop yet.
MyRulebase(R), // Capture the rulebase handler.
TimeToStop(false), // It's not time to stop yet.
RulebaseGetter("RulebaseGetter"), // Setup our ScriptCaller thread. RulebaseGetter("RulebaseGetter"), // Setup our ScriptCaller thread.
RulebaseGetterIsTurnedOn(false) { // Rulebase getter is off at first.
RulebaseGetterIsTurnedOn(false) { // Rulebase getter is off at first.
captureFileStats(); // Set up the initial stats. captureFileStats(); // Set up the initial stats.
captureGetterConfig(); // Set up RulebaseGetter config. captureGetterConfig(); // Set up RulebaseGetter config.
run(); // Run our maintenenace thread. run(); // Run our maintenenace thread.
// done it will reset from the "RefreshInProgress" state and along the way will throw any errors that // done it will reset from the "RefreshInProgress" state and along the way will throw any errors that
// are appropriate. The other functions can count on this one to polish off the various forms of rulebase // are appropriate. The other functions can count on this one to polish off the various forms of rulebase
// load activity. // load activity.
const LogicCheck SaneRefreshProcessCheck("snf_RulebaseHandler::_snf_LoadNewRulebase():SaneRefreshProcessCheck(RefreshInProgress)");
const LogicCheck SaneRefreshProcessCheck("snf_RulebaseHandler::_snf_LoadNewRulebase():SaneRefreshProcessCheck(RefreshInProgress)");


void snf_RulebaseHandler::_snf_LoadNewRulebase(){ // Common internal load/check routine. void snf_RulebaseHandler::_snf_LoadNewRulebase(){ // Common internal load/check routine.
SaneRefreshProcessCheck(RefreshInProgress); // We only get called when this flag is set. SaneRefreshProcessCheck(RefreshInProgress); // We only get called when this flag is set.


return ExtractedID; // Return the extracted id or substitute. return ExtractedID; // Return the extracted id or substitute.
} }
const LogicFault FaultBadMessageBuffer1("snf_EngineHandler::scanMessage():FaultBadMessageBuffer1(NULL == inputMessageBuffer)");
const LogicFault FaultBadMessageBuffer2("snf_EngineHandler::scanMessage():FaultBadMessageBuffer2(0 >= inputMessageLength)");
const LogicFault FaultBadMessageBuffer1("snf_EngineHandler::scanMessage():FaultBadMessageBuffer1(NULL == inputMessageBuffer)");
const LogicFault FaultBadMessageBuffer2("snf_EngineHandler::scanMessage():FaultBadMessageBuffer2(0 >= inputMessageLength)");


int snf_EngineHandler::scanMessage( // Scan this message (in buffer). int snf_EngineHandler::scanMessage( // Scan this message (in buffer).
const unsigned char* inputMessageBuffer, // -- this is the message buffer. const unsigned char* inputMessageBuffer, // -- this is the message buffer.
const IP4Address MessageSource // -- message source IP (for injection). const IP4Address MessageSource // -- message source IP (for injection).
) { ) {


ScopeTimer ScanTimeCapture(MyScanData.ScanTime); // Start the scan time clock.
unsigned char* MessageBuffer = NULL; // Explicitly initialize these two
int MessageLength = 0; // so the compiler will be happy.
FaultBadMessageBuffer1(NULL == inputMessageBuffer); // Fault on null message buffer.
FaultBadMessageBuffer2(0 >= inputMessageLength); // Fault on bad message bfr length.
ScopeTimer ScanTimeCapture(MyScanData.ScanTime); // Start the scan time clock.
unsigned char* MessageBuffer = NULL; // Explicitly initialize these two
int MessageLength = 0; // so the compiler will be happy.
FaultBadMessageBuffer1(NULL == inputMessageBuffer); // Fault on null message buffer.
FaultBadMessageBuffer2(0 >= inputMessageLength); // Fault on bad message bfr length.
// Protect this engine - only one scan at a time per EngineHandler ;-) // Protect this engine - only one scan at a time per EngineHandler ;-)


ScopeMutex ScannerIsBusy(MyMutex); // Serialize this... ScopeMutex ScannerIsBusy(MyMutex); // Serialize this...
break; // That's all. break; // That's all.
} }


case New: {
case New: {
break; break;
} }


} }
} }
break; break;
}
case Unknown: // Unknown - most likely we couldn't
default: { // find a usable source.
break; // Do nothing.
}
case Unknown: // Unknown - most likely we couldn't
default: { // find a usable source.
break; // Do nothing.
} }
} }
} // End of IP source depended work (GBUdbOverrides) } // End of IP source depended work (GBUdbOverrides)

+ 5
- 2
SNFMulti.hpp Wyświetl plik

Mutex MyMutex; // Protects internal data. Mutex MyMutex; // Protects internal data.
string SystemCallText; // Text to send to system(). string SystemCallText; // Text to send to system().
Timeout GuardTimer; // Guard time between triggers. Timeout GuardTimer; // Guard time between triggers.
bool GoFlag; // Go flag true when triggered.
bool DieFlag; // Die flag when it's time to leave.
volatile bool GoFlag; // Go flag true when triggered.
volatile bool DieFlag; // Die flag when it's time to leave.


string ScriptToRun(); // Safely grab the script. string ScriptToRun(); // Safely grab the script.
bool hasGuardExpired(); // True if guard time has expired. bool hasGuardExpired(); // True if guard time has expired.
void myTask(); // Thread task overload. void myTask(); // Thread task overload.


volatile int myLastResult; // Last result of system() call.

public: public:
ScriptCaller(string Name); // Constructor. ScriptCaller(string Name); // Constructor.
~ScriptCaller(); // Destructor. ~ScriptCaller(); // Destructor.
void SystemCall(string S); // Set system call text. void SystemCall(string S); // Set system call text.
void GuardTime(int T); // Change guard time. void GuardTime(int T); // Change guard time.
void trigger(); // Trigger if possible. void trigger(); // Trigger if possible.
int LastResult(); // Return myLastResult.


const static ThreadType Type; // The thread's type. const static ThreadType Type; // The thread's type.



Ładowanie…
Anuluj
Zapisz