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