|
1 /* |
|
2 * Copyright (c) 2002 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: Implementation of the CProfileChangeNotifyHandler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CProfileChangeNotifyHandler.h" |
|
22 #include "MProfileChangeObserver.h" |
|
23 #include "ProfileEngPanic.h" |
|
24 #include "ProfileEngineSDKCRKeys.h" |
|
25 #include "ProfileEnginePrivatePSKeys.h" |
|
26 #include <centralrepository.h> |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CProfileChangeNotifyHandler::CProfileChangeNotifyHandler |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CProfileChangeNotifyHandler::CProfileChangeNotifyHandler( |
|
37 MProfileChangeObserver* aProfileChangeObserver ) |
|
38 : iProfileChangeObserver( aProfileChangeObserver ) |
|
39 { |
|
40 |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CProfileChangeNotifyHandler::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CProfileChangeNotifyHandler::ConstructL() |
|
49 { |
|
50 iPSObserver = new ( ELeave ) CProfilePSObserver( |
|
51 KProEngActiveProfileModified ); |
|
52 iActiveProfileObserver = new ( ELeave ) CProfilePSObserver( |
|
53 KProEngActiveProfileChanged ); |
|
54 iPSObserver->iProfileChangeObserver = iProfileChangeObserver; |
|
55 iActiveProfileObserver->iProfileChangeObserver = iProfileChangeObserver; |
|
56 iRepository = CRepository::NewL( KCRUidProfileEngine ); |
|
57 iActiveProfileObserver->iCenRep = iRepository; |
|
58 iPSObserver->iCenRep = iRepository; |
|
59 iActiveProfileObserver->RequestNotificationL(); |
|
60 iPSObserver->RequestNotificationL(); |
|
61 } |
|
62 |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CProfileChangeNotifyHandler::NewL |
|
66 // Two-phased constructor. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 EXPORT_C CProfileChangeNotifyHandler* CProfileChangeNotifyHandler::NewL( |
|
70 MProfileChangeObserver* aProfileChangeObserver ) |
|
71 { |
|
72 __ASSERT_ALWAYS( aProfileChangeObserver, |
|
73 ProfileEngPanic::Panic( EProfileEngPanicNullPointer ) ); |
|
74 |
|
75 CProfileChangeNotifyHandler* self = |
|
76 new ( ELeave ) CProfileChangeNotifyHandler(aProfileChangeObserver); |
|
77 |
|
78 CleanupStack::PushL( self ); |
|
79 self->ConstructL(); |
|
80 CleanupStack::Pop(); |
|
81 |
|
82 return self; |
|
83 } |
|
84 |
|
85 // Destructor |
|
86 CProfileChangeNotifyHandler::~CProfileChangeNotifyHandler() |
|
87 { |
|
88 delete iActiveProfileObserver; |
|
89 delete iPSObserver; |
|
90 delete iRepository; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CProfileChangeNotifyHandler::CProfilePSObserver::CProfilePSObserver |
|
95 // |
|
96 // (other items were commented in a header). |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 CProfileChangeNotifyHandler::CProfilePSObserver::CProfilePSObserver( |
|
100 TUint32 aPSKey ) |
|
101 : CActive( EPriorityNormal ), iPSKey( aPSKey ) |
|
102 { |
|
103 CActiveScheduler::Add( this ); |
|
104 iAttached = EFalse; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CProfileChangeNotifyHandler::CProfilePSObserver::~CProfilePSObserver |
|
109 // |
|
110 // (other items were commented in a header). |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 CProfileChangeNotifyHandler::CProfilePSObserver::~CProfilePSObserver() |
|
114 { |
|
115 Cancel(); |
|
116 iProperty.Close(); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CProfileChangeNotifyHandler::CProfilePSObserver::RequestNotificationL() |
|
121 // |
|
122 // (other items were commented in a header). |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 void CProfileChangeNotifyHandler::CProfilePSObserver::RequestNotificationL() |
|
126 { |
|
127 if ( !iAttached ) |
|
128 { |
|
129 User::LeaveIfError( iProperty.Attach( KPSUidProfileEngine, iPSKey ) ); |
|
130 iAttached = ETrue; |
|
131 } |
|
132 |
|
133 iProperty.Subscribe( iStatus ); |
|
134 SetActive(); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CProfileChangeNotifyHandler::CProfilePSObserver::RunL() |
|
139 // |
|
140 // (other items were commented in a header). |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CProfileChangeNotifyHandler::CProfilePSObserver::RunL() |
|
144 { |
|
145 RequestNotificationL(); |
|
146 // The id of the current active profile is always passed to the observer: |
|
147 TInt profileId( 0 ); |
|
148 User::LeaveIfError( iCenRep->Get( KProEngActiveProfile, profileId ) ); |
|
149 TProfileEvent evt( iPSKey == KProEngActiveProfileModified ? |
|
150 EProfileActiveProfileModified : |
|
151 EProfileNewActiveProfile ); |
|
152 iProfileChangeObserver->HandleActiveProfileEventL( evt, profileId ); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CProfileChangeNotifyHandler::CProfilePSObserver::DoCancel() |
|
157 // |
|
158 // (other items were commented in a header). |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CProfileChangeNotifyHandler::CProfilePSObserver::DoCancel() |
|
162 { |
|
163 iProperty.Cancel(); |
|
164 } |
|
165 |
|
166 // End of File |
|
167 |
|
168 |