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