|
|
@@ -50,6 +50,60 @@ |
|
|
|
|
|
|
|
#include "CodeDweller/service.hpp" |
|
|
|
|
|
|
|
/// Callback functor for Pause message. |
|
|
|
class PauseCallback : public CodeDweller::Service::Callback { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
PauseCallback() : pauseFlag(false) {} |
|
|
|
|
|
|
|
bool pauseFlag; |
|
|
|
|
|
|
|
void operator()() { |
|
|
|
pauseFlag = true; |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
PauseCallback pauseCbck; |
|
|
|
PauseCallback pauseCbck1; |
|
|
|
|
|
|
|
/// Callback functor for Resume message. |
|
|
|
class ResumeCallback : public CodeDweller::Service::Callback { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
ResumeCallback() : resumeFlag(false) {} |
|
|
|
|
|
|
|
bool resumeFlag; |
|
|
|
|
|
|
|
void operator()() { |
|
|
|
resumeFlag = true; |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
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 { |
|
|
|
|
|
|
@@ -65,15 +119,17 @@ public: |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
StopCallback stopCallback; |
|
|
|
StopCallback stopCbck; |
|
|
|
StopCallback stopCbck1; |
|
|
|
StopCallback notStopCbck; |
|
|
|
|
|
|
|
int CodeDweller::Service::run() { |
|
|
|
|
|
|
|
// Get the singleton. |
|
|
|
CodeDweller::Service &service = CodeDweller::Service::getInstance(); |
|
|
|
CodeDweller::Service &svc = CodeDweller::Service::getInstance(); |
|
|
|
|
|
|
|
// Get the log file name. |
|
|
|
auto arguments = service.arguments(); |
|
|
|
auto arguments = svc.arguments(); |
|
|
|
|
|
|
|
if (arguments.size() != 2) { |
|
|
|
return(EXIT_FAILURE); |
|
|
@@ -82,19 +138,66 @@ int CodeDweller::Service::run() { |
|
|
|
// Get log file. |
|
|
|
std::ofstream logStream(arguments[1]); |
|
|
|
|
|
|
|
// Register the Stop callback. |
|
|
|
service.onStopCall(&stopCallback); |
|
|
|
// Register the callbacks. |
|
|
|
svc.onPauseCall(pauseCbck); |
|
|
|
svc.onPauseCall(pauseCbck1); |
|
|
|
|
|
|
|
while (!stopCallback.stopFlag) { |
|
|
|
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 << "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; |
|
|
|
logStream << "pauseCbck1.pauseFlag: " << pauseCbck1.pauseFlag << std::endl; |
|
|
|
logStream << "resumeCbck.resumeFlag: " << resumeCbck.resumeFlag |
|
|
|
<< 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; |
|
|
|
|
|
|
|
pauseCbck.pauseFlag = false; |
|
|
|
pauseCbck1.pauseFlag = false; |
|
|
|
resumeCbck.resumeFlag = false; |
|
|
|
resumeCbck1.resumeFlag = false; |
|
|
|
restartCbck.restartFlag = false; |
|
|
|
restartCbck1.restartFlag = false; |
|
|
|
|
|
|
|
logStream << std::endl; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
logStream << "receivedStop(): " << service.receivedStop() << std::endl; |
|
|
|
service.clearReceivedStop(); |
|
|
|
logStream << "receivedStop(): " << service.receivedStop() << std::endl; |
|
|
|
logStream << "Exiting." << std::endl; |
|
|
|
|
|
|
|
logStream.close(); |
|
|
|
|