BOOL CNdasDevice::Enable(BOOL bEnable) { ximeta::CAutoLock autolock(this); if (bEnable) { // // To enable this device // if (NDAS_DEVICE_STATUS_DISABLED != m_status) { return TRUE; } // // DISABLED -> DISCONNECTED // ChangeStatus(NDAS_DEVICE_STATUS_DISCONNECTED); } else { // // To disable this device // if (NDAS_DEVICE_STATUS_DISABLED == m_status) { return TRUE; } // // You cannot disable this device when a unit device is mounted // if (IsAnyUnitDevicesMounted()) { ::SetLastError(NDASHLPSVC_ERROR_CANNOT_DISABLE_MOUNTED_DEVICE); return FALSE; } // // DISCONNECTED/CONNECTED -> DISABLED // ChangeStatus(NDAS_DEVICE_STATUS_DISABLED); } BOOL fSuccess = _NdasSystemCfg.SetValueEx( m_szCfgContainer, TEXT("Enabled"), bEnable); if (!fSuccess) { DBGPRT_WARN_EX( _FT("%s: Writing device enable status to the registry failed at %s:"), ToString(), m_szCfgContainer); } return TRUE; }
BOOL CNdasDevice::Enable(BOOL bEnable) { ximeta::CAutoLock autolock(this); if (bEnable) { // // To enable this device // if (NDAS_DEVICE_STATUS_DISABLED != m_status) { return TRUE; } // // DISABLED -> DISCONNECTED // ChangeStatus(NDAS_DEVICE_STATUS_DISCONNECTED); } else { // // To disable this device // if (NDAS_DEVICE_STATUS_DISABLED == m_status) { return TRUE; } // // You cannot disable this device when a unit device is mounted // if (IsAnyUnitDevicesMounted()) { ::SetLastError(NDASHLPSVC_ERROR_CANNOT_DISABLE_MOUNTED_DEVICE); return FALSE; } // // DISCONNECTED/CONNECTED -> DISABLED // ChangeStatus(NDAS_DEVICE_STATUS_DISABLED); } (VOID) SetConfigValue(_T("Enabled"), bEnable); // // Clear Device Error // SetLastDeviceError(NDAS_DEVICE_ERROR_NONE); return TRUE; }
// // status check event handler // to reconcile the status // // to be connected status, broadcast packet // should be received within MAX_ALLOWED_HEARTBEAT_INTERVAL // // returns TRUE to detach from the monitor // FALSE otherwise. // BOOL CNdasDevice::OnStatusCheck() { ximeta::CAutoLock autolock(this); // // Only when the device is connected! // if (NDAS_DEVICE_STATUS_CONNECTED != m_status) { // _ASSERTE(FALSE && "OnStatusCheck should be called when connected!"); DBGPRT_WARN(_FT("OnStatusCheck is called on connected. Detaching.\n")); // Detach from the monitor return TRUE; } DWORD dwCurrentTick = ::GetTickCount(); DWORD dwElapsed = dwCurrentTick - m_dwLastHeartbeatTick; if (dwElapsed > MAX_ALLOWED_HEARTBEAT_INTERVAL) { // // When just a single unit device is mounted, // status will not be changed to DISCONNECTED! // if (IsAnyUnitDevicesMounted()) { return FALSE; } // // Do not disconnect the device when the debugger is attached // if (!NdasServiceConfig::Get(nscDisconnectOnDebug) && ::IsDebuggerPresent()) { return FALSE; } BOOL fSuccess = DestroyAllUnitDevices(); if (!fSuccess) { return FALSE; } ChangeStatus(NDAS_DEVICE_STATUS_DISCONNECTED); return TRUE; } return FALSE; }