vtengines/videoteleng/Logger/Inc/cvtlogger.h
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2004 - 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Video telephony engine debugging support.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CVTLOGGER_H
       
    21 #define CVTLOGGER_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <flogger.h>
       
    26 #include <f32file.h>
       
    27 #include "vtlogger.hrh"
       
    28 
       
    29 // CONSTANTS
       
    30 const TInt KVtDebugBufferSize = 100;
       
    31 const TInt KVtDebugReturnValNotApplicable = -1;
       
    32 
       
    33 // MACROS
       
    34 
       
    35 #define DEBUG_CONSTRUCT CVtLogger::ELogConstruction
       
    36 #define DEBUG_DESTRUCT CVtLogger::ELogDestruction
       
    37 #define DEBUG_MEDIA CVtLogger::ELogMedia
       
    38 #define DEBUG_AUDIO CVtLogger::ELogAudio
       
    39 #define DEBUG_SESSION CVtLogger::ELogSession
       
    40 #define DEBUG_DETAIL CVtLogger::ELogDetails
       
    41 #define DEBUG_ALL CVtLogger::ELogLogEverything
       
    42 #define DEBUG_GEN CVtLogger::ELogGeneric
       
    43 #define DEBUG_RETURN CVtLogger::ELogReturn
       
    44 
       
    45 #define DEBUG_FLAG1 CVtLogger::ELogApp1
       
    46 #define DEBUG_FLAG2 CVtLogger::ELogApp2
       
    47 #define DEBUG_FLAG3 CVtLogger::ELogApp3
       
    48 #define DEBUG_FLAG4 CVtLogger::ELogApp4
       
    49 
       
    50 #if defined(VTDEBUG) && defined(__CS_VIDEO_TELEPHONY)
       
    51 /**
       
    52 * Write a text buffer to log.
       
    53 */
       
    54 #define __VTPRINT(level,x) CVtLogger::Print(level, _L(x));
       
    55 
       
    56 /**
       
    57 * Write a text buffer and integer value to log.
       
    58 */
       
    59 #define __VTPRINT2(level,x,y) CVtLogger::Print(level, _L(x), y);
       
    60 
       
    61 /**
       
    62 * Write a text buffer and two integer values to log.
       
    63 */
       
    64 #define __VTPRINT3(level,x,y,z) CVtLogger::Print(level, _L(x), y, z);
       
    65 
       
    66 #define __VTPRINTENTER(x) CVtLogger::Print( CVtLogger::ELogGeneric, ETrue, _L(x));
       
    67 
       
    68 #define __VTPRINTEXIT(x) CVtLogger::Print( CVtLogger::ELogGeneric, EFalse, _L(x) );
       
    69 
       
    70 #define __VTPRINTEXITR(x,y) CVtLogger::Print( CVtLogger::ELogGeneric, EFalse, _L(x), y );
       
    71 
       
    72 /**
       
    73 * Initialize VT logging, must be called before any __VTPRINT's are called.
       
    74 */
       
    75 #define VTLOGINIT CVtLogger::Initialize();
       
    76 
       
    77 /**
       
    78 * Uninitializes VT logging, must be called client using logging is deleted.
       
    79 */
       
    80 #define VTLOGUNINIT CVtLogger::Uninitialize();
       
    81 
       
    82 /**
       
    83 * Returns logging and configuration flags
       
    84 */
       
    85 #define VTFLAGS CVtLogger::Flags();
       
    86 
       
    87 /**
       
    88 * check if baseband loopback is enabled
       
    89 */
       
    90 #define DEBUG_CFG_BB_LOOPBACK ( CVtLogger::Flags() & CVtLogger::ECfgBBLoopbackEnabled )
       
    91 
       
    92 /**
       
    93 * check if PV engine loopback is enabled
       
    94 */
       
    95 #define DEBUG_CFG_PV_LOOPBACK ( CVtLogger::Flags() & CVtLogger::ECfgPVLoopbackEnabled )
       
    96 
       
    97 /**
       
    98 * Disables passing of audio source to PV
       
    99 */
       
   100 #define DEBUG_CFG_NO_AUDIO_SOURCE ( CVtLogger::Flags() & CVtLogger::ECfgNoAudioSource )
       
   101 
       
   102 /**
       
   103 * Disables passing of audio source to PV
       
   104 */
       
   105 #define DEBUG_CFG_NO_AUDIO_SINK ( CVtLogger::Flags() & CVtLogger::ECfgNoAudioSink )
       
   106 
       
   107 /**
       
   108 * Disables passing of video sink to PV
       
   109 */
       
   110 #define DEBUG_CFG_NO_VIDEO_SINK ( CVtLogger::Flags() & CVtLogger::ECfgNoVideoSink )
       
   111 
       
   112 /**
       
   113 * Disables passing of video source to PV
       
   114 */
       
   115 #define DEBUG_CFG_NO_VIDEO_SOURCE ( CVtLogger::Flags() & CVtLogger::ECfgNoVideoSource )
       
   116 
       
   117 #else
       
   118 
       
   119 /**
       
   120 * Disables VT Debug mode if __CS_VIDEO_TELEPHONY is undefined
       
   121 */
       
   122 #undef VTDEBUG
       
   123 
       
   124 #define __VTPRINT(level,x) 
       
   125 #define __VTPRINT2(level,x,y) 
       
   126 #define __VTPRINT3(level,x,y,z) 
       
   127 #define __VTPRINTENTER(x)
       
   128 #define __VTPRINTEXIT(x)
       
   129 #define __VTPRINTEXITR(x,y)
       
   130 #define VTLOGINIT
       
   131 #define VTLOGUNINIT
       
   132 #define VTFLAGS 0
       
   133 #define DEBUG_CFG_BB_LOOPBACK 0
       
   134 #define DEBUG_CFG_PV_LOOPBACK 0
       
   135 #define DEBUG_CFG_NO_AUDIO_SINK 0
       
   136 #define DEBUG_CFG_NO_AUDIO_SOURCE 0
       
   137 #define DEBUG_CFG_NO_VIDEO_SINK 0
       
   138 #define DEBUG_CFG_NO_VIDEO_SOURCE 0
       
   139 
       
   140 #endif // VTDEBUG
       
   141 
       
   142 // FORWARD DECLARATIONS
       
   143 
       
   144 
       
   145 // CLASS DECLARATION
       
   146 
       
   147 /**
       
   148 *  Debbuging support.
       
   149 *  To enable logging (either with RDebug or RFileLogger) follow steps below:
       
   150 *  1. Create folder c:\Logs\VT
       
   151 *  2. Create file VTLOGCONF.txt
       
   152 *  3. Open the file and define logging level by hexadecimal digit, 
       
   153 *     see TLogLevel in class declaration below. Example: 2007 means that
       
   154 *     constructors (0x1), destructors (0x2 ) in media subsystem (0x4) are 
       
   155 *     logged to file (0x2000), i.e. the values are bitwise or'ed. Log file
       
   156 *     name is "<thread name>.txt" where <thread name> is name of the thread
       
   157 *     where logging takes places.
       
   158 *
       
   159 *  @lib videoteleng
       
   160 *  @since 2.6
       
   161 */
       
   162 class CVtLogger : public CActive
       
   163     {
       
   164     public:  // Constructors and destructor
       
   165         
       
   166         /**
       
   167         * Two-phased constructor.
       
   168         */
       
   169         static CVtLogger* NewL();
       
   170         
       
   171         /**
       
   172         * Destructor.
       
   173         */
       
   174         virtual ~CVtLogger();
       
   175 
       
   176     public: // New functions
       
   177         
       
   178         /**
       
   179         * Writes to log file or RDebug.
       
   180         * @param aDes text output
       
   181         */
       
   182         virtual void Print( TDesC& aDes );
       
   183 
       
   184         /**
       
   185         * Log level defining logging behavior.
       
   186         */
       
   187         enum TLogLevel {
       
   188             // Constructors are logged
       
   189             ELogConstruction  = 0x00000001,
       
   190             // Destructors are logged
       
   191             ELogDestruction   = 0x00000002,
       
   192             // Media subsystem methods are logged
       
   193             ELogMedia         = 0x00000004,
       
   194             // Session subsystem methods are logged
       
   195             ELogSession       = 0x00000008,
       
   196             // Audio subsystem methods are logged
       
   197             ELogAudio         = 0x00000010,
       
   198             // Details in methods are logged
       
   199             ELogDetails       = 0x00000020,
       
   200             // Generic framework methods are logged
       
   201             ELogGeneric       = 0x00000040,
       
   202             // Log return from function
       
   203             ELogReturn        = 0x00000080,
       
   204             // Everything is logged, as if all above were set.
       
   205             ELogLogEverything = 0x0000007F,
       
   206             // Insert time at the beginning of each log entry
       
   207             // For file logging time is always written because
       
   208             // it is automatically done by RFileLogger.
       
   209             ELogTime          = 0x00001000,
       
   210             // Log to file instead of using RDebug
       
   211             ELogToFile        = 0x00002000,
       
   212             // Application specific flag 1
       
   213             ELogApp1          = 0x00004000,
       
   214             // Application specific flag 2
       
   215             ELogApp2          = 0x00008000,
       
   216             // Application specific flag 3
       
   217             ELogApp3          = 0x00010000,
       
   218             // Application specific flag 4
       
   219             ELogApp4          = 0x00020000,
       
   220 
       
   221             // Configuration flags
       
   222 
       
   223             /** Loopback configuration (set only
       
   224             *   one of the following flags
       
   225             */
       
   226             // Baseband loopback enabled
       
   227             ECfgBBLoopbackEnabled = 0x00100000,
       
   228             // PV Engine loopback enabled
       
   229             ECfgPVLoopbackEnabled = 0x00200000,
       
   230 
       
   231             // Disable passing of audio source
       
   232             ECfgNoAudioSink       = 0x00400000,
       
   233 
       
   234             // Disable passing of audio sink
       
   235             ECfgNoAudioSource     = 0x00800000,
       
   236 
       
   237             // Disable passing of video source
       
   238             ECfgNoVideoSource     = 0x01000000,
       
   239 
       
   240             // Disable passing of video sink
       
   241             ECfgNoVideoSink      = 0x02000000
       
   242             };
       
   243 
       
   244         /**
       
   245         * Writes buffer to log.
       
   246         * @param aLevel combination of TLogLevel values
       
   247         * @param aBuffer buffer to log
       
   248         */
       
   249         IMPORT_C static void Print( 
       
   250             TInt aLevel, 
       
   251             TPtrC aBuffer );
       
   252 
       
   253         /**
       
   254         * Writes buffer to log.
       
   255         * @param aLevel combination of TLogLevel values
       
   256         * @param aBuffer buffer to log
       
   257         * @param aValue value appended to buffer
       
   258         */
       
   259         IMPORT_C static void Print( 
       
   260             TInt aLevel, 
       
   261             TPtrC aBuffer, 
       
   262             TInt aValue );
       
   263         
       
   264         /**
       
   265         * Writes buffer to log.
       
   266         * @param aLevel combination of TLogLevel values
       
   267         * @param aBuffer buffer to log
       
   268         * @param aValue1 first value appended to buffer
       
   269         * @param aValue2 second value appended to buffer
       
   270         */
       
   271         IMPORT_C static void Print( 
       
   272             TInt aLevel, 
       
   273             TPtrC aBuffer, 
       
   274             TInt aValue1,
       
   275             TInt aValue2 );
       
   276 
       
   277         /**
       
   278         * Writes buffer to log. This overloaded method is used
       
   279         * for printing entry or exit from a function.
       
   280         * @since Series60 2.8
       
   281         * @param aLevel combination of TLogLevel values
       
   282         * @param aEntry if ETrue "<" is appended to end of string
       
   283         *               if EFalse ">" is appended to end of string
       
   284         * @param aBuffer buffer to log
       
   285         * @param aRetVal return value of the function. If this value
       
   286         * is present (i.e. other than KVtDebugReturnValNotApplicable
       
   287         * is passed) then aBuffer should include format tag '%d' where
       
   288         * aRetValue should be placed.
       
   289         */
       
   290         IMPORT_C static void Print(
       
   291             TInt aLevel,
       
   292             const TBool aEntry,
       
   293             TPtrC aBuffer,
       
   294             TInt aRetVal = KVtDebugReturnValNotApplicable );
       
   295             
       
   296         /**
       
   297         * Initializes logging. This must be called before
       
   298         * any use of __VTPRINT macros.
       
   299         */
       
   300         IMPORT_C static void Initialize();
       
   301 
       
   302         /**
       
   303         * Uninitializes logging. This must be called when
       
   304         * client of logging service is deleted.
       
   305         */
       
   306         IMPORT_C static void Uninitialize();
       
   307 
       
   308         /**
       
   309         * Returns flags in configuration file
       
   310         * @return flags
       
   311         */
       
   312         IMPORT_C static TInt Flags();
       
   313 
       
   314     private:
       
   315     
       
   316         /**
       
   317         * Returns logger.
       
   318         * @return logger
       
   319         */
       
   320         static CVtLogger* Logger();
       
   321 
       
   322         /**
       
   323         * Returns if certain log levels are set.
       
   324         * @param aLevels bitmap of TLogLevel values
       
   325         * @return ETrue if all aLevels are set.
       
   326         */
       
   327         TBool CheckLevels( TInt aLevels ) const;
       
   328 
       
   329         /**
       
   330         * Reads configuration file and starts
       
   331         * monitoring changes on it.
       
   332         */
       
   333         void ReadCongigFile();
       
   334 
       
   335     private: // from CActive
       
   336         
       
   337         /**
       
   338         * Handles file change notification
       
   339         */
       
   340         void RunL();
       
   341 
       
   342         /**
       
   343         * Cancels monitoring file change
       
   344         */
       
   345         void DoCancel();
       
   346 
       
   347     private:
       
   348 
       
   349         /**
       
   350         * C++ default constructor.
       
   351         */
       
   352         CVtLogger();
       
   353 
       
   354         /**
       
   355         * By default Symbian 2nd phase constructor is private.
       
   356         */
       
   357         void ConstructL( );
       
   358 
       
   359     private:    // Data        
       
   360     
       
   361         // Buffer size for printed lines
       
   362         enum 
       
   363             {
       
   364             ETempBufLength = 80
       
   365             };
       
   366             
       
   367         TFileName               iFileName;
       
   368         RFs                     iFs;
       
   369         TInt                    iLogLevel;
       
   370         TInt                    iAccessCount;
       
   371         TBuf<ETempBufLength>    iBuffer;
       
   372         TBuf<ETempBufLength>    iTempBuf;
       
   373     };
       
   374 
       
   375 
       
   376 #endif      // CVTLOGGER_H
       
   377             
       
   378 // End of File