/*****************************************************************************
 * Copyright (C) Cinterion Wireless Modules GmbH
 *****************************************************************************
 * Project: Quinn-USB-Driver
 *****************************************************************************
 * Author : Siemens AG Berlin COM WM RD SW A2
 *****************************************************************************
 * $Workfile: Y:/z_ms-d/src/working/Quinn/HcUsbDrv/UsbTrace.h $
 * $Revision: /main/ms-d/3 $
 *     $Date: 2009-02-18 11:49:47 $
 *   $Author: ctna0256 $
 *****************************************************************************
 * Target:
 *  Microsoft Windows Mobile 5.0
 *****************************************************************************
 * Description:
 *  Definition of the Quinn USB Driver trace interface.
 *****************************************************************************
 *
 * $Log: Y:/z_ms-d/src/working/Quinn/HcUsbDrv/UsbTrace.h$ 
 * 
 * /main/ms-d/3   2009-02-18 11:49:47   ctna0256 
 * Set copyright text 
 * 
 * /main/ms-d/2   2008-08-20 11:40:04   ctna0450 
 * Prepared for new disclaimer handling 
 * 
 * /main/ms-d/1   2008-07-31 15:51:00   ht37010 
 * derived from RilTrace.h 
 * 
 * /main/ms-d/8   2007-07-04 08:57:13   mp49210 
 * Introduction of maximum trace file length 
 * 
 * /main/ms-d/7   2007-02-09 08:52:19   mp49210 
 * Added optional timestamps for retail traces
 * Fixed '%a' bug 
 * 
 * /main/ms-d/6   2006-11-14 12:55:50   wm36264 
 * Added missing trace functionality required by USB
 *
 * /main/ms-d/5   2006-10-26 16:51:25   wm36264
 * Fixed unicode and trace including problems
 *
 * /main/ms-d/4   2006-10-24 14:52:26   wm36264
 * Added TraceCRLFString()
 *
 * /main/ms-d/3   2006-10-13 16:58:57   wm36264
 * Added hex trace
 *
 * /main/ms-d/2   2006-09-29 15:35:10   wm36264
 * Cosmetics
 *
 * /main/ms-d/1   2006-09-27 17:04:29   wm36264
 * Central trace handling of USB driver
 *
*/

//////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2008 Cinterion Wireless Modules GmbH
// Copyright (C) 2006-2008 Siemens AG
//
// Version: 1.0
// Date:    dummy
//
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
//
// UsbTrace.cpp
//
// This file contains the definition of the functions for trace output of
// the Cinterion USB driver and conneted modules.
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

//////////////////////////////////////////////////////////////////////////////

#include <Windows.h>

//////////////////////////////////////////////////////////////////////////////

extern int UsbTrace(LPCTSTR lpszFmt, ...);
extern void TraceHexData(DWORD dwDbgZone, LPCTSTR lpszPre, BYTE* pData, DWORD dwLen);
extern void TraceCRLFString(LPCTSTR szPre, LPCTSTR szText, LPCTSTR szIn, LPCSTR szCrLf);

// Macro for retail trace output of Cinterion USB driver driver
// Sample usage: USBRetailTrace((TEXT("UsbDrv: Debug-Info %d"), 0x42));
#ifdef USB_INCLUDE_TIMESTAMPS_TO_RETAIL
extern int USBRetailTraceWithTimestamps(LPCTSTR lpszFmt, ...);
#define USBRETAILOUTPUT  USBRetailTraceWithTimestamps
#else
#define USBRETAILOUTPUT  NKDbgPrintfW
#endif
#ifndef DEBUG

  #ifdef WANT_RETAIL_USB_OUTPUT

    #if defined(USB_RETAIL_OUTPUT_PORT) || defined(USB_RETAIL_OUTPUT_FILE)

      #define USBRetailTrace(printf_exp)  USBRETAILOUTPUT printf_exp, UsbTrace printf_exp

    #else // USB_RETAIL_OUTPUT_PORT || USB_RETAIL_OUTPUT_FILE

      #define USBRetailTrace(printf_exp)  USBRETAILOUTPUT printf_exp

    #endif // USB_RETAIL_OUTPUT_PORT || USB_RETAIL_OUTPUT_FILE

    #define USB_TRACE_REQUIRED

  #else // WANT_RETAIL_USB_OUTPUT

    #if defined(USB_RETAIL_OUTPUT_PORT) || defined(USB_RETAIL_OUTPUT_FILE)

      #define USBRetailTrace(printf_exp)  UsbTrace printf_exp

      #define USB_TRACE_REQUIRED

    #else // USB_RETAIL_OUTPUT_PORT || USB_RETAIL_OUTPUT_FILE

      #define USBRetailTrace(printf_exp)  ((void)0)

    #endif // USB_RETAIL_OUTPUT_PORT || USB_RETAIL_OUTPUT_FILE

  #endif // WANT_RETAIL_USB_OUTPUT

  #undef DEBUGMSG
  #define DEBUGMSG(a, printf_exp)         ((void)((a) ? (USBRetailTrace(printf_exp)), 1 : 0))

#else // DEBUG

  #define USBRetailTrace(printf_exp)      USBRETAILOUTPUT printf_exp

#endif // DEBUG

#define DEBUGHEX(a, p, d, l)              TraceHexData(a, p, d, l)

//////////////////////////////////////////////////////////////////////////////

#if defined(USB_RETAIL_OUTPUT_PORT) || defined(USB_RETAIL_OUTPUT_FILE)
// This global variable allows to switch the port and file trace output on
// (g_dwDisableRetailTrace = 0) and off (g_dwDisableRetailTrace != 0) during
// runtime. So it is e.g. possible to build a module with file trace enabled
// and control it later via a registry key.
extern DWORD g_dwDisableTrace;
// To prevent a trace file to fill the entire memory, it is possible to define a
// maximum file length. If this length is reached, the trace file will be deleted
// to make room for new trace output. If this variable is set to 0, the file
// size of the trace file is unlimited.
extern DWORD g_dwTraceFileLength;
#endif
