|
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 <e32base.h> |
|
19 |
|
20 #include "mdsshutdownobserver.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 // CMDSShutdownObserver::NewL() |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CMDSShutdownObserver* CMDSShutdownObserver::NewL( MMDSShutdownObserver& aObserver/*, const TUid& aKeyCategory */) |
|
36 { |
|
37 CMDSShutdownObserver* self = new( ELeave )CMDSShutdownObserver( aObserver/*, aKeyCategory */); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // CMDSShutdownObserver::CMDSShutdownObserver() |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CMDSShutdownObserver::CMDSShutdownObserver( MMDSShutdownObserver& aObserver/*, const TUid& aKeyCategory */) |
|
49 : CActive( CActive::EPriorityUserInput ), iObserver( aObserver ), iValue( KErrNone )/*, iKeyCategory( aKeyCategory )*/ |
|
50 { |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CMDSShutdownObserver::ConstructL() |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 void CMDSShutdownObserver::ConstructL() |
|
58 { |
|
59 #ifdef _DEBUG |
|
60 PRINT(_L("CMDSShutdownObserver::ConstructL()")); |
|
61 #endif |
|
62 |
|
63 // attach to the property |
|
64 User::LeaveIfError( iProperty.Attach(KMdSPSShutdown,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 #ifdef _DEBUG |
|
74 PRINT(_L("CMDSShutdownObserver::ConstructL() end")); |
|
75 #endif |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CMDSShutdownObserver::~CMDSShutdownObserver() |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 CMDSShutdownObserver::~CMDSShutdownObserver() |
|
83 { |
|
84 #ifdef _DEBUG |
|
85 PRINT(_L("CMDSShutdownObserver::~CMDSShutdownObserver()")); |
|
86 #endif |
|
87 Cancel(); |
|
88 iProperty.Close(); |
|
89 #ifdef _DEBUG |
|
90 PRINT(_L("CMDSShutdownObserver::~CMDSShutdownObserver() end")); |
|
91 #endif |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CMDSShutdownObserver::RunL() |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CMDSShutdownObserver::RunL() |
|
99 { |
|
100 // resubscribe before processing new value to prevent missing updates |
|
101 iProperty.Subscribe(iStatus); |
|
102 SetActive(); |
|
103 |
|
104 // retrieve the Uid of the package going to be updated |
|
105 TInt value = 0; |
|
106 const TInt err = iProperty.Get(value); |
|
107 User::LeaveIfError(err); |
|
108 |
|
109 iValue = value; |
|
110 |
|
111 // observer callback |
|
112 if (value) |
|
113 { |
|
114 iObserver.ShutdownNotification(); |
|
115 } |
|
116 else |
|
117 { |
|
118 iObserver.RestartNotification(); |
|
119 } |
|
120 } |
|
121 |
|
122 TInt CMDSShutdownObserver::RunError( TInt /*aError*/ ) |
|
123 { |
|
124 return KErrNone; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CMDSShutdownObserver::DoCancel() |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CMDSShutdownObserver::DoCancel() |
|
132 { |
|
133 iProperty.Cancel(); |
|
134 } |
|
135 |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // CMDSShutdownObserver::UpdateInProgress() |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 TBool CMDSShutdownObserver::UpdateInProgress() |
|
142 { |
|
143 return iValue > 0 ? ETrue : EFalse; |
|
144 } |
|
145 |
|
146 // End of file |