omadm/lawmo/lawmoplugins/calllogsplugin/src/lawmocalllogsasyncwipe.cpp
branchRCL_3
changeset 23 c4687ff85147
child 26 ae4a65edc4fe
equal deleted inserted replaced
22:9360ca28b668 23:c4687ff85147
       
     1 /*
       
     2 * Copyright (c) 2009 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: Active Object for wiping Call-logs, called by lawmocalllogsplugin.
       
    15 *
       
    16 */
       
    17 #include <logcli.h>
       
    18 #include <f32file.h>
       
    19 #include <logwrap.h>
       
    20 #include <logview.h>
       
    21 #include <e32base.h>
       
    22 #include <logwraplimits.h>
       
    23 #include <logwrapconst.h>
       
    24 #include "lawmocalllogsasyncwipe.h"
       
    25 #include "fdebug.h"
       
    26 
       
    27 // Application Closing
       
    28 #include <apgtask.h>
       
    29 #include <w32std.h>
       
    30 #include <APGTASK.H>
       
    31 
       
    32 // ----------------------------------------------------------------------------- 
       
    33 // CActiveWipeObject::CActiveWipeObject
       
    34 // Description: CActiveWipeObject constructer . Initializes datamember of MLawmoPluginWipeObserver 
       
    35 // ----------------------------------------------------------------------------- 
       
    36 //
       
    37 CActiveWipeObject::CActiveWipeObject(MLawmoPluginWipeObserver* aObserver) :
       
    38     CActive(EPriorityStandard), iObserver(aObserver), ilogClient(NULL), iTimerStarted (EFalse)
       
    39     {
       
    40     FLOG(
       
    41             _L( " CAllLogs: CActiveWipeObject::CActiveWipeObject(MLawmoPluginWipeObserver* aObserver) >> "));
       
    42     // See ConstructL() for initialisation completion.
       
    43     FLOG(
       
    44             _L( " CAllLogs: CActiveWipeObject::CActiveWipeObject(MLawmoPluginWipeObserver* aObserver) << "));
       
    45     }
       
    46 
       
    47 // ----------------------------------------------------------------------------- 
       
    48 // CActiveWipeObject::NewL
       
    49 // Description: CActiveWipeObject constructer 
       
    50 // ----------------------------------------------------------------------------- 
       
    51 //
       
    52 CActiveWipeObject* CActiveWipeObject::NewL(
       
    53         MLawmoPluginWipeObserver* aObserver)
       
    54     {
       
    55     FLOG(_L( " CAllLogs: CActiveWipeObject::NewL >> "));
       
    56     CActiveWipeObject* self = new (ELeave) CActiveWipeObject(aObserver);
       
    57     CleanupStack::PushL(self);
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop();
       
    60     FLOG(_L( " CAllLogs: CActiveWipeObject::NewL << "));
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ----------------------------------------------------------------------------------------
       
    65 // CActiveWipeObject::ConstructL
       
    66 // ----------------------------------------------------------------------------------------
       
    67 void CActiveWipeObject::ConstructL()
       
    68     {
       
    69     FLOG(_L( " CAllLogs: CActiveWipeObject::ConstructL >> "));
       
    70     iTimer.CreateLocal();
       
    71     User::LeaveIfError(iWsSession.Connect());
       
    72     CActiveScheduler::Add(this); // Add to scheduler    
       
    73     FLOG(_L( " CAllLogs: CActiveWipeObject::ConstructL << "));
       
    74     }
       
    75 
       
    76 //
       
    77 //----------------------------------------------------------------------------- 
       
    78 // CActiveWipeObject:: CActiveWipeObject
       
    79 // Description: CActiveWipeObject Destructer
       
    80 // ----------------------------------------------------------------------------- 
       
    81 // 
       
    82 CActiveWipeObject::~CActiveWipeObject()
       
    83     {
       
    84     FLOG(_L( " CAllLogs: CActiveWipeObject::~CActiveWipeObject() >> "));
       
    85     Cancel();
       
    86     if (ilogClient)
       
    87     	{
       
    88         delete ilogClient;
       
    89       }
       
    90       
       
    91     if (ifs.Handle())
       
    92       	{
       
    93       		ifs.Close();
       
    94       	}
       
    95 
       
    96     iTimer.Close();
       
    97     
       
    98     iWsSession.Close();
       
    99         
       
   100     FLOG(_L( " CAllLogs: CActiveWipeObject::~CActiveWipeObject() << "));
       
   101     }
       
   102 
       
   103 //
       
   104 //----------------------------------------------------------------------------- 
       
   105 // CActiveWipeObject::WipeAsyncL
       
   106 // Description: Wipes the logs 
       
   107 // ---------------------------------------------------------------------------- 
       
   108 //
       
   109 
       
   110 void CActiveWipeObject::WipeAsyncL()
       
   111     {
       
   112     FLOG(_L(" CAllLogs: void CActiveWipeObject::WipeAsyncL () >>"));
       
   113     if (!WaitTillLogsAppKilled()) //Application is closed already
       
   114         {
       
   115         ClearLogsL();
       
   116         }
       
   117 
       
   118     FLOG(_L(" CAllLogs: void CActiveWipeObject::WipeAsyncL () <<"));
       
   119     }
       
   120 
       
   121 //
       
   122 //----------------------------------------------------------------------------- 
       
   123 // CActiveWipeObject::RunError
       
   124 // Description: This returns error 
       
   125 //----------------------------------------------------------------------------- 
       
   126 //
       
   127 
       
   128 TInt CActiveWipeObject::RunError(TInt aError)
       
   129     {
       
   130     FLOG(_L(" CAllLogs: TInt CActiveWipeObject::RunError(TInt aError) >>"));
       
   131     FLOG(_L(" CAllLogs: RunError error %d"), aError);
       
   132     iObserver->HandleWipeCompleted(aError);
       
   133     FLOG(_L(" CAllLogs: TInt CActiveWipeObject::RunError(TInt aError) <<"));
       
   134     return KErrNone;
       
   135     }
       
   136 
       
   137 //
       
   138 //----------------------------------------------------------------------------- 
       
   139 // CActiveWipeObject::DoCancel
       
   140 // Description: This calls CActive's Cancel 
       
   141 //----------------------------------------------------------------------------- 
       
   142 //
       
   143 void CActiveWipeObject::DoCancel()
       
   144     {
       
   145     FLOG(_L(" CAllLogs: void CActiveWipeObject::DoCancel() >>"));
       
   146     if (iTimerStarted)
       
   147     	{
       
   148     		iTimer.Cancel();
       
   149     	}
       
   150     else
       
   151     	{
       
   152     	ilogClient->Cancel();
       
   153       }
       
   154     FLOG(_L(" CAllLogs: void CActiveWipeObject::DoCancel() <<"));
       
   155     }
       
   156 
       
   157 TBool CActiveWipeObject::WaitTillLogsAppKilled()
       
   158     {
       
   159     FLOG(_L(" WaitTillLogsAppKilled() >>"));
       
   160 
       
   161     TBool ret(EFalse);
       
   162     TBool flag(ETrue);
       
   163 
       
   164     TApaTaskList list(iWsSession);
       
   165     TUid uid =
       
   166         {
       
   167         KCallLogsAppUid
       
   168         };
       
   169 
       
   170     while (flag)
       
   171         {
       
   172         TApaTask task(list.FindApp(uid));
       
   173         if (task.Exists())
       
   174             {
       
   175             FLOG(_L("Killing one instance..."));
       
   176             task.EndTask();
       
   177             User::After(500000);
       
   178             ret = ETrue;
       
   179             }
       
   180         else
       
   181             {
       
   182             flag = EFalse;
       
   183             }
       
   184         }
       
   185     if (ret)
       
   186         {
       
   187         FLOG(_L(" WaitTillPhonebookKilled: iTimer.After(iStatus,1000); "));
       
   188         iTimerStarted = ETrue; // If time is started, this is true
       
   189         iTimer.After(iStatus, 2000); // 0.002 sec
       
   190         SetActive();
       
   191         }
       
   192 
       
   193     FLOG(_L(" WaitTillLogsAppKilled(), ret = %d <<"), ret);
       
   194     return ret;
       
   195     }
       
   196 
       
   197 
       
   198 //
       
   199 //----------------------------------------------------------------------------- 
       
   200 // CActiveWipeObject::RunL 
       
   201 // Description: Clears the logs
       
   202 //----------------------------------------------------------------------------- 
       
   203 //
       
   204 void CActiveWipeObject::ClearLogsL()
       
   205     {
       
   206     FLOG(_L("void CActiveWipeObject::ClearLogs() >> "));
       
   207     TTime time(KMaxTime);
       
   208     User::LeaveIfError(ifs.Connect());
       
   209     ilogClient = CLogClient::NewL(ifs);
       
   210     FLOG(_L("iStatus.Int() = %d "), iStatus.Int());
       
   211     ilogClient->ClearLog(time, iStatus);
       
   212     SetActive();
       
   213 
       
   214     FLOG(_L("void CActiveWipeObject::ClearLogs() << "));
       
   215     }
       
   216 
       
   217 //
       
   218 //----------------------------------------------------------------------------- 
       
   219 // CActiveWipeObject::RunL 
       
   220 // Description: Called when either timer expires of logs are cleared
       
   221 //----------------------------------------------------------------------------- 
       
   222 //
       
   223 void CActiveWipeObject::RunL()
       
   224     {
       
   225     FLOG(_L(" CAllLogs: void CActiveWipeObject::RunL() >>"));
       
   226     FLOG(_L("void CActiveWipeObject::RunL(): iStatus= %d "), iStatus.Int());
       
   227 
       
   228     if (iTimerStarted)
       
   229         {
       
   230         iTimerStarted = EFalse;
       
   231         ClearLogsL();
       
   232         }
       
   233     else
       
   234         iObserver->HandleWipeCompleted(iStatus.Int());
       
   235     FLOG(_L(" CAllLogs: void CActiveWipeObject::RunL() <<"));
       
   236     }