utilityapps/creator/engine/src/creator_logelement.cpp
changeset 55 2d9cac8919d3
parent 17 4f2773374eff
equal deleted inserted replaced
53:819e59dfc032 55:2d9cac8919d3
       
     1 /*
       
     2 * Copyright (c) 2010 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "creator_logelement.h"
       
    21 #include "creator_traces.h"
       
    22 #include "creator_log.h"
       
    23 
       
    24 using namespace creatorlog;
       
    25 
       
    26 /*
       
    27  * 
       
    28  */
       
    29 CCreatorLogElement* CCreatorLogElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext )
       
    30     {
       
    31     CCreatorLogElement* self = new (ELeave) CCreatorLogElement(aEngine);
       
    32     CleanupStack::PushL(self);
       
    33     self->ConstructL(aName, aContext);
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36     }
       
    37 /*
       
    38  * 
       
    39  */
       
    40 CCreatorLogElement::CCreatorLogElement(CCreatorEngine* aEngine) 
       
    41 : 
       
    42 CCreatorScriptElement(aEngine)
       
    43     {
       
    44     iIsCommandElement = ETrue;
       
    45     }
       
    46 /*
       
    47  * 
       
    48  */
       
    49 void CCreatorLogElement::ExecuteCommandL()
       
    50     {
       
    51     const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount);
       
    52     TInt logAmount = 1;    
       
    53     if( amountAttr )
       
    54         {
       
    55         logAmount = ConvertStrToIntL(amountAttr->Value());
       
    56         }
       
    57     // Get 'fields' element 
       
    58     CCreatorScriptElement* fieldsElement = FindSubElement(KFields);
       
    59     if( fieldsElement && fieldsElement->SubElements().Count() > 0 )
       
    60         {
       
    61         // Get sub-elements
       
    62         const RPointerArray<CCreatorScriptElement>& fields = fieldsElement->SubElements();        
       
    63         // Create log entries, the amount of entries is defined by logAmount:
       
    64         for( TInt cI = 0; cI < logAmount; ++cI )
       
    65             {
       
    66             TInt direction = -1;
       
    67             CLogsParameters* param = new (ELeave) CLogsParameters;
       
    68             CleanupStack::PushL(param);
       
    69             
       
    70             for( TInt i = 0; i < fields.Count(); ++i )
       
    71                 {
       
    72                 CCreatorScriptElement* field = fields[i];
       
    73                 TPtrC elemName = field->Name();
       
    74                 TPtrC elemContent = field->Content();
       
    75                 const CCreatorScriptAttribute* randomAttr = field->FindAttributeByName(KRandomLength);
       
    76                 const CCreatorScriptAttribute* increaseAttr = field->FindAttributeByName(KIncrease);
       
    77                 TBool increase( EFalse );
       
    78                 if ( increaseAttr )
       
    79                     {
       
    80                     increase = ConvertStrToBooleanL( increaseAttr->Value() );
       
    81                     }
       
    82                 
       
    83                 if( elemName == KDirection )
       
    84                     {
       
    85                     direction = GetLogCommandL(elemContent, randomAttr || elemContent.Length() == 0); 
       
    86                     }
       
    87                 else if( elemName == KDuration )
       
    88                     {
       
    89                     if( randomAttr || elemContent.Length() == 0 )
       
    90                         {
       
    91                         param->iDuration = iEngine->RandomNumber(7200);
       
    92                         }
       
    93                     else
       
    94                         {
       
    95                         param->iDuration = ConvertStrToIntL(elemContent);
       
    96                         }
       
    97                     }
       
    98                 else if( elemName == KPhonenumber )
       
    99                     {
       
   100                     if( randomAttr || elemContent.Length() == 0 )
       
   101                         {
       
   102                         SetContentToTextParamL(param->iPhoneNumber, iEngine->RandomString(CCreatorEngine::EPhoneNumber));
       
   103                         }
       
   104                     else
       
   105                         {
       
   106                         if ( increase )
       
   107                             {
       
   108                             delete param->iPhoneNumber;
       
   109                             param->iPhoneNumber = NULL;
       
   110                             param->iPhoneNumber = HBufC::NewL( elemContent.Length() + 3 );
       
   111                             IncreasePhoneNumL( elemContent, cI, param->iPhoneNumber );
       
   112                             }
       
   113                         else
       
   114                             {
       
   115                             SetContentToTextParamL(param->iPhoneNumber, elemContent);
       
   116                             }
       
   117                         }                    
       
   118                     }
       
   119                 else if( elemName == KDatetime )
       
   120                     {
       
   121                     if( randomAttr || elemContent.Length() == 0 )
       
   122                         {
       
   123                         param->iEventTime = iEngine->RandomTime(iEngine->RandomDate(CCreatorEngine::EDatePast), CCreatorEngine::EDatePast); 
       
   124                         }
       
   125                     else
       
   126                         {
       
   127                         param->iEventTime = ConvertToDateTimeL(elemContent);
       
   128                         }
       
   129                     }
       
   130                 }
       
   131             
       
   132             if( direction == -1 )
       
   133                 {
       
   134                 direction = GetLogCommandL(KEmpty, ETrue); 
       
   135                 }
       
   136             iEngine->AppendToCommandArrayL(direction, param);
       
   137             CleanupStack::Pop(); // param
       
   138             }
       
   139         }
       
   140     else
       
   141     	{
       
   142     	for(TInt i = 0; i < logAmount; ++i )
       
   143     		{
       
   144     		iEngine->AppendToCommandArrayL(GetLogCommandL(KEmpty, ETrue), 0, 1);
       
   145     		}
       
   146     	}
       
   147     }
       
   148 
       
   149 TInt CCreatorLogElement::GetLogCommandL( const TDesC& aLogCmdStr, TBool aRandom ) const
       
   150     {      
       
   151     if( aRandom )
       
   152         {
       
   153         TInt commandArray[] = {
       
   154                     ECmdCreateLogEntryMissedCalls,
       
   155                     ECmdCreateLogEntryReceivedCalls,
       
   156                     ECmdCreateLogEntryDialledNumbers
       
   157             };
       
   158         return commandArray[iEngine->RandomNumber(0, 2)];
       
   159         }
       
   160     
       
   161     if( CompareIgnoreCase(aLogCmdStr, KMissed) == 0 )
       
   162         return ECmdCreateLogEntryMissedCalls;
       
   163     else if( CompareIgnoreCase(aLogCmdStr, KIn) == 0 )
       
   164         return ECmdCreateLogEntryReceivedCalls;
       
   165     else if( CompareIgnoreCase(aLogCmdStr, KOut) == 0 )
       
   166         return ECmdCreateLogEntryDialledNumbers;
       
   167     
       
   168     LOGSTRING2("CCreatorLogElement::GetLogCommandL: Unknown log direction: %S", &aLogCmdStr);
       
   169     User::Leave(KErrNotFound);
       
   170     return -1; // Not reached, but disables compiler warning...
       
   171     }