|
1 /* |
|
2 * Copyright (c) 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 "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // [INCLUDE FILES] - do not remove |
|
22 #include <e32std.h> |
|
23 #include <e32svr.h> |
|
24 #include <StifParser.h> |
|
25 #include <Stiftestinterface.h> |
|
26 #include <unistd.h> |
|
27 #include "stif_1.h" |
|
28 #include <sys/stat.h> |
|
29 |
|
30 #include <pthread.h> |
|
31 #include <fcntl.h> |
|
32 #include <string.h> |
|
33 #include <spawn.h> |
|
34 |
|
35 #include "errno.h" |
|
36 #define MAX_THREAD 25 |
|
37 #define MAX_SIGNALS 3 |
|
38 #define MAX_CONN 21 |
|
39 #define MAX_CONN_EXE 25 |
|
40 |
|
41 _LIT(KSuccess, "Test Successful"); |
|
42 _LIT(KOOM, "Out Of Memory"); |
|
43 int var_arg_ret_val = -3; |
|
44 int pending_call_ret_val = -6; |
|
45 TBool data_free_flag = FALSE; |
|
46 |
|
47 struct TestData |
|
48 { |
|
49 int num; |
|
50 char* str; |
|
51 }; |
|
52 |
|
53 struct TestData1 |
|
54 { |
|
55 int data_slot; |
|
56 TestData* data; |
|
57 }; |
|
58 |
|
59 |
|
60 void Free_Test_Data(void* data) |
|
61 { |
|
62 TestData* test_data; |
|
63 test_data = (TestData*)data; |
|
64 |
|
65 free(test_data->str); |
|
66 free(test_data); |
|
67 data_free_flag = TRUE; |
|
68 } |
|
69 |
|
70 void handle_reply_variable_args(DBusPendingCall* pending, void* data) |
|
71 { |
|
72 DBusMessage* msg1; |
|
73 DBusMessageIter return_iter; |
|
74 DBusError error; |
|
75 dbus_int32_t* return_value = (dbus_int32_t*)data; |
|
76 dbus_int32_t ret; |
|
77 |
|
78 // get the reply message |
|
79 msg1 = dbus_pending_call_steal_reply(pending); |
|
80 if (NULL == msg1) { |
|
81 *return_value = -2; |
|
82 } |
|
83 |
|
84 // free the pending message handle |
|
85 dbus_pending_call_unref(pending); |
|
86 |
|
87 dbus_error_init (&error); |
|
88 dbus_message_iter_init(msg1, &return_iter); |
|
89 |
|
90 dbus_message_iter_get_basic(&return_iter, return_value); |
|
91 ret = *return_value; |
|
92 RDebug::Printf("return value is:%d\n", ret); |
|
93 dbus_message_unref(msg1); |
|
94 } |
|
95 |
|
96 void handle_reply_pending_call_data_slot0(DBusPendingCall* pending, void* data) |
|
97 { |
|
98 DBusMessage* msg1; |
|
99 DBusError error; |
|
100 int return_value; |
|
101 TestData1* data1 = (TestData1*)data; |
|
102 TestData* test_data; |
|
103 TestData* new_data; |
|
104 DBusFreeFunction free_data; |
|
105 |
|
106 // get the reply message |
|
107 msg1 = dbus_pending_call_steal_reply(pending); |
|
108 if (NULL == msg1) { |
|
109 return_value = -2; |
|
110 return; |
|
111 } |
|
112 |
|
113 dbus_error_init (&error); |
|
114 |
|
115 dbus_message_get_args(msg1, &error, DBUS_TYPE_INT32, &return_value, DBUS_TYPE_INVALID); |
|
116 |
|
117 if(return_value == 9090) |
|
118 return_value = 0; |
|
119 |
|
120 test_data = (TestData*)dbus_pending_call_get_data(pending, data1->data_slot); |
|
121 if(test_data->num != data1->data->num || strcmp(test_data->str, data1->data->str)) |
|
122 { |
|
123 return_value = -3; |
|
124 return; |
|
125 } |
|
126 |
|
127 new_data = (TestData *)malloc(sizeof(TestData)); |
|
128 new_data->num = 234; |
|
129 new_data->str = (char*)malloc(20); |
|
130 strcpy(new_data->str, "Check DBus New"); |
|
131 free_data = Free_Test_Data; |
|
132 data_free_flag = FALSE; |
|
133 if(!dbus_pending_call_set_data(pending, data1->data_slot, new_data, free_data)) |
|
134 { |
|
135 return_value = -4; |
|
136 return; |
|
137 } |
|
138 |
|
139 if(!data_free_flag) |
|
140 { |
|
141 return_value = -5; |
|
142 return; |
|
143 } |
|
144 data_free_flag = FALSE; |
|
145 |
|
146 pending_call_ret_val = return_value; |
|
147 dbus_message_unref(msg1); |
|
148 // free the pending message handle |
|
149 dbus_pending_call_unref(pending); |
|
150 } |
|
151 |
|
152 void free_mem(void* data) |
|
153 { |
|
154 dbus_int32_t* return_value = (dbus_int32_t*)data; |
|
155 var_arg_ret_val = *return_value; |
|
156 free(data); |
|
157 } |
|
158 |
|
159 // ============================ MEMBER FUNCTIONS =============================== |
|
160 |
|
161 int Cstif_1::handle_error(DBusError* error) |
|
162 { |
|
163 iLog->Log(_L8("%s"), error->name); |
|
164 iLog->Log(_L8("%s"), error->message); |
|
165 dbus_error_free(error); |
|
166 return 1; |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // Cstif_1::Delete |
|
171 // Delete here all resources allocated and opened from test methods. |
|
172 // Called from destructor. |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void Cstif_1::Delete() |
|
176 { |
|
177 |
|
178 } |
|
179 TBool TestConnectionEqual(DBusConnection* conn1, DBusConnection* conn2) |
|
180 { |
|
181 return (conn1==conn2? TRUE : FALSE); |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // Cstif_1::RunMethodL |
|
186 // Run specified method. Contains also table of test mothods and their names. |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 TInt Cstif_1::RunMethodL( |
|
190 CStifItemParser& aItem ) |
|
191 { |
|
192 |
|
193 static TStifFunctionInfo const KFunctions[] = |
|
194 { |
|
195 // Copy this line for every implemented function. |
|
196 // First string is the function name used in TestScripter script file. |
|
197 // Second is the actual implementation member function. |
|
198 ENTRY( "stif_Test_Names", Cstif_1::stif_Test_Names ), |
|
199 ENTRY( "stif_Method_Call", Cstif_1::stif_Method_Call ), |
|
200 ENTRY( "stif_N_Connections", Cstif_1::stif_N_Connections ), |
|
201 ENTRY( "stif_Variable_Args", Cstif_1::stif_Variable_Args ), |
|
202 ENTRY( "stif_N_Messages", Cstif_1::stif_N_Messages ), |
|
203 ENTRY( "stif_N_Messages1", Cstif_1::stif_N_Messages1 ), |
|
204 ENTRY( "stif_Signal", Cstif_1::stif_Signal ), |
|
205 ENTRY( "stif_File_Send", Cstif_1::stif_File_Send ), |
|
206 ENTRY( "stif_File_Send_Whole", Cstif_1::stif_File_Send_Whole ), |
|
207 ENTRY( "stif_Match_Rule", Cstif_1::stif_Match_Rule ), |
|
208 ENTRY( "stif_Sign_Test", Cstif_1::stif_Sign_Test ), |
|
209 ENTRY( "stif_N_Separate_Connections", Cstif_1::stif_N_Separate_Connections ), |
|
210 ENTRY( "stif_Pending_Call_Data_Slot0", Cstif_1::stif_Pending_Call_Data_Slot0), |
|
211 ENTRY( "stif_Time0", Cstif_1::stif_Time0), |
|
212 ENTRY( "stif_Simultaneous_Connections", Cstif_1::stif_Simultaneous_Connections), |
|
213 ENTRY( "stif_Daemon_Run_Time0", Cstif_1::stif_Daemon_Run_Time0) |
|
214 |
|
215 //ADD NEW ENTRY HERE |
|
216 // [test cases entries] - Do not remove |
|
217 |
|
218 }; |
|
219 |
|
220 const TInt count = sizeof( KFunctions ) / |
|
221 sizeof( TStifFunctionInfo ); |
|
222 |
|
223 return RunInternalL( KFunctions, count, aItem ); |
|
224 |
|
225 } |
|
226 |
|
227 void Cstif_1::TestName(DBusConnection *connection, const char *name, int expectedSuccess, int* result) |
|
228 { |
|
229 DBusError error; |
|
230 dbus_error_init (&error); |
|
231 |
|
232 (void) dbus_bus_request_name (connection, name, 0, &error); |
|
233 if (dbus_error_is_set (&error)) |
|
234 { |
|
235 if (expectedSuccess) |
|
236 { |
|
237 iLog->Log(_L8("Error acquiring name '%s': %s\n"), name, error.message); |
|
238 *result = 1; |
|
239 } |
|
240 else |
|
241 { |
|
242 iLog->Log(_L8("Expected Error acquiring name '%s': %s\n"), name, error.message); |
|
243 *result = 1; |
|
244 } |
|
245 dbus_error_free (&error); |
|
246 } |
|
247 else |
|
248 { |
|
249 if (!expectedSuccess) |
|
250 { |
|
251 iLog->Log(_L8("Unexpected Success acquiring name '%s'\n"), name); |
|
252 *result = 1; |
|
253 } |
|
254 else |
|
255 iLog->Log(_L8("Successfully acquired name '%s'\n"), name); |
|
256 } |
|
257 } |
|
258 |
|
259 |
|
260 TInt Cstif_1::stif_Test_Names( CStifItemParser& aItem ) |
|
261 { |
|
262 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
263 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
264 |
|
265 |
|
266 DBusError error; |
|
267 DBusConnection *connection; |
|
268 int result = 0; |
|
269 |
|
270 dbus_error_init (&error); |
|
271 connection = dbus_bus_get_private (DBUS_BUS_SESSION, &error); |
|
272 if (connection == NULL) |
|
273 { |
|
274 iLog->Log(_L8("*** Failed to open connection to system bus: %s\n%s"), error.name, error.message); |
|
275 dbus_error_free (&error); |
|
276 return 1; |
|
277 } |
|
278 |
|
279 TestName(connection, "org.freedesktop.DBus.Test", TRUE, &result); |
|
280 TestName(connection, "org.freedesktop.DBus.Test-2", TRUE, &result); |
|
281 TestName(connection, "org.freedesktop.DBus.Test_2", TRUE, &result); |
|
282 #if 0 |
|
283 TestName(connection, "Test_2", TRUE, &result); |
|
284 #endif |
|
285 if(result) |
|
286 return 1; |
|
287 |
|
288 dbus_connection_close(connection); |
|
289 dbus_connection_unref(connection); |
|
290 dbus_shutdown(); |
|
291 |
|
292 iLog->Log(KSuccess); |
|
293 return KErrNone; |
|
294 } |
|
295 |
|
296 |
|
297 TInt Cstif_1::stif_Method_Call( CStifItemParser& aItem ) |
|
298 { |
|
299 |
|
300 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
301 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
302 |
|
303 |
|
304 __UHEAP_MARK; |
|
305 _LIT(KStart, "Test Start"); |
|
306 |
|
307 DBusError error; |
|
308 DBusConnection* connection; |
|
309 DBusMessage* msg; |
|
310 DBusMessageIter args; |
|
311 DBusMessageIter append_args; |
|
312 //~!@#$%^&*()_ . hjgfyh34348#$!%^4567 |
|
313 char* str = "DBus Testing"; |
|
314 char* str1; |
|
315 int i; |
|
316 |
|
317 DBusPendingCall* pending; |
|
318 iLog->Log(KStart); |
|
319 |
|
320 dbus_error_init(&error); |
|
321 |
|
322 iLog->Log(_L8("creating connection")); |
|
323 |
|
324 connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); |
|
325 |
|
326 if(dbus_error_is_set(&error)) |
|
327 return handle_error(&error); |
|
328 |
|
329 iLog->Log(_L8("connection created successfully")); |
|
330 msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", NULL, "method"); |
|
331 |
|
332 if(msg == NULL) |
|
333 { |
|
334 iLog->Log(_L8("message error")); |
|
335 return 1; |
|
336 } |
|
337 iLog->Log(_L8("message created successfully")); |
|
338 |
|
339 dbus_message_iter_init_append(msg, &append_args); |
|
340 for(i=0;i<255;i++) |
|
341 { |
|
342 if(!dbus_message_iter_append_basic(&append_args, DBUS_TYPE_STRING, &str)) |
|
343 { |
|
344 iLog->Log(_L8("Unable to append arguments. msg no. %d")); |
|
345 return 1; |
|
346 } |
|
347 } |
|
348 |
|
349 // send message and get a handle for a reply |
|
350 if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout |
|
351 iLog->Log(_L8("message send error")); |
|
352 exit(1); |
|
353 } |
|
354 if (NULL == pending) { |
|
355 iLog->Log(_L8("pending is null")); |
|
356 exit(1); |
|
357 } |
|
358 dbus_connection_flush(connection); |
|
359 |
|
360 // free message |
|
361 dbus_message_unref(msg); |
|
362 |
|
363 // block until we recieve a reply |
|
364 dbus_pending_call_block(pending); |
|
365 |
|
366 // get the reply message |
|
367 msg = dbus_pending_call_steal_reply(pending); |
|
368 if (NULL == msg) { |
|
369 iLog->Log(_L8("Reply error")); |
|
370 return 1; |
|
371 } |
|
372 // free the pending message handle |
|
373 dbus_pending_call_unref(pending); |
|
374 |
|
375 dbus_error_init (&error); |
|
376 dbus_message_iter_init(msg, &args); |
|
377 i=1; |
|
378 do{ |
|
379 dbus_message_iter_get_basic(&args, &str1); |
|
380 iLog->Log(_L8("%d th Reply = %s"), i, str1); |
|
381 |
|
382 if(strcmp(str, str1)) |
|
383 { |
|
384 iLog->Log(_L8("Invalid reply error")); |
|
385 return 1; |
|
386 } |
|
387 |
|
388 i++; |
|
389 }while(dbus_message_iter_next(&args)); |
|
390 |
|
391 // free reply and close connection |
|
392 dbus_message_unref(msg); |
|
393 |
|
394 dbus_connection_close(connection); |
|
395 dbus_connection_unref(connection); |
|
396 dbus_shutdown(); |
|
397 |
|
398 iLog->Log( KSuccess ); |
|
399 __UHEAP_MARKEND; |
|
400 return KErrNone; |
|
401 } |
|
402 |
|
403 |
|
404 // Currently 21 connections are created If tried more will failed to get connection |
|
405 TInt Cstif_1::stif_N_Connections( CStifItemParser& aItem ) |
|
406 { |
|
407 // __UHEAP_MARK; |
|
408 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
409 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
410 |
|
411 |
|
412 DBusConnection* connection[MAX_CONN]; |
|
413 DBusError error; |
|
414 int cnt=0; |
|
415 int cnt1=0; |
|
416 |
|
417 dbus_error_init(&error); |
|
418 for(cnt=0;cnt<MAX_CONN;cnt++) |
|
419 { |
|
420 connection[cnt] = dbus_bus_get_private(DBUS_BUS_SESSION, &error); |
|
421 if(!connection[cnt] || dbus_error_is_set(&error)) |
|
422 { |
|
423 iLog->Log(_L8("Error_name = %s"), error.name); |
|
424 iLog->Log(_L8("Error_msg = %s"), error.message); |
|
425 break; |
|
426 } |
|
427 else |
|
428 { |
|
429 for(cnt1=0;cnt1<cnt;cnt1++) |
|
430 { |
|
431 if(TestConnectionEqual(connection[cnt], connection[cnt1])) |
|
432 { |
|
433 iLog->Log(_L8("%d and %d Connections are equal."), cnt, cnt1); |
|
434 dbus_connection_close(connection[cnt]); |
|
435 dbus_connection_unref(connection[cnt]); |
|
436 break; |
|
437 } |
|
438 } |
|
439 iLog->Log(_L8("Connection Success %d"), cnt); |
|
440 } |
|
441 } |
|
442 |
|
443 for(cnt1=0;cnt1<cnt;cnt1++) |
|
444 { |
|
445 dbus_connection_close(connection[cnt1]); |
|
446 dbus_connection_unref(connection[cnt1]); |
|
447 } |
|
448 dbus_shutdown(); |
|
449 |
|
450 if(cnt!=MAX_CONN) |
|
451 return 1; |
|
452 iLog->Log(KSuccess); |
|
453 |
|
454 // __UHEAP_MARKEND; |
|
455 return KErrNone; |
|
456 |
|
457 } |
|
458 |
|
459 |
|
460 TInt Cstif_1::stif_Variable_Args( CStifItemParser& aItem ) |
|
461 { |
|
462 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
463 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
464 |
|
465 |
|
466 _LIT(KOOM, "Out Of Memory"); |
|
467 DBusConnection* connection; |
|
468 DBusError error; |
|
469 DBusMessage* msg; |
|
470 DBusMessageIter append_iter; |
|
471 DBusMessageIter sub_iter; |
|
472 DBusPendingCall* pending; |
|
473 |
|
474 dbus_bool_t arg_bool = TRUE; |
|
475 dbus_int16_t arg_int16 = -16; |
|
476 dbus_int32_t arg_int32 = -32; |
|
477 dbus_int64_t arg_int64 = -64; |
|
478 dbus_uint16_t arg_uint16 = 16; |
|
479 dbus_uint32_t arg_uint32 = 32; |
|
480 dbus_uint64_t arg_uint64 = 64; |
|
481 double arg_double = 12.34567; |
|
482 char* arg_str = "DBus Testing"; |
|
483 const dbus_int32_t array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; |
|
484 const dbus_int32_t *arr = array; |
|
485 |
|
486 DBusPendingCallNotifyFunction reply_handler; |
|
487 DBusFreeFunction free_data; |
|
488 dbus_int32_t* return_value; |
|
489 |
|
490 dbus_error_init(&error); |
|
491 |
|
492 connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); |
|
493 if(!connection) |
|
494 return handle_error(&error); |
|
495 |
|
496 msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "variable_args_method"); |
|
497 if(msg == NULL) |
|
498 { |
|
499 iLog->Log(_L8("message error")); |
|
500 return 1; |
|
501 } |
|
502 iLog->Log(_L8("message created successfully")); |
|
503 |
|
504 dbus_message_iter_init_append(msg, &append_iter); |
|
505 |
|
506 if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_BOOLEAN, &arg_bool)) |
|
507 { |
|
508 iLog->Log(KOOM); |
|
509 return 1; |
|
510 } |
|
511 if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_INT16, &arg_int16)) |
|
512 { |
|
513 iLog->Log(KOOM); |
|
514 return 1; |
|
515 } |
|
516 if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_INT32, &arg_int32)) |
|
517 { |
|
518 iLog->Log(KOOM); |
|
519 return 1; |
|
520 } |
|
521 if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_INT64, &arg_int64)) |
|
522 { |
|
523 iLog->Log(KOOM); |
|
524 return 1; |
|
525 } |
|
526 if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_UINT16, &arg_uint16)) |
|
527 { |
|
528 iLog->Log(KOOM); |
|
529 return 1; |
|
530 } |
|
531 if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_UINT32, &arg_uint32)) |
|
532 { |
|
533 iLog->Log(KOOM); |
|
534 return 1; |
|
535 } |
|
536 if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_UINT64, &arg_uint64)) |
|
537 { |
|
538 iLog->Log(KOOM); |
|
539 return 1; |
|
540 } |
|
541 if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_DOUBLE, &arg_double)) |
|
542 { |
|
543 iLog->Log(KOOM); |
|
544 return 1; |
|
545 } |
|
546 |
|
547 if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_STRING, &arg_str)) |
|
548 { |
|
549 iLog->Log(KOOM); |
|
550 return 1; |
|
551 } |
|
552 |
|
553 // For Array |
|
554 if(!dbus_message_iter_open_container(&append_iter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &sub_iter)) |
|
555 { |
|
556 iLog->Log(KOOM); |
|
557 return 1; |
|
558 } |
|
559 if(!dbus_message_iter_append_fixed_array(&sub_iter, DBUS_TYPE_INT32, &arr, 10)) |
|
560 { |
|
561 iLog->Log(KOOM); |
|
562 return 1; |
|
563 } |
|
564 dbus_message_iter_close_container(&append_iter, &sub_iter); |
|
565 |
|
566 |
|
567 //For Structure |
|
568 if(!dbus_message_iter_open_container(&append_iter, DBUS_TYPE_STRUCT, NULL, &sub_iter)) |
|
569 { |
|
570 iLog->Log(KOOM); |
|
571 return 1; |
|
572 } |
|
573 if(!dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_INT32, &arg_int32)) |
|
574 { |
|
575 iLog->Log(KOOM); |
|
576 return 1; |
|
577 } |
|
578 if(!dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_STRING, &arg_str)) |
|
579 { |
|
580 iLog->Log(KOOM); |
|
581 return 1; |
|
582 } |
|
583 if(!dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_DOUBLE, &arg_double)) |
|
584 { |
|
585 iLog->Log(KOOM); |
|
586 return 1; |
|
587 } |
|
588 dbus_message_iter_close_container(&append_iter, &sub_iter); |
|
589 |
|
590 |
|
591 |
|
592 // send message and get a handle for a reply |
|
593 if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout |
|
594 iLog->Log(_L8("message send error")); |
|
595 exit(1); |
|
596 } |
|
597 if (NULL == pending) { |
|
598 iLog->Log(_L8("pending is null")); |
|
599 exit(1); |
|
600 } |
|
601 dbus_connection_flush(connection); |
|
602 |
|
603 // free message |
|
604 dbus_message_unref(msg); |
|
605 |
|
606 reply_handler = handle_reply_variable_args; |
|
607 return_value = (dbus_int32_t*)malloc(sizeof(dbus_int32_t)); |
|
608 free_data = free_mem; |
|
609 dbus_pending_call_set_notify(pending, reply_handler, return_value, free_data); |
|
610 |
|
611 |
|
612 // block until we recieve a reply |
|
613 dbus_pending_call_block(pending); |
|
614 |
|
615 iLog->Log(_L8("Reply = %d"), var_arg_ret_val); |
|
616 switch(var_arg_ret_val) |
|
617 { |
|
618 case 0: |
|
619 break; |
|
620 case -2: |
|
621 iLog->Log(_L8("Error while stealing reply from pending call")); |
|
622 return 1; |
|
623 case -3: |
|
624 iLog->Log(_L8("free_data function not called.")); |
|
625 return 1; |
|
626 default: |
|
627 iLog->Log(_L8("Undefined return value")); |
|
628 return 1; |
|
629 } |
|
630 |
|
631 dbus_connection_close(connection); |
|
632 dbus_connection_unref(connection); |
|
633 dbus_shutdown(); |
|
634 |
|
635 iLog->Log( KSuccess ); |
|
636 return KErrNone; |
|
637 } |
|
638 |
|
639 |
|
640 static void* send_msg(void* data) |
|
641 { |
|
642 threadData* thrData = (threadData*)data; |
|
643 |
|
644 pthread_mutex_lock(&thrData->mutex); |
|
645 |
|
646 //static int cnt = 1; |
|
647 dbus_int32_t no = 5; |
|
648 DBusPendingCall* pending; |
|
649 DBusMessage* msg1; |
|
650 DBusMessage* msg; |
|
651 DBusError error; |
|
652 |
|
653 msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "simple"); |
|
654 |
|
655 dbus_message_append_args(msg, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID); |
|
656 |
|
657 pthread_cond_wait(&thrData->cond, &thrData->mutex); |
|
658 |
|
659 // send message and get a handle for a reply |
|
660 if (!dbus_connection_send_with_reply (thrData->connection, msg, &pending, -1)) { // -1 is default timeout |
|
661 thrData->ret = 2; |
|
662 } |
|
663 |
|
664 if (NULL == pending) { |
|
665 thrData->ret = 2; |
|
666 } |
|
667 dbus_connection_flush(thrData->connection); |
|
668 |
|
669 // free message |
|
670 dbus_message_unref(msg); |
|
671 |
|
672 // block until we recieve a reply |
|
673 dbus_pending_call_block(pending); |
|
674 |
|
675 // get the reply message |
|
676 msg1 = dbus_pending_call_steal_reply(pending); |
|
677 if (NULL == msg1) { |
|
678 thrData->ret = 2; |
|
679 |
|
680 } |
|
681 // free the pending message handle |
|
682 dbus_pending_call_unref(pending); |
|
683 |
|
684 dbus_error_init(&error); |
|
685 dbus_message_get_args(msg1, &error, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID); |
|
686 |
|
687 FILE* fp = fopen("C:\\new.txt", "a+"); |
|
688 fprintf(fp, "%d\n", no); |
|
689 fclose(fp); |
|
690 |
|
691 if(no == 9090) |
|
692 { |
|
693 thrData->ret++; |
|
694 } |
|
695 |
|
696 |
|
697 // free reply and close connection |
|
698 dbus_message_unref(msg1); |
|
699 pthread_mutex_unlock(&thrData->mutex); |
|
700 return NULL; |
|
701 } |
|
702 |
|
703 |
|
704 TInt Cstif_1::stif_N_Messages( CStifItemParser& aItem ) |
|
705 { |
|
706 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
707 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
708 |
|
709 |
|
710 DBusError error; |
|
711 char err[80]; |
|
712 int cnt; |
|
713 |
|
714 pthread_t thread[MAX_THREAD]; |
|
715 int thrVal[MAX_THREAD]={0}; |
|
716 void* thrValPtr[MAX_THREAD]; |
|
717 |
|
718 for(cnt=0; cnt<MAX_THREAD; cnt++) |
|
719 thrValPtr[cnt] = (void*)&thrVal[cnt]; |
|
720 |
|
721 threadData thrData; |
|
722 |
|
723 dbus_error_init(&error); |
|
724 thrData.connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); |
|
725 if(!thrData.connection || dbus_error_is_set(&error)) |
|
726 return handle_error(&error); |
|
727 |
|
728 pthread_mutex_init(&thrData.mutex, NULL); |
|
729 pthread_cond_init(&thrData.cond, NULL); |
|
730 thrData.ret = 0; |
|
731 |
|
732 for(cnt=0; cnt<MAX_THREAD; cnt++) |
|
733 pthread_create(&thread[cnt], NULL, &send_msg, &thrData); |
|
734 |
|
735 sleep(1); |
|
736 |
|
737 pthread_cond_broadcast(&thrData.cond); |
|
738 |
|
739 for(cnt=0; cnt<MAX_THREAD; cnt++) |
|
740 pthread_join(thread[cnt], &thrValPtr[cnt]); |
|
741 |
|
742 if(thrData.ret != MAX_THREAD) |
|
743 { |
|
744 sprintf(err, "No. of threads crashed %d", (MAX_THREAD - thrData.ret)); |
|
745 iLog->Log(_L8(err)); |
|
746 return 1; |
|
747 } |
|
748 |
|
749 dbus_connection_close(thrData.connection); |
|
750 dbus_connection_unref(thrData.connection); |
|
751 dbus_shutdown(); |
|
752 |
|
753 iLog->Log(KSuccess); |
|
754 return KErrNone; |
|
755 } |
|
756 |
|
757 static void* send_msg1(void* data) |
|
758 { |
|
759 DBusConnection* connection; |
|
760 DBusError error; |
|
761 //static int cnt = 1; |
|
762 dbus_int32_t no = 5; |
|
763 DBusPendingCall* pending; |
|
764 DBusMessage* msg1; |
|
765 DBusMessage* msg; |
|
766 int data_slot = *(int*)data; |
|
767 |
|
768 dbus_error_init(&error); |
|
769 connection = dbus_bus_get(DBUS_BUS_SESSION, &error); |
|
770 |
|
771 threadData1* thrData = (threadData1*)dbus_connection_get_data(connection, data_slot); |
|
772 if(!thrData) |
|
773 return NULL; |
|
774 |
|
775 pthread_mutex_lock(&thrData->mutex); |
|
776 |
|
777 msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "simple"); |
|
778 |
|
779 dbus_message_append_args(msg, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID); |
|
780 |
|
781 pthread_cond_wait(&thrData->cond, &thrData->mutex); |
|
782 |
|
783 // send message and get a handle for a reply |
|
784 if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout |
|
785 thrData->ret = 2; |
|
786 // exit(1); |
|
787 } |
|
788 if (NULL == pending) { |
|
789 thrData->ret = 2; |
|
790 // exit(1); |
|
791 } |
|
792 dbus_connection_flush(connection); |
|
793 |
|
794 // free message |
|
795 dbus_message_unref(msg); |
|
796 |
|
797 // block until we recieve a reply |
|
798 dbus_pending_call_block(pending); |
|
799 |
|
800 // get the reply message |
|
801 msg1 = dbus_pending_call_steal_reply(pending); |
|
802 if (NULL == msg1) { |
|
803 thrData->ret = 2; |
|
804 |
|
805 } |
|
806 // free the pending message handle |
|
807 dbus_pending_call_unref(pending); |
|
808 |
|
809 |
|
810 dbus_message_get_args(msg1, &error, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID); |
|
811 |
|
812 FILE* fp = fopen("C:\\new.txt", "a+"); |
|
813 fprintf(fp, "%d\n", no); |
|
814 fclose(fp); |
|
815 |
|
816 if(no == 9090) |
|
817 { |
|
818 thrData->ret++; |
|
819 } |
|
820 |
|
821 |
|
822 // free reply and close connection |
|
823 dbus_message_unref(msg1); |
|
824 dbus_connection_unref(connection); |
|
825 pthread_mutex_unlock(&thrData->mutex); |
|
826 return NULL; |
|
827 } |
|
828 |
|
829 TInt Cstif_1::stif_N_Messages1( CStifItemParser& aItem ) |
|
830 { |
|
831 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
832 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
833 |
|
834 |
|
835 DBusConnection* connection; |
|
836 DBusError error; |
|
837 int cnt; |
|
838 int data_slot = -1; |
|
839 |
|
840 pthread_t thread[MAX_THREAD]; |
|
841 int thrVal[MAX_THREAD]={0}; |
|
842 void* thrValPtr[MAX_THREAD]; |
|
843 |
|
844 for(cnt=0; cnt<MAX_THREAD; cnt++) |
|
845 thrValPtr[cnt] = (void*)&thrVal[cnt]; |
|
846 |
|
847 threadData1 thrData; |
|
848 |
|
849 dbus_error_init(&error); |
|
850 connection = dbus_bus_get(DBUS_BUS_SESSION, &error); |
|
851 if(!connection || dbus_error_is_set(&error)) |
|
852 return handle_error(&error); |
|
853 |
|
854 pthread_mutex_init(&thrData.mutex, NULL); |
|
855 pthread_cond_init(&thrData.cond, NULL); |
|
856 thrData.ret = 0; |
|
857 |
|
858 dbus_connection_allocate_data_slot(&data_slot); |
|
859 dbus_connection_set_data(connection, data_slot, &thrData, NULL); |
|
860 |
|
861 dbus_threads_init_default(); |
|
862 |
|
863 for(cnt=0; cnt<MAX_THREAD; cnt++) |
|
864 pthread_create(&thread[cnt], NULL, &send_msg1, &data_slot); |
|
865 |
|
866 sleep(1); |
|
867 |
|
868 pthread_cond_broadcast(&thrData.cond); |
|
869 |
|
870 for(cnt=0; cnt<MAX_THREAD; cnt++) |
|
871 pthread_join(thread[cnt], &thrValPtr[cnt]); |
|
872 |
|
873 if(thrData.ret != MAX_THREAD) |
|
874 { |
|
875 iLog->Log(_L8("No. of threads crashed %d"), (MAX_THREAD - thrData.ret)); |
|
876 return 1; |
|
877 } |
|
878 |
|
879 dbus_connection_unref(connection); |
|
880 |
|
881 iLog->Log(KSuccess); |
|
882 return KErrNone; |
|
883 } |
|
884 |
|
885 |
|
886 TInt Cstif_1::stif_Signal( CStifItemParser& aItem ) |
|
887 { |
|
888 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
889 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
890 |
|
891 |
|
892 DBusConnection* connection; |
|
893 DBusError error; |
|
894 DBusMessage* msg; |
|
895 //dbus_int32_t arg_int32 = 1010; |
|
896 DBusObjectPathVTable vtable = |
|
897 { |
|
898 NULL,NULL,NULL |
|
899 }; |
|
900 char* str = "DBus Testing. hjgfyh34348#$!%^45678901730952698376092869876DBus Testing. hjgfyh34348#$!%^~!@#$%^&*()_+`-=<>?:{},./;'[]45678901730952698376092869876"; |
|
901 FILE* fp[MAX_SIGNALS]={NULL}; |
|
902 |
|
903 int cnt=0; |
|
904 char exe_param[100]; |
|
905 char names[][40]={"test.Signal.Send3 ", |
|
906 "test.Signal.Send4 ", |
|
907 "test.Signal.Send5 "}; |
|
908 char obj_path[][40]={"/Test/Signal/Object3", |
|
909 "/Test/Signal/Object4", |
|
910 "/Test/Signal/Object5"}; |
|
911 |
|
912 for(cnt=0;cnt< MAX_SIGNALS;cnt++) |
|
913 { |
|
914 #if defined(__WINSCW__) || defined(__WINS__) |
|
915 strcpy(exe_param,"Z:\\sys\\bin\\Simple_Server.exe "); |
|
916 #else |
|
917 strcpy(exe_param,"C:\\sys\\bin\\Simple_Server.exe "); |
|
918 #endif |
|
919 strcat(exe_param, names[cnt]); |
|
920 strcat(exe_param, obj_path[cnt]); |
|
921 fp[cnt] = popen(exe_param, "r"); |
|
922 if(!fp[cnt]) |
|
923 { |
|
924 iLog->Log(_L8("fp %d is NULL"), cnt); |
|
925 return 1; |
|
926 } |
|
927 //User::After(3000000); |
|
928 } |
|
929 |
|
930 //User::After(3000000); |
|
931 |
|
932 dbus_error_init(&error); |
|
933 connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); |
|
934 |
|
935 if(!connection || dbus_error_is_set(&error)) |
|
936 return handle_error(&error); |
|
937 |
|
938 msg = dbus_message_new_signal("/Test/Signal/Object", "Test.Signal.Send", "first"); |
|
939 |
|
940 sleep(2); |
|
941 if(!msg) |
|
942 { |
|
943 iLog->Log(_L8("msg is NULL")); |
|
944 return 1; |
|
945 } |
|
946 |
|
947 if(!dbus_message_append_args(msg, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID)) |
|
948 { |
|
949 iLog->Log(_L8("Fail to append args")); |
|
950 return 1; |
|
951 } |
|
952 |
|
953 dbus_connection_send(connection, msg, NULL); |
|
954 dbus_connection_flush(connection); |
|
955 |
|
956 dbus_message_unref(msg); |
|
957 |
|
958 str = ""; |
|
959 iLog->Log(_L8("First part over")); |
|
960 |
|
961 dbus_bus_add_match(connection, "type='signal',interface='Test.Signal.Send1'",&error); |
|
962 |
|
963 if(dbus_error_is_set(&error)) |
|
964 return handle_error(&error); |
|
965 |
|
966 iLog->Log(_L8("Registering path")); |
|
967 if(!dbus_connection_register_object_path (connection, "/Test/Signal/Object1", &vtable, NULL)) |
|
968 { |
|
969 iLog->Log(_L8("Registering path fail")); |
|
970 return 1; |
|
971 } |
|
972 iLog->Log(_L8("Requesting name")); |
|
973 if(!dbus_bus_request_name (connection, "test.Signal.Send1", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &error) == (unsigned int)-1) |
|
974 { |
|
975 iLog->Log(_L8("Requesting name fail")); |
|
976 return 1; |
|
977 } |
|
978 |
|
979 iLog->Log(_L8("Starting while loop")); |
|
980 cnt=0; |
|
981 while(TRUE) |
|
982 { |
|
983 dbus_connection_read_write(connection, 0); |
|
984 |
|
985 msg = dbus_connection_pop_message(connection); |
|
986 |
|
987 if(msg == NULL) |
|
988 { |
|
989 continue; |
|
990 } |
|
991 |
|
992 iLog->Log(_L8("Message Detected")); |
|
993 |
|
994 if(dbus_message_is_signal(msg, "Test.Signal.Send1", "second")) |
|
995 { |
|
996 if(!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID)) |
|
997 { |
|
998 iLog->Log(_L8("Error while retriving arguments :: %s"), error.name); |
|
999 dbus_error_free(&error); |
|
1000 return 1; |
|
1001 } |
|
1002 iLog->Log(_L8("Got %d MSG : %s"), cnt, str); |
|
1003 cnt++; |
|
1004 if(cnt==MAX_SIGNALS) |
|
1005 break; |
|
1006 } |
|
1007 |
|
1008 dbus_message_unref(msg); |
|
1009 } |
|
1010 |
|
1011 dbus_connection_close(connection); |
|
1012 dbus_connection_unref(connection); |
|
1013 dbus_shutdown(); |
|
1014 for(cnt=0;cnt<MAX_SIGNALS;cnt++) |
|
1015 if(fp[cnt]) |
|
1016 pclose(fp[cnt]); |
|
1017 |
|
1018 iLog->Log(KSuccess); |
|
1019 return KErrNone; |
|
1020 } |
|
1021 |
|
1022 |
|
1023 TInt Cstif_1::stif_File_Send( CStifItemParser& aItem ) |
|
1024 { |
|
1025 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
1026 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
1027 |
|
1028 |
|
1029 //_LIT(KOOM, "Out Of Memory"); |
|
1030 FILE* fp; |
|
1031 unsigned char arr[200]; |
|
1032 const unsigned char* p_arr = arr; |
|
1033 DBusError error; |
|
1034 DBusConnection* connection; |
|
1035 DBusMessage* msg; |
|
1036 int num; |
|
1037 |
|
1038 dbus_error_init(&error); |
|
1039 |
|
1040 connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); |
|
1041 |
|
1042 if(!connection || dbus_error_is_set(&error)) |
|
1043 return handle_error(&error); |
|
1044 |
|
1045 fp = fopen("c:\\bunbask1.jpg", "r"); |
|
1046 if(!fp) |
|
1047 { |
|
1048 iLog->Log(_L8("Not able to open File")); |
|
1049 return 1; |
|
1050 } |
|
1051 int i=0; |
|
1052 while (!feof(fp)) |
|
1053 { |
|
1054 num = fread(&arr, sizeof(unsigned char), 200, fp); |
|
1055 i++; |
|
1056 |
|
1057 msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "file_send"); |
|
1058 if(!msg) |
|
1059 { |
|
1060 iLog->Log(_L8("msg is NULL.")); |
|
1061 return 1; |
|
1062 } |
|
1063 |
|
1064 iLog->Log(_L8("msg is created")); |
|
1065 |
|
1066 iLog->Log(_L8("num = %d"), num); |
|
1067 if(!dbus_message_append_args(msg, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &p_arr, num, DBUS_TYPE_INVALID)) |
|
1068 { |
|
1069 iLog->Log(_L8("Fail to append ARRAY.")); |
|
1070 return 1; |
|
1071 } |
|
1072 |
|
1073 iLog->Log(_L8("Array Appended")); |
|
1074 dbus_connection_send(connection, msg, NULL); |
|
1075 dbus_connection_flush(connection); |
|
1076 |
|
1077 dbus_message_unref(msg); |
|
1078 msg=NULL; |
|
1079 } |
|
1080 if(fp) |
|
1081 fclose(fp); |
|
1082 |
|
1083 dbus_connection_close(connection); |
|
1084 dbus_connection_unref(connection); |
|
1085 dbus_shutdown(); |
|
1086 return KErrNone; |
|
1087 } |
|
1088 |
|
1089 TInt Cstif_1::stif_File_Send_Whole( CStifItemParser& aItem ) |
|
1090 { |
|
1091 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
1092 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
1093 |
|
1094 |
|
1095 FILE* fp; |
|
1096 int ret =0; |
|
1097 |
|
1098 #if defined(__WINSCW__) || defined(__WINS__) |
|
1099 fp = popen("Z:\\sys\\bin\\file_send_whole.exe", "r"); |
|
1100 #else |
|
1101 fp = popen("C:\\sys\\bin\\file_send_whole.exe", "r"); |
|
1102 #endif |
|
1103 if(!fp) |
|
1104 { |
|
1105 iLog->Log(_L8("Failed to open file_send_whole.exe")); |
|
1106 return 1; |
|
1107 } |
|
1108 |
|
1109 ret = pclose(fp); |
|
1110 if(ret) |
|
1111 { |
|
1112 iLog->Log(_L8("Test Fail")); |
|
1113 return 1; |
|
1114 } |
|
1115 iLog->Log(KSuccess); |
|
1116 return KErrNone; |
|
1117 } |
|
1118 |
|
1119 |
|
1120 int Cstif_1::send_message(DBusConnection* connection, char* path, char* iface, char* member) |
|
1121 { |
|
1122 DBusMessage* msg; |
|
1123 char* str = "DBus Testing."; |
|
1124 |
|
1125 msg = dbus_message_new_signal(path, iface, member); |
|
1126 |
|
1127 if(!msg) |
|
1128 { |
|
1129 iLog->Log(_L8("msg is NULL")); |
|
1130 return 1; |
|
1131 } |
|
1132 |
|
1133 if(!dbus_message_append_args(msg, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID)) |
|
1134 { |
|
1135 iLog->Log(_L8("Fail to append args")); |
|
1136 return 1; |
|
1137 } |
|
1138 |
|
1139 dbus_connection_send(connection, msg, NULL); |
|
1140 dbus_connection_flush(connection); |
|
1141 dbus_message_unref(msg); |
|
1142 return 0; |
|
1143 } |
|
1144 |
|
1145 |
|
1146 TInt Cstif_1::stif_Match_Rule( CStifItemParser& aItem ) |
|
1147 { |
|
1148 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
1149 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
1150 |
|
1151 |
|
1152 DBusConnection* connection; |
|
1153 DBusError error; |
|
1154 DBusMessage* msg; |
|
1155 char* str; |
|
1156 DBusObjectPathVTable vtable ={ |
|
1157 NULL, |
|
1158 NULL, |
|
1159 NULL, |
|
1160 }; |
|
1161 char buf[180] = ""; |
|
1162 FILE* fp = NULL; |
|
1163 |
|
1164 const char* fifopath = "C:\\mkfifo1.file"; |
|
1165 int err; |
|
1166 err = mkfifo (fifopath, 0666); |
|
1167 if(err != 0) |
|
1168 { |
|
1169 // probably file already exists, delete the file |
|
1170 unlink(fifopath); |
|
1171 // try once more.. |
|
1172 err = mkfifo (fifopath, 0666); |
|
1173 if(err != 0) |
|
1174 { |
|
1175 return 1; |
|
1176 } |
|
1177 } |
|
1178 |
|
1179 #if defined(__WINSCW__) || defined(__WINS__) |
|
1180 fp = popen("Z:\\sys\\bin\\match_rule_server.exe", "r"); |
|
1181 #else |
|
1182 fp = popen("C:\\sys\\bin\\match_rule_server.exe", "r"); |
|
1183 #endif |
|
1184 if(!fp) |
|
1185 iLog->Log(_L8("fp is NULL")); |
|
1186 |
|
1187 |
|
1188 int fd = open(fifopath, O_RDONLY); |
|
1189 if(fd > 0) |
|
1190 { |
|
1191 err = read (fd, buf, 20); |
|
1192 close(fd); |
|
1193 } |
|
1194 else |
|
1195 { |
|
1196 iLog->Log(_L8("Error in FIFO open().")); |
|
1197 return 1; |
|
1198 } |
|
1199 unlink(fifopath); |
|
1200 if(strcmp("done", buf)) |
|
1201 { |
|
1202 iLog->Log(_L8("done is not returned from server.")); |
|
1203 return 1; |
|
1204 } |
|
1205 |
|
1206 dbus_error_init(&error); |
|
1207 connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); |
|
1208 |
|
1209 if(!connection || dbus_error_is_set(&error)) |
|
1210 return handle_error(&error); |
|
1211 |
|
1212 send_message(connection, "/Test/Signal/Object", "Test.Signal.Send2", "first"); |
|
1213 |
|
1214 iLog->Log(_L8("First part over")); |
|
1215 |
|
1216 dbus_bus_add_match(connection, "type='signal',interface='Test.Signal.Send3'",&error); |
|
1217 |
|
1218 if(dbus_error_is_set(&error)) |
|
1219 return handle_error(&error); |
|
1220 |
|
1221 iLog->Log(_L8("Registering path")); |
|
1222 if(!dbus_connection_register_object_path (connection, "/Test/Signal/Object1", &vtable, NULL)) |
|
1223 { |
|
1224 iLog->Log(_L8("Registering path fail")); |
|
1225 return 1; |
|
1226 } |
|
1227 iLog->Log(_L8("Requesting name")); |
|
1228 |
|
1229 if(!dbus_bus_request_name (connection, "test.Signal.Send1", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &error) == (unsigned int)-1) |
|
1230 { |
|
1231 iLog->Log(_L8("Requesting name fail")); |
|
1232 return 1; |
|
1233 } |
|
1234 |
|
1235 iLog->Log(_L8("Starting while loop")); |
|
1236 while(TRUE) |
|
1237 { |
|
1238 dbus_connection_read_write(connection, 0); |
|
1239 |
|
1240 msg = dbus_connection_pop_message(connection); |
|
1241 |
|
1242 if(msg == NULL) |
|
1243 { |
|
1244 continue; |
|
1245 } |
|
1246 |
|
1247 iLog->Log(_L8("Message Detected")); |
|
1248 |
|
1249 if(dbus_message_is_signal(msg, "Test.Signal.Send3", "second")) |
|
1250 { |
|
1251 if(!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID)) |
|
1252 { |
|
1253 dbus_error_free(&error); |
|
1254 return 1; |
|
1255 } |
|
1256 iLog->Log(_L8("Got MSG : %s"), str); |
|
1257 break; |
|
1258 } |
|
1259 |
|
1260 dbus_message_unref(msg); |
|
1261 } |
|
1262 |
|
1263 // sleep(2); |
|
1264 send_message(connection, "/Test/Signal/Object", "Test.Signal.Send2", "third"); |
|
1265 send_message(connection, "/Test/Signal/Object", "Test.Signal.Send2", "first"); |
|
1266 send_message(connection, "/Test/Signal/Object", "Test.Signal.Send2", "third"); |
|
1267 |
|
1268 while(TRUE) |
|
1269 { |
|
1270 dbus_connection_read_write(connection, 0); |
|
1271 msg = dbus_connection_pop_message(connection); |
|
1272 if(!msg) |
|
1273 continue; |
|
1274 if(!dbus_message_has_destination(msg, "test.Signal.Send1")) |
|
1275 { |
|
1276 iLog->Log(_L8("dbus_message_has_destination() failed to check Destination.")); |
|
1277 return 1; |
|
1278 } |
|
1279 |
|
1280 if(dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_ERROR) |
|
1281 { |
|
1282 iLog->Log(_L8("Error is returned.")); |
|
1283 if(!dbus_message_has_member(msg, "error")) |
|
1284 iLog->Log(_L8("dbus_message_has_destination() failed to check Destination.")); |
|
1285 return 1; |
|
1286 } |
|
1287 else if(dbus_message_get_type(msg) == DBUS_MESSAGE_TYPE_METHOD_CALL) |
|
1288 { |
|
1289 iLog->Log(_L8("Method call is returned.")); |
|
1290 if(!dbus_message_has_member(msg, "success")) |
|
1291 { |
|
1292 iLog->Log(_L8("dbus_message_has_destination() failed to check Destination.")); |
|
1293 return 1; |
|
1294 } |
|
1295 break; |
|
1296 } |
|
1297 |
|
1298 } |
|
1299 dbus_connection_close(connection); |
|
1300 dbus_connection_unref(connection); |
|
1301 dbus_shutdown(); |
|
1302 if(fp) |
|
1303 pclose(fp); |
|
1304 |
|
1305 iLog->Log(KSuccess); |
|
1306 return KErrNone; |
|
1307 } |
|
1308 |
|
1309 TInt Cstif_1::stif_Sign_Test( CStifItemParser& aItem ) |
|
1310 { |
|
1311 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
1312 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
1313 |
|
1314 |
|
1315 DBusConnection* connection; |
|
1316 DBusError error; |
|
1317 DBusMessage* msg; |
|
1318 DBusMessage* reply = NULL; |
|
1319 dbus_int32_t int_32 = -32; |
|
1320 double d = 1.1234; |
|
1321 char* str = "DBus Testing"; |
|
1322 const char* sign; |
|
1323 const char* sub_sign; |
|
1324 const char* iter_sign; |
|
1325 const char* iter_sign1; |
|
1326 dbus_int32_t type; |
|
1327 dbus_int32_t arr[] = {0,1,2,3,4,5,6,7,8,9}; |
|
1328 dbus_int32_t* v_arr = arr; |
|
1329 DBusMessageIter iter; |
|
1330 DBusMessageIter sub_iter; |
|
1331 DBusMessageIter sub_iter1; |
|
1332 struct SignTest |
|
1333 { |
|
1334 int num1; |
|
1335 int num2; |
|
1336 int num3; |
|
1337 }st; |
|
1338 |
|
1339 dbus_error_init(&error); |
|
1340 connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); |
|
1341 if(!connection || dbus_error_is_set(&error)) |
|
1342 return handle_error(&error); |
|
1343 |
|
1344 msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", NULL, "sign_test"); |
|
1345 if(!msg) |
|
1346 { |
|
1347 iLog->Log(_L8("msg is NULL")); |
|
1348 return 1; |
|
1349 } |
|
1350 |
|
1351 st.num1 = 100; |
|
1352 st.num2 = 200; |
|
1353 st.num3 = 300; |
|
1354 |
|
1355 dbus_message_iter_init_append(msg, &iter); |
|
1356 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &int_32); |
|
1357 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &str); |
|
1358 dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, NULL, &sub_iter); |
|
1359 dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_INT32, &st.num1); |
|
1360 dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_INT32, &st.num2); |
|
1361 dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_INT32, &st.num3); |
|
1362 dbus_message_iter_close_container(&iter, &sub_iter); |
|
1363 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_INT32_AS_STRING, &sub_iter1); |
|
1364 dbus_message_iter_append_fixed_array(&sub_iter1, DBUS_TYPE_INT32, &v_arr, 10); |
|
1365 dbus_message_iter_close_container(&iter, &sub_iter1); |
|
1366 dbus_message_iter_append_basic(&iter, DBUS_TYPE_DOUBLE, &d); |
|
1367 |
|
1368 reply = dbus_connection_send_with_reply_and_block(connection, msg, 10000, &error); |
|
1369 if(!reply) |
|
1370 return handle_error(&error); |
|
1371 |
|
1372 if(!dbus_message_get_args(reply, &error, DBUS_TYPE_SIGNATURE, &sign, DBUS_TYPE_SIGNATURE, &sub_sign, DBUS_TYPE_INT32, &type, DBUS_TYPE_SIGNATURE, &iter_sign, DBUS_TYPE_SIGNATURE, &iter_sign1, DBUS_TYPE_INVALID)) |
|
1373 return handle_error(&error); |
|
1374 |
|
1375 iLog->Log(_L8("Signature :: %s\n\tSubSignature :: %s\n\tType :: %c\n\tMessageIterSignature :: %s\n\tMessageIterSignature1 :: %s"), sign, sub_sign, type, iter_sign, iter_sign1); |
|
1376 if(!dbus_message_has_signature(msg, sign)) |
|
1377 { |
|
1378 iLog->Log(_L8("Signature returned is not correct.")); |
|
1379 return 1; |
|
1380 } |
|
1381 if(strcmp("i", iter_sign)) |
|
1382 { |
|
1383 iLog->Log(_L8("Signature returned is not correct.")); |
|
1384 return 1; |
|
1385 } |
|
1386 if(strcmp("(iii)", sub_sign)) |
|
1387 { |
|
1388 iLog->Log(_L8("SubSignature returned is not correct.")); |
|
1389 return 1; |
|
1390 } |
|
1391 if(strcmp("(iii)", iter_sign1)) |
|
1392 { |
|
1393 iLog->Log(_L8("SubSignature returned is not correct.")); |
|
1394 return 1; |
|
1395 } |
|
1396 if('i' != type) |
|
1397 { |
|
1398 iLog->Log(_L8("type returned is not correct")); |
|
1399 return 1; |
|
1400 } |
|
1401 |
|
1402 dbus_message_unref(msg); |
|
1403 dbus_message_unref(reply); |
|
1404 |
|
1405 dbus_connection_close(connection); |
|
1406 dbus_connection_unref(connection); |
|
1407 dbus_shutdown(); |
|
1408 |
|
1409 iLog->Log(KSuccess); |
|
1410 return KErrNone; |
|
1411 } |
|
1412 |
|
1413 |
|
1414 |
|
1415 TInt Cstif_1::stif_N_Separate_Connections( CStifItemParser& aItem ) |
|
1416 { |
|
1417 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
1418 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
1419 |
|
1420 const char* fifopath = "C:\\mkfifo.file"; |
|
1421 int cnt =0; |
|
1422 int err =0; |
|
1423 int fd; |
|
1424 char buf[20] = {NULL}; |
|
1425 pid_t pid; |
|
1426 |
|
1427 err = mkfifo (fifopath, 0666); |
|
1428 if(err != 0) |
|
1429 { |
|
1430 // probably file already exists, delete the file |
|
1431 unlink(fifopath); |
|
1432 // try once more.. |
|
1433 err = mkfifo (fifopath, 0666); |
|
1434 if(err != 0) |
|
1435 { |
|
1436 return 1; |
|
1437 } |
|
1438 } |
|
1439 |
|
1440 for(cnt=0; cnt<MAX_CONN_EXE; cnt++) |
|
1441 { |
|
1442 #if defined(__WINSCW__) || defined(__WINS__) |
|
1443 posix_spawn(&pid, "Z:\\sys\\bin\\private_connection.exe", NULL, NULL, NULL, NULL); |
|
1444 #else |
|
1445 posix_spawn(&pid, "C:\\sys\\bin\\private_connection.exe", NULL, NULL, NULL, NULL); |
|
1446 #endif |
|
1447 fd = open(fifopath, O_RDONLY); |
|
1448 if(fd > 0) |
|
1449 { |
|
1450 err = read (fd, buf, 20); |
|
1451 close(fd); |
|
1452 iLog->Log(_L8("%d :: %s"), cnt, buf); |
|
1453 if(!strcmp("Error Occured", buf)) |
|
1454 { |
|
1455 iLog->Log(_L8("Error at %d EXE"), cnt); |
|
1456 return 1; |
|
1457 } |
|
1458 } |
|
1459 } |
|
1460 |
|
1461 unlink(fifopath); |
|
1462 |
|
1463 return KErrNone; |
|
1464 } |
|
1465 |
|
1466 TInt Cstif_1::stif_Pending_Call_Data_Slot0( CStifItemParser& aItem ) |
|
1467 { |
|
1468 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
1469 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
1470 |
|
1471 |
|
1472 DBusConnection* connection; |
|
1473 DBusError error; |
|
1474 DBusMessage* msg; |
|
1475 DBusPendingCall* pending; |
|
1476 dbus_int32_t no; |
|
1477 int data_slot = -1; |
|
1478 TestData* data; |
|
1479 TestData1 data1; |
|
1480 DBusFreeFunction free_data; |
|
1481 |
|
1482 DBusPendingCallNotifyFunction reply_handler; |
|
1483 |
|
1484 dbus_error_init(&error); |
|
1485 |
|
1486 connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); |
|
1487 if(!connection || dbus_error_is_set(&error)) |
|
1488 handle_error(&error); |
|
1489 |
|
1490 msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "simple"); |
|
1491 if(!msg) |
|
1492 { |
|
1493 iLog->Log(_L8("Failed to creat Messsage")); |
|
1494 return 1; |
|
1495 } |
|
1496 |
|
1497 dbus_message_append_args(msg, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID); |
|
1498 dbus_connection_send_with_reply(connection, msg, &pending, -1); |
|
1499 if(!pending) |
|
1500 { |
|
1501 iLog->Log(_L8("pending is NULL")); |
|
1502 return 1; |
|
1503 } |
|
1504 |
|
1505 if(!dbus_pending_call_allocate_data_slot(&data_slot)) |
|
1506 { |
|
1507 iLog->Log(_L8("Not able to allocate data slot")); |
|
1508 return 1; |
|
1509 } |
|
1510 |
|
1511 data = (TestData*)malloc(sizeof(TestData)); |
|
1512 data->num = 123; |
|
1513 data->str = (char*)malloc(20); |
|
1514 strcpy(data->str, "Check DBus"); |
|
1515 free_data = Free_Test_Data; |
|
1516 data_free_flag = FALSE; |
|
1517 data1.data = data; |
|
1518 data1.data_slot = data_slot; |
|
1519 if(!dbus_pending_call_set_data(pending, data_slot, data, free_data)) |
|
1520 { |
|
1521 iLog->Log(KOOM); |
|
1522 return 1; |
|
1523 } |
|
1524 |
|
1525 dbus_connection_flush(connection); |
|
1526 |
|
1527 reply_handler = handle_reply_pending_call_data_slot0; |
|
1528 if(!dbus_pending_call_set_notify(pending, reply_handler, &data1, NULL)) |
|
1529 { |
|
1530 iLog->Log(_L8("Failed to set handler for pending call")); |
|
1531 return 1; |
|
1532 } |
|
1533 |
|
1534 dbus_pending_call_block(pending); |
|
1535 dbus_message_unref(msg); |
|
1536 |
|
1537 iLog->Log(_L8("Reply = %d"), pending_call_ret_val); |
|
1538 switch(pending_call_ret_val) |
|
1539 { |
|
1540 case 0: |
|
1541 break; |
|
1542 case -2: |
|
1543 iLog->Log(_L8("Error while stealing reply from pending call.")); |
|
1544 return 1; |
|
1545 case -3: |
|
1546 iLog->Log(_L8("Not able to retrive data from pending call.")); |
|
1547 return 1; |
|
1548 case -4: |
|
1549 iLog->Log(_L8("Not able to Reset data for pending call.")); |
|
1550 return 1; |
|
1551 case -5: |
|
1552 iLog->Log(_L8("Free Function is not called.")); |
|
1553 return 1; |
|
1554 default: |
|
1555 iLog->Log(_L8("Notify function is not called")); |
|
1556 return 1; |
|
1557 } |
|
1558 if(!data_free_flag) |
|
1559 { |
|
1560 iLog->Log(_L8("Free Function is not called.")); |
|
1561 return 1; |
|
1562 } |
|
1563 |
|
1564 dbus_connection_close(connection); |
|
1565 dbus_connection_unref(connection); |
|
1566 dbus_shutdown(); |
|
1567 iLog->Log(KSuccess); |
|
1568 return KErrNone; |
|
1569 } |
|
1570 |
|
1571 |
|
1572 int Cstif_1::send_file(DBusConnection* connection, char* file_name) |
|
1573 { |
|
1574 FILE* fp; |
|
1575 unsigned char arr[200]; |
|
1576 unsigned char* data; |
|
1577 //const unsigned char* p_arr = arr; |
|
1578 DBusError error; |
|
1579 DBusMessage* msg; |
|
1580 DBusMessage* reply; |
|
1581 DBusMessageIter append_iter; |
|
1582 DBusMessageIter sub_iter; |
|
1583 int num=1; |
|
1584 int size=0; |
|
1585 TTime NowTime; |
|
1586 TTime NowTime1; |
|
1587 TTimeIntervalMicroSeconds micro_sec; |
|
1588 TInt64 diff_int64; |
|
1589 dbus_error_init(&error); |
|
1590 |
|
1591 fp = fopen(file_name, "r"); |
|
1592 if(!fp) |
|
1593 { |
|
1594 iLog->Log(_L8("Not able to open File")); |
|
1595 return 1; |
|
1596 } |
|
1597 |
|
1598 while(num) |
|
1599 { |
|
1600 num = fread(&arr, sizeof(unsigned char), 200, fp); |
|
1601 size = size + num; |
|
1602 } |
|
1603 if(fp) |
|
1604 fclose(fp); |
|
1605 |
|
1606 fp = NULL; |
|
1607 fp = fopen(file_name, "r"); |
|
1608 if(!fp) |
|
1609 { |
|
1610 iLog->Log(_L8("Not able to open File")); |
|
1611 return 1; |
|
1612 } |
|
1613 data = (unsigned char*)dbus_malloc(size); |
|
1614 if(!data) |
|
1615 { |
|
1616 iLog->Log(_L8("Errno %d"), errno); |
|
1617 iLog->Log(_L8("data is NULL for %s of size %d."), file_name, size); |
|
1618 return 1; |
|
1619 } |
|
1620 if(size != fread(data, sizeof(unsigned char), size, fp)) |
|
1621 { |
|
1622 iLog->Log(_L8("Error while reading file")); |
|
1623 return 1; |
|
1624 } |
|
1625 |
|
1626 if(fp) |
|
1627 fclose(fp); |
|
1628 msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "file_send_time"); |
|
1629 if(!msg) |
|
1630 { |
|
1631 iLog->Log(_L8("msg is NULL.")); |
|
1632 return 1; |
|
1633 } |
|
1634 |
|
1635 iLog->Log(_L8("msg is created")); |
|
1636 |
|
1637 dbus_message_iter_init_append(msg, &append_iter); |
|
1638 dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_STRING, &file_name); |
|
1639 |
|
1640 // For Array |
|
1641 if(!dbus_message_iter_open_container(&append_iter, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &sub_iter)) |
|
1642 { |
|
1643 iLog->Log(KOOM); |
|
1644 return 1; |
|
1645 } |
|
1646 if(!dbus_message_iter_append_fixed_array(&sub_iter, DBUS_TYPE_BYTE, &data, size)) |
|
1647 { |
|
1648 iLog->Log(KOOM); |
|
1649 return 1; |
|
1650 } |
|
1651 dbus_message_iter_close_container(&append_iter, &sub_iter); |
|
1652 |
|
1653 iLog->Log(_L8("Array Appended")); |
|
1654 NowTime.HomeTime(); |
|
1655 reply = dbus_connection_send_with_reply_and_block(connection, msg, 15000, &error); |
|
1656 NowTime1.HomeTime(); |
|
1657 if(!reply) |
|
1658 { |
|
1659 iLog->Log(_L8("Failed to get reply for %s of size %d"), file_name, size); |
|
1660 iLog->Log(_L8("Error Message :: %s"), error.message); |
|
1661 return 1; |
|
1662 } |
|
1663 |
|
1664 micro_sec = NowTime1.MicroSecondsFrom(NowTime); |
|
1665 diff_int64 = micro_sec.Int64(); |
|
1666 iLog->Log(_L8("Time to send %s file of size %d is %d"), file_name, size, diff_int64); |
|
1667 dbus_free(data); |
|
1668 |
|
1669 return 0; |
|
1670 } |
|
1671 |
|
1672 TInt Cstif_1::stif_Time0( CStifItemParser& aItem ) |
|
1673 { |
|
1674 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
1675 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
1676 |
|
1677 DBusError error; |
|
1678 DBusConnection *connection; |
|
1679 |
|
1680 TTime NowTime; |
|
1681 TTime NowTime1; |
|
1682 TTimeIntervalMicroSeconds micro_sec; |
|
1683 TInt64 diff_int64; |
|
1684 |
|
1685 dbus_error_init (&error); |
|
1686 NowTime.HomeTime(); |
|
1687 connection = dbus_bus_get_private (DBUS_BUS_SESSION, &error); |
|
1688 NowTime1.HomeTime(); |
|
1689 if (connection == NULL) |
|
1690 { |
|
1691 iLog->Log(_L8("*** Failed to open connection to system bus: %s\n%s"), error.name, error.message); |
|
1692 dbus_error_free (&error); |
|
1693 return 1; |
|
1694 } |
|
1695 micro_sec = NowTime1.MicroSecondsFrom(NowTime); |
|
1696 diff_int64 = micro_sec.Int64(); |
|
1697 iLog->Log(_L8("Time to get 1st time connection is %d"), diff_int64); |
|
1698 |
|
1699 if(send_file(connection, "c:\\inbox1.jpg")) |
|
1700 return 1; |
|
1701 sleep(1); |
|
1702 |
|
1703 if(send_file(connection, "c:\\bunbask1.jpg")) |
|
1704 return 1; |
|
1705 sleep(1); |
|
1706 |
|
1707 if(send_file(connection, "c:\\sound_clip.amr")) |
|
1708 return 1; |
|
1709 sleep(1); |
|
1710 |
|
1711 if(send_file(connection, "c:\\inbox.jpg")) |
|
1712 return 1; |
|
1713 sleep(1); |
|
1714 |
|
1715 if(send_file(connection, "c:\\sound_clip1.amr")) |
|
1716 return 1; |
|
1717 sleep(1); |
|
1718 |
|
1719 if(send_file(connection, "c:\\sound_clip2.amr")) |
|
1720 return 1; |
|
1721 sleep(1); |
|
1722 |
|
1723 if(send_file(connection, "c:\\sound_clip4.amr")) |
|
1724 return 1; |
|
1725 sleep(1); |
|
1726 |
|
1727 if(send_file(connection, "c:\\sound_clip5.amr")) |
|
1728 return 1; |
|
1729 sleep(1); |
|
1730 |
|
1731 if(send_file(connection, "c:\\sound_clip6.amr")) |
|
1732 return 1; |
|
1733 sleep(1); |
|
1734 |
|
1735 if(send_file(connection, "c:\\sound_clip3.amr")) |
|
1736 return 1; |
|
1737 |
|
1738 dbus_connection_close(connection); |
|
1739 dbus_connection_unref(connection); |
|
1740 dbus_shutdown(); |
|
1741 iLog->Log(KSuccess); |
|
1742 return 0; |
|
1743 } |
|
1744 |
|
1745 TInt Cstif_1::stif_Daemon_Run_Time0( CStifItemParser& aItem ) |
|
1746 { |
|
1747 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksRequests ); |
|
1748 TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles ); |
|
1749 |
|
1750 #if defined(__WINSCW__) || defined(__WINS__) |
|
1751 FILE* fp = popen("z:\\sys\\bin\\idle_daemon_run.exe", "r"); |
|
1752 #else |
|
1753 FILE* fp = popen("c:\\sys\\bin\\idle_daemon_run.exe", "r"); |
|
1754 #endif |
|
1755 if(!fp) |
|
1756 { |
|
1757 iLog->Log(_L8("Fail to open exe")); |
|
1758 return 1; |
|
1759 } |
|
1760 |
|
1761 iLog->Log(KSuccess); |
|
1762 return KErrNone; |
|
1763 } |
|
1764 |
|
1765 int make_fifo(char* fifopath) |
|
1766 { |
|
1767 int err =0; |
|
1768 err = mkfifo (fifopath, 0666); |
|
1769 if(err != 0) |
|
1770 { |
|
1771 // probably file already exists, delete the file |
|
1772 unlink(fifopath); |
|
1773 // try once more.. |
|
1774 err = mkfifo (fifopath, 0666); |
|
1775 if(err != 0) |
|
1776 { |
|
1777 return 1; |
|
1778 } |
|
1779 } |
|
1780 return 0; |
|
1781 } |
|
1782 |
|
1783 int read_fifo(char* fifopath, char* str) |
|
1784 { |
|
1785 int fd = open(fifopath, O_RDONLY); |
|
1786 int err; |
|
1787 char buf[180]; |
|
1788 |
|
1789 if(fd > 0) |
|
1790 { |
|
1791 err = read (fd, buf, 80); |
|
1792 RDebug::Printf("error value is:%d\n", err); |
|
1793 close(fd); |
|
1794 } |
|
1795 else |
|
1796 { |
|
1797 return 1; |
|
1798 } |
|
1799 unlink(fifopath); |
|
1800 if(strcmp(buf, "done")) |
|
1801 { |
|
1802 strcpy(str, buf); |
|
1803 return 1; |
|
1804 } |
|
1805 |
|
1806 return 0; |
|
1807 } |
|
1808 |
|
1809 TInt Cstif_1::stif_Simultaneous_Connections( CStifItemParser& aItem ) |
|
1810 { |
|
1811 FILE* fp[3]; |
|
1812 int cnt; |
|
1813 char res[80]; |
|
1814 |
|
1815 char* fifopath[3] = { "C:\\mkfifo001.file", |
|
1816 "C:\\mkfifo002.file", |
|
1817 "C:\\mkfifo003.file"}; |
|
1818 for(cnt=0; cnt<3; cnt++) |
|
1819 { |
|
1820 if(make_fifo(fifopath[cnt])) |
|
1821 { |
|
1822 iLog->Log(_L8("Failed to open FIFO for %d count"), cnt); |
|
1823 return 1; |
|
1824 } |
|
1825 } |
|
1826 |
|
1827 #if defined(__WINSCW__) || defined(__WINS__) |
|
1828 char* exe_names[] = { "z:\\sys\\bin\\get_connection_1.exe", |
|
1829 "z:\\sys\\bin\\get_connection_2.exe", |
|
1830 "z:\\sys\\bin\\get_connection_3.exe" |
|
1831 }; |
|
1832 #else |
|
1833 char* exe_names[] = { "c:\\sys\\bin\\get_connection_1.exe", |
|
1834 "c:\\sys\\bin\\get_connection_2.exe", |
|
1835 "c:\\sys\\bin\\get_connection_3.exe" |
|
1836 }; |
|
1837 #endif |
|
1838 |
|
1839 |
|
1840 for(cnt=0; cnt<3; cnt++) |
|
1841 { |
|
1842 fp[cnt] = popen(exe_names[cnt], "r"); |
|
1843 if(!fp[cnt]) |
|
1844 { |
|
1845 iLog->Log(_L8("Failed to open %d th EXE."), cnt); |
|
1846 return 1; |
|
1847 } |
|
1848 } |
|
1849 |
|
1850 for(cnt=0; cnt<3; cnt++) |
|
1851 { |
|
1852 if(read_fifo(fifopath[cnt], res)) |
|
1853 { |
|
1854 iLog->Log(_L8("Failed to read FIFO for %d exe and %s"), cnt, res); |
|
1855 return 1; |
|
1856 } |
|
1857 } |
|
1858 |
|
1859 iLog->Log(KSuccess); |
|
1860 return KErrNone; |
|
1861 } |
|
1862 |