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;
32 DBusConnection* connection;
36 #define LOG_FILE "c:\\logs\\send_messages_log1.txt"
37 #include "std_log_result.h"
38 #define LOG_FILENAME_LINE __FILE__, __LINE__
40 void create_xml(int result)
45 testResultXml("send_messages");
49 int handle_error(DBusError* error)
51 std_log(LOG_FILENAME_LINE,"%s", error->name);
52 std_log(LOG_FILENAME_LINE,"%s", error->message);
53 dbus_error_free(error);
58 static void* send_msg(void* data)
62 DBusPendingCall* pending;
67 threadData* thrData = (threadData*)data;
69 pthread_mutex_lock(&thrData->mutex);
71 msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "simple");
73 dbus_message_append_args(msg, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID);
75 pthread_cond_wait(&thrData->cond, &thrData->mutex);
77 // send message and get a handle for a reply
78 if (!dbus_connection_send_with_reply (thrData->connection, msg, &pending, -1)) { // -1 is default timeout
81 if (NULL == pending) {
84 dbus_connection_flush(thrData->connection);
87 dbus_message_unref(msg);
89 // block until we recieve a reply
90 dbus_pending_call_block(pending);
92 // get the reply message
93 msg1 = dbus_pending_call_steal_reply(pending);
98 // free the pending message handle
99 dbus_pending_call_unref(pending);
101 dbus_error_init(&error);
102 dbus_message_get_args(msg1, &error, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID);
104 std_log(LOG_FILENAME_LINE, "%d\n", no);
112 // free reply and close connection
113 dbus_message_unref(msg1);
114 pthread_mutex_unlock(&thrData->mutex);
124 unsigned int thread[MAX_THREAD];
125 int thrVal[MAX_THREAD]={0};
126 void* thrValPtr[MAX_THREAD];
128 for(cnt=0; cnt<MAX_THREAD; cnt++)
129 thrValPtr[cnt] = (void*)&thrVal[cnt];
131 dbus_error_init(&error);
132 thrData.connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
133 if(!thrData.connection || dbus_error_is_set(&error))
134 return handle_error(&error);
136 pthread_mutex_init(&thrData.mutex, NULL);
137 pthread_cond_init(&thrData.cond, NULL);
140 for(cnt=0; cnt<MAX_THREAD; cnt++)
141 pthread_create(&thread[cnt], NULL, &send_msg, &thrData);
145 pthread_cond_broadcast(&thrData.cond);
147 for(cnt=0; cnt<MAX_THREAD; cnt++)
148 pthread_join(thread[cnt], &thrValPtr[cnt]);
150 if(thrData.ret != MAX_THREAD)
152 std_log(LOG_FILENAME_LINE,"No. of threads crashed %d", (MAX_THREAD - thrData.ret));
157 dbus_connection_unref(thrData.connection);
159 std_log(LOG_FILENAME_LINE, "Test Successful");