// Streams Driver Routines

//
//	Adds the Streams Service
//
//		$0 = Adapter Driver Name
//
[AddStreamsService]

	read-syms DriverConstants
	read-syms DriverConstants-Streams
	_Enter("AddStreamService", "")

	set Installed = TRUE

	_Trace("Installing Streams Driver", "")
	_LocalShell AddService "Streams"
	_AssertGoto($($R0), Error)

	// Install the Performance Monitor Counters
	_LocalShell InstallPerfMon "Streams"

	_LocalShell AddGroupToServiceGroupOrder $(MiniPortDependOnGroup) $(DStreamsDependOnGroup)
	_AssertGoto($($R0), Error)

	goto Exit

Error = +

	set Installed = FALSE

Exit = +

	_Exit("AddStreamService", _Show(Installed))
	Return $(Installed)


//
//	Adds adapters to the Streams Miniport Adapters Key
//
//		$0 = Adapter Driver Name
//
[AddAdapterToMiniportAdapters]

	set AdapterName = $($0)

	read-syms DriverConstants-Streams
	_Enter("AddAdapterToMiniportAdapters", _Show(AdapterName))

	set Status = "STATUS_SUCCESSFUL"

	//  Add the adapter to the list of DigiSoh Miniport Adapters
	set KeyParameters = KEY_NULL
	_OpenRegKey_HKLM($(!NTN_ServiceBase)"\\"$(ProductSoftwareName)"\\Parameters", KeyParameters)
	_IfNotValidKey($(KeyParameters))
		set Status = "STATUS_UNSUCCESSFUL"
		goto Exit
	endif

	_MakeStdRegKey($(KeyParameters), $(MiniportAdapterKey), KeyMiniportAdapters)
	_MakeStdRegKey($(KeyMiniportAdapters), $(AdapterName), KeyService)
	_CloseRegKey($(KeyService))
	_CloseRegKey($(KeyMiniportAdapters))
	_CloseRegKey($(KeyParameters))

Exit = +

	_Exit("AddAdapterToMiniportAdapters", _Show(Status))
	Return $(Status)


//
//	Removes adapters from the Streams Miniport Adapters Key
//
//		$0 = Adapter Driver Name
//
[RemoveAdapterFromMiniportAdapters]

	set AdapterName = $($0)

	read-syms GlobalConstants
	read-syms DriverConstants-Streams
	_Enter("RemoveAdapterFromMiniportAdapters", _Show(AdapterName))

	set Status = "STATUS_SUCCESSFUL"

	// Remove the Adapter Key from the list of installed DigiSOH adapters. If it is
	// the last adapter install then remove DigiSoh
	set KeyMiniportAdapters = KEY_NULL
	_OpenRegKey_HKLM($(!NTN_ServiceBase)"\\"$(ProductSoftwareName)"\\Parameters\\"$(MiniportAdapterKey), KeyMiniportAdapters)
	_IfNotValidKey($(KeyMiniportAdapters))
		set Status = "STATUS_UNSUCCESSFUL"
		goto Exit
	endif

	DeleteRegKey $(KeyMiniportAdapters) $(AdapterName)
	EnumRegKey $(KeyMiniportAdapters) MiniportAdaptersList
	_CloseRegKey($(KeyMiniportAdapters))

	QueryListSize NumMiniportAdapters $(MiniportAdaptersList)

	ifint $(NumMiniportAdapters) == 0
	   // HKLM\SOFTWARE\Digi\DigiSoh

		// When removing DigiSoh we also need to remove the Miniport Group
		// from the control\ServiceGroupOrder List
		_LocalShell RemoveGroupFromServiceGroupOrder $(MiniPortDependOnGroup)

		// UnInstall the Performance Monitor Counters
		_LocalShell UnInstallPerfMon "Streams"

	   _UtilityShell RemoveSoftwareComponent $(Manufacturer) $(ProductSoftwareName)
#if defined(_DEBUG)
		_ShellError(DontCare)
		_UtilityShellError($($R0), DontCare)
#endif

	endif

Exit = +

	_Exit("RemoveAdapterFromMiniportAdapters", _Show(Status))
	Return $(Status)
