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

📄 logutils.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
字号:
/*
 * Copyright (C) 2003-2007 Funambol, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */




#include <stdio.h>
#include "logutils.h"
#include "base/startcmd.h"
#include "pim/SettingFunctions.h"

static int logLevel = 1;

static FILE *logFile = NULL;
static wchar_t currentLogPath [256] = TEXT("");

static void getLogPath(wchar_t* currentLogPath) {
    wchar_t path[256];
    getClientConfigurationInternal (NULL, PROPERTY_SPDM_PATH_INFO, path, NULL);
    wcscpy(currentLogPath, path);
    wcscat(currentLogPath, TEXT("\\"));
    wcscat(currentLogPath, TEXT("wap_push.txt"));
}

void Print(TCHAR *pFormat, ...) {
    va_list ArgList;
    TCHAR   Buffer[256];

    va_start (ArgList, pFormat);

    (void)wvsprintf (Buffer, pFormat, ArgList);
    MessageBox(NULL, Buffer, TEXT(""), MB_OK);

    va_end(ArgList);
}

void DebugPrint(TCHAR *pFormat, ...) {

	if(!logLevel)
		return;
    if(!logFile)
        DebugInit(logLevel, true);
    if(!logFile)
        return;

    va_list ArgList;
    va_start (ArgList, pFormat);
    vfwprintf(logFile, pFormat, ArgList);
	fflush(logFile);
    va_end(ArgList);
	DebugEnd();
}

void DebugInit(int level, bool reset) {
	if(logFile)
		DebugEnd();

	logLevel = level;
	if(!logLevel)
		return;
    getLogPath(currentLogPath);
    logFile  = _wfopen(currentLogPath, (reset)?TEXT("w"):TEXT("a+"));
}

void DebugEnd(void) {
	if(logFile) {
		fclose(logFile);
		logFile=NULL;
	}
}

void HexDump(char *buf, int len){

	if (logLevel<2)
		return;

    int i=0, byte;

    for(i=0;i<len;i++){
        if(i%8==0){
            DebugPrint(L"\n%08x: ", i);
        }
        byte = buf[i];
        DebugPrint(L"%02x%s", byte  & 0xFF, (i%2)?" ":"");
    }
    DebugPrint(L"\n");
}

// Debug log.
void PrintMessage(SyncNotification& np)
{

    DebugPrint(L"Version:\t%d\n", np.getVersion());
    DebugPrint(L"UIMode:\t%d\n", np.getUIMode());
    DebugPrint(L"Initiator:\t%S\n",
            ( np.getInitiator() == UserInitiated )
            ? "UserInitiated" : "ServerInitiated" );
    DebugPrint(L"Session ID:\t%d (%x)\n",
            np.getSessionId(), np.getSessionId() );
    DebugPrint(L"Server ID:\t%S\n", np.getServerId() );
    DebugPrint(L"NumSyncs:\t%d\n", np.getNumSyncs() );

    for (int i=0; i<np.getNumSyncs(); i++){
        SyncAlert *sync;

        sync=np.getSyncAlert(i);

        if( ! sync ){
            DebugPrint(L"Error on sync #%d\n", i);
        }
        DebugPrint(L"Sync type:\t%d\n", sync->getSyncType() );
        DebugPrint(L"Content type:\t%d\n", sync->getContentType() );
        DebugPrint(L"Server URI:\t%S\n", sync->getServerURI() );
    }
}


HRESULT SaveFile(LPPUSHMSG pPushMsg)
{

    FILE* f;
    f = fopen("\\wap.txt", "wb+");
    fwrite (pPushMsg->pbBody , 1 , pPushMsg->cbBodyLength , f);

    fflush(f);
    fclose(f);

    return 0;

}

⌨️ 快捷键说明

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