|
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: Shutdown Observer |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32base.h> |
|
19 |
|
20 #include "wdshutdownobserver.h" |
|
21 #include "mdscommoninternal.h" |
|
22 |
|
23 // Print macro |
|
24 #ifdef _DEBUG |
|
25 #include <e32svr.h> |
|
26 #define PRINT(x) RDebug::Print x |
|
27 #else |
|
28 #define PRINT(x) |
|
29 #endif |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CWDShutdownObserver::NewL() |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CWDShutdownObserver* CWDShutdownObserver::NewL( MWDShutdownObserver& aObserver/*, const TUid& aKeyCategory */) |
|
36 { |
|
37 CWDShutdownObserver* self = new( ELeave )CWDShutdownObserver( aObserver/*, aKeyCategory */); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CWDShutdownObserver::CWDShutdownObserver() |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CWDShutdownObserver::CWDShutdownObserver( MWDShutdownObserver& aObserver/*, const TUid& aKeyCategory */) |
|
49 : CActive( CActive::EPriorityStandard ), iObserver( aObserver )/*, iKeyCategory( aKeyCategory )*/ |
|
50 { |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CWDShutdownObserver::ConstructL() |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 void CWDShutdownObserver::ConstructL() |
|
58 { |
|
59 PRINT(_L("CWDShutdownObserver::ConstructL()")); |
|
60 |
|
61 // attach to the property |
|
62 User::LeaveIfError( iProperty.Attach(KHarvesterPSShutdown,KShutdown,EOwnerThread) ); |
|
63 |
|
64 CActiveScheduler::Add( this ); |
|
65 |
|
66 // wait for the previously attached property to be updated |
|
67 iProperty.Subscribe(iStatus); |
|
68 |
|
69 SetActive(); |
|
70 |
|
71 PRINT(_L("CWDShutdownObserver::ConstructL() end")); |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CWDShutdownObserver::~CWDShutdownObserver() |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CWDShutdownObserver::~CWDShutdownObserver() |
|
79 { |
|
80 PRINT(_L("CWDShutdownObserver::~CWDShutdownObserver()")); |
|
81 Cancel(); |
|
82 iProperty.Close(); |
|
83 PRINT(_L("CWDShutdownObserver::~CWDShutdownObserver() end")); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // CWDShutdownObserver::RunL() |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 void CWDShutdownObserver::RunL() |
|
91 { |
|
92 |
|
93 PRINT(_L("CWDShutdownObserver::RunL()")); |
|
94 |
|
95 // resubscribe before processing new value to prevent missing updates |
|
96 iProperty.Subscribe(iStatus); |
|
97 SetActive(); |
|
98 |
|
99 // retrieve the Uid of the package going to be updated |
|
100 TInt value = 0; |
|
101 const TInt err = iProperty.Get(value); |
|
102 User::LeaveIfError(err); |
|
103 |
|
104 // observer callback |
|
105 if (value) |
|
106 { |
|
107 iObserver.ShutdownNotification(); |
|
108 } |
|
109 else |
|
110 { |
|
111 iObserver.RestartNotification(); |
|
112 } |
|
113 } |
|
114 |
|
115 TInt CWDShutdownObserver::RunError( TInt /*aError*/ ) |
|
116 { |
|
117 return KErrNone; |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CWDShutdownObserver::DoCancel() |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CWDShutdownObserver::DoCancel() |
|
125 { |
|
126 iProperty.Cancel(); |
|
127 } |
|
128 |
|
129 // End of file |