123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include <cstdlib>
- #include <fstream>
- #include <thread>
-
- #include "CodeDweller/service.hpp"
-
-
- class PauseCallback : public CodeDweller::Service::Callback {
-
- public:
-
- PauseCallback() : pauseFlag(false) {}
-
- bool pauseFlag;
-
- void operator()() {
- pauseFlag = true;
- }
-
- };
-
- PauseCallback pauseCbck;
- PauseCallback pauseCbck1;
-
-
- class ResumeCallback : public CodeDweller::Service::Callback {
-
- public:
-
- ResumeCallback() : resumeFlag(false) {}
-
- bool resumeFlag;
-
- void operator()() {
- resumeFlag = true;
- }
-
- };
-
- ResumeCallback resumeCbck;
- ResumeCallback resumeCbck1;
-
-
- class StopCallback : public CodeDweller::Service::Callback {
-
- public:
-
- StopCallback() : stopFlag(false) {}
-
- bool stopFlag;
-
- void operator()() {
- stopFlag = true;
- }
-
- };
-
- StopCallback stopCbck;
- StopCallback stopCbck1;
- StopCallback notStopCbck;
-
- int CodeDweller::Service::run() {
-
-
- auto arguments = CodeDweller::Service::arguments();
-
- if (arguments.size() != 2) {
- return(EXIT_FAILURE);
- }
-
-
- std::ofstream logStream(arguments[1]);
-
-
- CodeDweller::Service::onPauseCall(pauseCbck);
- CodeDweller::Service::onPauseCall(pauseCbck1);
-
- CodeDweller::Service::onResumeCall(resumeCbck);
- CodeDweller::Service::onResumeCall(resumeCbck1);
-
- CodeDweller::Service::onStopCall(stopCbck);
- CodeDweller::Service::onStopCall(stopCbck1);
-
- while (!stopCbck.stopFlag) {
-
- logStream << "Sleeping 2 s...";
- logStream.flush();
- std::this_thread::sleep_for(std::chrono::milliseconds(2000));
- logStream << "done." << std::endl;
-
- logStream << "receivedPause(): "
- << CodeDweller::Service::receivedPause() << std::endl;
- logStream << "receivedResume(): "
- << CodeDweller::Service::receivedResume() << std::endl;
- logStream << "receivedStop(): "
- << CodeDweller::Service::receivedStop() << std::endl;
-
- logStream << "Clearing all flags." << std::endl;
- CodeDweller::Service::clearReceivedPause();
- CodeDweller::Service::clearReceivedResume();
- CodeDweller::Service::clearReceivedStop();
-
- logStream << "receivedPause(): "
- << CodeDweller::Service::receivedPause() << std::endl;
- logStream << "receivedResume(): "
- << CodeDweller::Service::receivedResume() << std::endl;
- logStream << "receivedStop(): "
- << CodeDweller::Service::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 << "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;
-
- logStream << std::endl;
-
- }
-
- logStream << "Exiting." << std::endl;
-
- logStream.close();
-
- return(EXIT_SUCCESS);
- }
|