syncmltransport.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 1,990 行 · 第 1/5 页

CPP
1,990
字号
        hr = E_INVALIDARG;
    }
    //MessageBox(0, pszName, L"SetCapability", MB_OK);

    // Test pszName against the specific capability strings that the
    // transport supports, and set the requested value when a match
    // is found.  If no match is found, return MAPI_E_NOT_FOUND.
    // [ Omitted ]

    return hr;
}





/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::DecodeEvent()
//
//  Description:
//      This DLL entry point is used by the Inbox to map a transport event
//      to an descriptive string.
//
//  Parameters:
//      pevt        IN  Event to map
//      ppszEvent   OUT String describing the event
//
//  Returns:    HRESULT
//
/////////////////////////////////////////////////////////////////////////////

HRESULT CTransportSyncHandler::DecodeEvent(
    TRANSPORTEVENT * pevt,
    LPWSTR * ppszEvent
    )
{
    UINT    nStringId = 0;
    LPCTSTR pszFormat;
    HRESULT hr;

    //MessageBox(NULL, L"DecodeEvent", L"TransportDemo", MB_OK);

    ASSERT(pevt != NULL);

    // We use cbData to determine whether the error is Send or Receive related.
    BOOL fReceiving =(pevt->cbData != 0);

    switch (pevt->hr)
    {
        // Map HRESULTs to error string resource IDs here:


        // General errors...
        case E_OUTOFMEMORY:
            //nStringId = IDS_ERROR_OUTOFMEMORY;
            break;

        // Socket errors.
        case HrFromWSAError(WSAETIMEDOUT):
            //nStringId = IDS_ERROR_TIMEDOUT;
            break;

        case HrFromWSAError(WSAHOST_NOT_FOUND):
        case HrFromWSAError(WSAENOTCONN):
        case HrFromWSAError(WSATRY_AGAIN):      //Non-Authoritative Host not found
        case HrFromWSAError(WSANOTINITIALISED): // Can be returned by GetHostByName / Successful WSASTARTUP not yet performed
            //nStringId =(fReceiving ? IDS_ERROR_SERVERNOTFOUND_INCOMING :
            //                          IDS_ERROR_SERVERNOTFOUND_OUTGOING);
            break;

        case HrFromWSAError(WSAECONNREFUSED):  // Happens if user supplied wrong port number.
            //nStringId =(fReceiving ? IDS_ERROR_SERVERNOTREADY_INCOMING :
            //                          IDS_ERROR_SERVERNOTREADY_OUTGOING);
            break;

        case CEMAPI_E_PROTOCOL_ERROR:
            //nStringId = IDS_ERROR_LOGIN_INCOMING;
            break;

        case CEMAPI_E_PLAINTEXT_NOTSUPPORTED:
            //nStringId = IDS_IMAP_NO_PLAINTEXT;
            break;

        case CEMAPI_E_NO_ACCOUNT_INFO:
            //nStringId = IDS_ERROR_LOGIN_INCOMING;
            break;

        case E_FAIL:
            //nStringId = IDS_ERROR_NO_NETWORK;
            break;

        // Logon error...
        case ERROR_LOGON_FAILURE:
            //nStringId =(fReceiving ? IDS_ERROR_LOGIN_INCOMING :
            //                          IDS_ERROR_LOGIN_OUTGOING);
            break;

        // POP uses this report that the server didn't like initial connection.
        case ERROR_NOT_READY:
            //nStringId = IDS_ERROR_SERVERNOTREADY_INCOMING;
            break;

        // Handle errors specific to this transport
        /*
        case TRANSPORTDEMO_???:
            nStringId = IDS_ERROR_SERVEROVERLOADED;
            break;
        */

        default: // General failure message.
            //nStringId =(fReceiving ? IDS_ERROR_UNKNOWN_INCOMING :
            //                          IDS_ERROR_UNKNOWN_OUTGOING);
            break;
    }

    pszFormat =(LPCTSTR)LoadString(g_hInst, nStringId, 0, 0);
    if(NULL == pszFormat)
    {
        hr = E_FAIL;
        goto Exit;
    }


    hr = m_pCallback->AllocateMem((lstrlen(pszFormat) + 1) * sizeof(WCHAR),(LPBYTE*) ppszEvent);
    if(FAILED(hr))
    {
        goto Exit;
    }

    // Everything worked ok.
    wcscpy(*ppszEvent, pszFormat);

Exit:
    return hr;
}





/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::GetFolderHierarchy()
//
//  Description:
//      This DLL entry point is used by the Inbox to retrieve the complete
//      folder hierarchy for the current service(m_pszProfile).
//
//  Parameters:
//      ppRootNode      OUT     Folder hierarchy
//
//  Returns:    HRESULT
//
/////////////////////////////////////////////////////////////////////////////

HRESULT CTransportSyncHandler::GetFolderHierarchy(
    FOLDERNODE ** ppRootNode
    )
{
    HRESULT hr = S_OK;

    // MessageBox(NULL, L"GetFolderHierarchy", L"TransportDemo", MB_OK);

    ASSERT(ppRootNode);

    // Allocate the FOLDERNODE
    hr = m_pCallback->AllocateMem(sizeof(FOLDERNODE),(LPBYTE *) ppRootNode);
    if(FAILED(hr))
    {
        hr = E_FAIL;
        goto Exit;
    }

    ZeroMemory(*ppRootNode, sizeof(FOLDERNODE));


    // Traverse the folder hierarchy and populate the ppRootNode tree.
    // This data can come from CEMAPI(GetHierarchyTable()), or some other
    // data store if the CEMAPI folder hierarchy doesn't accurately represent
    // the server's hierarchy(eg, you only create synced folders in CEMAPI).
    // [ Omitted ]

Exit:
    return hr;
}


