|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <string> |
|
|
#include <string> |
|
|
#include <vector> |
|
|
#include <vector> |
|
|
|
|
|
#include <mutex> |
|
|
|
|
|
|
|
|
namespace CodeDweller { |
|
|
namespace CodeDweller { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
/// Get the instance of the singleton. |
|
|
/// Get the instance of the singleton. |
|
|
static Service& getInstance() |
|
|
|
|
|
{ |
|
|
|
|
|
static Service service; |
|
|
|
|
|
return service; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// |
|
|
|
|
|
// \returns a reference to the singleton. |
|
|
|
|
|
// |
|
|
|
|
|
static Service& getInstance(); |
|
|
|
|
|
|
|
|
/// Callback functor interface. |
|
|
/// Callback functor interface. |
|
|
class Callback { |
|
|
class Callback { |
|
|
|
|
|
|
|
|
// |
|
|
// |
|
|
int main(int argc, char *argv[]); |
|
|
int main(int argc, char *argv[]); |
|
|
|
|
|
|
|
|
|
|
|
/// Register a callback for receipt of Pause. |
|
|
|
|
|
// |
|
|
|
|
|
// \param[in] pauseFunctor is the function object to invoke when |
|
|
|
|
|
// Pause is received. |
|
|
|
|
|
// |
|
|
|
|
|
void onPauseCall(Callback &pauseFunctor); |
|
|
|
|
|
|
|
|
|
|
|
/// Register a callback for receipt of Resume. |
|
|
|
|
|
// |
|
|
|
|
|
// \param[in] resumeFunctor is the function object to invoke when |
|
|
|
|
|
// Resume is received. |
|
|
|
|
|
// |
|
|
|
|
|
void onResumeCall(Callback &resumeFunctor); |
|
|
|
|
|
|
|
|
|
|
|
/// Register a callback for receipt of Restart. |
|
|
|
|
|
// |
|
|
|
|
|
// \param[in] restartFunctor is the function object to invoke when |
|
|
|
|
|
// Restart is received. |
|
|
|
|
|
// |
|
|
|
|
|
void onRestartCall(Callback &restartFunctor); |
|
|
|
|
|
|
|
|
/// Register a callback for receipt of Stop. |
|
|
/// Register a callback for receipt of Stop. |
|
|
// |
|
|
// |
|
|
// \param[in] stopFunctor is the function object to invoke when |
|
|
// \param[in] stopFunctor is the function object to invoke when |
|
|
// Stop is received. |
|
|
// Stop is received. |
|
|
// |
|
|
// |
|
|
void onStopCall(Callback *stopFunctor); |
|
|
|
|
|
|
|
|
void onStopCall(Callback &stopFunctor); |
|
|
|
|
|
|
|
|
/// Check whether Pause was received. |
|
|
/// Check whether Pause was received. |
|
|
// |
|
|
// |
|
|
|
|
|
|
|
|
// |
|
|
// |
|
|
int run(); |
|
|
int run(); |
|
|
|
|
|
|
|
|
|
|
|
/// Mutex to serialize access to the object. |
|
|
|
|
|
static std::mutex objectMutex; |
|
|
|
|
|
|
|
|
/// Thread start function to receive messages. |
|
|
/// Thread start function to receive messages. |
|
|
void processMessages(); |
|
|
void processMessages(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// True if Stop message was received. |
|
|
/// True if Stop message was received. |
|
|
bool stopReceived; |
|
|
bool stopReceived; |
|
|
|
|
|
|
|
|
|
|
|
/// Functions to invoke when the Pause is received. |
|
|
|
|
|
std::vector<Callback *> pauseCallbacks; |
|
|
|
|
|
|
|
|
|
|
|
/// Functions to invoke when the Resume is received. |
|
|
|
|
|
std::vector<Callback *> resumeCallbacks; |
|
|
|
|
|
|
|
|
|
|
|
/// Functions to invoke when the Restart is received. |
|
|
|
|
|
std::vector<Callback *> restartCallbacks; |
|
|
|
|
|
|
|
|
/// Functions to invoke when the Stop is received. |
|
|
/// Functions to invoke when the Stop is received. |
|
|
std::vector<Callback *> stopCallbacks; |
|
|
std::vector<Callback *> stopCallbacks; |
|
|
|
|
|
|