clientpushmanager.cpp
来自「funambol window mobile客户端源代码」· C++ 代码 · 共 656 行 · 第 1/2 页
CPP
656 行
///////////////////////////////////////////////////////////////////////////////
// Function:
// DlgMainProc
//
// Process WM messages to the dialog box.
//
// Purpose:
// Checks if the app dialog class already exists. If so, it means the app
// is already running so we quit this instance.
//
// Parameters:
// hDlg - [IN] Handle to main dialog
// message - [IN] WM message
// wParam - [IN] WPARAM for WM message
// lParam - [IN] LPARAM for WM message. It is the folder when the
// PIM_ITEM_ is invoked
//
// Returns:
// An LRESULT
//
LRESULT CALLBACK wndMainProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HRESULT hr = S_OK;
static HWND hWndStats;
WORD wHi = HIWORD(wParam),
wLo = LOWORD(wParam);
ClientPushManager* cpManager = ClientPushManager::getInstance();
// Keep this static so we reuse the same variable each time this function is called.
static IPOutlookItemCollection *pCol;
CBR(hwnd);
switch (message)
{
case WM_CLOSE:
LOG.info("CP: WM_CLOSE the application");
cpManager->UnInitPOOM();
LOG.debug("Unregister class");
UnregisterClass(cpManager->cp_wncClass.lpszClassName, cpManager->cp_wncClass.hInstance);
LOG.debug("End dialog");
EndDialog(hwnd, 0);
LOG.debug("Destroy wnd");
DestroyWindow (hwnd);
break;
case WM_DESTROY:
cpManager->UnInitPOOM();
PostQuitMessage(0);
break;
case PIM_ITEM_CREATED_LOCAL:
case PIM_ITEM_DELETED_LOCAL:
case PIM_ITEM_CHANGED_LOCAL:
// no modification in local
break;
case PIM_ITEM_CREATED_REMOTE:
case PIM_ITEM_DELETED_REMOTE:
case PIM_ITEM_CHANGED_REMOTE:
cpManager->setPIMModifications(lParam);
LOG.debug("CP: Item is %lu", wParam);
// Caught a POOM notification.
CHR(hr);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
Error:
return FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// Function:
// ItemTypeToFolder
//
// Purpose:
// Returns the Outlook folder type given the Outlook Item type.
//
// Parameters:
// olItemType - Outlook item type
//
// Returns:
// An OlDefaultFolders to the specified Item Type
//
OlDefaultFolders ClientPushManager::ItemTypeToFolder(int olItemType)
{
OlDefaultFolders olFolder = (OlDefaultFolders) 0;
switch(olItemType)
{
case olAppointmentItem:
olFolder = olFolderCalendar;
break;
case olContactItem:
olFolder = olFolderContacts;
break;
case olTaskItem:
olFolder = olFolderTasks;
break;
default:
ASSERT(FALSE);
}
return olFolder;
}
///////////////////////////////////////////////////////////////////////////////
// Function:
// SubscribeToNotifications
//
// Purpose:
// This function is used to set the level of notification the current process
// want to get from POOM. The options include any one of the three values:
// PIMFOLDERNOTIFICATION_REMOTE, PIMFOLDERNOTIFICATION_LOCAL,
// or PIMFOLDERNOTIFICATION_ALL
//
// Parameters:
// pPoom - [IN] ptr to POOM app.
// olItemType - [IN] Item type.
// uiNotificationsType - [IN] Type of notification, remote or local?
//
// Returns:
// An HRESULT
//
HRESULT ClientPushManager::subscribeToNotifications(IPOutlookApp2 *pPoom, int olItemType, uint uiNotificationsType)
{
HRESULT hr = 0;
IFolder *pFolder = NULL;
IItem *pItem = NULL;
CEPROPVAL propval = {0};
// Parameter check
CBR(NULL != pPoom);
if(!uiNotificationsType)
{
CHR(E_INVALIDARG);
}
// Get the folder for the item type.
hr = pPoom->GetDefaultFolder(ItemTypeToFolder(olItemType), &pFolder);
CHR(hr);
CBR(NULL != pFolder);
hr = pFolder->QueryInterface(IID_IItem, (LPVOID*)&pItem);
CHR(hr);
CBR(NULL != pItem);
// Set the props on the folder.
propval.propid = PIMPR_FOLDERNOTIFICATIONS;
propval.val.ulVal = uiNotificationsType;
hr = pItem->SetProps(0, 1, &propval);
CHR(hr);
Error:
RELEASE_OBJ(pItem);
RELEASE_OBJ(pFolder);
return hr;
}
///////////////////////////////////////////////////////////////////////////////
// Function:
// InitPOOM2
//
// Purpose:
// Initilizes COM, creates the POOM COM object and calls Logon.
//
// Parameters:
// void
//
// Returns:
// An HRESULT
//
HRESULT ClientPushManager::InitPOOM()
{
HRESULT hr = S_OK;
CHR(CoInitializeEx(NULL, 0));
hr = CoCreateInstance(CLSID_Application, NULL, CLSCTX_INPROC_SERVER,
IID_IPOutlookApp2, (LPVOID *) &g_polApp);
CHR(hr);
CBR(NULL != g_polApp);
Error:
return hr;
}
///////////////////////////////////////////////////////////////////////////////
// Function:
// UnInitPOOM2
//
// Purpose:
// Does a logoff on POOM, and un-initilazize COM.
//
// Parameters:
// void
//
// Returns:
// An HRESULT
//
HRESULT ClientPushManager::UnInitPOOM()
{
HRESULT hr = S_OK;
// Lets release the global ptr
RELEASE_OBJ(g_pCol);
CBR(g_polApp != NULL);
// This logoff is for safety. (if its already logged off, S_FALSE will get returned)
hr = g_polApp->Logoff();
Error:
RELEASE_OBJ(g_polApp);
CoUninitialize();
return hr;
}
/**
* olFolderType is the value of the contact, calendar and task.
* olFolderType == -1 means that the function is called by the startCP
* If the mask is not 0, means that the device is restarted and the flag is not
*
*/
void ClientPushManager::setPIMModifications(int olFolderType) {
DMTree* dmt = NULL;
ManagementNode* node = NULL;
char* value = NULL;
int mask = 0;
char buf[4];
dmt = DMTreeFactory::getDMTree(APPLICATION_URI);
if (!dmt) goto finally;
node = dmt->readManagementNode(APPLICATION_URI);
if (!node) goto finally;
// Check if we use the queue (queuePush = "1")
value = node->readPropertyValue(CP_PUSH_LIST);
if (!value) {
value = stringdup("0");
}
mask = atoi(value);
if (olFolderType == -1 && mask != 0) {
startProgram(TEXT("startsync.exe"), TEXT("remove-schedule"));
Sleep(1000);
startProgram(TEXT("startsync.exe"), TEXT("schedule"));
return;
}
/*
* If the flag is empty, schedule the next sync. Otherwise it is already scheduled
*/
if (mask == 0 ) {
startProgram(TEXT("startsync.exe"), TEXT("schedule"));
}
//
// Update the bit-mask with current sources
//
switch(olFolderType)
{
case olFolderContacts:
mask = mask | 2;
break;
case olFolderCalendar:
mask = mask | 4;
break;
case olFolderTasks:
mask = mask | 8;
break;
default:
break;
}
// Write 'clientPushList' value to registry
sprintf(buf, "%d", mask);
node->setPropertyValue(CP_PUSH_LIST, buf);
finally:
if (dmt) delete dmt;
if (node) delete node;
if (value) delete [] value;
}
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow) {
int ret = 0;
//MessageBox (NULL, TEXT("ClientPush"), TEXT("title"), MB_SETFOREGROUND |MB_OK);
// Init log.
LOG.setLogPath(CP_LOG_PATH);
LOG.setLogName(CP_LOG_NAME);
LogLevel l = getLOGLevel();
LOG.setLevel(l);
// Start CP.
ClientPushManager* cp = ClientPushManager::getInstance();
cp->startCP(GetModuleHandle(0));
return ret;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?