1 /* |
|
2 * Copyright (c) 2006-2007 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: Processor |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 |
|
21 #include "tmshutdownobserver.h" |
|
22 #include "thumbnailmanagerconstants.h" |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // CTMShutdownObserver::NewL() |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CTMShutdownObserver* CTMShutdownObserver::NewL( MTMShutdownObserver& aObserver, |
|
29 const TUid& aKeyCategory, |
|
30 const TInt aPropertyKey, |
|
31 TBool aDefineKey) |
|
32 { |
|
33 CTMShutdownObserver* self = new( ELeave )CTMShutdownObserver( aObserver, |
|
34 aKeyCategory, |
|
35 aPropertyKey, |
|
36 aDefineKey); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CTMShutdownObserver::CTMShutdownObserver() |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CTMShutdownObserver::CTMShutdownObserver( MTMShutdownObserver& aObserver, |
|
48 const TUid& aKeyCategory, |
|
49 const TInt aPropertyKey, |
|
50 TBool aDefineKey) |
|
51 : CActive( CActive::EPriorityStandard ), iObserver( aObserver ), |
|
52 iKeyCategory( aKeyCategory ), iPropertyKey(aPropertyKey), iDefineKey( aDefineKey ) |
|
53 { |
|
54 CActiveScheduler::Add( this ); |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CTMShutdownObserver::ConstructL() |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 void CTMShutdownObserver::ConstructL() |
|
62 { |
|
63 // define P&S property types |
|
64 if (iDefineKey) |
|
65 { |
|
66 RProperty::Define(iKeyCategory,iPropertyKey, |
|
67 RProperty::EInt,KAllowAllPolicy,KPowerMgmtPolicy); |
|
68 } |
|
69 |
|
70 // attach to the property |
|
71 TInt err = iProperty.Attach(iKeyCategory,iPropertyKey,EOwnerThread); |
|
72 User::LeaveIfError(err); |
|
73 |
|
74 // wait for the previously attached property to be updated |
|
75 iProperty.Subscribe(iStatus); |
|
76 SetActive(); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // CTMShutdownObserver::~CTMShutdownObserver() |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 CTMShutdownObserver::~CTMShutdownObserver() |
|
84 { |
|
85 Cancel(); |
|
86 iProperty.Close(); |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CTMShutdownObserver::RunL() |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CTMShutdownObserver::RunL() |
|
94 { |
|
95 // resubscribe before processing new value to prevent missing updates |
|
96 iProperty.Subscribe(iStatus); |
|
97 SetActive(); |
|
98 |
|
99 // retrieve the value |
|
100 TInt value = 0; |
|
101 iProperty.Get(value); |
|
102 |
|
103 // observer callback |
|
104 if (value) |
|
105 { |
|
106 iObserver.ShutdownNotification(); |
|
107 } |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CTMShutdownObserver::DoCancel() |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 void CTMShutdownObserver::DoCancel() |
|
115 { |
|
116 iProperty.Cancel(); |
|
117 } |
|
118 |
|
119 // End of file |
|