creator/src/creator_logelement.cpp
branchRCL_3
changeset 50 9b2cffad4b5e
parent 0 d6fe6244b863
child 60 6646c35e558c
--- a/creator/src/creator_logelement.cpp	Tue Sep 14 21:20:12 2010 +0300
+++ b/creator/src/creator_logelement.cpp	Wed Sep 15 12:13:45 2010 +0300
@@ -45,6 +45,118 @@
 /*
  * 
  */
+
+void CCreatorLogElement::AsyncExecuteCommandL()
+    {
+    const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount);
+    TInt logAmount = 1;    
+    if( amountAttr )
+        {
+        logAmount = ConvertStrToIntL(amountAttr->Value());
+        }
+    // Get 'fields' element 
+    CCreatorScriptElement* fieldsElement = FindSubElement(KFields);
+    if( fieldsElement && fieldsElement->SubElements().Count() > 0 )
+        {
+        // Get sub-elements
+        const RPointerArray<CCreatorScriptElement>& fields = fieldsElement->SubElements();        
+        // Create log entries, the amount of entries is defined by logAmount:
+        if( iLoopIndex < logAmount )
+            {
+            TInt direction = -1;
+            CLogsParameters* param = new (ELeave) CLogsParameters;
+            CleanupStack::PushL(param);
+            
+            for( TInt i = 0; i < fields.Count(); ++i )
+                {
+                CCreatorScriptElement* field = fields[i];
+                TPtrC elemName = field->Name();
+                TPtrC elemContent = field->Content();
+                const CCreatorScriptAttribute* randomAttr = field->FindAttributeByName(KRandomLength);
+                const CCreatorScriptAttribute* increaseAttr = field->FindAttributeByName(KIncrease);
+                TBool increase( EFalse );
+                if ( increaseAttr )
+                    {
+                    increase = ConvertStrToBooleanL( increaseAttr->Value() );
+                    }
+                
+                if( elemName == KDirection )
+                    {
+                    direction = GetLogCommandL(elemContent, randomAttr || elemContent.Length() == 0); 
+                    }
+                else if( elemName == KDuration )
+                    {
+                    if( randomAttr || elemContent.Length() == 0 )
+                        {
+                        param->iDuration = iEngine->RandomNumber(7200);
+                        }
+                    else
+                        {
+                        param->iDuration = ConvertStrToIntL(elemContent);
+                        }
+                    }
+                else if( elemName == KPhonenumber )
+                    {
+                    if( randomAttr || elemContent.Length() == 0 )
+                        {
+                        SetContentToTextParamL(param->iPhoneNumber, iEngine->RandomString(CCreatorEngine::EPhoneNumber));
+                        }
+                    else
+                        {
+                        if ( increase )
+                            {
+                            delete param->iPhoneNumber;
+                            param->iPhoneNumber = NULL;
+                            param->iPhoneNumber = HBufC::NewL( elemContent.Length() + 3 );
+                            IncreasePhoneNumL( elemContent, iLoopIndex, param->iPhoneNumber );
+                            }
+                        else
+                            {
+                            SetContentToTextParamL(param->iPhoneNumber, elemContent);
+                            }
+                        }                    
+                    }
+                else if( elemName == KDatetime )
+                    {
+                    if( randomAttr || elemContent.Length() == 0 )
+                        {
+                        param->iEventTime = iEngine->RandomTime(iEngine->RandomDate(CCreatorEngine::EDatePast), CCreatorEngine::EDatePast); 
+                        }
+                    else
+                        {
+                        param->iEventTime = ConvertToDateTimeL(elemContent);
+                        }
+                    }
+                }
+            
+            if( direction == -1 )
+                {
+                direction = GetLogCommandL(KEmpty, ETrue); 
+                }
+            iEngine->AppendToCommandArrayL(direction, param);
+            CleanupStack::Pop(); // param
+            StartNextLoop();
+            }
+        else
+            {
+            AsyncCommandFinished();
+            }
+        }
+    else
+        {
+        if( iLoopIndex < logAmount )
+            {
+            iEngine->AppendToCommandArrayL(GetLogCommandL(KEmpty, ETrue), 0, 1);
+            StartNextLoop();
+            }
+        else
+            {
+            AsyncCommandFinished();
+            }
+        }
+    }
+
+
 void CCreatorLogElement::ExecuteCommandL()
     {
     const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount);