Esempio n. 1
0
CNdasUnitDevice::CNdasUnitDevice(
	CNdasDevicePtr pParentDevice, 
	DWORD dwUnitNo, 
	NDAS_UNITDEVICE_TYPE type,
	NDAS_UNITDEVICE_SUBTYPE subType,
	const NDAS_UNITDEVICE_HARDWARE_INFO& unitDeviceInfo,
	const NDAS_LOGICALDEVICE_GROUP& ldGroup,
	DWORD ldSequence) :
	CStringizerA<32>("%s.%02d", pParentDevice->ToStringA(), dwUnitNo),
	m_pParentDevice(pParentDevice),
	m_unitDeviceId(pCreateUnitDeviceId(pParentDevice,dwUnitNo)),
	m_type(type),
	m_subType(subType),
	m_status(NDAS_UNITDEVICE_STATUS_NOT_MOUNTED),
	m_lastError(NDAS_UNITDEVICE_ERROR_NONE),
	m_udinfo(unitDeviceInfo),
	m_ldGroup(ldGroup),
	m_ldSequence(ldSequence),
	m_bSupposeFault(FALSE)
{
	XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_INFORMATION,
		__FUNCTION__ " %s\n", ToStringA());

	::ZeroMemory(
		&m_PrimaryHostInfo, 
		sizeof(NDAS_UNITDEVICE_PRIMARY_HOST_INFO));

	COMVERIFY( StringCchPrintf(
		m_szRegContainer,
		30,
		_T("Devices\\%04d\\%04d"),
		pParentDevice->GetSlotNo(),
		m_unitDeviceId.UnitNo));
}
Esempio n. 2
0
BOOL 
CNdasDeviceRegistrar::Unregister(const NDAS_DEVICE_ID& DeviceId)
{
	InstanceAutoLock autolock(this);

	XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_INFORMATION,
		"Unregister device %s\n", CNdasDeviceId(DeviceId).ToStringA());

	DeviceIdMap::iterator itrId = m_deviceIdMap.find(DeviceId);
	if (m_deviceIdMap.end() == itrId) 
	{
		::SetLastError(NDASSVC_ERROR_DEVICE_ENTRY_NOT_FOUND);
	}

	CNdasDevicePtr pDevice = itrId->second;
	
	if (pDevice->GetStatus() != NDAS_DEVICE_STATUS_DISABLED) 
	{
		::SetLastError(NDASSVC_ERROR_CANNOT_UNREGISTER_ENABLED_DEVICE);
		return FALSE;
	}

	DWORD SlotNo = pDevice->GetSlotNo();
	XTLASSERT(0 != SlotNo);

	DeviceSlotMap::iterator itrSlot = m_deviceSlotMap.find(SlotNo);

	m_deviceIdMap.erase(itrId);
	m_deviceSlotMap.erase(itrSlot);
	m_slotbit[SlotNo] = false;

	XTL::CStaticStringBuffer<30> containerName(_T("Devices\\%04d"), SlotNo);
	BOOL fSuccess = _NdasSystemCfg.DeleteContainer(containerName, TRUE);
	if (!fSuccess) 
	{
		XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING,
			"Deleting registration entry from the registry failed at %ls, error=0x%X\n", 
			containerName, GetLastError());
	}

	(void) m_service.GetEventPublisher().DeviceEntryChanged();

	return TRUE;
}
Esempio n. 3
0
BOOL
CNdasAutoRegister::ProcessRegister(
	const NDAS_DEVICE_ID& deviceId, 
	ACCESS_MASK autoRegAccess)
{
	CNdasDeviceRegistrar& registrar = m_service.GetDeviceRegistrar();

	CNdasDevicePtr pExistingDevice = registrar.Find(deviceId);
	if (CNdasDeviceNullPtr != pExistingDevice) 
	{
		return TRUE;
	}

	DWORD dwRegFlags = 
		NDAS_DEVICE_REG_FLAG_AUTO_REGISTERED |
		NDAS_DEVICE_REG_FLAG_VOLATILE;

	CNdasDevicePtr pDevice = 
		registrar.Register(deviceId, dwRegFlags);
	if (0 == pDevice.get()) {
		return FALSE;
	}

	pDevice->SetGrantedAccess(autoRegAccess);

	BOOL fSuccess = pDevice->Enable(TRUE);
	if (!fSuccess) {
		DBGPRT_ERR(_FT("Enable failed: "));
	}

	TCHAR szName[MAX_NDAS_DEVICE_NAME_LEN + 1];
	HRESULT hr = ::StringCchPrintf(szName, MAX_NDAS_DEVICE_NAME_LEN + 1,
		_T("NDAS Device A%04d"), pDevice->GetSlotNo());
	XTLASSERT(SUCCEEDED(hr));

	pDevice->SetName(szName);

	return TRUE;
}