IWMSDataSourcePlugin::OpenDirectory
Previous | Next |
IWMSDataSourcePlugin::OpenDirectory
The OpenDirectory method opens a directory data container.
Syntax
HRESULT OpenDirectory( 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 contains a command context.
pUserContext
[in] Pointer to an IWMSContext object that contains a user context.
pPresentationContext
[in] Pointer to an IWMSContext interface that contains a presentation context.
pszContainerName
[in] Pointer to a null-terminated string containing the directory name that the server resolved from the requested URL. This includes the scheme type, as in file://C:\wmpub\wmroot\.
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 has requested read access. |
WMS_DATA_CONTAINER_WRITE_ACCESS | The server has requested write access. |
WMS_DATA_CONTAINER_CREATE_NEW_CONTAINER | The server has requested that a new data container be created. |
WMS_DATA_CONTAINER_ALLOW_BUFFER_IO | Buffered data does not need to be page-aligned. |
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::OnOpenDirectory to return a result to the server.
qwContext
[in] QWORD containing a value defined by the server to identify which OpenDirectory request the plug-in is responding to when it calls IWMSDataSourcePluginCallback::OnOpenDirectory. 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.
Example Code
HRESULT STDMETHODCALLTYPE CDataSourcePlugin::OpenDirectory( IWMSCommandContext *pCommandContext, IWMSContext *pUserContext, IWMSContext *pPresentationContext, LPWSTR pszContainerName, DWORD dwFlags, IWMSBufferAllocator *pBufferAllocator, IWMSDataSourcePluginCallback *pCallback, QWORD qwContext ) { HRESULT hr = S_OK; CDirectoryImpl *pDirectory = NULL; // TODO: Allocate a CDirectoryImpl object. The // CDirectoryImpl object is user-defined // and implements the IWMSDirectory interface. // pDirectory points to the object. hr = pDirectory->Initialize( pUserContext, pszContainerName, this, pCallback, qwContext ); if (FAILED(hr)) goto EXIT; hr = pDirectory->Release(); if (FAILED(hr)) goto EXIT; EXIT: // TODO: Release temporary objects. return( hr ); } // Create a CDirectory object and a method, Initialize(), to // enumerate the files in a directory and store information // about them in a linked list of CDirectoryInfo objects. The // CDirectory and CDirectoryInfo objects are user-defined, and // the CDirectory object implements the IWMSDirectory interface. CDirectory::Initialize( IWMSContext *pUserContext, LPWSTR pszContainerName, CNTFSStorageSystem *pOwnerStorageSystem, IWMSDataSourcePluginCallback *pCallback, QWORD qwContext ) { HRESULT hr = S_OK; HRESULT hr = S_OK; WCHAR *pszNtfsPathname; size_t sFileName; DWORD dwFileAttributes; DWORD dwIndex; HANDLE hFileEnum = INVALID_HANDLE_VALUE; BOOL fSuccess = FALSE; WIN32_FIND_DATA FileInfo; // Parse the path name to remove the scheme type and // use the GetFileAttributes() function to determine // whether the path identifies a directory. pszNtfsPathname = pszContainerName + URL_SCHEME_LENGTH; dwFileAttributes = GetFileAttributes( pszNtfsPathname ); if( !( FILE_ATTRIBUTE_DIRECTORY & dwFileAttributes ) ) { hr = HRESULT_FROM_WIN32( ERROR_DIRECTORY ); } // Add the global wildcard character '*' to the end // of the directory name. sFileName = wcslen( pszNtfsPathname ); pSearchDirName = new WCHAR[ sFileName + 8 ]; pSearchDirName[sFileName] = '*'; pSearchDirName[sFileName + 1] = '\0'; // Find the first entry in the directory. hFileEnum = FindFirstFileW( m_pSearchDirName, &FileInfo ); dwIndex = 0; fSuccess = TRUE; while ( TRUE ) { // TODO: Determine whether you have reached the end of // the directory items. If so, break. // If the directory item is empty or '.' or '..' or a hidden file, // skip it, get the next file and start the loop again. if( ( '\0' == FileInfo.cFileName[0] ) || ( ( '.' == FileInfo.cFileName[0] ) && ('\0' == FileInfo.cFileName[1] ) ) || ( ( '.' == FileInfo.cFileName[0] ) && ( '.' == FileInfo.cFileName[1] ) && ( '\0' == FileInfo.cFileName[2] ) ) || ( FileInfo.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN ) ) { fSuccess = FindNextFileW( hFileEnum, &FileInfo ); continue; } // TODO: Retrieve information about each file, such as // the name and size, and save it in a linked list of // user-defined CDirectoryInfo objects. In this example, // the CDirectoryInfo class contains four data members // that save information about a file: // CDirectoryInfo() // { // m_cRef = 1; // Reference count. // m_pszwName = NULL; // File name. // m_qwSize = 0; // File size. // m_pNext = NULL; // Pointer to next CDirectoryInfo. // } // Increment the index and find the next file. dwIndex++; fSuccess = FindNextFileW( hFileEnum, &FileInfo ); } // Callback to the server. hr = pCallback->OnOpenDirectory( hr, this, qwContext ); if (FAILED(hr)) goto EXIT; // Because errors are passed through the callback, return S_OK. return( S_OK ); EXIT: // TODO: Release temporary objects. }
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 |