syncmltransport.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 1,990 行 · 第 1/5 页
CPP
1,990 行
// message creates/deletes/modifications/moves.
// [ Omitted ]
advise = new CAdviseSink();
m_advise = advise;
advise->AddRef();
ULONG m_ulAdviseConnection = 0;
pMsgStore->Advise(
0,
NULL,//notify on entire store
fnevObjectModified,
(IMAPIAdviseSink *)advise,
&m_ulAdviseConnection);
// Some transports may need to know the Entry IDs for
// system folders(Inbox, Outbox, Drafts, Sent Items,
// Deleted Items(Wastebasket)). This is a good place
// to query the IMsgStore* to get those.
// [ Omitted ]
Exit:
return hr;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::Synchronize()
//
// Description:
// This DLL entry point is called by Inbox to synchronize the
// current service
//
// Parameters:
// pRqst IN Sync options requested by Inbox
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::Synchronize(
MAILSYNCREQUEST * pRqst
)
{
HRESULT hr = S_OK;
//SetCursor(LoadCursor(NULL, IDC_WAIT));
//Get sources from registry
// MessageBox(NULL, TEXT("Inside"), TEXT("Alert"), MB_ICONWARNING);
wchar_t* sources = NULL;
sources = getValueFromReg(TEXT("transportSources"));
unsigned long pid;
if(!sources) {
//pid = startcmd(SYNCAPP, TEXT("transport mail"));
pid = startProgram(SYNCAPP, TEXT("transport mail")); // start sync process
} else {
wchar_t* value = NULL;
int sizew = 0;
wchar_t* transportCommand = getValueFromReg(TEXT("transportCommand"));
if (!transportCommand) {
transportCommand = wstrdup(TEXT("transport"));
}
sizew = wcslen(transportCommand) + 1 + wcslen(sources); // +1 is the space between "command values"
value = new wchar_t[sizew + 1];
wcscpy(value, transportCommand);
wcscat(value, TEXT(" "));
wcscat(value, sources);
pid = startProgram(SYNCAPP, value); // start sync process
//pid = startcmd(SYNCAPP, value);
delete [] value; value = NULL;
if (sources) { delete [] sources; sources = NULL;}
}
if (pid) {
/*
for (int j = 0; j < 5; j++) {
wchar_t toIn[256];
m_SyncProgressItemPending.cbSize = sizeof(SYNCPROGRESSITEM);
m_SyncProgressItemPending.mask = SYNCPROGRESSITEM_STATUSTEXT |
SYNCPROGRESSITEM_PROGVALUE |
SYNCPROGRESSITEM_MAXVALUE;
m_SyncProgressItemPending.cbIdNewMsg = 0; // not used
wsprintf(toIn, TEXT("Inserting %i/%i"), j, 5);
m_SyncProgressItemPending.pwszStatusText = toIn;
m_SyncProgressItemPending.dwStatusType = 0; // not used
m_SyncProgressItemPending.ulProgValue = j;
m_SyncProgressItemPending.ulMaxValue = 5;
m_SyncProgressItemPending.ulTotalNewMail = 0; // not used
m_SyncProgressItemPending.cbIdNewMsg = 0;
m_SyncProgressItemPending.cbIdNewMsg = 0;
HandlePendingProgressItem();
Sleep(1000);
}
*/
SetStatusText(IDS_STRING_SYNC_IN_PROGRESS);
waitProcess(pid, FIVE_MINUTES_MSEC);
}
else {
//SetStatusText(IDS_STRING_PLUG_IN_NOT_INSTALLED);
}
//SetCursor(NULL);
if(NULL == pRqst)
{
// Inbox is requesting a full sync.
// Synchronize all folders and messages.
// [ Omitted ]
// [ Assumed to return hr ]
}
else
{
switch(pRqst->ffFlags)
{
case SYNC_NORMAL:
// Inbox is requesting a full sync.
// Synchronize all folders and messages.
// [ Omitted ]
// [ Assumed to return hr ]
break;
case SYNC_FOLDER:
// Inbox is requesting to synchronize a specific folder.
// [ Omitted ]
// [ Assumed to return hr ]
break;
case SYNC_RESETHIERARCHY:
// Inbox is requesting to synchronize the folder hierarchy.
// [ Omitted ]
// [ Assumed to return hr ]
break;
case SYNC_CREATE_FOLDER:
// The user created a folder, and Inbox is asking the
// transport to create the local and server folders for it.
// [ Omitted ]
// [ Assumed to return hr ]
break;
case SYNC_RENAME_FOLDER:
// The user renamed a folder, and Inbox is asking the
// transport to rename the local and server folders for it.
// [ Omitted ]
// [ Assumed to return hr ]
break;
case SYNC_DELETE_FOLDER:
// The user deleted a folder, and Inbox is asking the
// transport to delete the local and server folders for it.
// [ Omitted ]
// [ Assumed to return hr ]
break;
default:
break;
}
}
if(hr == E_OUTOFMEMORY)
{
LogErrorEvent(E_OUTOFMEMORY, TRUE);
}
if(FAILED(hr) &&(pRqst == NULL || pRqst->ffFlags == SYNC_NORMAL))
{
//Get the body fetch thread to close now
m_fShutDown = TRUE;
// to disconnect after sync
//SendProgressMessage(SYNCPROGRESSITEM_DISCONNECTED);
}
ASSERT(m_pszProfile);
return hr;
}
//Simply get the value of the HKLM\Software\Funambol\SyncclientPIM
//put it in a buffer and cancel the value in the registry
wchar_t* CTransportSyncHandler::getValueFromReg(wchar_t* regval){
HKEY key = NULL;
DWORD res;
long err = 0;
wchar_t* buf = NULL;
ULONG dim = 0;
RegCreateKeyEx(
HKEY_LOCAL_MACHINE,
TEXT("Software\\") ROOT_CONTEXT_W,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&key,
&res
);
if (key == 0) {
goto finally;
}
// Get value length
err = RegQueryValueEx(
key,
regval,
NULL,
NULL, // we currently support only strings
NULL,
&dim
);
if (err == ERROR_SUCCESS) {
if (dim > 0) {
buf = new wchar_t[dim + 1];
err = RegQueryValueEx(
key,
regval,
NULL,
NULL, // we currently support only strings
(UCHAR*)buf,
&dim
);
}
RegDeleteValue(key, regval);
}
finally:
if (key != 0) {
RegCloseKey(key);
}
return buf;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::ShutDown()
//
// Description:
// This DLL entry point is used by the Inbox to shut down the transport
// object. Perform any clean-up or thread signalling here. After this
// function returns, Inbox will likely Release() the IMailSyncHandler*.
//
// Parameters:
// dwReserved IN Reserved.
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::ShutDown(
DWORD dwReserved
)
{
HRESULT hr = S_OK;
// to abort the sync pressing stop send/receive
abortSync();
/*
// open the plug-in window so the user can press stop to abort
// the sync
HWND wnd = HwndFunctions::getWindowHandle();
Sleep(1000);
if(wnd == NULL){
startcmd(_T(PROVIDER) _T(".exe"), TEXT(""));
};
if(wnd != NULL) {
SetForegroundWindow(wnd);
}
*/
m_fShutDown = TRUE;
SetEvent(m_hEventShutdown);
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::Install()
//
// Description:
// This DLL entry point is used by the Inbox to create a new service
// using this transport.
//
// Parameters:
// pszProfileName IN Name of the new service
// pszIncomingServer IN Name of the incoming server
// pszOutgoingServer IN Name of the outgoing server
// pidNetwork IN GUID that identifies the connection manager
// network to use to connect to these servers
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::Install
(
LPCWSTR pszProfileName,
LPCWSTR pszIncomingServer,
LPCWSTR pszOutgoingServer,
GUID * pidNetwork
)
{
HRESULT hr = S_OK;
//MessageBox(NULL, L"Install", L"TransportDemo", MB_SETFOREGROUND|MB_OK);
//MessageBox(NULL, pszProfileName, L"TransportDemo", MB_OK);
//MessageBox(NULL, pszIncomingServer, L"TransportDemo", MB_OK);
//MessageBox(NULL, pszOutgoingServer, L"TransportDemo", MB_OK);
// Most transports create a profile key in the registry and
// store these settings under that key.
// [ Omitted ]
return hr;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::UnInstall()
//
// Description:
// This DLL entry point is used by the Inbox to remove a service that
// uses this transport.
//
//
// *** NOTE ***
// This is currently not used by Inbox.
//
//
// Parameters:
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::UnInstall()
{
HRESULT hr = S_OK;
//MessageBox(NULL, L"Uninstall", L"TransportDemo", MB_OK);
return hr;
}
/////////////////////////////////////////////////////////////////////////////
//
// CTransportSyncHandler::Connect()
//
// Description:
// This DLL entry point is used by the Inbox to connect to the
// network identified by the pidNetwork parameter passed to
// the Install() method when the service was created.
//
// Parameters:
// dwReserved IN Reserved
// pCredentials IN Account credentials specified by the user
//
// Returns: HRESULT
//
/////////////////////////////////////////////////////////////////////////////
HRESULT CTransportSyncHandler::Connect(
DWORD dwReserved,
SYNCCREDENTIALS* pCredentials
)
{
HRESULT hr = S_OK;
SYNCCREDENTIALS * pCurrentCreds = pCredentials;
ULONG cTries = 0;
//MessageBox(NULL, L"Connect", L"SyncMLTransport", MB_OK);
// The transport is no longer shut down
// ASSERT(m_hEventShutdown != NULL);
m_fShutDown = FALSE;
// ResetEvent(m_hEventShutdown);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?