Changeset - 79fd6782fbf1
[Not reviewed]
0 3 0
Vitaly Takmazov - 13 years ago 2012-12-19 08:42:00
vitalyster@gmail.com
handle Ctrl-C from win32 console
3 files changed with 18 insertions and 9 deletions:
0 comments (0 inline, 0 general)
spectrum/src/main.cpp
Show inline comments
 
@@ -47,12 +47,6 @@ Component *component_ = NULL;
 
UserManager *userManager_ = NULL;
 
Config *config_ = NULL;
 

	
 
void stop() {
 
	userManager_->removeAllUsers(false);
 
	component_->stop();
 
	eventLoop_->stop();
 
}
 

	
 
static void stop_spectrum() {
 
	userManager_->removeAllUsers(false);
 
	component_->stop();
 
@@ -67,6 +61,16 @@ static void spectrum_sigterm_handler(int sig) {
 
	eventLoop_->postEvent(&stop_spectrum);
 
}
 

	
 
#ifdef WIN32
 
BOOL spectrum_control_handler( DWORD fdwCtrlType ) { 
 
	if (fdwCtrlType == CTRL_C_EVENT || fdwCtrlType == CTRL_CLOSE_EVENT) {
 
		eventLoop_->postEvent(&stop_spectrum);
 
		return TRUE;
 
	}
 
	return FALSE;
 
} 
 
#endif
 

	
 
static void removeOldIcons(std::string iconDir) {
 
	std::vector<std::string> dirs;
 
	dirs.push_back(iconDir);
 
@@ -126,7 +130,6 @@ static void daemonize(const char *cwd, const char *lock_file) {
 
		exit(1);
 
	}
 
}
 

	
 
#endif
 

	
 
int mainloop() {
 
@@ -291,6 +294,12 @@ int main(int argc, char **argv)
 
		std::cout << "SIGTERM handler can't be set\n";
 
		return -1;
 
	}
 
#else
 
	if( !SetConsoleCtrlHandler( (PHANDLER_ROUTINE) spectrum_control_handler, TRUE ) ) 
 
	{ 
 
		std::cout << "control handler can't be set\n";
 
		return -1;
 
	} 
 
#endif
 
	boost::program_options::options_description desc(std::string("Spectrum version: ") + SPECTRUM_VERSION + "\nUsage: spectrum [OPTIONS] <config_file.cfg>\nAllowed options");
 
	desc.add_options()
spectrum/src/win32/ServiceWrapper.cpp
Show inline comments
 
@@ -87,7 +87,7 @@ void WINAPI ServiceControlHandler(DWORD controlCode) {
 
		break;
 
	}
 
	SetServiceStatus(ServiceStatusHandle, &ServiceStatus);	
 
	stop();
 
	spectrum_control_handler(CTRL_CLOSE_EVENT);
 
}
 

	
 
void WINAPI ServiceMain(DWORD argc, LPSTR *argv) {
spectrum/src/win32/ServiceWrapper.h
Show inline comments
 
@@ -15,5 +15,5 @@ public:
 
};
 

	
 
int mainloop();
 
void stop();
 
BOOL spectrum_control_handler( DWORD fdwCtrlType );
 

	
0 comments (0 inline, 0 general)