commsfwtools/commstools/utracedecoder/src/logevents/nodemessageevent.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <string>
       
    17 #include <iostream>
       
    18 #include <sstream>
       
    19 #include <iomanip>
       
    20 
       
    21 #include "utracedecoderapp.h"
       
    22 #include "logevents\nodemessageevent.h"
       
    23 #include "messagedefparser\definitionparser.h"
       
    24 #include "messagedefparser\signatureidentifier.h"
       
    25 #include "messagedefparser\contextidentifier.h"
       
    26 #include "messagedefparser\messageidentifier.h"
       
    27 
       
    28 CNodeMessageEvent::CNodeMessageEvent(const CUTraceFrame& aFrame, MEventOutputHandler& aOutputHandler)
       
    29     : CSimpleLogEvent(aFrame, aOutputHandler)
       
    30     {
       
    31     SetPrefix("ENodeMessages");
       
    32     }
       
    33 
       
    34 CNodeMessageEvent::CNodeMessageEvent(const CMultiPartFrameCollection& aFrameCollection, MEventOutputHandler& aOutputHandler)
       
    35     : CSimpleLogEvent(aFrameCollection, aOutputHandler)
       
    36     {
       
    37     SetPrefix("ENodeMessages");
       
    38     }
       
    39 
       
    40 void CNodeMessageEvent::Describe(std::ostream& aOutput) const
       
    41     {
       
    42     unsigned char* payload = Data();
       
    43     unsigned int length = DataLength();
       
    44     unsigned int subCategory = SubCategory();
       
    45     unsigned int textLength = Arg1();
       
    46 
       
    47     if (subCategory == ELogMessage || subCategory == ELogAddress || subCategory == ELogNode)
       
    48         {
       
    49         if (textLength > length)
       
    50             {
       
    51             aOutput << "**** ERROR: Corrupt event. Embedded text length > Event length **** ";
       
    52             return;
       
    53             }
       
    54 
       
    55         if (textLength > 0)
       
    56             {
       
    57             std::string embeddedText = std::string(reinterpret_cast<char*>(Data())).substr(0, textLength);
       
    58             aOutput << embeddedText << " ";
       
    59             payload += textLength;
       
    60             length -= textLength;
       
    61             }
       
    62 
       
    63         if (length <= 0)
       
    64             {
       
    65             aOutput << "**** ERROR: Corrupt event. No data after embedded text **** ";
       
    66             return;
       
    67             }
       
    68         }
       
    69 
       
    70     switch (subCategory)
       
    71         {
       
    72         case ELogMessage:
       
    73             {
       
    74             const SMessageHeader& header = *reinterpret_cast<const SMessageHeader*>(payload);
       
    75             const Parser::CSignatureIdentifier* msgSig = ::gMsgDefParser->FindSignatureByTypeId(header.iTypeId);
       
    76             if (msgSig)
       
    77                 {
       
    78                 aOutput << "[Signature=" + std::string(msgSig->Name()) + "] ";
       
    79 
       
    80                 //if (msgSig->IsNodeSignalDerived())
       
    81                 //    {
       
    82                 //    const TMessageId& msgId = *reinterpret_cast<const TMessageId*>(payload + header.iLength - sizeof(TMessageId));
       
    83             
       
    84                 //    const Parser::CMessageIdentifier* msg = ::gMsgDefParser->FindMessageByMessageId(msgId);
       
    85                 //    if (msg)
       
    86                 //        {
       
    87                 //        aOutput << "[Message=" + std::string(msg->Name()) + "] ";
       
    88                 //        }
       
    89                 //    }
       
    90                 if (header.iLength - sizeof(header) == msgSig->TotalSize())
       
    91                     {
       
    92                     msgSig->Describe(payload + sizeof(header), header.iLength - sizeof(header), NULL, aOutput);
       
    93                     }
       
    94                 else
       
    95                     {
       
    96                     aOutput << "**** ERROR: Corrupt event or incorrect signature definition - "
       
    97                         << "[Signature=0x" << std::noshowbase << std::setw(8) << std::setfill('0')
       
    98                         << std::nouppercase << std::hex << header.iTypeId.iUid
       
    99                         << ":0x" << std::noshowbase << std::setw(8) << std::setfill('0')
       
   100                         << std::nouppercase << std::hex << header.iTypeId.iType << "] **** ";
       
   101                     }
       
   102 
       
   103                 }
       
   104             else
       
   105                 {
       
   106                 aOutput << "**** ERROR: Undefined signature - [Signature=0x"
       
   107                     << std::noshowbase << std::setw(8) << std::setfill('0') << std::nouppercase << std::hex << header.iTypeId.iUid
       
   108                     << ":0x"
       
   109                     << std::noshowbase << std::setw(8) << std::setfill('0') << std::nouppercase << std::hex << header.iTypeId.iType
       
   110                     << "] **** ";
       
   111                 }
       
   112             }
       
   113             break;
       
   114 
       
   115         case ELogBlockStart:
       
   116             EventOutputHandler().PushNewLineEnabled(false);
       
   117             aOutput << "[STARTBLOCK=";
       
   118             CSimpleLogEvent::DescribeText(aOutput);
       
   119             aOutput << "] ";
       
   120             break;
       
   121 
       
   122         case ELogBlockEnd:
       
   123             aOutput << "[ENDBLOCK=";
       
   124             CSimpleLogEvent::DescribeText(aOutput);
       
   125             aOutput << "] ";
       
   126             EventOutputHandler().PopNewLineEnabled();
       
   127             break;
       
   128 
       
   129         case ELogNodeCreate:
       
   130         case ELogNodeDestroy:
       
   131         case ELogInfo:
       
   132             CSimpleLogEvent::DescribeText(aOutput);
       
   133             break;
       
   134 
       
   135         case ELogAddress:
       
   136             {
       
   137             const SRuntimeContextBase& rtCtx = *reinterpret_cast<const SRuntimeContextBase*>(payload);
       
   138             if (rtCtx.iSize & 0x80) // top bit set indicates not null
       
   139                 {
       
   140                 aOutput << "[Address=";
       
   141                 const Parser::CContextIdentifier* context = ::gMsgDefParser->FindContextBySize(rtCtx.iSize & 0x7f); // top bit indicates NULL
       
   142                 if (context)
       
   143                     {
       
   144                     if (length == context->TotalSize())
       
   145                         {
       
   146                         context->Describe(payload, length, NULL, aOutput);
       
   147                         }
       
   148                     else
       
   149                         {
       
   150                         aOutput << "**** ERROR: ELogAddress - Event data size and context size don't match **** ";
       
   151                         }
       
   152                     }
       
   153                 else
       
   154                     {
       
   155                     aOutput << "**** ERROR: ELogAddress - Logged address uses undefined context type **** ";
       
   156                     }
       
   157                 aOutput << "] ";
       
   158                 }
       
   159             else
       
   160                 {
       
   161                 aOutput << "[Address=Null] ";
       
   162                 }
       
   163             }
       
   164             break;
       
   165 
       
   166         case ELogNode:
       
   167             {
       
   168             aOutput << "[ANode=0x" << std::hex << std::setw(8)
       
   169                 << std::setfill('0') << std::nouppercase  << std::noshowbase
       
   170                 << BytesToInt(payload)
       
   171                 << "] ";
       
   172             }
       
   173             break;
       
   174 
       
   175         default:
       
   176             aOutput << "**** ERROR: Unknown or unsupported log statement **** ";
       
   177             break;
       
   178         }
       
   179     }
       
   180