mediator/inc/Server/MediatorDebug.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 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:  Mediator logging services
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef MEDIATORDEBUG_H
       
    19 #define MEDIATORDEBUG_H
       
    20 
       
    21 // INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <ecom/ecom.h>
       
    24 #include <flogger.h>
       
    25 #include "MediatorServiceDefs.h"
       
    26 #include "MediatorCommon.h"
       
    27 #include "MediatorDebug.hrh"
       
    28 
       
    29 // CONSTANTS
       
    30 const TInt KMediatorDebugBufferLength = 512;
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class CMediatorServer;
       
    34 class CMediatorServerSession;
       
    35 
       
    36 using namespace MediatorService;
       
    37 
       
    38 // CLASS DECLARATION
       
    39 
       
    40 /**
       
    41 *  Mediator logging services
       
    42 *  
       
    43 *
       
    44 *  @lib MediatorServer.exe
       
    45 *  @since S60 3.1
       
    46 */
       
    47 class RMediatorDebug
       
    48     {
       
    49     public:  
       
    50         
       
    51         /**
       
    52         * Mediator logging service initialization
       
    53         * @since S60 3.1
       
    54         * @param aMediator mediator server
       
    55         * @return void
       
    56         */
       
    57         inline static void Initialize(CMediatorServer* aMediator);
       
    58         
       
    59         /**
       
    60         * Mediator logging service uninitialization
       
    61         * @since S60 3.1
       
    62         * @return void
       
    63         */
       
    64         inline static void Uninitialize();
       
    65         
       
    66         /**
       
    67         * Prints debug information of the operation 
       
    68         * @since S60 3.1
       
    69         * @param aMessage message
       
    70         * @param aSession session
       
    71         * @return void
       
    72         */
       
    73         inline static void Log(const RMessage2& aMessage, CMediatorServerSession& aSession);
       
    74         
       
    75         /**
       
    76         * Prints event list
       
    77         * @since S60 3.1
       
    78         * @param aMessage message
       
    79         * @param aSession session
       
    80         * @param aEventList event list
       
    81         * @return void
       
    82         */
       
    83         inline static void LogData(const RMessage2& aMessage, CMediatorServerSession& aSession, const MediatorService::REventList& aEventList);
       
    84         
       
    85         /**
       
    86         * Prints a single event
       
    87         * @since S60 3.1
       
    88         * @param aMessage message
       
    89         * @param aSession session
       
    90         * @param aEvent event
       
    91         * @return void
       
    92         */
       
    93         inline static void LogData(const RMessage2& aMessage, CMediatorServerSession& aSession, const MediatorService::TEvent& aEvent);
       
    94         
       
    95         /**
       
    96         * Prints command list
       
    97         * @since S60 3.1
       
    98         * @param aMessage message
       
    99         * @param aSession session
       
   100         * @param aCommandList command list
       
   101         * @return void
       
   102         */
       
   103         inline static void LogData(const RMessage2& aMessage, CMediatorServerSession& aSession, const MediatorService::RCommandList& aCommandList);
       
   104         
       
   105         /**
       
   106         * Prints a single command
       
   107         * @since S60 3.1
       
   108         * @param aMessage message
       
   109         * @param aSession session
       
   110         * @param aCommand command
       
   111         * @return void
       
   112         */
       
   113         inline static void LogData(const RMessage2& aMessage, CMediatorServerSession& aSession, const MediatorService::TCommand& aCommand);
       
   114         
       
   115         /**
       
   116         * Prints a list of UIDs, depending on context either list of domains or categories
       
   117         * @since S60 3.1
       
   118         * @param aMessage message
       
   119         * @param aSession session
       
   120         * @param aCategoryList category list
       
   121         * @return void
       
   122         */
       
   123         inline static void LogData(const RMessage2& aMessage, CMediatorServerSession& aSession, const MediatorService::RCategoryList& aCategoryList);
       
   124         
       
   125         /**
       
   126         * Prints raw parameter data
       
   127         * @since S60 3.1
       
   128         * @param aMessage message
       
   129         * @param aSession session
       
   130         * @param aData data
       
   131         * @return void
       
   132         */
       
   133         inline static void LogData(const RMessage2& aMessage, CMediatorServerSession& aSession, const TDesC8& aData);
       
   134         
       
   135         /**
       
   136         * Prints status report for mediator
       
   137         * @since S60 3.1
       
   138         * @return void
       
   139         */
       
   140         inline static void LogStatus();                
       
   141         
       
   142         /**
       
   143         * Prints the error information of the failed operation
       
   144         * @since S60 3.1
       
   145         * @param aMessage message
       
   146         * @param aError error identifier
       
   147         * @return void
       
   148         */
       
   149         inline static void LogError(const RMessage2& aMessage, TInt aError);
       
   150         
       
   151         /**
       
   152         * Prints implementation information of the plugin
       
   153         * @since S60 3.1
       
   154         * @param aImpl plugin implementation
       
   155         * @return void
       
   156         */
       
   157         inline static void LogPlugin(const CImplementationInformation* aImpl);
       
   158                         
       
   159         /**
       
   160         * C++ default destructor.
       
   161         */
       
   162         ~RMediatorDebug();
       
   163          
       
   164     private:
       
   165 
       
   166         /**
       
   167         * C++ default constructor.
       
   168         */
       
   169         RMediatorDebug();
       
   170         
       
   171         /**
       
   172         * Two-phased constructor.
       
   173         */
       
   174         static RMediatorDebug* NewL(CMediatorServer* aMediator);
       
   175         
       
   176         /**
       
   177         * By default Symbian 2nd phase constructor is private.
       
   178         */
       
   179         void ConstructL(CMediatorServer* aMediator);
       
   180         
       
   181         /**
       
   182         * Checks whether the log for the message should be printed.
       
   183         * @since S60 3.1
       
   184         * @param aMessage message
       
   185         * @param aSession session
       
   186         * @return TBool ETrue if log should be printed, otherwise EFalse.
       
   187         */
       
   188         TBool ShouldPrintLogL(const RMessage2& aMessage, CMediatorServerSession& aSession);
       
   189         
       
   190         /**
       
   191         * Prints debug information of the operation 
       
   192         * @since S60 3.1
       
   193         * @param aMessage message
       
   194         * @param aSession session
       
   195         * @return void
       
   196         */
       
   197         void PrintOperationL(const RMessage2& aMessage, CMediatorServerSession& aSession);
       
   198         
       
   199         /**
       
   200         * Prints the error information of the failed operation
       
   201         * @since S60 3.1
       
   202         * @param aMessage message
       
   203         * @param aError error identifier
       
   204         * @return void
       
   205         */
       
   206         void PrintErrorL(const RMessage2& aMessage, TInt aError);
       
   207         
       
   208         /**
       
   209         * Prints status report for mediator
       
   210         * @since S60 3.1
       
   211         * @return void
       
   212         */                    
       
   213         void PrintServerStatusL();
       
   214         
       
   215         /**
       
   216         * Prints raw parameter data
       
   217         * @since S60 3.1
       
   218         * @param aMessage message
       
   219         * @param aSession session
       
   220         * @param aData data
       
   221         * @return void
       
   222         */
       
   223         void PrintRawL(const RMessage2& aMessage, CMediatorServerSession& aSession, const TDesC8& aData);
       
   224         
       
   225         /**
       
   226         * Prints a single event
       
   227         * @since S60 3.1
       
   228         * @param aMessage message
       
   229         * @param aSession session
       
   230         * @param aEvent event
       
   231         * @return void
       
   232         */
       
   233         void PrintEventL(const RMessage2& aMessage, CMediatorServerSession& aSession, const MediatorService::TEvent& aEvent, TInt aEventNmbr);
       
   234         
       
   235         /**
       
   236         * Prints event list
       
   237         * @since S60 3.1
       
   238         * @param aMessage message
       
   239         * @param aSession session
       
   240         * @param aEventList event list
       
   241         * @return void
       
   242         */
       
   243         void PrintEventListL(const RMessage2& aMessage, CMediatorServerSession& aSession, const MediatorService::REventList& aList);
       
   244         
       
   245         /**
       
   246         * Prints a single command
       
   247         * @since S60 3.1
       
   248         * @param aMessage message
       
   249         * @param aSession session
       
   250         * @param aCommand command
       
   251         * @return void
       
   252         */
       
   253         void PrintCommandL(const RMessage2& aMessage, CMediatorServerSession& aSession, const MediatorService::TCommand& aCmd, TInt aCmdNmbr);
       
   254         
       
   255         /**
       
   256         * Prints command list
       
   257         * @since S60 3.1
       
   258         * @param aMessage message
       
   259         * @param aSession session
       
   260         * @param aCommandList command list
       
   261         * @return void
       
   262         */
       
   263         void PrintCommandListL(const RMessage2& aMessage, CMediatorServerSession& aSession, const MediatorService::RCommandList& aList);
       
   264         
       
   265         /**
       
   266         * Prints a list of UIDs, depending on context either list of domains or categories
       
   267         * @since S60 3.1
       
   268         * @param aMessage message
       
   269         * @param aSession session
       
   270         * @param aCategoryList category list
       
   271         * @return void
       
   272         */
       
   273         void PrintCategoryListL(const RMessage2& aMessage, CMediatorServerSession& aSession, const MediatorService::RCategoryList& aList);
       
   274         
       
   275         /**
       
   276         * Prints implementation information of the plugin
       
   277         * @since S60 3.1
       
   278         * @param aImpl plugin implementation
       
   279         * @return void
       
   280         */
       
   281         void PrintPluginL(const CImplementationInformation* aImpl);
       
   282         
       
   283         /**
       
   284         * Prints the data stored in internal write buffer.
       
   285         * @since S60 3.1
       
   286         * @param None
       
   287         * @return void
       
   288         */
       
   289         void PrintL();
       
   290         
       
   291         /**
       
   292         * Prints the text passed as parameter. Depending on configuration,
       
   293         * the print target can console and/or file.
       
   294         * @since S60 3.1
       
   295         * @param aText  text to be printed
       
   296         * @return void
       
   297         */
       
   298         void Print(const TDesC& aText);
       
   299         
       
   300         /**
       
   301         * Prints the current configuration of logging service.
       
   302         * 
       
   303         * @since S60 3.1
       
   304         * @param None.
       
   305         * @return None.
       
   306         */
       
   307         void RMediatorDebug::PrintConfigurationL();
       
   308         
       
   309         /**
       
   310         * Handles internal error (usually leave due to buffer overflow),
       
   311         * if one occurs
       
   312         * @since S60 3.1
       
   313         * @param aError error code
       
   314         * @return void
       
   315         */
       
   316         void HandleInternalError(TInt aError);
       
   317         
       
   318         /**
       
   319         * Returns whether operation has a category.
       
   320         * @since S60 3.1
       
   321         * @param aMessage operation message
       
   322         * @return ETrue if category exists for this operation.
       
   323         */
       
   324         TBool HasCategory(const RMessage2& aMessage);
       
   325         
       
   326         /**
       
   327         * Returns whether operation has a domain.
       
   328         * @since S60 3.1
       
   329         * @param aMessage operation message
       
   330         * @return ETrue if domain exists for this operation.
       
   331         */
       
   332         TBool HasDomain(const RMessage2& aMessage);   
       
   333         
       
   334         /**
       
   335         * Returns string presentation of an operation.
       
   336         * @since S60 3.1
       
   337         * @param aOperation operation code
       
   338         * @return TPtrC string descriptor containing operation's name.
       
   339         */
       
   340         TPtrC OperationString(TInt aOperation);
       
   341         
       
   342         /**
       
   343         * Returns string presentation of an error code.
       
   344         * @since S60 3.1
       
   345         * @param aError error code
       
   346         * @return TPtrC string descriptor containing error's name.
       
   347         */
       
   348         TPtrC ErrorString(TInt aError);
       
   349         
       
   350         /**
       
   351         * Returns abbreviated (2-3 letters) string presentation of a capability.
       
   352         * @since S60 3.1
       
   353         * @param aCapability capability
       
   354         * @return TPtrC string descriptor containing abbreviated capability name.
       
   355         */
       
   356         TPtrC CapabilityString( TCapability aCapability );
       
   357         
       
   358         /**
       
   359         * Appends list of capability names specifiec in capability set
       
   360         * into internal print buffer.
       
   361         * @since S60 3.1
       
   362         * @param aCaps capability set
       
   363         * @return None.
       
   364         */
       
   365         void AppendCapabilitiesL( const TCapabilitySet& aCaps );
       
   366         
       
   367         /**
       
   368         * Handles initialization error
       
   369         * @since S60 3.1
       
   370         */
       
   371         static void HandleInitError( TInt aError );
       
   372         
       
   373         /**
       
   374         *  Overflow handler for buffer overlow checking.
       
   375         *  
       
   376         *
       
   377         *  @lib MediatorServer.exe
       
   378         *  @since S60 3.1
       
   379         */
       
   380         class TDebugOverflow : public TDesOverflow
       
   381             {
       
   382             /**
       
   383             * From TDesOverflow.
       
   384             * Handles overflow situation by resetting the buffer and
       
   385             * raising a leave.
       
   386             * @since S60 3.1
       
   387             * @param aBufferThatOverflowed buffer that caused overflow
       
   388             * @return TPtrC string descriptor containing error's name.
       
   389             */
       
   390             void Overflow(TDes& aBufferThatOverflowed)
       
   391                 {
       
   392                 aBufferThatOverflowed.Zero(); // reset buffer for new usage
       
   393                 
       
   394                 /*
       
   395                 This non-leaving method can leave because implementing this oveflow
       
   396                 check functionality would lead to more bloated and error-prone code.
       
   397                 This method will be only called from functions that can leave and the leaves
       
   398                 are trapped in the highest abstraction level of logging services.
       
   399                 */
       
   400                 User::Leave(KErrOverflow);
       
   401                 }
       
   402             };
       
   403                 
       
   404     private:    // Data
       
   405         
       
   406         /**
       
   407         * mediator server
       
   408         * Not own.
       
   409         */
       
   410         CMediatorServer* iMediator;
       
   411         
       
   412         /**
       
   413         * filtering options for domains
       
   414         */
       
   415         EDebugLogMode iDomainOptions;
       
   416         
       
   417         /**
       
   418         * filtered domains
       
   419         */
       
   420         RArray<TUid> iDomains;
       
   421         
       
   422         /**
       
   423         * filtering options for categories
       
   424         */
       
   425         EDebugLogMode iCategoryOptions;
       
   426         
       
   427         /**
       
   428         * filtered categories
       
   429         */
       
   430         RArray<TUid> iCategories;
       
   431         
       
   432         /**
       
   433         * general logging options
       
   434         */
       
   435         TInt iOptions;
       
   436         
       
   437         /**
       
   438         * print buffer
       
   439         */
       
   440         TBuf<KMediatorDebugBufferLength> iBuf;
       
   441         
       
   442         /**
       
   443         * overflow handler for internal buffers
       
   444         */
       
   445         TDebugOverflow iOf;
       
   446                 
       
   447         /**
       
   448         * The only instance of this class
       
   449         * Own.
       
   450         */
       
   451         static RMediatorDebug* iInstance;
       
   452         
       
   453         /**
       
   454         * File logger.
       
   455         */
       
   456         RFileLogger iFileLogger;
       
   457          
       
   458     };
       
   459 
       
   460 #include "MediatorDebug.inl"
       
   461 
       
   462 #endif      // MEDIADOR_DEBUG_H
       
   463            
       
   464 //  End of File