First public contribution.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include <dbus/dbus.h>
30 pthread_mutex_t mutex;
35 #define LOG_FILE "c:\\logs\\send_messages1_log1.txt"
36 #include "std_log_result.h"
37 #define LOG_FILENAME_LINE __FILE__, __LINE__
39 void create_xml(int result)
44 testResultXml("send_messages1");
48 int handle_error(DBusError* error)
50 std_log(LOG_FILENAME_LINE,"%s", error->name);
51 std_log(LOG_FILENAME_LINE,"%s", error->message);
52 dbus_error_free(error);
57 static void* send_msg1(void* data)
59 DBusConnection* connection;
63 DBusPendingCall* pending;
66 int data_slot = *(int*)data;
69 dbus_error_init(&error);
70 connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
77 thrData = (threadData1*)dbus_connection_get_data(connection, data_slot);
81 pthread_mutex_lock(&thrData->mutex);
83 msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "simple");
85 dbus_message_append_args(msg, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID);
87 pthread_cond_wait(&thrData->cond, &thrData->mutex);
89 // send message and get a handle for a reply
90 if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout
93 if (NULL == pending) {
96 dbus_connection_flush(connection);
99 dbus_message_unref(msg);
101 // block until we recieve a reply
102 dbus_pending_call_block(pending);
104 // get the reply message
105 msg1 = dbus_pending_call_steal_reply(pending);
110 // free the pending message handle
111 dbus_pending_call_unref(pending);
114 dbus_message_get_args(msg1, &error, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID);
116 std_log(LOG_FILENAME_LINE, "%d\n", no);
124 // free reply and close connection
125 dbus_message_unref(msg1);
126 dbus_connection_unref(connection);
127 pthread_mutex_unlock(&thrData->mutex);
133 DBusConnection* connection;
138 pthread_t thread[MAX_THREAD];
139 int thrVal[MAX_THREAD]={0};
140 void* thrValPtr[MAX_THREAD];
143 for(cnt=0; cnt<MAX_THREAD; cnt++)
144 thrValPtr[cnt] = (void*)&thrVal[cnt];
146 dbus_error_init(&error);
147 connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
148 if(!connection || dbus_error_is_set(&error))
149 return handle_error(&error);
151 pthread_mutex_init(&thrData.mutex, NULL);
152 pthread_cond_init(&thrData.cond, NULL);
155 dbus_connection_allocate_data_slot(&data_slot);
156 dbus_connection_set_data(connection, data_slot, &thrData, NULL);
158 dbus_threads_init_default();
160 for(cnt=0; cnt<MAX_THREAD; cnt++)
161 pthread_create(&thread[cnt], NULL, &send_msg1, &data_slot);
165 pthread_cond_broadcast(&thrData.cond);
167 for(cnt=0; cnt<MAX_THREAD; cnt++)
168 pthread_join(thread[cnt], &thrValPtr[cnt]);
170 if(thrData.ret != MAX_THREAD)
172 std_log(LOG_FILENAME_LINE, "No. of threads crashed %d", (MAX_THREAD - thrData.ret));
177 dbus_connection_unref(connection);
179 std_log(LOG_FILENAME_LINE, "Test Successful");