1 // TestTelephonyModel.cpp |
|
2 // Copyright (c) Symbian Software Ltd 2008. All rights reserved. |
|
3 // |
|
4 // Implementation of the Class CTestTelephonyModel |
|
5 |
|
6 // CTSY include |
|
7 #include <bautils.h> |
|
8 |
|
9 #include "TestLtsyModel.h" |
|
10 #include "testltsycallshareddata.h" |
|
11 #include "TestLtsyPktSharedData.h" |
|
12 #include "TestLtsySmsSharedData.h" |
|
13 #include "TestLtsyPhoneStoreSharedData.h" |
|
14 |
|
15 // the file used to identify if we run on real environment |
|
16 //_LIT(KCTsyRealEnvFilePath, "z:\\systemtest\\testdata\\telephony\\ctsyrealenv.txt"); |
|
17 //_LIT(KMmTsyModuleName, "PhoneTsy"); |
|
18 |
|
19 /** |
|
20 * Factory function |
|
21 * |
|
22 */ |
|
23 CTestLtsyModel* CTestLtsyModel::NewL() |
|
24 { |
|
25 CTestLtsyModel* self = new (ELeave) CTestLtsyModel(); |
|
26 CleanupStack::PushL(self); |
|
27 self->ConstructL(); |
|
28 CleanupStack::Pop(); |
|
29 return self; |
|
30 } |
|
31 |
|
32 /** |
|
33 * Destructor |
|
34 * |
|
35 */ |
|
36 CTestLtsyModel::~CTestLtsyModel() |
|
37 { |
|
38 delete iSharedPhoneEnv; |
|
39 delete iCallSharedData; |
|
40 delete iPktSharedData; |
|
41 delete iSmsSharedData; |
|
42 delete iPhoneStoreSharedData; |
|
43 } |
|
44 |
|
45 /** |
|
46 * 2nd Constructor |
|
47 * |
|
48 */ |
|
49 void CTestLtsyModel::ConstructL() |
|
50 { |
|
51 iSharedPhoneEnv = CTestLtsySharedEnv::NewL(); |
|
52 iCallSharedData = CTestLtsyCallSharedData::NewL(); |
|
53 iPktSharedData = CTestLtsyPktSharedData::NewL(); |
|
54 iSmsSharedData = CTestLtsySmsSharedData::NewL(); |
|
55 iPhoneStoreSharedData = CTestLtsyPhoneStoreSharedData::NewL(); |
|
56 } |
|
57 |
|
58 //============================================================================= |
|
59 // class CTestTelephonyAdaptorEnv |
|
60 //============================================================================= |
|
61 /** |
|
62 * Constructor |
|
63 * |
|
64 */ |
|
65 CTestLtsySharedEnv::CTestLtsySharedEnv() |
|
66 { |
|
67 // reset iPhoneInitialized |
|
68 iPhoneInitialized = EFalse; |
|
69 iPhoneIndex = -1; |
|
70 } |
|
71 |
|
72 /** |
|
73 * Destructor |
|
74 */ |
|
75 CTestLtsySharedEnv::~CTestLtsySharedEnv() |
|
76 { |
|
77 ClosePhone(); |
|
78 DestroyTelephony(); |
|
79 } |
|
80 |
|
81 /** |
|
82 * Factory function |
|
83 * |
|
84 */ |
|
85 CTestLtsySharedEnv* CTestLtsySharedEnv::NewL() |
|
86 { |
|
87 CTestLtsySharedEnv* self = new (ELeave) CTestLtsySharedEnv(); |
|
88 CleanupStack::PushL(self); |
|
89 self->ConstructL(); |
|
90 CleanupStack::Pop(); |
|
91 return self; |
|
92 } |
|
93 |
|
94 /** |
|
95 * 2nd constructor |
|
96 */ |
|
97 void CTestLtsySharedEnv::ConstructL() |
|
98 { |
|
99 } |
|
100 |
|
101 /** |
|
102 * Load phone module |
|
103 * |
|
104 * @param const TDesC& aModuleName The phone module used by ETel server for loading a specific TSY |
|
105 */ |
|
106 void CTestLtsySharedEnv::LoadModuleL(const TDesC& aModuleName) |
|
107 { |
|
108 |
|
109 RFs fs; |
|
110 User::LeaveIfError(fs.Connect()); |
|
111 CleanupClosePushL(fs); |
|
112 CleanupStack::PopAndDestroy(&fs); |
|
113 |
|
114 TInt ret = iSharedTelServer.LoadPhoneModule(aModuleName); |
|
115 |
|
116 if (ret != KErrNone) |
|
117 { |
|
118 iSharedTelServer.Close(); |
|
119 User::Leave(ret); |
|
120 } |
|
121 } |
|
122 |
|
123 /** |
|
124 * Open the shared phone |
|
125 * |
|
126 * @param const TDesC& aModuleName The phone module used by ETel server for loading a specific TSY |
|
127 */ |
|
128 void CTestLtsySharedEnv::OpenPhoneL(const TDesC& aModuleName) |
|
129 { |
|
130 THandleInfo handleInfo; |
|
131 iSharedTelServer.HandleInfo(&handleInfo); |
|
132 if(iPhoneInitialized) |
|
133 { |
|
134 // a panic occurs if handleInfo.iNumThreads <= 0 |
|
135 if(handleInfo.iNumThreads <= 0) |
|
136 { |
|
137 iSharedPhone = NULL; |
|
138 iPhoneInitialized = EFalse; |
|
139 iSharedTelServer.Close(); |
|
140 } |
|
141 else |
|
142 { |
|
143 // return if phone has already been opened before |
|
144 return; |
|
145 } |
|
146 } |
|
147 |
|
148 // make sure this pointer was NULL |
|
149 ASSERT(iSharedPhone == NULL); |
|
150 |
|
151 // make a copy of module name |
|
152 iModuleName.Copy(aModuleName); |
|
153 |
|
154 // start connect to ETel server |
|
155 User::LeaveIfError(iSharedTelServer.Connect()); |
|
156 User::LeaveIfError(iSharedTelServer.ShareAuto()); |
|
157 |
|
158 // start load module |
|
159 LoadModuleL(aModuleName); |
|
160 |
|
161 // check if we can find corresponding phone object according to passed TSY module name |
|
162 if(!FindPhoneIndex()) |
|
163 { |
|
164 // the phone index could not be found |
|
165 User::Leave(KErrNotFound); |
|
166 } |
|
167 |
|
168 // create a new RMobilePhone instance |
|
169 iSharedPhone = new (ELeave) RMobilePhone(); |
|
170 RTelServer::TPhoneInfo phoneInfo; |
|
171 User::LeaveIfError(iSharedTelServer.GetPhoneInfo(iPhoneIndex,phoneInfo)); |
|
172 |
|
173 // start openning phone |
|
174 TInt ret = iSharedPhone->Open(iSharedTelServer,phoneInfo.iName); |
|
175 if(ret != KErrNone) |
|
176 { |
|
177 User::Leave(ret); |
|
178 } |
|
179 |
|
180 iPhoneInitialized = ETrue; |
|
181 } |
|
182 |
|
183 /** |
|
184 * Find the phone index according to TSY name |
|
185 * |
|
186 */ |
|
187 TBool CTestLtsySharedEnv::FindPhoneIndex() |
|
188 { |
|
189 TInt phoneNum = 0; |
|
190 TInt err = iSharedTelServer.EnumeratePhones(phoneNum); |
|
191 if(err != KErrNone) |
|
192 { |
|
193 return EFalse; |
|
194 } |
|
195 |
|
196 TBool found = EFalse; |
|
197 for(TInt i = 0; i < phoneNum; i++) |
|
198 { |
|
199 RTelServer::TPhoneInfo phoneInfo; |
|
200 TBuf<KModuleNameLen> moduleName; |
|
201 err = iSharedTelServer.GetTsyName(i,moduleName); |
|
202 if(err != KErrNone) |
|
203 { |
|
204 return EFalse; |
|
205 } |
|
206 else |
|
207 { |
|
208 if(moduleName.CompareF(iModuleName) == 0) |
|
209 { |
|
210 iPhoneIndex = i; |
|
211 found = ETrue; |
|
212 break; |
|
213 } |
|
214 } |
|
215 } |
|
216 |
|
217 return found; |
|
218 } |
|
219 |
|
220 /** |
|
221 * Close the shared phone and server |
|
222 * Client must call this function, if it has called OpenPhoneL(). |
|
223 * |
|
224 */ |
|
225 void CTestLtsySharedEnv::ClosePhone() |
|
226 { |
|
227 // close and delete the shared phone |
|
228 iSharedPhone->Close(); |
|
229 delete iSharedPhone; |
|
230 iSharedPhone = NULL; |
|
231 |
|
232 // unload the phone module |
|
233 iSharedTelServer.UnloadPhoneModule(iModuleName); |
|
234 iSharedTelServer.Close(); |
|
235 |
|
236 // reset iPhoneInitialized |
|
237 iPhoneInitialized = EFalse; |
|
238 } |
|
239 |
|
240 /** |
|
241 * Create a CTelephony object and related resource. |
|
242 * |
|
243 */ |
|
244 void CTestLtsySharedEnv::CreateTelephonyL() |
|
245 { |
|
246 iActiveSchaduler = new (ELeave) CActiveScheduler(); |
|
247 CActiveScheduler::Install(iActiveSchaduler); |
|
248 |
|
249 iTelephony = CTelephony::NewL(); |
|
250 } |
|
251 |
|
252 /** |
|
253 * Delete CTelephony object related source. |
|
254 * |
|
255 */ |
|
256 void CTestLtsySharedEnv::DestroyTelephony() |
|
257 { |
|
258 |
|
259 delete iActiveSchaduler; |
|
260 iActiveSchaduler = NULL; |
|
261 delete iTelephony; |
|
262 iTelephony = NULL; |
|
263 |
|
264 delete iSharedPhone; |
|
265 iSharedPhone = NULL; |
|
266 |
|
267 // reset iPhoneInitialized |
|
268 iPhoneInitialized = EFalse; |
|
269 } |
|
270 |
|
271 CTelephony* CTestLtsySharedEnv::Telephony() |
|
272 { |
|
273 return iTelephony; |
|
274 } |
|
275 |
|
276 // end of file |
|