Kaynağa Gözat

Implemented and on Windows (built with Visual Studio 2013 Express).

git-svn-id: https://svn.microneil.com/svn/CodeDweller-Tests/trunk@20 b3372362-9eaa-4a85-aa2b-6faa1ab7c995
master
adeniz 10 yıl önce
ebeveyn
işleme
5fd0917d2f
1 değiştirilmiş dosya ile 10 ekleme ve 44 silme
  1. 10
    44
      TestService/serviceProgram.cpp

+ 10
- 44
TestService/serviceProgram.cpp Dosyayı Görüntüle

// //
// This program: // 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. // Copyright (C) 2014 MicroNeil Research Corporation.
// //
// Place, Suite 330, Boston, MA 02111-1307 USA // Place, Suite 330, Boston, MA 02111-1307 USA
//============================================================================== //==============================================================================


#include <unistd.h>

#include <cstdlib> #include <cstdlib>
#include <fstream> #include <fstream>
#include <thread>


#include "CodeDweller/service.hpp" #include "CodeDweller/service.hpp"


ResumeCallback resumeCbck; ResumeCallback resumeCbck;
ResumeCallback resumeCbck1; 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. /// Callback functor for Stop message.
class StopCallback : public CodeDweller::Service::Callback { class StopCallback : public CodeDweller::Service::Callback {


svc.onResumeCall(resumeCbck); svc.onResumeCall(resumeCbck);
svc.onResumeCall(resumeCbck1); svc.onResumeCall(resumeCbck1);


svc.onRestartCall(restartCbck);
svc.onRestartCall(restartCbck1);

svc.onStopCall(stopCbck); svc.onStopCall(stopCbck);
svc.onStopCall(stopCbck1); svc.onStopCall(stopCbck1);


while (!stopCbck.stopFlag) { 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 << "receivedPause(): " << svc.receivedPause() << std::endl;
logStream << "receivedResume(): " << svc.receivedResume() << std::endl; logStream << "receivedResume(): " << svc.receivedResume() << std::endl;
logStream << "receivedRestart(): " << svc.receivedRestart() << std::endl;
logStream << "receivedStop(): " << svc.receivedStop() << std::endl; logStream << "receivedStop(): " << svc.receivedStop() << std::endl;


logStream << "Clearing all flags." << std::endl; logStream << "Clearing all flags." << std::endl;
svc.clearReceivedPause(); svc.clearReceivedPause();
svc.clearReceivedResume(); svc.clearReceivedResume();
svc.clearReceivedRestart();
svc.clearReceivedStop(); svc.clearReceivedStop();


logStream << "receivedPause(): " << svc.receivedPause() << std::endl; logStream << "receivedPause(): " << svc.receivedPause() << std::endl;
logStream << "receivedResume(): " << svc.receivedResume() << std::endl; logStream << "receivedResume(): " << svc.receivedResume() << std::endl;
logStream << "receivedRestart(): " << svc.receivedRestart() << std::endl;
logStream << "receivedStop(): " << svc.receivedStop() << std::endl; logStream << "receivedStop(): " << svc.receivedStop() << std::endl;


logStream << "pauseCbck.pauseFlag: " << pauseCbck.pauseFlag << std::endl; logStream << "pauseCbck.pauseFlag: " << pauseCbck.pauseFlag << std::endl;
<< std::endl; << std::endl;
logStream << "resumeCbck1.resumeFlag: " << resumeCbck1.resumeFlag logStream << "resumeCbck1.resumeFlag: " << resumeCbck1.resumeFlag
<< std::endl; << std::endl;
logStream << "restartCbck.restartFlag: " << restartCbck.restartFlag
<< std::endl;
logStream << "restartCbck1.restartFlag: " << restartCbck1.restartFlag
<< std::endl;
logStream << "stopCbck.stopFlag: " << stopCbck.stopFlag << std::endl; logStream << "stopCbck.stopFlag: " << stopCbck.stopFlag << std::endl;
logStream << "stopCbck1.stopFlag: " << stopCbck1.stopFlag << std::endl; logStream << "stopCbck1.stopFlag: " << stopCbck1.stopFlag << std::endl;
logStream << "notStopCbck.stopFlag: " << notStopCbck.stopFlag << std::endl; logStream << "notStopCbck.stopFlag: " << notStopCbck.stopFlag << std::endl;
pauseCbck1.pauseFlag = false; pauseCbck1.pauseFlag = false;
resumeCbck.resumeFlag = false; resumeCbck.resumeFlag = false;
resumeCbck1.resumeFlag = false; resumeCbck1.resumeFlag = false;
restartCbck.restartFlag = false;
restartCbck1.restartFlag = false;


logStream << std::endl; logStream << std::endl;



Loading…
İptal
Kaydet