sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #define MAX_THREAD 25 sl@0: sl@0: typedef struct{ sl@0: pthread_mutex_t mutex; sl@0: pthread_cond_t cond; sl@0: DBusConnection* connection; sl@0: int ret; sl@0: }threadData; sl@0: sl@0: #define LOG_FILE "c:\\logs\\send_messages_log1.txt" sl@0: #include "std_log_result.h" sl@0: #define LOG_FILENAME_LINE __FILE__, __LINE__ sl@0: sl@0: void create_xml(int result) sl@0: { sl@0: if(result) sl@0: assert_failed = 1; sl@0: sl@0: testResultXml("send_messages"); sl@0: close_log_file(); sl@0: } sl@0: sl@0: int handle_error(DBusError* error) sl@0: { sl@0: std_log(LOG_FILENAME_LINE,"%s", error->name); sl@0: std_log(LOG_FILENAME_LINE,"%s", error->message); sl@0: dbus_error_free(error); sl@0: create_xml(1); sl@0: return 1; sl@0: } sl@0: sl@0: static void* send_msg(void* data) sl@0: { sl@0: static int cnt = 1; sl@0: dbus_int32_t no = 5; sl@0: DBusPendingCall* pending; sl@0: DBusMessage* msg1; sl@0: DBusMessage* msg; sl@0: DBusError error; sl@0: sl@0: threadData* thrData = (threadData*)data; sl@0: sl@0: pthread_mutex_lock(&thrData->mutex); sl@0: sl@0: msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "simple"); sl@0: sl@0: dbus_message_append_args(msg, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID); sl@0: sl@0: pthread_cond_wait(&thrData->cond, &thrData->mutex); sl@0: sl@0: // send message and get a handle for a reply sl@0: if (!dbus_connection_send_with_reply (thrData->connection, msg, &pending, -1)) { // -1 is default timeout sl@0: thrData->ret = 2; sl@0: } sl@0: if (NULL == pending) { sl@0: thrData->ret = 2; sl@0: } sl@0: dbus_connection_flush(thrData->connection); sl@0: sl@0: // free message sl@0: dbus_message_unref(msg); sl@0: sl@0: // block until we recieve a reply sl@0: dbus_pending_call_block(pending); sl@0: sl@0: // get the reply message sl@0: msg1 = dbus_pending_call_steal_reply(pending); sl@0: if (NULL == msg1) { sl@0: thrData->ret = 2; sl@0: sl@0: } sl@0: // free the pending message handle sl@0: dbus_pending_call_unref(pending); sl@0: sl@0: dbus_error_init(&error); sl@0: dbus_message_get_args(msg1, &error, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID); sl@0: sl@0: std_log(LOG_FILENAME_LINE, "%d\n", no); sl@0: sl@0: if(no == 9090) sl@0: { sl@0: thrData->ret++; sl@0: } sl@0: sl@0: sl@0: // free reply and close connection sl@0: dbus_message_unref(msg1); sl@0: pthread_mutex_unlock(&thrData->mutex); sl@0: return NULL; sl@0: } sl@0: sl@0: int main() sl@0: { sl@0: DBusError error; sl@0: int cnt; sl@0: sl@0: threadData thrData; sl@0: unsigned int thread[MAX_THREAD]; sl@0: int thrVal[MAX_THREAD]={0}; sl@0: void* thrValPtr[MAX_THREAD]; sl@0: sl@0: for(cnt=0; cnt