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