/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::SetFolderOptions()
//
//  Description:
//      This DLL entry point is used by Inbox to perform various configuration
//      options on folders, if the transport supports folder synchronization.
//
//  Parameters:
//      pfldr       IN  Folder being modified
//      pnode       IN  Folder structure for folder being modified
//      opts        IN  Requested operation
//      pval        OUT Value requested(depends on opts)
//
//  Returns:    HRESULT
//
/////////////////////////////////////////////////////////////////////////////

HRESULT CTransportSyncHandler::SetFolderOptions(
    LPMAPIFOLDER pfldr,
    FOLDERNODE* pnode,
    FOLDEROPTIONS opts,
    LPSPropValue pval
    )
{
    HRESULT hr = MAPI_E_INVALID_PARAMETER;

    // MessageBox(NULL, L"DoProperties", L"TransportDemo", MB_OK);

    if (!pfldr)
    {
        return hr;
    }

    switch (opts)
    {
        case IMailSyncHandler::koptDownload:
            if(pval != NULL && pval->ulPropTag == PT_BOOLEAN)
            {
                hr = OnFolderOptions_Download(pfldr, pval);
            }
            break;

        case IMailSyncHandler::koptQueryDownload:
            if(pval != NULL)
            {
                hr = OnFolderOptions_QueryDownload(pfldr, pval);
            }
            break;

        case IMailSyncHandler::koptCreate:
            hr = OnFolderOptions_Create(&pfldr);
            break;

        case IMailSyncHandler::koptQueryCreate:
            if(pval != NULL)
            {
                hr = OnFolderOptions_QueryCreate(pfldr, pval);
            }
            break;

        case IMailSyncHandler::koptSetAge:
        case IMailSyncHandler::koptSetBodyFetchSize:
        case IMailSyncHandler::koptSetAttachFetchSize:
            if(pval != NULL)
            {
                hr = OnFolderOptions_SetFetchOption(opts, pfldr, pval);
            }
            break;

        case IMailSyncHandler::koptGetAge:
        case IMailSyncHandler::koptGetBodyFetchSize:
        case IMailSyncHandler::koptGetAttachFetchSize:
            if(pval != NULL)
            {
                hr = OnFolderOptions_GetFetchOption(opts, pfldr, pval);
            }
            break;

        default:
            break;
    }

    return hr;
}


/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::SetStatusText()
//
//  Description:
//      Uses a callback to set the status bar text in Inbox.
//
//  Parameters:
//      nId     IN  Resource ID for string to display
//
//  Returns:    void
//
/////////////////////////////////////////////////////////////////////////////

void CTransportSyncHandler::SetStatusText(
    UINT nId
    )
{
    SYNCPROGRESSITEM item = { 0 };

    /* 
    * use a buffer to store the returned string resource instead
    */
    wchar_t toDisplay[128];
    LoadString(getLocalizationUtils()->getLocaleResource(), nId, toDisplay, 128);

    item.cbSize         =   sizeof(item);
    item.mask           =   SYNCPROGRESSITEM_STATUSTEXT;
    item.pwszStatusText =   toDisplay; 
    //item.pwszStatusText =(LPCTSTR) LoadString(g_hInst, nId, 0, 0);

    ASSERT(item.pwszStatusText != NULL);

    if(m_pCallback != NULL)
    {
        m_pCallback->Progress(m_pszProfile, &item);
    }
}


/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::SendProgressMessage()
//
//  Description:
//      Uses a callback to set the sync progress in Inbox.  Currently
//      only appropriate for SYNCPROGRESSITEM_DISCONNECTED.
//
//  Parameters:
//      dwMask      IN  SYNCPROGRESSITEM_xxx from cemapi.h
//
//  Returns:    void
//
/////////////////////////////////////////////////////////////////////////////

void CTransportSyncHandler::SendProgressMessage(
    DWORD dwMask
    )
{
    SYNCPROGRESSITEM item = { 0 };

    item.cbSize =   sizeof(item);
    item.mask   =   dwMask;

    if(m_pCallback != NULL)
    {
        m_pCallback->Progress(m_pszProfile, &item);
    }
}



/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::HandlePendingProgressItem()
//
//  Description:
//      Uses a callback to inform the Inbox of any pending progress items
//      and then resets the global progress item.
//
//  Parameters:
//
//  Returns:    void
//
/////////////////////////////////////////////////////////////////////////////

void CTransportSyncHandler::HandlePendingProgressItem()
{
    if(m_SyncProgressItemPending.mask != 0)
    {
        if(m_pCallback != NULL)
        {
            m_pCallback->Progress(m_pszProfile, &m_SyncProgressItemPending);
        }
    }

    ZeroMemory(&m_SyncProgressItemPending, sizeof(m_SyncProgressItemPending));
}



/////////////////////////////////////////////////////////////////////////////
//
//  CTransportSyncHandler::LogErrorEvent()
//
//  Description:
//      Use a callback to log an error event with Inbox
//
//  Parameters:
//      hr          IN      HRESULT of error code
//      cbData      IN      Amount of data read from the server
//
//  Returns:    HRESULT
//
/////////////////////////////////////////////////////////////////////////////

HRESULT CTransportSyncHandler::LogErrorEvent(
    HRESULT hr,
    ULONG cbData
    )
{
    TRANSPORTEVENT evt = { 0 };

⌨️ 快捷键说明

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