|
1 /* |
|
2 * Copyright (c) 2005-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: A base class for write operations |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef VPBKSIMSTOREIMPL_CWRITECMDBASE_H |
|
21 #define VPBKSIMSTOREIMPL_CWRITECMDBASE_H |
|
22 |
|
23 // INCLUDES |
|
24 #include "CStoreBase.h" |
|
25 #include "METelStoreNotificationObserver.h" |
|
26 |
|
27 #include <e32base.h> |
|
28 #include <MVPbkSimStoreOperation.h> |
|
29 #include <MVPbkSimCommandObserver.h> |
|
30 #include <VPbkDebug.h> |
|
31 |
|
32 // FORWARD DECLARATIONS |
|
33 class MVPbkSimContactObserver; |
|
34 |
|
35 namespace VPbkSimStoreImpl { |
|
36 |
|
37 // FORWARD DECLARATIONS |
|
38 class CStoreBase; |
|
39 |
|
40 // CLASS DECLARATION |
|
41 |
|
42 /** |
|
43 * An operation that writes a contact to (U)SIM card |
|
44 * |
|
45 */ |
|
46 NONSHARABLE_CLASS(CWriteCmdBase) : public CActive, |
|
47 public MVPbkSimStoreOperation, |
|
48 protected METelStoreNotificationObserver, |
|
49 protected MVPbkSimCommandObserver |
|
50 { |
|
51 public: // Constructors and destructor |
|
52 |
|
53 /** |
|
54 * Destructor. |
|
55 */ |
|
56 ~CWriteCmdBase(); |
|
57 |
|
58 public: // Functions from base classes |
|
59 |
|
60 /** |
|
61 * From CActive |
|
62 */ |
|
63 void RunL(); |
|
64 |
|
65 /** |
|
66 * From CActive |
|
67 */ |
|
68 void DoCancel(); |
|
69 |
|
70 protected: // Functions from base classes |
|
71 |
|
72 /** |
|
73 * From METelStoreNotificationObserver |
|
74 */ |
|
75 TBool ETelStoreChanged( TInt aSimIndex, TUint32 aEvents ); |
|
76 |
|
77 /** |
|
78 * From METelStoreNotificationObserver |
|
79 */ |
|
80 TBool ETelStoreChangeError( TInt aError ); |
|
81 |
|
82 /** |
|
83 * From MVPbkSimCommandObserver |
|
84 */ |
|
85 void CommandDone( MVPbkSimCommand& aCommand ); |
|
86 |
|
87 /** |
|
88 * From MVPbkSimCommandObserver |
|
89 */ |
|
90 void CommandError( MVPbkSimCommand& aCommand, TInt aError ); |
|
91 |
|
92 protected: // Construction |
|
93 |
|
94 /** |
|
95 * C++ constructor |
|
96 */ |
|
97 CWriteCmdBase( CStoreBase& aStore, TInt& aSimIndex, |
|
98 MVPbkSimContactObserver& aObserver ); |
|
99 |
|
100 /** |
|
101 * By default Symbian 2nd phase constructor is private. |
|
102 */ |
|
103 void BaseConstructL(); |
|
104 |
|
105 protected: // New functions |
|
106 |
|
107 /** |
|
108 * Must be called from the subclass Execute to |
|
109 * active the command |
|
110 */ |
|
111 void Activate(); |
|
112 |
|
113 /** |
|
114 * Handles error case |
|
115 * @param aError the error to notify observers |
|
116 */ |
|
117 |
|
118 void HandleError( TInt aError ); |
|
119 |
|
120 /** |
|
121 * Removes this instance from the ETel notification |
|
122 */ |
|
123 void RemoveNotificationObserver(); |
|
124 |
|
125 /** |
|
126 * @return the store |
|
127 */ |
|
128 inline CStoreBase& StoreBase() const; |
|
129 |
|
130 /** |
|
131 * Activates the object and completes command using aResult. |
|
132 * @param aResult The completion code. |
|
133 */ |
|
134 void CompleteCommandAsynchronously( TInt aResult ); |
|
135 |
|
136 protected: // Data |
|
137 /// a refence to the sim index which is updated by the |
|
138 /// ETel if the value is -1 |
|
139 TInt& iSimIndex; |
|
140 private: // Data |
|
141 /// the store for making the ETel request |
|
142 CStoreBase& iStoreBase; |
|
143 /// an observer to notify in error case |
|
144 MVPbkSimContactObserver& iObserver; |
|
145 /// Own: the update command to execute |
|
146 MVPbkSimCommand* iUpdateCommand; |
|
147 /// an observer for command framework |
|
148 MVPbkSimCommandObserver* iCommandObserver; |
|
149 }; |
|
150 |
|
151 // INLINE FUNCTIONS |
|
152 inline CStoreBase& CWriteCmdBase::StoreBase() const |
|
153 { |
|
154 return iStoreBase; |
|
155 } |
|
156 |
|
157 /** |
|
158 * A write operation template for RMobilePhoneStore::Write |
|
159 */ |
|
160 template<class ETelContact> |
|
161 NONSHARABLE_CLASS( CBasicWriteCmd ) : public CWriteCmdBase |
|
162 { |
|
163 public: // New functions |
|
164 |
|
165 /** |
|
166 * Starts this operation |
|
167 */ |
|
168 void Execute(); |
|
169 |
|
170 protected: // Functions from base classes |
|
171 |
|
172 /** |
|
173 * From CActive |
|
174 */ |
|
175 void RunL(); |
|
176 |
|
177 protected: // Construction |
|
178 |
|
179 /** |
|
180 * C++ constructor |
|
181 */ |
|
182 CBasicWriteCmd( CStoreBase& aStore, TInt& aSimIndex, |
|
183 MVPbkSimContactObserver& aObserver ); |
|
184 |
|
185 protected: // Data |
|
186 /// The ETel contact |
|
187 ETelContact iETelContact; |
|
188 |
|
189 private: // Data |
|
190 /// A package for the ETel contact |
|
191 TPckg<ETelContact> iETelContactPckg; |
|
192 /// a reference to the index to write |
|
193 TInt& iSimIndex; |
|
194 }; |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CBasicWriteCmd::CBasicWriteCmd |
|
198 // C++ default constructor can NOT contain any code, that |
|
199 // might leave. |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 template<class ETelContact> |
|
203 CBasicWriteCmd<ETelContact>::CBasicWriteCmd( CStoreBase& aStore, |
|
204 TInt& aSimIndex, MVPbkSimContactObserver& aObserver ) |
|
205 : CWriteCmdBase( aStore, iETelContact.iIndex, aObserver ), |
|
206 iETelContactPckg( iETelContact ), |
|
207 iSimIndex( aSimIndex ) |
|
208 { |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CBasicWriteCmd::Execute |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 template<class ETelContact> |
|
216 void CBasicWriteCmd<ETelContact>::Execute() |
|
217 { |
|
218 VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING( |
|
219 "VPbkSimStoreImpl: RMobilePhoneStore::Write h%d request slot=%d"), |
|
220 StoreBase().ETelStoreBase().SubSessionHandle(),iSimIndex); |
|
221 StoreBase().ETelStoreBase().Write( iStatus, iETelContactPckg ); |
|
222 CWriteCmdBase::Activate(); |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CBasicWriteCmd::RunL |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 template<class ETelContact> |
|
230 void CBasicWriteCmd<ETelContact>::RunL() |
|
231 { |
|
232 // ETel writes to iETelContact.iIndex. It must be copied to the index |
|
233 // reference offered by the client of this dll |
|
234 iSimIndex = iETelContact.iIndex; |
|
235 CWriteCmdBase::RunL(); |
|
236 } |
|
237 |
|
238 } // namespace VPbkSimStoreImpl |
|
239 #endif // VPBKSIMSTOREIMPL_CWRITECMDBASE_H |
|
240 |
|
241 // End of File |