IWMSDataSourcePlugin::OpenDataContainer
Previous | Next |
IWMSDataSourcePlugin::OpenDataContainer
The server calls the OpenDataContainer method to open or create a data container.
Syntax
HRESULT OpenDataContainer( IWMSCommandContext* pCommandContext, IWMSContext* pUserContext, IWMSContext* pPresentationContext, LPWSTR pszContainerName, DWORD dwFlags, IWMSBufferAllocator* pBufferAllocator, IWMSDataSourcePluginCallback* pCallback, QWORD qwContext );
Parameters
pCommandContext
[in] Pointer to an IWMSCommandContext interface that specifies the request command context.
pUserContext
[in] Pointer to an IWMSContext interface that specifies the user context.
pPresentationContext
[in] Pointer to an IWMSContext interface that specifies the presentation context.
pszContainerName
[in] Pointer to a null-terminated string containing the name of the container to be opened.
dwFlags
[in] DWORD containing a member of the WMS_DATA_CONTAINER_OPEN_FLAGS enumeration type that indicates the type of access requested. This must be a bitwise OR of one or more of the following values.
Values | Description |
WMS_DATA_CONTAINER_READ_ACCESS | The server requested read access. |
WMS_DATA_CONTAINER_WRITE_ACCESS | The server requested write access. |
WMS_DATA_CONTAINER_CREATE_NEW_CONTAINER | The server requested that a new data container be created. |
WMS_DATA_CONTAINER_ALLOW_BUFFER_IO | The buffered data does not need to be page-aligned. |
WMS_DATA_CONTAINER_SHARED_SOURCE | The server requested that the data container be used for a shared resource such as a broadcast. If the plug-in determines that the data path must not be shared, it can return COMADMIN_E_PRIVATE_ACCESSDENIED when it calls IWMSDataSourcePluginCallback::OnOpenDataContainer. |
pBufferAllocator
[in] Pointer to an IWMSBufferAllocator interface that can be used by the data source plug-in to allocate additional buffers for reading or writing data.
pCallback
[in] Pointer to an IWMSDataSourcePluginCallback interface. The plug-in calls IWMSDataSourcePluginCallback::OnOpenDataContainer to return a result to the server.
qwContext
[in] QWORD containing a value defined by the server to identify which OpenDataContainer request the plug-in is responding to when it calls IWMSDataSourcePluginCallback::OnOpenDataContainer. The plug-in must pass this value back unaltered.
Return Values
If the method succeeds, the plug-in must return S_OK. To report an error, the plug-in can return any HRESULT other than S_OK. If the plug-in uses the IWMSEventLog interface to log error information directly to the Windows Event Viewer, it is recommended that it return NS_E_PLUGIN_ERROR_REPORTED. Typically, the server attempts to make plug-in error information available to the server object model, the Windows Event Viewer, and the troubleshooting list in the details pane of the Windows Media Services MMC. However, if the plug-in uses the IWMSEventLog interface to send custom error information to the Windows Event Viewer, returning NS_E_PLUGIN_ERROR_REPORTED stops the server from also logging to the event viewer. For more information about retrieving plug-in error information, see Identifying Plug-in Errors.
Remarks
If the server requests that the data container be used for a shared broadcast by sending WMS_DATA_CONTAINER_SHARED_SOURCE in the dwFlags parameter when it calls OpenDataContainer, and the plug-in determines that the source cannot be shared, the plug-in can return COMADMIN_E_PRIVATE_ACCESSDENIED to the server in the hr parameter of IWMSDataSourcePluginCallback::OnOpenDataContainer. The COMADMIN_E_PRIVATE_ACCESSDENIED error is defined in the WinError.h file. A plug-in can decide that a source must not be shared if, for example, a distribution connection requires authentication or the content must be personalized for a specific end user. When the server receives this error, it deletes the shared data path and creates an on-demand (non-shared) data path instead.
Example Code
HRESULT STDMETHODCALLTYPE CDataSourcePlugin::OpenDataContainer( IWMSCommandContext *pCommandContext, IWMSContext *pUserContext, IWMSContext *pPresentationContext, LPWSTR pszContainerName, DWORD dwFlags, IWMSBufferAllocator *pBufferAllocator, IWMSDataSourcePluginCallback *pCallback, QWORD qwContext) { HRESULT hr = S_OK; CDataContainer *pDataContainer = NULL; pDataContainer = new CDataContainer; hr = pDataContainer->Initialize( pUserContext, pszContainerName, dwFlags, pBufferAllocator, this, pCallback, qwContext ); if ( FAILED( hr ) ) goto EXIT; EXIT: if( NULL != pDataContainer ) { pDataContainer->Release(); pDataContainer = NULL; } return( hr ); } HRESULT CDataContainer::Initialize( IWMSContext *pUserContext, LPWSTR pszContainerName, DWORD dwFlags, IWMSBufferAllocator *pBufferAllocator, CSDKSampleStorageSystem *pOwnerStorageSystem, IWMSDataSourcePluginCallback *pCallback, QWORD qwContext) { HRESULT hr = S_OK; DWORD dwSDKSampleStorageSystemFlags = 0; CHAR *pResult = NULL; DWORD cbDriveNameLen = 0; BOOL fSuccess = TRUE; DWORD dwOpenStyle = 0; CHAR *pszSDKSampleStorageSystemPathname = NULL; DWORD dwFileAccess = 0; DWORD dwSizeHigh = 0, dwError = 0, dwSizeLow = 0; int cchNeeded = WideCharToMultiByte( CP_ACP, 0, pszContainerName, -1, NULL, 0, NULL, NULL); if( 0 >= cchNeeded ) { hr = HRESULT_FROM_WIN32( GetLastError() ); goto EXIT; } m_pszPathName = new CHAR[ cchNeeded ]; int cchConverted = WideCharToMultiByte( CP_ACP, 0, pszContainerName, -1, m_pszPathName, cchNeeded, NULL, NULL); if( cchConverted != cchNeeded ) { delete [] m_pszPathName; m_pszPathName = NULL; hr = E_UNEXPECTED; goto EXIT; } m_pOwnerStorageSystem = pOwnerStorageSystem; pOwnerStorageSystem->AddRef(); if ( dwFlags & WMS_DATA_CONTAINER_CREATE_NEW_CONTAINER ) dwOpenStyle = OPEN_ALWAYS; else dwOpenStyle = OPEN_EXISTING; dwFileAccess = GENERIC_READ; if ( ( dwFlags & WMS_DATA_CONTAINER_WRITE_ACCESS ) || ( dwFlags & WMS_DATA_CONTAINER_CREATE_NEW_CONTAINER ) ) dwFileAccess |= GENERIC_WRITE; pszSDKSampleStorageSystemPathname = m_pszPathName + URL_SCHEME_LENGTH; m_hFile = CreateFileA( pszSDKSampleStorageSystemPathname, dwFileAccess, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, dwOpenStyle, dwSDKSampleStorageSystemFlags, NULL); if ( INVALID_HANDLE_VALUE == m_hFile ) { hr = HRESULT_FROM_WIN32( GetLastError() ); goto EXIT; } else { DWORD dwFileType = GetFileType( m_hFile ); if( FILE_TYPE_DISK != dwFileType ) { hr = HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ); goto EXIT; } } dwSizeLow = GetFileSize( m_hFile, & dwSizeHigh ) ; if( ( dwSizeLow == 0xFFFFFFFF ) && ( ( dwError = GetLastError() ) != NO_ERROR ) ) { hr = HRESULT_FROM_WIN32( dwError ); goto EXIT; } m_qwFileSize = MAKEQWORD( dwSizeLow, dwSizeHigh ); EXIT: if( FAILED(hr) && ( INVALID_HANDLE_VALUE != m_hFile ) ) { CloseHandle( m_hFile ); m_hFile = INVALID_HANDLE_VALUE; } if ( NULL != pCallback ) { pCallback->OnOpenDataContainer( hr, this, qwContext ); hr = S_OK; } return( hr ); }
Requirements
Header: datacontainer.h.
Library: WMSServerTypeLib.dll.
Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.
See Also
Previous | Next |