⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contentdirectoryservice.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:


STDMETHODIMP ContentDirectoryServiceImpl::UpdateObject(BSTR ObjectID,
                                                       BSTR CurrentTagValue,
                                                       BSTR NewTagValue)
{
    if(!m_pContentDirectory)
        return m_ErrReport.ReportError(ERROR_AV_UPNP_ACTION_FAILED);


    // Setup arguments to call to IContentDirectory
    wstring strstrObjectID, strCurrentTagValue, strNewTagValue;
    if(   !strstrObjectID.assign(ObjectID,            SysStringLen(ObjectID))
       || !strCurrentTagValue.assign(CurrentTagValue, SysStringLen(CurrentTagValue))
       || !strNewTagValue.assign(NewTagValue,         SysStringLen(NewTagValue))   )
        return m_ErrReport.ReportError(ERROR_AV_OOM);


    // Make the call
    const DWORD retPFC = m_pContentDirectory->UpdateObject(strstrObjectID, strCurrentTagValue, strNewTagValue);
    if(SUCCESS_AV != retPFC)
        return m_ErrReport.ReportError(retPFC);


    return S_OK;
}


STDMETHODIMP ContentDirectoryServiceImpl::ImportResource(BSTR SourceURI,
                                                         BSTR DestinationURI,
                                                         unsigned long* pTransferID)
{
    if(!pTransferID)
        return E_POINTER;

    if(!m_pContentDirectory)
        return m_ErrReport.ReportError(ERROR_AV_UPNP_ACTION_FAILED);


    // Setup arguments to call to IContentDirectory
    wstring strSourceURI, strDestinationURI;
    if(   !strSourceURI.assign(SourceURI,           SysStringLen(SourceURI))
       || !strDestinationURI.assign(DestinationURI, SysStringLen(DestinationURI))   )
        return m_ErrReport.ReportError(ERROR_AV_OOM);


    // Make the call
    const DWORD retPFC = m_pContentDirectory->ImportResource(strSourceURI, strDestinationURI, pTransferID);
    if(SUCCESS_AV != retPFC)
        return m_ErrReport.ReportError(retPFC);


    return S_OK;
}


STDMETHODIMP ContentDirectoryServiceImpl::ExportResource(BSTR SourceURI,
                                                         BSTR DestinationURI,
                                                         unsigned long* pTransferID)
{
    if(!pTransferID)
        return E_POINTER;

    if(!m_pContentDirectory)
        return m_ErrReport.ReportError(ERROR_AV_UPNP_ACTION_FAILED);


    // Setup arguments to call to IContentDirectory
    wstring strSourceURI, strDestinationURI;
    if(   !strSourceURI.assign(SourceURI,           SysStringLen(SourceURI))
       || !strDestinationURI.assign(DestinationURI, SysStringLen(DestinationURI))   )
        return m_ErrReport.ReportError(ERROR_AV_OOM);


    // Make the call
    const DWORD retPFC = m_pContentDirectory->ExportResource(strSourceURI, strDestinationURI, pTransferID);
    if(SUCCESS_AV != retPFC)
        return m_ErrReport.ReportError(retPFC);


    return S_OK;
}


STDMETHODIMP ContentDirectoryServiceImpl::StopTransferResource(unsigned long TransferID)
{
    if(!m_pContentDirectory)
        return m_ErrReport.ReportError(ERROR_AV_UPNP_ACTION_FAILED);


    // Make the call
    const DWORD retPFC = m_pContentDirectory->StopTransferResource(TransferID);
    if(SUCCESS_AV != retPFC)
        return m_ErrReport.ReportError(retPFC);


    return S_OK;
}


