syncmltransport.cpp
来自「funambol windows mobile plugin source co」· C++ 代码 · 共 1,886 行 · 第 1/4 页
CPP
1,886 行
// 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 };
ASSERT(m_pszProfile);
evt.pszSourceDLL = _T("SyncMLTransport");
evt.pszSourceProfile = m_pszProfile;
evt.hr = hr;
evt.cbData = cbData;
evt.pbData = NULL;
m_pCallback->LogEvent(&evt);
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::QueryInterface()
//
// Description:
// COM plumbing
//
// Parameters:
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT STDMETHODCALLTYPE CTransportSyncHandler::QueryInterface(
REFIID rif,
LPVOID* ppobj
)
{
return E_NOINTERFACE;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::AddRef()
//
// Description:
// COM plumbing
//
// Parameters:
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
ULONG STDMETHODCALLTYPE CTransportSyncHandler::AddRef()
{
return ++m_cRef;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::Release()
//
// Description:
// COM plumbing
//
// Parameters:
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
ULONG STDMETHODCALLTYPE CTransportSyncHandler::Release()
{
--m_cRef;
if(m_cRef == 0)
{
delete this;
return 0;
}
return m_cRef;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::OnFolderOptions_Download()
//
// Description:
// Called when the user sets the 'Marked for Download' flag on a folder
//
// Parameters:
// pfldr IN Folder marked for download
// pval IN Boolean indicating whether to mark or unmark the folder
// for download
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::OnFolderOptions_Download(
LPMAPIFOLDER pfldr,
LPSPropValue pval
)
{
HRESULT hr = S_OK;
//LOG.debug(("Inside SyncMLTransport::OnFolderOptions_Download>> LPMAPIFOLDER: 0x%x"), pfldr);
// dump LPSPropValue
LPSPropValue lpProp = pval;
// 32 bit integer for a property
ULONG ulPropTag = lpProp->ulPropTag;
// higher 16 bit: property ID
ULONG ulPropID = PROP_ID(ulPropTag);
// lower 16 bit: property type
ULONG ulPropType = PROP_TYPE(ulPropTag);
// name
/*LPCTSTR pcszPropName = CMAPIHelper::GetPropertyName(ulPropTag);
LPCTSTR pcszPropTypeName = CMAPIHelper::GetPropertyTypeName(ulPropType);
LOG.debug("Inside CTransportSyncHandler::OnFolderOptions_Download>> PropertyTag %u, Name: %s, Type: %sID: 0x%x", ulPropTag, pcszPropName, pcszPropTypeName, ulPropID); */
// MessageBox(NULL, L"OnFolderOptions_Download", L"TransportDemo", MB_OK);
// Mark or unmark the folder for sync. The details of this
// are transport-specific.
// [ Omitted ]
return hr;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::OnFolderOptions_QueryDownload()
//
// Description:
// Called when Inbox tries to determine if the given folder
// is marked for sync.
//
// Parameters:
// pfldr IN Folder marked for download
// pval OUT Boolean indicating whether the folder is marked for sync
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::OnFolderOptions_QueryDownload(
LPMAPIFOLDER pfldr,
LPSPropValue pval
)
{
HRESULT hr = S_OK;
//LOG.debug("Inside CTransportSyncHandler::OnFolderOptions_QueryDownload>> LPMAPIFOLDER: 0x%x", pfldr);
// dump LPSPropValue
LPSPropValue lpProp = pval;
// 32 bit integer for a property
ULONG ulPropTag = lpProp->ulPropTag;
// higher 16 bit: property ID
ULONG ulPropID = PROP_ID(ulPropTag);
// lower 16 bit: property type
ULONG ulPropType = PROP_TYPE(ulPropTag);
// name
/*LPCTSTR pcszPropName = CMAPIHelper::GetPropertyName(ulPropTag);
LPCTSTR pcszPropTypeName = CMAPIHelper::GetPropertyTypeName(ulPropType);
LOG.debug("Inside CTransportSyncHandler::OnFolderOptions_QueryDownload>> PropertyTag %u, Name: %s, Type: %sID: 0x%x", ulPropTag, pcszPropName, pcszPropTypeName, ulPropID); */
// MessageBox(NULL, L"OnFolderOptions_QueryDownload", L"TransportDemo", MB_OK);
// The details of this are transport-specific.
// [ Omitted ]
return hr;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::OnFolderOptions_Create()
//
// Description:
// Called when the user creates a new folder to allow the transport
// to set any properties it needs to on the folder, and add it to
// its change tracking so that it can create the folder when the
// service connects next.
//
// Parameters:
// pfldr IN Newly created folder
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::OnFolderOptions_Create(
LPMAPIFOLDER * ppfldrret
)
{
HRESULT hr = S_OK;
// MessageBox(NULL, L"OnFolderOptions_Create", L"TransportDemo", MB_OK);
// The details of this are transport-specific.
// [ Omitted ]
return hr;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::OnFolderOptions_QueryCreate()
//
// Description:
// Called when Inbox wants to know if a folder has been marked
// for creation on the server.
//
// Parameters:
// pfldr IN Folder to check
// pval OUT Boolean indicating whether the folder is marked for creation
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::OnFolderOptions_QueryCreate(
LPMAPIFOLDER pfldr,
LPSPropValue pval
)
{
HRESULT hr = S_OK;
//MessageBox(NULL, L"OnFolderOptions_QueryCreate", L"TransportDemo", MB_OK);
// The details of this are transport-specific.
// [ Omitted ]
return hr;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::OnFolderOptions_SetFetchOption()
//
// Description:
// Called when the users sets the download options for a folder.
//
// Parameters:
// opts IN Folder options to set
// pfldr IN Folder being modified
// pval IN Property tag used to set the option
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::OnFolderOptions_SetFetchOption(
FOLDEROPTIONS opts,
LPMAPIFOLDER pfldr,
LPSPropValue pval
)
{
//LOG.debug("Inside CTransportSyncHandler::OnFolderOptions_SetFetchOption>> LPMAPIFOLDER: 0x%x", pfldr);
// dump LPSPropValue
LPSPropValue lpProp = pval;
// 32 bit integer for a property
ULONG ulPropTag = lpProp->ulPropTag;
// higher 16 bit: property ID
ULONG ulPropID = PROP_ID(ulPropTag);
// lower 16 bit: property type
ULONG ulPropType = PROP_TYPE(ulPropTag);
// name
/* LPCTSTR pcszPropName = CMAPIHelper::GetPropertyName(ulPropTag);
LPCTSTR pcszPropTypeName = CMAPIHelper::GetPropertyTypeName(ulPropType);
LOG.debug("Inside CTransportSyncHandler::OnFolderOptions_SetFetchOption>> PropertyTag %u, Name: %s, Type: %sID: 0x%x", ulPropTag, pcszPropName, pcszPropTypeName, ulPropID);
*/
HRESULT hr = E_FAIL;
//MessageBox(NULL, L"OnFolderOptions_SetFetchOption", L"TransportDemo", MB_OK);
pval->ulPropTag = 0;
switch(opts)
{
case koptSetAge:
pval->ulPropTag = 0; // Replace with named prop ID for max age
break;
case koptSetBodyFetchSize:
pval->ulPropTag = 0; // Replace with named prop ID for max body size
break;
case koptSetAttachFetchSize:
pval->ulPropTag = 0; // Replace with named prop ID for max attachment size
break;
default:
ASSERT(FALSE);
break;
}
if(pval->ulPropTag)
{
hr = pfldr->SetProps(1, pval, NULL);
}
return hr;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::OnFolderOptions_GetFetchOption()
//
// Description:
// Called when Inbox needs the download options for a folder
//
// Parameters:
// opts IN Folder options to set
// pfldr IN Folder being modified
// pval OUT Property tag used to set the option
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::OnFolderOptions_GetFetchOption(
FOLDEROPTIONS opts,
LPMAPIFOLDER pfldr,
LPSPropValue pval
)
{
//LOG.debug("Inside CTransportSyncHandler::OnFolderOptions_GetFetchOption>> LPMAPIFOLDER: 0x%x", pfldr);
// dump LPSPropValue
LPSPropValue lpProp = pval;
// 32 bit integer for a property
ULONG ulPropTag = lpProp->ulPropTag;
// higher 16 bit: property ID
ULONG ulPropID = PROP_ID(ulPropTag);
// lower 16 bit: property type
ULONG ulPropType = PROP_TYPE(ulPropTag);
// name
/*LPCTSTR pcszPropName = CMAPIHelper::GetPropertyName(ulPropTag);
LPCTSTR pcszPropTypeName = CMAPIHelper::GetPropertyTypeName(ulPropType);
LOG.debug("Inside CTransportSyncHandler::OnFolderOptions_GetFetchOption>> PropertyTag %u, Name: %s, Type: %sID: 0x%x", ulPropTag, pcszPropName, pcszPropTypeName, ulPropID);
*/
HRESULT hr = E_FAIL;
ULONG rgtags[] = { 1, 0 };
//MessageBox(NULL, L"OnFolderOptions_GetFetchOption", L"TransportDemo", MB_OK);
switch(opts)
{
case koptGetAge:
rgtags[1] = 0; // Replace with named prop ID for max age
pval->Value.ul = 0; // Replace with default value for max age
break;
case koptGetBodyFetchSize:
rgtags[1] = 0; // Replace with named prop ID for max body size
pval->Value.ul = 0; // Replace with default value for max body size
break;
case koptSetAttachFetchSize:
rgtags[1] = 0; // Replace with named prop ID for max attachment size
pval->Value.ul = 0; // Replace with default value for max attachment size
break;
default:
ASSERT(FALSE);
break;
}
if(rgtags[1] != 0)
{
ULONG cItems = 0;
LPSPropValue rgvals = NULL;
hr = pfldr->GetProps((LPSPropTagArray) rgtags, MAPI_UNICODE, &cItems, &rgvals);
if(SUCCEEDED(hr))
{
ASSERT(cItems);
// If we got a value return it to the caller; otherwise we initialized
// to the default already.
if(rgtags[1] == rgvals[0].ulPropTag)
{
pval->Value.ul = rgvals[0].Value.ul;
}
MAPIFreeBuffer(rgvals);
}
}
return hr;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?