git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@36 d34b734f-a00e-4b39-a726-e4eeb87269abadeniz_1
@@ -46,7 +46,10 @@ int main(int argc, char *argv[]) { | |||
namespace CodeDweller { | |||
Service::Service() : | |||
lastMessage(Message::None) { | |||
pauseReceived(false), | |||
resumeReceived(false), | |||
restartReceived(false), | |||
stopReceived(false) { | |||
} | |||
int Service::main(int argc, char *argv[]) { | |||
@@ -151,6 +154,9 @@ namespace CodeDweller { | |||
int status; | |||
status = run(); | |||
// Send a Stop message so that messageThread exits. | |||
pthread_kill(messageThread.native_handle(), SIGTERM); | |||
messageThread.join(); | |||
return(status); | |||
@@ -172,8 +178,36 @@ namespace CodeDweller { | |||
stopCallbacks.push_back(stopFunctor); | |||
} | |||
bool Service::receivedPause() { | |||
return (pauseReceived); | |||
} | |||
bool Service::receivedResume() { | |||
return (resumeReceived); | |||
} | |||
bool Service::receivedRestart() { | |||
return (restartReceived); | |||
} | |||
bool Service::receivedStop() { | |||
return (Message::Stop == lastMessage); | |||
return (stopReceived); | |||
} | |||
void Service::clearReceivedPause() { | |||
pauseReceived = false; | |||
} | |||
void Service::clearReceivedResume() { | |||
resumeReceived = false; | |||
} | |||
void Service::clearReceivedRestart() { | |||
restartReceived = false; | |||
} | |||
void Service::clearReceivedStop() { | |||
stopReceived = false; | |||
} | |||
void Service::processMessages() { | |||
@@ -195,19 +229,19 @@ namespace CodeDweller { | |||
switch (sigNum) { | |||
case SIGTSTP: | |||
lastMessage = Message::Pause; | |||
pauseReceived = true; | |||
break; | |||
case SIGCONT: | |||
lastMessage = Message::Resume; | |||
resumeReceived = true; | |||
break; | |||
case SIGHUP: | |||
lastMessage = Message::Restart; | |||
restartReceived = true; | |||
break; | |||
case SIGTERM: | |||
lastMessage = Message::Stop; | |||
stopReceived = true; | |||
for (auto callback : stopCallbacks) { | |||
(*callback)(); |
@@ -123,6 +123,24 @@ namespace CodeDweller { | |||
// | |||
void onStopCall(Callback *stopFunctor); | |||
/// Check whether Pause was received. | |||
// | |||
// \returns if the Pause message was received, false otherwise. | |||
// | |||
bool receivedPause(); | |||
/// Check whether Resume was received. | |||
// | |||
// \returns if the Resume message was received, false otherwise. | |||
// | |||
bool receivedResume(); | |||
/// Check whether Restart was received. | |||
// | |||
// \returns if the Restart message was received, false otherwise. | |||
// | |||
bool receivedRestart(); | |||
/// Check whether the last message received was Stop. | |||
// | |||
// \returns true if Stop was the most recent message received, | |||
@@ -130,6 +148,18 @@ namespace CodeDweller { | |||
// | |||
bool receivedStop(); | |||
/// Clear receiving the Pause message. | |||
void clearReceivedPause(); | |||
/// Clear receiving the Resume message. | |||
void clearReceivedResume(); | |||
/// Clear receiving the Restart message. | |||
void clearReceivedRestart(); | |||
/// Clear receiving the Stop message. | |||
void clearReceivedStop(); | |||
/// Get a reference to the command-line arguments. | |||
// | |||
// \returns a reference to the vector of command-line arguments of | |||
@@ -182,8 +212,17 @@ namespace CodeDweller { | |||
None | |||
}; | |||
/// Most recent message received. | |||
Message lastMessage; | |||
/// True if Pause message was received. | |||
bool pauseReceived; | |||
/// True if Resume message was received. | |||
bool resumeReceived; | |||
/// True if Restart message was received. | |||
bool restartReceived; | |||
/// True if Stop message was received. | |||
bool stopReceived; | |||
/// Functions to invoke when the Stop is received. | |||
std::vector<Callback *> stopCallbacks; |