STDMETHODIMP ContentDirectoryServiceImpl::GetTransferProgress(unsigned long TransferID,
                                                              BSTR* pTransferStatus,
                                                              BSTR* pTransferLength,
                                                              BSTR* pTransferTotal)
{
    if(!pTransferStatus || !pTransferLength || !pTransferTotal)
        return E_POINTER;

    if(!m_pContentDirectory)
        return m_ErrReport.ReportError(ERROR_AV_UPNP_ACTION_FAILED);


    // Setup arguments for call to IContentDirectory
    wstring strTransferStatus, strTransferLength, strTransferTotal;

    // Make the call
    const DWORD retPFC = m_pContentDirectory->GetTransferProgress(TransferID, &strTransferStatus, &strTransferLength, &strTransferTotal);
    if(SUCCESS_AV != retPFC)
        return m_ErrReport.ReportError(retPFC);

    // Set out args
    if(   !(*pTransferStatus = SysAllocString(strTransferStatus))
       || !(*pTransferLength = SysAllocString(strTransferLength))
       || !(*pTransferTotal  = SysAllocString(strTransferTotal))   )
       return m_ErrReport.ReportError(ERROR_AV_OOM);


    return S_OK;
}


STDMETHODIMP ContentDirectoryServiceImpl::DeleteResource(BSTR ResourceURI)
{
    if(!m_pContentDirectory)
        return m_ErrReport.ReportError(ERROR_AV_UPNP_ACTION_FAILED);


    // Setup arguments to call to IContentDirectory
    wstring strResourceURI;
    if(!strResourceURI.assign(ResourceURI, SysStringLen(ResourceURI)))
        return m_ErrReport.ReportError(ERROR_AV_OOM);


    // Make the call
    const DWORD retPFC = m_pContentDirectory->DeleteResource(strResourceURI);
    if(SUCCESS_AV != retPFC)
        return m_ErrReport.ReportError(retPFC);


    return S_OK;
}


STDMETHODIMP ContentDirectoryServiceImpl::CreateReference(BSTR ContainerID,
                                                          BSTR ObjectID,
                                                          BSTR* pNewID)
{
    if(!pNewID)
        return E_POINTER;

    if(!m_pContentDirectory)
        return m_ErrReport.ReportError(ERROR_AV_UPNP_ACTION_FAILED);


    // Setup argument for call to IContentDirectory
    wstring strContainerID, strObjectID;
    wstring strNewID;

    if(   !strContainerID.assign(ContainerID,   SysStringLen(ContainerID))
       || !strObjectID.assign(ObjectID,         SysStringLen(ObjectID))   )
        return m_ErrReport.ReportError(ERROR_AV_OOM);


    // Make the call
    const DWORD retPFC = m_pContentDirectory->CreateReference(strContainerID, strObjectID, &strNewID);
    if(SUCCESS_AV != retPFC)
        return m_ErrReport.ReportError(retPFC);

    // Set out arg
    *pNewID = SysAllocString(strNewID);
    if(!*pNewID)
       return m_ErrReport.ReportError(ERROR_AV_OOM);


    return S_OK;
}


// InvokeVendorAction
DWORD ContentDirectoryServiceImpl::InvokeVendorAction(
        /* [in] */ LPCWSTR pszActionName,
        /* [in] */ DISPPARAMS* pdispparams, 
        /* [in, out] */ VARIANT* pvarResult)
{
    return m_pContentDirectory->InvokeVendorAction(pszActionName, pdispparams, pvarResult);
}



//
// Private
//

HRESULT ContentDirectoryServiceImpl::InitToolkitErrs()
{
    const int vErrMap[][2] =
    {
        {ERROR_AV_POINTER,          ERROR_AV_UPNP_ACTION_FAILED},
        {ERROR_AV_OOM,              ERROR_AV_UPNP_ACTION_FAILED},
        {ERROR_AV_INVALID_INSTANCE, ERROR_AV_UPNP_ACTION_FAILED},
        {ERROR_AV_INVALID_STATEVAR, ERROR_AV_UPNP_ACTION_FAILED},
        {ERROR_AV_ALREADY_INITED,   ERROR_AV_UPNP_ACTION_FAILED},
        {0,                         0} // 0 is used to denote the end of this array
    };


    for(unsigned int i=0; 0 != vErrMap[i][0]; ++i)
    {
        if(ERROR_AV_OOM == m_ErrReport.AddToolkitError(vErrMap[i][0], vErrMap[i][1]))
            return E_OUTOFMEMORY;
    }

    return S_OK;
}


