creator/engine/src/creator_log.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     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 <cntdef.h>
       
    21 
       
    22 #include "engine.h"
       
    23 #include "enginewrapper.h"
       
    24 #include "creator_log.h" 
       
    25 #include "creator_traces.h"
       
    26 
       
    27 static const TInt KLogsFieldLength = 256;
       
    28 
       
    29 //_LIT(KCreatorLogsPrefixName, "CR_");
       
    30 
       
    31 //----------------------------------------------------------------------------
       
    32 
       
    33 CLogsParameters::CLogsParameters()
       
    34     {
       
    35     LOGSTRING("Creator: CLogsParameters::CLogsParameters");
       
    36 
       
    37     iPhoneNumber = HBufC::New(KLogsFieldLength);
       
    38     /*iMissedCallPhoneNumber = HBufC::New(KLogsFieldLength);
       
    39     iReceivedCallPhoneNumber = HBufC::New(KLogsFieldLength);
       
    40     iDialledNumberPhoneNumber = HBufC::New(KLogsFieldLength);*/
       
    41     }
       
    42 
       
    43 CLogsParameters::~CLogsParameters()
       
    44     {
       
    45     LOGSTRING("Creator: CLogsParameters::~CLogsParameters");
       
    46 
       
    47     delete iPhoneNumber;
       
    48     /*delete iDialledNumberPhoneNumber;
       
    49     delete iReceivedCallPhoneNumber;
       
    50     delete iMissedCallPhoneNumber;*/
       
    51     }
       
    52 
       
    53 //----------------------------------------------------------------------------
       
    54 
       
    55 CCreatorLogs* CCreatorLogs::NewL(CCreatorEngine* aEngine)
       
    56     {
       
    57     CCreatorLogs* self = CCreatorLogs::NewLC(aEngine);
       
    58     CleanupStack::Pop(self);
       
    59     return self;
       
    60     }
       
    61 
       
    62 CCreatorLogs* CCreatorLogs::NewLC(CCreatorEngine* aEngine)
       
    63     {
       
    64     CCreatorLogs* self = new (ELeave) CCreatorLogs;
       
    65     CleanupStack::PushL(self);
       
    66     self->ConstructL(aEngine);
       
    67     return self;
       
    68     }
       
    69 
       
    70 CCreatorLogs::CCreatorLogs() : CActive(0)
       
    71     {
       
    72     iEntriesToBeCreated = 1;
       
    73     }
       
    74 
       
    75 void CCreatorLogs::ConstructL(CCreatorEngine* aEngine)
       
    76     {
       
    77     LOGSTRING("Creator: CCreatorLogs::ConstructL");
       
    78 
       
    79     iEngine = aEngine;
       
    80 
       
    81     iLogClient = CLogClient::NewL(CEikonEnv::Static()->FsSession());
       
    82     iLogEvent = CLogEvent::NewL();
       
    83 
       
    84 	CActiveScheduler::Add(this); // needed by CActive
       
    85     }
       
    86 
       
    87 CCreatorLogs::~CCreatorLogs()
       
    88     {
       
    89     LOGSTRING("Creator: CCreatorLogs::~CCreatorLogs");
       
    90 
       
    91     Cancel(); //from CActive
       
    92 
       
    93     if ( iEngine && iEntryIds.Count() )
       
    94         {
       
    95         TRAP_IGNORE( iEngine->WriteEntryIdsToStoreL( iEntryIds, KUidDictionaryUidLogs ) );
       
    96         }
       
    97     iEntryIds.Reset();
       
    98     iEntryIds.Close();
       
    99     
       
   100     delete iLogEvent;
       
   101     delete iLogClient;
       
   102 
       
   103     if (iParameters)
       
   104         delete iParameters;
       
   105     }
       
   106 
       
   107 //----------------------------------------------------------------------------
       
   108 
       
   109 void CCreatorLogs::QueryDialogClosedL(TBool aPositiveAction, TInt aUserData)
       
   110     {
       
   111     LOGSTRING("Creator: CCreatorModuleBase::QueryDialogClosedL");
       
   112     
       
   113     if( aPositiveAction == EFalse )
       
   114         {
       
   115         iEngine->ShutDownEnginesL();
       
   116         return;
       
   117         }
       
   118     
       
   119     const TDesC* showText = &KSavingText;
       
   120     TBool finished(EFalse);
       
   121     TBool retval(ETrue);
       
   122     switch(aUserData)
       
   123         {
       
   124         case ECreatorLogsDelete:
       
   125             showText = &KDeletingText;
       
   126             iEntriesToBeCreated = 1;
       
   127             finished = ETrue;
       
   128             break;
       
   129         case ECreatorLogsStart:
       
   130             finished = ETrue;
       
   131             break;
       
   132         default:
       
   133             //some error
       
   134             retval = EFalse;
       
   135             break;
       
   136         }
       
   137     if( retval == EFalse )
       
   138         {
       
   139         iEngine->ShutDownEnginesL();
       
   140         }
       
   141     else if( finished )
       
   142         {
       
   143         // add this command to command array
       
   144         iEngine->AppendToCommandArrayL(iCommand, NULL, iEntriesToBeCreated);
       
   145         // started exucuting commands
       
   146         iEngine->ExecuteFirstCommandL( *showText );
       
   147         }
       
   148     }
       
   149     
       
   150 //----------------------------------------------------------------------------
       
   151 
       
   152 TBool CCreatorLogs::AskDataFromUserL(TInt aCommand)
       
   153     {
       
   154     LOGSTRING("Creator: CCreatorLogs::AskDataFromUserL");
       
   155     
       
   156     iCommand = aCommand;
       
   157     
       
   158     if ( aCommand == ECmdDeleteLogs )
       
   159         {
       
   160         return iEngine->GetEngineWrapper()->YesNoQueryDialog( _L("Delete all log entries?"), this, ECreatorLogsDelete );
       
   161         }
       
   162     else if ( aCommand ==  ECmdDeleteCreatorLogs )
       
   163         {
       
   164         return iEngine->GetEngineWrapper()->YesNoQueryDialog( _L("Delete all log entries created with Creator?"), this, ECreatorLogsDelete );
       
   165         }
       
   166     return iEngine->GetEngineWrapper()->EntriesQueryDialog( &iEntriesToBeCreated, _L("How many entries to create?"), EFalse, this, ECreatorLogsStart );
       
   167     }
       
   168 
       
   169 //----------------------------------------------------------------------------
       
   170 
       
   171 void CCreatorLogs::RunL()
       
   172 	{
       
   173     LOGSTRING("Creator: CCreatorLogs::RunL");
       
   174 
       
   175     // log writing finished, stop the async waiting
       
   176     iLogWriteWait.AsyncStop();
       
   177     }
       
   178 
       
   179 //----------------------------------------------------------------------------
       
   180 
       
   181 void CCreatorLogs::DoCancel()
       
   182 	{
       
   183     }
       
   184 
       
   185 //----------------------------------------------------------------------------
       
   186 
       
   187 TInt CCreatorLogs::CreateMissedCallEntryL(CLogsParameters *aParameters)
       
   188     {
       
   189     LOGSTRING("Creator: CCreatorLogs::CreateMissedCallEntryL");
       
   190 
       
   191     // clear any existing parameter definations
       
   192     delete iParameters;
       
   193     iParameters = NULL;
       
   194     
       
   195     CLogsParameters* parameters = aParameters;
       
   196     
       
   197     // random data needed if no predefined data available
       
   198     if (!parameters)
       
   199         {
       
   200         iParameters = new(ELeave) CLogsParameters;
       
   201         parameters = iParameters;
       
   202 
       
   203         /*iParameters->iMissedCallPhoneNumber->Des().Zero();
       
   204         iParameters->iMissedCallPhoneNumber->Des().AppendNum( iEngine->RandomNumber(1000000, 9999999) );
       
   205 
       
   206         iParameters->iMissedCallEventTime.UniversalTime();
       
   207         iParameters->iMissedCallEventTime -= TTimeIntervalMinutes( iEngine->RandomNumber(12000) );*/
       
   208         parameters->iPhoneNumber->Des().Zero();
       
   209         parameters->iPhoneNumber->Des().AppendNum( iEngine->RandomNumber(1000000, 9999999) );
       
   210         
       
   211         parameters->iEventTime.UniversalTime();
       
   212         parameters->iEventTime -= TTimeIntervalMinutes( iEngine->RandomNumber(12000) );
       
   213 
       
   214         }
       
   215     
       
   216     // defaults
       
   217     iLogEvent->SetId( KLogNullId );
       
   218     iLogEvent->SetEventType( KNullUid );
       
   219     iLogEvent->SetRemoteParty( KNullDesC );
       
   220     iLogEvent->SetDirection( KNullDesC );
       
   221     iLogEvent->SetTime( Time::NullTTime() );
       
   222     iLogEvent->SetDurationType( KLogNullDurationType );
       
   223     iLogEvent->SetDuration( KLogNullDuration );
       
   224     iLogEvent->SetStatus( KNullDesC );
       
   225     iLogEvent->SetSubject( KNullDesC );
       
   226     iLogEvent->SetNumber( KNullDesC );
       
   227     iLogEvent->SetContact( KNullContactId );
       
   228     iLogEvent->SetLink( KLogNullLink );
       
   229     iLogEvent->SetDescription( KNullDesC );
       
   230     iLogEvent->SetFlags( KLogNullFlags );
       
   231     iLogEvent->SetEventType(KLogCallEventTypeUid);
       
   232     iLogEvent->SetSubject(_L("A"));
       
   233 
       
   234     // set direction
       
   235     TLogString missed;
       
   236     iLogClient->GetString(missed, R_LOG_DIR_MISSED);
       
   237     iLogEvent->SetDirection(missed);
       
   238 
       
   239     // set duration
       
   240     iLogEvent->SetDurationType( KLogDurationNone );
       
   241     TLogDuration duration = 0;
       
   242     iLogEvent->SetDuration(duration);
       
   243 
       
   244     // set the phone number
       
   245     //iLogEvent->SetNumber( iParameters->iMissedCallPhoneNumber->Des() );
       
   246     iLogEvent->SetNumber( parameters->iPhoneNumber->Des() );
       
   247 
       
   248     // set event time
       
   249     //iLogEvent->SetTime( iParameters->iMissedCallEventTime );
       
   250     iLogEvent->SetTime( parameters->iEventTime );
       
   251 
       
   252     // start writing
       
   253     __ASSERT_ALWAYS(!IsActive(), User::Panic(_L("LogWriter"), 150));
       
   254 	iLogClient->AddEvent(*iLogEvent, iStatus);
       
   255 	SetActive();
       
   256 
       
   257     // wait till adding has finished
       
   258     iLogWriteWait.Start();
       
   259 
       
   260     // id has been generated, store it for being able to delete
       
   261     // entries created only with Creator
       
   262     iEntryIds.Append( iLogEvent->Id() );
       
   263 
       
   264     return iStatus.Int();  // should be KErrNone if writing was succesful
       
   265     }
       
   266 
       
   267 //----------------------------------------------------------------------------
       
   268 
       
   269 TInt CCreatorLogs::CreateReceivedCallEntryL(CLogsParameters *aParameters)
       
   270     {
       
   271     LOGSTRING("Creator: CCreatorLogs::CreateReceivedCallEntryL");
       
   272 
       
   273     // clear any existing parameter definations
       
   274     delete iParameters;
       
   275     iParameters = NULL;
       
   276     
       
   277     CLogsParameters* parameters = aParameters;
       
   278         
       
   279     // random data needed if no predefined data available
       
   280     if (!parameters)
       
   281         {
       
   282         iParameters = new(ELeave) CLogsParameters;
       
   283         parameters = iParameters;
       
   284 
       
   285         /*iParameters->iReceivedCallPhoneNumber->Des().Zero();
       
   286         iParameters->iReceivedCallPhoneNumber->Des().AppendNum( iEngine->RandomNumber(1000000, 9999999) );
       
   287 
       
   288         iParameters->iReceivedCallEventTime.UniversalTime();
       
   289         iParameters->iReceivedCallEventTime -= TTimeIntervalMinutes( iEngine->RandomNumber(12000) );
       
   290 
       
   291         iParameters->iReceivedCallDuration = iEngine->RandomNumber(7200);*/
       
   292         parameters->iPhoneNumber->Des().Zero();
       
   293         parameters->iPhoneNumber->Des().AppendNum( iEngine->RandomNumber(1000000, 9999999) );
       
   294         
       
   295         parameters->iEventTime.UniversalTime();
       
   296         parameters->iEventTime -= TTimeIntervalMinutes( iEngine->RandomNumber(12000) );
       
   297         
       
   298         parameters->iDuration = iEngine->RandomNumber(7200);
       
   299         }
       
   300    
       
   301     // defaults
       
   302     iLogEvent->SetId( KLogNullId );
       
   303     iLogEvent->SetEventType( KNullUid );
       
   304     iLogEvent->SetRemoteParty( KNullDesC );
       
   305     iLogEvent->SetDirection( KNullDesC );
       
   306     iLogEvent->SetTime( Time::NullTTime() );
       
   307     iLogEvent->SetDurationType( KLogNullDurationType );
       
   308     iLogEvent->SetDuration( KLogNullDuration );
       
   309     iLogEvent->SetStatus( KNullDesC );
       
   310     iLogEvent->SetSubject( KNullDesC );
       
   311     iLogEvent->SetNumber( KNullDesC );
       
   312     iLogEvent->SetContact( KNullContactId );
       
   313     iLogEvent->SetLink( KLogNullLink );
       
   314     iLogEvent->SetDescription( KNullDesC );
       
   315     iLogEvent->SetFlags( KLogNullFlags );
       
   316     iLogEvent->SetEventType(KLogCallEventTypeUid);
       
   317     iLogEvent->SetSubject(_L("A"));
       
   318 
       
   319     // set direction
       
   320     TLogString incoming;
       
   321     iLogClient->GetString(incoming, R_LOG_DIR_IN);
       
   322     iLogEvent->SetDirection(incoming);
       
   323 
       
   324     // set duration
       
   325     iLogEvent->SetDurationType( KLogDurationValid );
       
   326     //iLogEvent->SetDuration( iParameters->iReceivedCallDuration );
       
   327     iLogEvent->SetDuration( parameters->iDuration );
       
   328 
       
   329     // set the phone number
       
   330     //iLogEvent->SetNumber( iParameters->iReceivedCallPhoneNumber->Des() );
       
   331     iLogEvent->SetNumber( parameters->iPhoneNumber->Des() );
       
   332 
       
   333     // set event time
       
   334     //iLogEvent->SetTime( iParameters->iReceivedCallEventTime );
       
   335     iLogEvent->SetTime( parameters->iEventTime );
       
   336 
       
   337     // start writing
       
   338     __ASSERT_ALWAYS(!IsActive(), User::Panic(_L("LogWriter"), 151));
       
   339 	iLogClient->AddEvent(*iLogEvent, iStatus);
       
   340 	SetActive();
       
   341 
       
   342     // wait till adding has finished
       
   343     iLogWriteWait.Start();
       
   344 
       
   345     // id has been generated, store it for being able to delete
       
   346     // entries created only with Creator
       
   347     iEntryIds.Append( iLogEvent->Id() );
       
   348 
       
   349     return iStatus.Int();  // should be KErrNone if writing was succesful
       
   350     }
       
   351 
       
   352 //----------------------------------------------------------------------------
       
   353 
       
   354 
       
   355 TInt CCreatorLogs::CreateDialledNumberEntryL(CLogsParameters *aParameters)
       
   356     {
       
   357     LOGSTRING("Creator: CCreatorLogs::CreateDialledNumberEntryL");
       
   358 
       
   359     // clear any existing parameter definations
       
   360     delete iParameters;
       
   361     iParameters = NULL;
       
   362     
       
   363     CLogsParameters* parameters = aParameters; 
       
   364         
       
   365     // random data needed if no predefined data available
       
   366     if (!parameters)
       
   367         {
       
   368         iParameters = new(ELeave) CLogsParameters;
       
   369         parameters = iParameters;
       
   370 
       
   371         /*iParameters->iDialledNumberPhoneNumber->Des().Zero();
       
   372         iParameters->iDialledNumberPhoneNumber->Des().AppendNum( iEngine->RandomNumber(1000000, 9999999) );
       
   373 
       
   374         iParameters->iDialledNumberEventTime.UniversalTime();
       
   375         iParameters->iDialledNumberEventTime -= TTimeIntervalMinutes( iEngine->RandomNumber(12000) );
       
   376 
       
   377         iParameters->iDialledNumberDuration = iEngine->RandomNumber(7200);*/
       
   378         parameters->iPhoneNumber->Des().Zero();
       
   379         parameters->iPhoneNumber->Des().AppendNum( iEngine->RandomNumber(1000000, 9999999) );
       
   380 
       
   381         parameters->iEventTime.UniversalTime();
       
   382         parameters->iEventTime -= TTimeIntervalMinutes( iEngine->RandomNumber(12000) );
       
   383 
       
   384         parameters->iDuration = iEngine->RandomNumber(7200);
       
   385 
       
   386         }
       
   387    
       
   388     // defaults
       
   389     iLogEvent->SetId( KLogNullId );
       
   390     iLogEvent->SetEventType( KNullUid );
       
   391     iLogEvent->SetRemoteParty( KNullDesC );
       
   392     iLogEvent->SetDirection( KNullDesC );
       
   393     iLogEvent->SetTime( Time::NullTTime() );
       
   394     iLogEvent->SetDurationType( KLogNullDurationType );
       
   395     iLogEvent->SetDuration( KLogNullDuration );
       
   396     iLogEvent->SetStatus( KNullDesC );
       
   397     iLogEvent->SetSubject( KNullDesC );
       
   398     iLogEvent->SetNumber( KNullDesC );
       
   399     iLogEvent->SetContact( KNullContactId );
       
   400     iLogEvent->SetLink( KLogNullLink );
       
   401     iLogEvent->SetDescription( KNullDesC );
       
   402     iLogEvent->SetFlags( KLogNullFlags );
       
   403     iLogEvent->SetEventType(KLogCallEventTypeUid);
       
   404     iLogEvent->SetSubject(_L("A"));
       
   405 
       
   406     // set direction
       
   407     TLogString outgoing;
       
   408     iLogClient->GetString(outgoing, R_LOG_DIR_OUT);
       
   409     iLogEvent->SetDirection(outgoing);
       
   410 
       
   411     // set duration
       
   412     iLogEvent->SetDurationType( KLogDurationValid );
       
   413     //iLogEvent->SetDuration( iParameters->iDialledNumberDuration );
       
   414     iLogEvent->SetDuration( parameters->iDuration );
       
   415 
       
   416     // set the phone number
       
   417     //iLogEvent->SetNumber( iParameters->iDialledNumberPhoneNumber->Des() );
       
   418     iLogEvent->SetNumber( parameters->iPhoneNumber->Des() );
       
   419 
       
   420     // set event time
       
   421     //iLogEvent->SetTime( iParameters->iDialledNumberEventTime );
       
   422     iLogEvent->SetTime( parameters->iEventTime );
       
   423 
       
   424     // start writing
       
   425     __ASSERT_ALWAYS(!IsActive(), User::Panic(_L("LogWriter"), 152));
       
   426 	iLogClient->AddEvent(*iLogEvent, iStatus);
       
   427 	SetActive();
       
   428 
       
   429     // wait till adding has finished
       
   430     iLogWriteWait.Start();
       
   431 
       
   432     // id has been generated, store it for being able to delete
       
   433     // only entries created with Creator
       
   434     iEntryIds.Append( iLogEvent->Id() );
       
   435     
       
   436     return iStatus.Int();  // should be KErrNone if writing was succesful
       
   437     }
       
   438 
       
   439 //----------------------------------------------------------------------------
       
   440 void CCreatorLogs::DeleteAllL()
       
   441     {
       
   442     LOGSTRING("Creator: CCreatorLogs::DeleteAllL");
       
   443     iLogClient->ClearLog( TTime( Time::MaxTTime() ), iStatus ); 
       
   444     SetActive();
       
   445     
       
   446     // wait till delete has finished
       
   447     iLogWriteWait.Start();
       
   448     User::LeaveIfError( iStatus.Int() );
       
   449 
       
   450     // reset must be done here, because iEntryIds is stored in destructor
       
   451     iEntryIds.Reset();
       
   452     
       
   453     // all entries deleted, remove the Logs related registry
       
   454     iEngine->RemoveStoreL( KUidDictionaryUidLogs );
       
   455     }
       
   456 
       
   457 //----------------------------------------------------------------------------
       
   458 void CCreatorLogs::DeleteAllCreatedByCreatorL()
       
   459     {
       
   460     LOGSTRING("Creator: CCreatorLogs::DeleteAllCreatedByCreatorL");
       
   461     iEntryIds.Reset();
       
   462     
       
   463     // fetch ids of entries created by Creator
       
   464     iEngine->ReadEntryIdsFromStoreL( iEntryIds, KUidDictionaryUidLogs );
       
   465     
       
   466     // delete entries
       
   467     for ( TInt i = 0; i < iEntryIds.Count(); i++ )
       
   468         {
       
   469         // This could be implemented with while loop
       
   470         // with additional cancel flag. That would enable 
       
   471         // using CancelOp() and cancelling would be bit smoother.
       
   472         // With this for loop implementation all entries will be
       
   473         // deleted whether or not user cancels during logs operation.
       
   474 
       
   475         iLogClient->DeleteEvent( iEntryIds[i], iStatus );
       
   476         SetActive();        
       
   477         // wait till delete has finished
       
   478         iLogWriteWait.Start();
       
   479         }
       
   480     
       
   481     // reset must be done here, because iEntryIds is stored in destructor
       
   482     iEntryIds.Reset();
       
   483     
       
   484     // all entries deleted, remove the Logs related registry
       
   485     iEngine->RemoveStoreL( KUidDictionaryUidLogs );
       
   486     }