//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The use and distribution terms for this software are covered by the
// Microsoft Limited Public License (Ms-LPL)
// which can be found in the file MS-LPL.txt at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license.
//
// The software is licensed “as-is.”
//
// You must not remove this notice, or any other, from this software.
//
//
//
// Demux code for Windows CE
//
//-------------------------------------------------------------------------
//======================================================================
// Demux code for Windows CE
//======================================================================
/*++
Module Name:
trace.h
Abstract:
This module contains macro wrappers of the DirectShow debug API.
The custom logging is used as follows:
LOG_CUSTOM1 constructor/destructor
LOG_CUSTOM2 timeout
LOG_CUSTOM3 media samples
LOG_CUSTOM4 pins (input & output)
LOG_CUSTOM5 PSI
Revision History:
02-Jul-1999 created
--*/
#ifndef _mp2demux__trace_h
#define _mp2demux__trace_h
// standard levels
#define TRACE_ENTER_LEAVE_LEVEL 5
#define TRACE_ERROR_LEVEL 3
#define CONSTRUCTOR_DESTRUCTOR_LEVEL (TRACE_ENTER_LEAVE_LEVEL - 1)
#define LOG_DEMUX_CONSTRUCTOR_DESTRUCTOR LOG_TRACE
#define LOG_DEMUX_CLOCK_SUBORDINATE LOG_CUSTOM1
#define LOG_DEMUX_TIMEOUT LOG_CUSTOM2
#define LOG_DEMUX_MEDIA_SAMPLES LOG_CUSTOM3
#define LOG_DEMUX_PINS LOG_CUSTOM4
#define LOG_DEMUX_PSI LOG_CUSTOM5
#ifdef DEBUG
#define TRACE_0(ds,l,fmt) DbgLog((ds,l,fmt))
#define TRACE_1(ds,l,fmt,a) DbgLog((ds,l,fmt,a))
#define TRACE_2(ds,l,fmt,a,b) DbgLog((ds,l,fmt,a,b))
#define TRACE_3(ds,l,fmt,a,b,c) DbgLog((ds,l,fmt,a,b,c))
#define TRACE_4(ds,l,fmt,a,b,c,d) DbgLog((ds,l,fmt,a,b,c,d))
#define TRACE_5(ds,l,fmt,a,b,c,d,e) DbgLog((ds,l,fmt,a,b,c,d,e))
#define TRACE_6(ds,l,fmt,a,b,c,d,e,f) DbgLog((ds,l,fmt,a,b,c,d,e,f))
#define TRACE_7(ds,l,fmt,a,b,c,d,e,f,g) DbgLog((ds,l,fmt,a,b,c,d,e,f,g))
#define TRACE_8(ds,l,fmt,a,b,c,d,e,f,g,h) DbgLog((ds,l,fmt,a,b,c,d,e,f,g,h))
#else
#define TRACE_0(ds,l,fmt) 0
#define TRACE_1(ds,l,fmt,a) 0
#define TRACE_2(ds,l,fmt,a,b) 0
#define TRACE_3(ds,l,fmt,a,b,c) 0
#define TRACE_4(ds,l,fmt,a,b,c,d) 0
#define TRACE_5(ds,l,fmt,a,b,c,d,e) 0
#define TRACE_6(ds,l,fmt,a,b,c,d,e,f) 0
#define TRACE_7(ds,l,fmt,a,b,c,d,e,f,g) 0
#define TRACE_8(ds,l,fmt,a,b,c,d,e,f,g,h) 0
#endif
// ---------------------------------------------------------------------------
// error
// ---------------------------------------------------------------------------
#define TRACE_ERROR() TRACE_2(LOG_ERROR,TRACE_ERROR_LEVEL,TEXT("ERROR: %s(%u)"),TEXT(__FILE__), __LINE__)
#define TRACE_ERROR_0(fmt) TRACE_2(LOG_ERROR,TRACE_ERROR_LEVEL,TEXT("ERROR: %s(%u); ") fmt,TEXT(__FILE__), __LINE__)
#define TRACE_ERROR_1(fmt,a) TRACE_3(LOG_ERROR,TRACE_ERROR_LEVEL,TEXT("ERROR: %s(%u); ") fmt,TEXT(__FILE__), __LINE__,a)
#define TRACE_ERROR_2(fmt,a,b) TRACE_4(LOG_ERROR,TRACE_ERROR_LEVEL,TEXT("ERROR: %s(%u); ") fmt,TEXT(__FILE__), __LINE__,a,b)
#define TRACE_ERROR_3(fmt,a,b,c) TRACE_5(LOG_ERROR,TRACE_ERROR_LEVEL,TEXT("ERROR: %s(%u); ") fmt,TEXT(__FILE__), __LINE__,a,b,c)
#define TRACE_ERROR_4(fmt,a,b,c,d) TRACE_6(LOG_ERROR,TRACE_ERROR_LEVEL,TEXT("ERROR: %s(%u); ") fmt,TEXT(__FILE__), __LINE__,a,b,c,d)
#define TRACE_ERROR_5(fmt,a,b,c,d,e) TRACE_7(LOG_ERROR,TRACE_ERROR_LEVEL,TEXT("ERROR: %s(%u); ") fmt,TEXT(__FILE__), __LINE__,a,b,c,d,e)
#define TRACE_ERROR_6(fmt,a,b,c,d,e,f) TRACE_8(LOG_ERROR,TRACE_ERROR_LEVEL,TEXT("ERROR: %s(%u); ") fmt,TEXT(__FILE__), __LINE__,a,b,c,d,e,f)
#define ERROR_SPEW(v,op,c) TRACE_ERROR_5(TEXT("(%s = 0x%08xh) %s (%s = 0x%08xh)"),TEXT(#v),v,TEXT(#op),TEXT(#c),c)
#define ERROR_SPEW_EX(v,op,c,m) TRACE_ERROR_6(TEXT("(%s = 0x%08xh) %s (%s = 0x%08xh); %s"),TEXT(#v),v,TEXT(#op),TEXT(#c),c,m)
#define ERROR_RET(v,op,c) if ((v) op (c)) { ERROR_SPEW(v,op,c); return ; }
#define ERROR_RET_VAL(v,op,c,r) if ((v) op (c)) { ERROR_SPEW(v,op,c); return (r) ; }
#define ERROR_RET_EX(v,op,c,m) if ((v) op (c)) { ERROR_SPEW_EX(v,op,c,m); return ; }
#define ERROR_RET_VAL_EX(v,op,c,r,m) if ((v) op (c)) { ERROR_SPEW_EX(v,op,c,m); return (r) ; }
// ---------------------------------------------------------------------------
// constructor / destructor
// ---------------------------------------------------------------------------
#define TRACE_CONSTRUCTOR(fmt) TRACE_1(LOG_DEMUX_CONSTRUCTOR_DESTRUCTOR,CONSTRUCTOR_DESTRUCTOR_LEVEL,TEXT("[%08xh] CONSTRUCTOR : ") fmt TEXT("::") fmt, this)
#define TRACE_DESTRUCTOR(fmt) TRACE_1(LOG_DEMUX_CONSTRUCTOR_DESTRUCTOR,CONSTRUCTOR_DESTRUCTOR_LEVEL,TEXT("[%08xh] DESTRUCTOR : ") fmt TEXT("::~") fmt, this)
// ---------------------------------------------------------------------------
// enter
// ---------------------------------------------------------------------------
#define TRACE_ENTER_0(fmt) TRACE_0(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("ENTER : ") fmt)
#define TRACE_ENTER_1(fmt,a) TRACE_1(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("ENTER : ") fmt,a)
#define TRACE_ENTER_2(fmt,a,b) TRACE_2(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("ENTER : ") fmt,a,b)
#define TRACE_ENTER_3(fmt,a,b,c) TRACE_3(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("ENTER : ") fmt,a,b,c)
#define TRACE_ENTER_4(fmt,a,b,c,d) TRACE_4(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("ENTER : ") fmt,a,b,c,d)
#define TRACE_ENTER_5(fmt,a,b,c,d,e) TRACE_5(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("ENTER : ") fmt,a,b,c,d,e)
#define TRACE_ENTER_6(fmt,a,b,c,d,e,f) TRACE_6(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("ENTER : ") fmt,a,b,c,d,e,f)
// ---------------------------------------------------------------------------
// object enter
// ---------------------------------------------------------------------------
#define O_TRACE_ENTER_0(fmt) TRACE_ENTER_1(TEXT("[%08xh] ") fmt, this)
#define O_TRACE_ENTER_1(fmt,a) TRACE_ENTER_2(TEXT("[%08xh] ") fmt, this,a)
#define O_TRACE_ENTER_2(fmt,a,b) TRACE_ENTER_3(TEXT("[%08xh] ") fmt, this,a,b)
#define O_TRACE_ENTER_3(fmt,a,b,c) TRACE_ENTER_4(TEXT("[%08xh] ") fmt, this,a,b,c)
#define O_TRACE_ENTER_4(fmt,a,b,c,d) TRACE_ENTER_5(TEXT("[%08xh] ") fmt, this,a,b,c,d)
#define O_TRACE_ENTER_5(fmt,a,b,c,d,e) TRACE_ENTER_6(TEXT("[%08xh] ") fmt, this,a,b,c,d,e)
// ---------------------------------------------------------------------------
// leave
// ---------------------------------------------------------------------------
#define TRACE_LEAVE_0(fmt) TRACE_0(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("LEAVE : ") fmt)
#define TRACE_LEAVE_1(fmt,a) TRACE_1(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("LEAVE : ") fmt,a)
#define TRACE_LEAVE_2(fmt,a,b) TRACE_2(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("LEAVE : ") fmt,a,b)
#define TRACE_LEAVE_3(fmt,a,b,c) TRACE_3(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("LEAVE : ") fmt,a,b,c)
#define TRACE_LEAVE_4(fmt,a,b,c,d) TRACE_4(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("LEAVE : ") fmt,a,b,c,d)
#define TRACE_LEAVE_5(fmt,a,b,c,d,e) TRACE_5(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("LEAVE : ") fmt,a,b,c,d,e)
#define TRACE_LEAVE_6(fmt,a,b,c,d,e,f) TRACE_6(LOG_TRACE,TRACE_ENTER_LEAVE_LEVEL,TEXT("LEAVE : ") fmt,a,b,c,d,e,f)
// ---------------------------------------------------------------------------
// object leave
// ---------------------------------------------------------------------------
#define O_TRACE_LEAVE_0(fmt) TRACE_LEAVE_1(TEXT("[%08xh] ") fmt, this)
#define O_TRACE_LEAVE_1(fmt,a) TRACE_LEAVE_2(TEXT("[%08xh] ") fmt, this,a)
#define O_TRACE_LEAVE_2(fmt,a,b) TRACE_LEAVE_3(TEXT("[%08xh] ") fmt, this,a,b)
#define O_TRACE_LEAVE_3(fmt,a,b,c) TRACE_LEAVE_4(TEXT("[%08xh] ") fmt, this,a,b,c)
#define O_TRACE_LEAVE_4(fmt,a,b,c,d) TRACE_LEAVE_5(TEXT("[%08xh] ") fmt, this,a,b,c,d)
#define O_TRACE_LEAVE_5(fmt,a,b,c,d,e) TRACE_LEAVE_6(TEXT("[%08xh] ") fmt, this,a,b,c,d,e)
// lock contention
/*
class CContCritSec :
public CCritSec
{
CRITICAL_SECTION m_crt ;
public :
CContCritSec () : CCritSec ()
{
InitializeCriticalSection (& m_crt) ;
}
~CContCritSec ()
{
DeleteCriticalSection (& m_crt) ;
// destructor ~CCritSec fires as well
}
void Lock ()
{
// these always lock in pairs, so this is safe
if (TryEnterCriticalSection (& m_crt) == FALSE) {
DbgLog ((LOG_TRACE, 2, TEXT ("contention !"))) ;
EnterCriticalSection (& m_crt) ;
}
// still wrap to this call so we get this logging as well
CCritSec::Lock () ;
}
void Unlock ()
{
CCritSec::Unlock () ;
LeaveCriticalSection (& m_crt) ;
}
} ;
// should be able to define something else as well
#ifdef DEBUG
#define CRIT_SECT CContCritSec
#else
#define CRIT_SECT CCritSec
#endif
*/
#endif // _mp2demux__trace_h