IWMSDataSourcePluginCallback::OnOpenDataContainer

banner art

Previous Next

IWMSDataSourcePluginCallback::OnOpenDataContainer

The OnOpenDataContainer method is called by a data source plug-in to respond when the server calls IWMSDataSourcePlugin::OpenDataContainer.

Syntax

  HRESULT OnOpenDataContainer(
  HRESULT  hr,
  IWMSDataContainer*  pDataContainer,
  QWORD  qwContext
);

Parameters

hr

[in] HRESULT containing the result of the call to IWMSDataSourcePlugin::OpenDataContainer.

pDataContainer

[in] Pointer to the IWMSDataContainer interface identifying the data container opened by the plug-in.

qwContext

[in] QWORD containing a value defined by the server to identify which IWMSDataSourcePlugin::OpenDataContainer request the plug-in is responding to when it calls 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 IWMSDataSourcePlugin::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 OnOpenDataContainer. The COMADMIN_E_PRIVATE_ACCESSDENIED error is defined in the WinError.h file. A plug-in can limit access to a source 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