logutils.cpp

来自「funambol window mobile客户端源代码」· C++ 代码 · 共 163 行

CPP
163
字号
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * 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 Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */




#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 + =
减小字号Ctrl + -
显示快捷键?