Listen for suspend/resume signals and disconnect all usb-devices. This closes #171
This commit is contained in:
parent
c35be687c0
commit
5f1d6e7fe5
3 changed files with 29 additions and 0 deletions
|
@ -38,6 +38,24 @@ void TelldusMain::deviceInsertedOrRemoved(int vid, int pid, bool inserted) {
|
|||
d->controllerChangeEvent->signal(data);
|
||||
}
|
||||
|
||||
void TelldusMain::resume() {
|
||||
Log::notice("Came back from suspend");
|
||||
ControllerChangeEventData *data = new ControllerChangeEventData;
|
||||
data->vid = 0x0;
|
||||
data->pid = 0x0;
|
||||
data->inserted = true;
|
||||
d->controllerChangeEvent->signal(data);
|
||||
}
|
||||
|
||||
void TelldusMain::suspend() {
|
||||
Log::notice("Preparing for suspend");
|
||||
ControllerChangeEventData *data = new ControllerChangeEventData;
|
||||
data->vid = 0x0;
|
||||
data->pid = 0x0;
|
||||
data->inserted = false;
|
||||
d->controllerChangeEvent->signal(data);
|
||||
}
|
||||
|
||||
void TelldusMain::start(void) {
|
||||
EventRef clientEvent = d->eventHandler.addEvent();
|
||||
EventRef dataEvent = d->eventHandler.addEvent();
|
||||
|
|
|
@ -12,6 +12,8 @@ public:
|
|||
|
||||
//Thread safe!
|
||||
void deviceInsertedOrRemoved(int vid, int pid, bool inserted);
|
||||
void resume();
|
||||
void suspend();
|
||||
|
||||
private:
|
||||
class PrivateData;
|
||||
|
|
|
@ -40,6 +40,13 @@ DWORD WINAPI TelldusWinService::serviceControlHandler( DWORD controlCode, DWORD
|
|||
serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
|
||||
SetServiceStatus( serviceStatusHandle, &serviceStatus );
|
||||
|
||||
return NO_ERROR;
|
||||
case SERVICE_CONTROL_POWEREVENT:
|
||||
if (dwEventType == PBT_APMSUSPEND) {
|
||||
tm->suspend();
|
||||
} else if (dwEventType == PBT_APMRESUMEAUTOMATIC) {
|
||||
tm->resume();
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
return ERROR_CALL_NOT_IMPLEMENTED;
|
||||
|
@ -137,6 +144,8 @@ void WINAPI TelldusWinService::serviceMain( DWORD argc, TCHAR* argv[] ) {
|
|||
|
||||
// running
|
||||
instance.serviceStatus.dwControlsAccepted |= (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
|
||||
// Register for power management notification
|
||||
instance.serviceStatus.dwControlsAccepted |= SERVICE_ACCEPT_POWEREVENT;
|
||||
instance.serviceStatus.dwCurrentState = SERVICE_RUNNING;
|
||||
SetServiceStatus( instance.serviceStatusHandle, &instance.serviceStatus );
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue