|
|
@@ -10,18 +10,13 @@ |
|
|
|
// |
|
|
|
// This program: |
|
|
|
// |
|
|
|
// 1) Registers a callback for the Stop message that sets a stop |
|
|
|
// flag. |
|
|
|
// 1) Registers callbacks for various messages. |
|
|
|
// |
|
|
|
// 2) While the stop flag is false, output a message to the log file |
|
|
|
// every 2 seconds. |
|
|
|
// 2) While the stop flag is false, outputs the status of all flags |
|
|
|
// to the log file every 2 seconds, and clears all flags. |
|
|
|
// |
|
|
|
// 3) After Stop is received, output the value returned by |
|
|
|
// Service::receivedStop(). |
|
|
|
// |
|
|
|
// 4) Call Service::clearReceivedStop(), and repeate step 3. |
|
|
|
// |
|
|
|
// 5) Exit. |
|
|
|
// 3) After Stop is received, output the status of all flags, and |
|
|
|
// exit. |
|
|
|
// |
|
|
|
// Copyright (C) 2014 MicroNeil Research Corporation. |
|
|
|
// |
|
|
@@ -43,10 +38,9 @@ |
|
|
|
// Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
|
//============================================================================== |
|
|
|
|
|
|
|
#include <unistd.h> |
|
|
|
|
|
|
|
#include <cstdlib> |
|
|
|
#include <fstream> |
|
|
|
#include <thread> |
|
|
|
|
|
|
|
#include "CodeDweller/service.hpp" |
|
|
|
|
|
|
@@ -86,24 +80,6 @@ public: |
|
|
|
ResumeCallback resumeCbck; |
|
|
|
ResumeCallback resumeCbck1; |
|
|
|
|
|
|
|
/// Callback functor for Restart message. |
|
|
|
class RestartCallback : public CodeDweller::Service::Callback { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
RestartCallback() : restartFlag(false) {} |
|
|
|
|
|
|
|
bool restartFlag; |
|
|
|
|
|
|
|
void operator()() { |
|
|
|
restartFlag = true; |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
RestartCallback restartCbck; |
|
|
|
RestartCallback restartCbck1; |
|
|
|
|
|
|
|
/// Callback functor for Stop message. |
|
|
|
class StopCallback : public CodeDweller::Service::Callback { |
|
|
|
|
|
|
@@ -145,31 +121,27 @@ int CodeDweller::Service::run() { |
|
|
|
svc.onResumeCall(resumeCbck); |
|
|
|
svc.onResumeCall(resumeCbck1); |
|
|
|
|
|
|
|
svc.onRestartCall(restartCbck); |
|
|
|
svc.onRestartCall(restartCbck1); |
|
|
|
|
|
|
|
svc.onStopCall(stopCbck); |
|
|
|
svc.onStopCall(stopCbck1); |
|
|
|
|
|
|
|
while (!stopCbck.stopFlag) { |
|
|
|
|
|
|
|
logStream << "Sleeping 2 s" << std::endl; |
|
|
|
sleep(2); |
|
|
|
logStream << "Sleeping 2 s..."; |
|
|
|
logStream.flush(); |
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000)); |
|
|
|
logStream << "done." << std::endl; |
|
|
|
|
|
|
|
logStream << "receivedPause(): " << svc.receivedPause() << std::endl; |
|
|
|
logStream << "receivedResume(): " << svc.receivedResume() << std::endl; |
|
|
|
logStream << "receivedRestart(): " << svc.receivedRestart() << std::endl; |
|
|
|
logStream << "receivedStop(): " << svc.receivedStop() << std::endl; |
|
|
|
|
|
|
|
logStream << "Clearing all flags." << std::endl; |
|
|
|
svc.clearReceivedPause(); |
|
|
|
svc.clearReceivedResume(); |
|
|
|
svc.clearReceivedRestart(); |
|
|
|
svc.clearReceivedStop(); |
|
|
|
|
|
|
|
logStream << "receivedPause(): " << svc.receivedPause() << std::endl; |
|
|
|
logStream << "receivedResume(): " << svc.receivedResume() << std::endl; |
|
|
|
logStream << "receivedRestart(): " << svc.receivedRestart() << std::endl; |
|
|
|
logStream << "receivedStop(): " << svc.receivedStop() << std::endl; |
|
|
|
|
|
|
|
logStream << "pauseCbck.pauseFlag: " << pauseCbck.pauseFlag << std::endl; |
|
|
@@ -178,10 +150,6 @@ int CodeDweller::Service::run() { |
|
|
|
<< std::endl; |
|
|
|
logStream << "resumeCbck1.resumeFlag: " << resumeCbck1.resumeFlag |
|
|
|
<< std::endl; |
|
|
|
logStream << "restartCbck.restartFlag: " << restartCbck.restartFlag |
|
|
|
<< std::endl; |
|
|
|
logStream << "restartCbck1.restartFlag: " << restartCbck1.restartFlag |
|
|
|
<< std::endl; |
|
|
|
logStream << "stopCbck.stopFlag: " << stopCbck.stopFlag << std::endl; |
|
|
|
logStream << "stopCbck1.stopFlag: " << stopCbck1.stopFlag << std::endl; |
|
|
|
logStream << "notStopCbck.stopFlag: " << notStopCbck.stopFlag << std::endl; |
|
|
@@ -190,8 +158,6 @@ int CodeDweller::Service::run() { |
|
|
|
pauseCbck1.pauseFlag = false; |
|
|
|
resumeCbck.resumeFlag = false; |
|
|
|
resumeCbck1.resumeFlag = false; |
|
|
|
restartCbck.restartFlag = false; |
|
|
|
restartCbck1.restartFlag = false; |
|
|
|
|
|
|
|
logStream << std::endl; |
|
|
|
|