1 /* |
|
2 * Copyright (c) 2008 - 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 the License "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: Used for Search Related Test Cases |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 //Include files |
|
22 #include <e32err.h> |
|
23 #include <e32const.h> |
|
24 #include <e32base.h> |
|
25 #include <glib.h> |
|
26 #include <TestScripterInternal.h> |
|
27 #include "telepathygabbleutils.h" |
|
28 #include "telepathygabblesearch.h" |
|
29 #include "telepathygabbletestdata.h" |
|
30 #include "tp-chan.h" |
|
31 #include "tp-conn-gen.h" |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 //----------------------------------------------------------------------------- |
|
37 // function_name : CTelepathyGabbleSearch |
|
38 // description : constructor |
|
39 //----------------------------------------------------------------------------- |
|
40 |
|
41 CTelepathyGabbleSearch::CTelepathyGabbleSearch() |
|
42 { |
|
43 } |
|
44 |
|
45 //----------------------------------------------------------------------------- |
|
46 // function_name : ConstructL |
|
47 // description : constructor |
|
48 //----------------------------------------------------------------------------- |
|
49 void CTelepathyGabbleSearch::ConstructL() |
|
50 { |
|
51 |
|
52 } |
|
53 |
|
54 //----------------------------------------------------------------------------- |
|
55 // function_name : NewL |
|
56 // description : NewL |
|
57 //----------------------------------------------------------------------------- |
|
58 CTelepathyGabbleSearch* CTelepathyGabbleSearch::NewL() |
|
59 { |
|
60 CTelepathyGabbleSearch* self = new(ELeave) CTelepathyGabbleSearch; |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL(); |
|
63 CleanupStack::Pop(); |
|
64 return self; |
|
65 } |
|
66 |
|
67 //----------------------------------------------------------------------------- |
|
68 // function_name : ~CTelepathyGabbleSearch |
|
69 // description : Destructor |
|
70 //----------------------------------------------------------------------------- |
|
71 CTelepathyGabbleSearch::~CTelepathyGabbleSearch() |
|
72 { |
|
73 } |
|
74 |
|
75 |
|
76 //----------------------------------------------------------------------------- |
|
77 // function_name : SearchL |
|
78 // description : Used for searching contacts |
|
79 //----------------------------------------------------------------------------- |
|
80 TInt CTelepathyGabbleSearch::SearchL( GHashTable *aDataToSearch, CTestData* aTestData ) |
|
81 { |
|
82 Search_UserData *userData = new(ELeave) Search_UserData; |
|
83 |
|
84 userData->data_to_search = aDataToSearch; |
|
85 userData->testData = aTestData; |
|
86 |
|
87 iTestData = aTestData; |
|
88 |
|
89 if( iTestData->GetSearchChan() ) |
|
90 { |
|
91 SearchAgainL( aDataToSearch, iTestData ); |
|
92 //Run the mainloop |
|
93 g_main_loop_run (iTestData->GetMainLoop()); |
|
94 } |
|
95 else |
|
96 { |
|
97 if (!tp_conn_request_channel_async( DBUS_G_PROXY( aTestData->GetTpConn() ), |
|
98 TP_IFACE_CHANNEL_TYPE_CONTACT_SEARCH, |
|
99 TP_CONN_HANDLE_TYPE_NONE, 0, TRUE, |
|
100 do_search_reply,(gpointer) userData ) ) |
|
101 |
|
102 { |
|
103 return KErrGeneral; |
|
104 } |
|
105 //Run the mainloop |
|
106 g_main_loop_run (iTestData->GetMainLoop()); |
|
107 DoSearchL( aDataToSearch, aTestData); |
|
108 } |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 if(userData) |
|
114 { |
|
115 delete userData; |
|
116 userData = NULL; |
|
117 } |
|
118 |
|
119 //return the Message_sent that was updated in the callback sendmessage_cb |
|
120 return iTestData->GetSearchState(); |
|
121 } |
|
122 |
|
123 //----------------------------------------------------------------------------- |
|
124 // function_name : SearchAgainL |
|
125 // description : Used for searching contacts second or more number of times |
|
126 //----------------------------------------------------------------------------- |
|
127 |
|
128 void CTelepathyGabbleSearch::SearchAgainL( GHashTable *aDataToSearch, CTestData* aTestData ) |
|
129 { |
|
130 |
|
131 DBusGProxy *search_iface = NULL; |
|
132 TpChan *search_chan = NULL; |
|
133 |
|
134 if(aTestData) |
|
135 { |
|
136 search_chan = aTestData->GetSearchChan(); |
|
137 } |
|
138 if ( NULL == search_chan ) |
|
139 { |
|
140 return ; |
|
141 } |
|
142 //Get chan interface |
|
143 search_iface = tp_chan_get_interface( search_chan , |
|
144 TELEPATHY_CHAN_IFACE_CONTACTSEARCH_QUARK ); |
|
145 |
|
146 if ( NULL == search_iface ) |
|
147 { |
|
148 return ; |
|
149 } |
|
150 |
|
151 //Call the search on tp |
|
152 tp_chan_type_search_async( search_iface, aDataToSearch, searchreply_cb, |
|
153 aTestData ); |
|
154 |
|
155 |
|
156 } |
|
157 |
|
158 |
|
159 //----------------------------------------------------------------------------- |
|
160 // function_name : GetSearchKeysL |
|
161 // description : Used for getting search keys |
|
162 //----------------------------------------------------------------------------- |
|
163 TInt CTelepathyGabbleSearch::GetSearchKeysL( CTestData* aTestData ) |
|
164 { |
|
165 Search_UserData *userData = new(ELeave) Search_UserData; |
|
166 |
|
167 userData->data_to_search = NULL; |
|
168 userData->testData = aTestData; |
|
169 |
|
170 iTestData = aTestData; |
|
171 |
|
172 if (!tp_conn_request_channel_async( DBUS_G_PROXY( aTestData->GetTpConn() ), |
|
173 TP_IFACE_CHANNEL_TYPE_CONTACT_SEARCH, |
|
174 TP_CONN_HANDLE_TYPE_NONE, 0, TRUE, |
|
175 do_search_reply,(gpointer) userData ) ) |
|
176 |
|
177 { |
|
178 return KErrGeneral; |
|
179 } |
|
180 |
|
181 //Run the mainloop |
|
182 g_main_loop_run (aTestData->GetMainLoop()); |
|
183 |
|
184 DoSearchL(NULL,aTestData); |
|
185 |
|
186 if(userData) |
|
187 { |
|
188 delete userData; |
|
189 userData = NULL; |
|
190 } |
|
191 |
|
192 //return the Message_sent that was updated in the callback sendmessage_cb |
|
193 return iTestData->GetSearchState(); |
|
194 } |
|
195 |
|
196 |
|
197 void CTelepathyGabbleSearch::do_search_reply( DBusGProxy* /*proxy*/, char *chan_object_path, |
|
198 GError *error, gpointer user_data ) |
|
199 { |
|
200 Search_UserData* userData = static_cast<Search_UserData*> (user_data); |
|
201 TpChan *search_chan = NULL; |
|
202 |
|
203 TInt search_state = userData->testData->GetSearchState(); |
|
204 |
|
205 |
|
206 /* Create the object to represent the channel */ |
|
207 if ( error ) |
|
208 { |
|
209 userData->testData->SetSearchState(CTestData::ESearchError); |
|
210 return; |
|
211 } |
|
212 search_chan = tp_chan_new( userData->testData->GetDBusConnection(), CONNMGR_BUS, chan_object_path, |
|
213 TP_IFACE_CHANNEL_TYPE_CONTACT_SEARCH, TP_CONN_HANDLE_TYPE_NONE, 0 ); |
|
214 |
|
215 |
|
216 g_free(chan_object_path); |
|
217 |
|
218 |
|
219 if ( NULL == search_chan ) |
|
220 { |
|
221 userData->testData->SetSearchState(CTestData::ESearchError); |
|
222 return ; |
|
223 } |
|
224 |
|
225 userData->testData->SetSearchChan( search_chan ); |
|
226 |
|
227 g_main_loop_quit(userData->testData->GetMainLoop()); |
|
228 |
|
229 |
|
230 } |
|
231 |
|
232 |
|
233 void CTelepathyGabbleSearch::DoSearchL(GHashTable *aDataToSearch,CTestData *testData) |
|
234 { |
|
235 DBusGProxy *search_iface = NULL; |
|
236 TInt testType = testData->GetTestType(); |
|
237 |
|
238 //Get chan interface |
|
239 search_iface = tp_chan_get_interface( testData->GetSearchChan(), |
|
240 TELEPATHY_CHAN_IFACE_CONTACTSEARCH_QUARK ); |
|
241 |
|
242 if ( NULL == search_iface ) |
|
243 { |
|
244 testData->SetSearchState(CTestData::ESearchError); |
|
245 return ; |
|
246 } |
|
247 //Register for the SearchResultReceived signal |
|
248 //ownership of the srch_result->user_data is transfered |
|
249 dbus_g_proxy_connect_signal( search_iface, "SearchResultReceived", |
|
250 G_CALLBACK( search_result_received_cb ), |
|
251 (gpointer)this, NULL ); |
|
252 |
|
253 |
|
254 //Register for the SearchStateChanged signal |
|
255 dbus_g_proxy_connect_signal( search_iface, "SearchStateChanged", |
|
256 G_CALLBACK( search_state_changed_cb ), |
|
257 (gpointer)this, NULL ); |
|
258 |
|
259 if( testType == CTestData::EGetSearchKeys ) |
|
260 { |
|
261 //Call the getsearchkeys on tp |
|
262 tp_chan_type_search_get_search_keys_async(search_iface,getsearchkeys_cb, testData ); |
|
263 |
|
264 } |
|
265 else if( testType == CTestData::ESearch ) |
|
266 { |
|
267 //Call the search on tp |
|
268 tp_chan_type_search_async( search_iface, aDataToSearch, |
|
269 searchreply_cb, testData); |
|
270 } |
|
271 |
|
272 g_main_loop_run(testData->GetMainLoop()); |
|
273 |
|
274 } |
|
275 void CTelepathyGabbleSearch::getsearchkeys_cb( DBusGProxy* /*proxy*/, gchar* /*instr*/, |
|
276 gchar** keys, GError *error, gpointer user_data ) |
|
277 { |
|
278 CTestData* testData = static_cast<CTestData*> (user_data); |
|
279 |
|
280 if(!keys || error ) |
|
281 { |
|
282 testData->SetSearchState( CTestData::ESearchError ); |
|
283 } |
|
284 |
|
285 if(keys) |
|
286 { |
|
287 testData->GetStifLogger()->Log( _L("getsearchkeys_cb:SearchKeysFound") ); |
|
288 testData->SetSearchState( CTestData::ESearchKeysFound ); |
|
289 testData->SetSearchKeys(keys); |
|
290 } |
|
291 g_main_loop_quit(testData->GetMainLoop()); |
|
292 |
|
293 } |
|
294 |
|
295 |
|
296 |
|
297 void CTelepathyGabbleSearch::searchreply_cb( DBusGProxy* /*proxy*/, GError *error, gpointer user_data ) |
|
298 { |
|
299 CTestData* testData = static_cast<CTestData*> (user_data); |
|
300 TInt testType = testData->GetTestType(); |
|
301 |
|
302 testData->GetStifLogger()->Log( _L("searchreply_cb") ); |
|
303 |
|
304 if ( testType == CTestData::ESearch ) |
|
305 { |
|
306 if(error) |
|
307 { |
|
308 testData->GetStifLogger()->Log( _L("Error in search") ); |
|
309 testData->SetSearchState(CTestData::ESearchError); |
|
310 tp_chan_close_async( DBUS_G_PROXY( testData->GetSearchChan() ), search_chan_closed_cb, testData ); |
|
311 } |
|
312 } |
|
313 |
|
314 } |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 void CTelepathyGabbleSearch::search_result_received_cb ( DBusGProxy* /*proxy*/, |
|
320 guint /*contact_handle*/, |
|
321 GHashTable *values, |
|
322 gpointer user_data |
|
323 ) |
|
324 { |
|
325 CTelepathyGabbleSearch* search_userData = static_cast<CTelepathyGabbleSearch*> (user_data); |
|
326 guint result_count = 0; |
|
327 |
|
328 //iTestData->GetStifLogger()->Log( _L("search_result_received_cb") ); |
|
329 search_userData->GetTestData()->GetStifLogger()->Log( _L("search_result_received_cb") ); |
|
330 |
|
331 if(values ) |
|
332 result_count = g_hash_table_size(values); |
|
333 |
|
334 |
|
335 //do this later |
|
336 /*if(result_count) |
|
337 { |
|
338 g_hash_table_foreach(values,setfield_foreach,NULL); |
|
339 }*/ |
|
340 |
|
341 |
|
342 } |
|
343 |
|
344 void CTelepathyGabbleSearch::search_state_changed_cb ( DBusGProxy* /*proxy*/, |
|
345 guint search_state, |
|
346 gpointer user_data |
|
347 ) |
|
348 { |
|
349 CTelepathyGabbleSearch* search_userData = static_cast<CTelepathyGabbleSearch*> (user_data); |
|
350 DBusGProxy *search_iface = NULL; |
|
351 GError **err = NULL; |
|
352 guint *state = NULL; |
|
353 TpChan *search_chan = NULL; |
|
354 CTestData* testData = search_userData->GetTestData(); |
|
355 |
|
356 if(search_userData && testData ) |
|
357 { |
|
358 testData->GetStifLogger()->Log( _L("search_state_changed_cb") ); |
|
359 search_chan = testData->GetSearchChan(); |
|
360 } |
|
361 |
|
362 |
|
363 if( search_state == TP_CHANNEL_CONTACT_SEARCH_STATE_AFTER && search_userData && search_chan ) |
|
364 { |
|
365 testData->SetSearchState(CTestData::ESearchCompleted); |
|
366 search_iface = tp_chan_get_interface( search_chan, |
|
367 TELEPATHY_CHAN_IFACE_CONTACTSEARCH_QUARK ); |
|
368 tp_chan_type_search_get_search_state( search_iface,state,err); |
|
369 g_main_loop_quit(testData->GetMainLoop()); |
|
370 } |
|
371 |
|
372 } |
|
373 |
|
374 void CTelepathyGabbleSearch::search_chan_closed_cb ( DBusGProxy* /*proxy*/, |
|
375 GError *error, |
|
376 gpointer user_data |
|
377 ) |
|
378 { |
|
379 CTestData* testData = static_cast<CTestData*> (user_data); |
|
380 |
|
381 testData->GetStifLogger()->Log( _L("search_chan_closed_cb") ); |
|
382 if(error) |
|
383 { |
|
384 testData->GetStifLogger()->Log( _L("search_chan_closed_cb : Error ") ); |
|
385 testData->SetSearchState(CTestData::ESearchError); |
|
386 } |
|
387 else |
|
388 { |
|
389 |
|
390 TInt testType = testData->GetTestType(); |
|
391 if( testType == CTestData::EGetSearchKeys ) |
|
392 { |
|
393 testData->SetSearchState(CTestData::ESearchKeysFound); |
|
394 testData->GetStifLogger()->Log( _L("search_chan_closed_cb : SearchKeysFound ") ); |
|
395 } |
|
396 else if( testType == CTestData::ESearch ) |
|
397 { |
|
398 testData->SetSearchState(CTestData::ESearchCompleted); |
|
399 testData->GetStifLogger()->Log( _L("search_chan_closed_cb : SearchCompleted ") ); |
|
400 } |
|
401 } |
|
402 g_main_loop_quit(testData->GetMainLoop()); |
|
403 } |
|
404 |
|
405 CTestData* CTelepathyGabbleSearch::GetTestData() |
|
406 { |
|
407 return iTestData; |
|
408 } |
|
409 |
|
410 /*void CTelepathyGabbleSearch::setfield_foreach (gpointer key, gpointer value, gpointer user_data) |
|
411 { |
|
412 gchar *k = (gchar *) key; |
|
413 const char *v = g_value_get_string ( (const GValue*)value); |
|
414 CTestData* testdata = static_cast<CTestData*> (user_data); |
|
415 |
|
416 //testdata->GetStifLogger()->Log( _L("setfield_foreach") ); |
|
417 |
|
418 }*/ |
|
419 |
|
420 void CTelepathyGabbleSearch::CloseChannel( CTestData* aTestdata ) |
|
421 { |
|
422 if( aTestdata->GetSearchChan() ) |
|
423 { |
|
424 tp_chan_close_async( DBUS_G_PROXY( aTestdata->GetSearchChan() ), search_chan_closed_cb, aTestdata ); |
|
425 } |
|
426 //Run the mainloop |
|
427 g_main_loop_run (aTestdata->GetMainLoop()); |
|
428 } |
|
429 |
|
430 // End of File |
|