HRESULT ContentDirectoryServiceImpl::InitErrDescrips()
{
    const int vErrNums[] =
    {
        // UPnP
        ERROR_AV_UPNP_INVALID_ACTION,
        ERROR_AV_UPNP_ACTION_FAILED,
        // ContentDirectory
        ERROR_AV_UPNP_CD_NO_SUCH_OBJECT,
        ERROR_AV_UPNP_CD_INVALID_CURRENTTAGVALUE,
        ERROR_AV_UPNP_CD_INVALID_NEWTAGVALUE,
        ERROR_AV_UPNP_CD_REQUIRED_TAG_DELETE,
        ERROR_AV_UPNP_CD_READONLY_TAG_UPDATE,
        ERROR_AV_UPNP_CD_PARAMETER_NUM_MISMATCH,
        /* there does not exist an error 707 (ContentDirectory:1 Service Template Version 1.01) */
        ERROR_AV_UPNP_CD_BAD_SEARCH_CRITERIA,
        ERROR_AV_UPNP_CD_BAD_SORT_CRITERIA,
        ERROR_AV_UPNP_CD_NO_SUCH_CONTAINER,
        ERROR_AV_UPNP_CD_RESTRICTED_OBJECT,
        ERROR_AV_UPNP_CD_BAD_METADATA,
        ERROR_AV_UPNP_CD_RESTRICTED_PARENT_OBJECT,
        ERROR_AV_UPNP_CD_NO_SUCH_SOURCE_RESOURCE,
        ERROR_AV_UPNP_CD_SOURCE_RESOURCE_ACCESS_DENIED,
        ERROR_AV_UPNP_CD_TRANSFER_BUSY,
        ERROR_AV_UPNP_CD_NO_SUCH_FILE_TRANSFER,
        ERROR_AV_UPNP_CD_NO_SUCH_DESTINATION_RESOURCE,
        ERROR_AV_UPNP_CD_DESTINATION_RESOURCE_ACCESS_DENIED,
        ERROR_AV_UPNP_CD_REQUEST_FAILED,
        0 // 0 is used to denote the end of this array
    };
    
    const wstring vErrDescrips[] =
    {
        // UPnP
        L"Invalid Action",
        L"Action Failed",
        // ContentDirectory
        L"No such object",
        L"Invalid CurrentTagValue",
        L"Invalid NewTagValue",
        L"Required tag",
        L"Read only tag",
        L"Parameter Mismatch",
        /* there does not exist an error 707 (ContentDirectory:1 Service Template Version 1.01) */
        L"Unsupported or invalid search criteria",
        L"Unsupported or invalid sort cirteria",
        L"No such container",
        L"Restricted object",
        L"Bad metadata",
        L"Restricted parent object",
        L"No such source resource",
        L"Source resource access denied",
        L"Transfer busy",
        L"No such file transfer",
        L"No such destination resource",
        L"Destination resource access denied",
        L"Cannot process the request"
    };


    for(unsigned int i=0; 0 != vErrNums[i]; ++i)
    {
        if(ERROR_AV_OOM == m_ErrReport.AddErrorDescription(vErrNums[i], vErrDescrips[i]))
            return E_OUTOFMEMORY;
    }

    return S_OK;
}


void ContentDirectoryServiceImpl::InitDISPIDs()
{
    // Evented variables for ContentDirectory
    LPCWSTR vpszStateVarNames[] =
    {
        ContentDirectoryState::TransferIDs,
        ContentDirectoryState::SystemUpdateID,
        ContentDirectoryState::ContainerUpdateIDs,
        0 // 0 is used to denote the end of this array
    };

    const DISPID vdispidStateVarDISPIDs[] =
    {
        DISPID_TRANSFERIDS,
        DISPID_SYSTEMUPDATEID,
        DISPID_CONTAINERUPDATEIDS
    };


    for(unsigned int i=0; 0 != vpszStateVarNames[i]; ++i)
    {
        if(m_mapDISPIDs.end() == m_mapDISPIDs.insert(vpszStateVarNames[i], vdispidStateVarDISPIDs[i]))
            return;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -