|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "harvesterlog.h" |
|
19 #include "cclientkeywatcherao.h" |
|
20 #include "crestorewatcher.h" |
|
21 |
|
22 CClientKeyWatcherAO* CClientKeyWatcherAO::NewL( CRestoreWatcher* aRestoreWatcher ) |
|
23 { |
|
24 WRITELOG("CClientKeyWatcherAO::NewL()"); |
|
25 CClientKeyWatcherAO* self = new (ELeave) CClientKeyWatcherAO( aRestoreWatcher ); |
|
26 CleanupStack::PushL( self ); |
|
27 self->ConstructL(); |
|
28 CleanupStack::Pop( self ); |
|
29 return self; |
|
30 } |
|
31 |
|
32 CClientKeyWatcherAO::~CClientKeyWatcherAO() |
|
33 { |
|
34 Cancel(); |
|
35 iClientsProperty.Close(); |
|
36 |
|
37 iRestoreWatcher = NULL; |
|
38 } |
|
39 |
|
40 |
|
41 CClientKeyWatcherAO::CClientKeyWatcherAO( CRestoreWatcher* aRestoreWatcher ) : |
|
42 CActive( CActive::EPriorityUserInput ) |
|
43 { |
|
44 CActiveScheduler::Add( this ); |
|
45 iRestoreWatcher = aRestoreWatcher; |
|
46 } |
|
47 |
|
48 void CClientKeyWatcherAO::ConstructL() |
|
49 { |
|
50 WRITELOG("CClientKeyWatcherAO::ConstructL()"); |
|
51 |
|
52 User::LeaveIfError( iClientsProperty.Attach( KPSRestoreWatcherCategory, |
|
53 KPSRestoreWatcherClientsKey, EOwnerThread ) ); |
|
54 |
|
55 iClientsProperty.Subscribe( iStatus ); |
|
56 SetActive(); |
|
57 WRITELOG("CClientKeyWatcherAO::ConstructL() - ends"); |
|
58 } |
|
59 |
|
60 void CClientKeyWatcherAO::RunL() |
|
61 { |
|
62 WRITELOG("CClientKeyWatcherAO::RunL()"); |
|
63 if( iStatus.Int() != KErrNone ) |
|
64 { |
|
65 #ifdef _DEBUG |
|
66 WRITELOG1("CClientKeyWatcherAO::RunL() - error: %d", iStatus.Int()); |
|
67 #endif |
|
68 return; |
|
69 } |
|
70 |
|
71 TInt clients = 0; |
|
72 iClientsProperty.Get( clients ); |
|
73 |
|
74 if ( clients < iClients ) |
|
75 { |
|
76 WRITELOG("CClientKeyWatcherAO::RunL() - unregistering"); |
|
77 iRestoreWatcher->UnregisterL(); |
|
78 } |
|
79 else if ( clients > iClients ) |
|
80 { |
|
81 WRITELOG("CClientKeyWatcherAO::RunL() - registering"); |
|
82 iRestoreWatcher->Register(); |
|
83 } |
|
84 |
|
85 iClients = clients; |
|
86 |
|
87 iClientsProperty.Subscribe( iStatus ); |
|
88 SetActive(); |
|
89 } |
|
90 |
|
91 void CClientKeyWatcherAO::DoCancel() |
|
92 { |
|
93 iClientsProperty.Cancel(); |
|
94 } |
|
95 |
|
96 TInt CClientKeyWatcherAO::RunError( TInt ) |
|
97 { |
|
98 return KErrNone; |
|
99 } |