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: sl@0: #define LOG_FILE "c:\\logs\\file_writecontact0_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("file_writecontact0"); sl@0: close_log_file(); sl@0: } sl@0: sl@0: int main() sl@0: { sl@0: DBusConnection* connection; sl@0: DBusError error; sl@0: DBusMessage* msg; sl@0: DBusMessage* msg1; sl@0: DBusMessageIter append_iter; sl@0: DBusMessageIter return_iter; sl@0: DBusMessageIter sub_iter; sl@0: DBusPendingCall* pending; sl@0: char error_name[40]; sl@0: char error_msg[40]; sl@0: dbus_int32_t return_value; sl@0: char ret_msg[20]; sl@0: int i; sl@0: sl@0: sl@0: char* arg_str = "DBus Testing"; sl@0: char* arg_obj_path = "\Test\Object\Path"; sl@0: int size; sl@0: struct data_contact sl@0: { sl@0: char *name; sl@0: char *ph_no; sl@0: dbus_int32_t cnt; sl@0: }data; sl@0: size = sizeof(struct data_contact); sl@0: std_log(LOG_FILENAME_LINE, "size of struct is %d",size); sl@0: sl@0: sl@0: sl@0: data.name = "DBus"; sl@0: data.ph_no = "+91234455"; sl@0: //cnt=0; sl@0: sl@0: sl@0: dbus_error_init(&error); sl@0: sl@0: connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); sl@0: if(!connection) sl@0: { sl@0: sl@0: std_log(LOG_FILENAME_LINE, "error_name",error.name); sl@0: std_log(LOG_FILENAME_LINE, "error_msg",error.message); sl@0: create_xml(1); sl@0: return 1; sl@0: } sl@0: msg = dbus_message_new_method_call("Test.Method.Call1", "/Test/Method/Object", "test.Method.Call", "file_writecontact"); sl@0: if(msg == NULL) sl@0: { sl@0: std_log(LOG_FILENAME_LINE, "message error"); sl@0: create_xml(1); sl@0: return 1; sl@0: } sl@0: std_log(LOG_FILENAME_LINE, "message created successfully"); sl@0: sl@0: sl@0: dbus_message_iter_init_append(msg, &append_iter); sl@0: sl@0: if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_STRING, &arg_str)) sl@0: { sl@0: std_log(LOG_FILENAME_LINE, "No memory"); sl@0: create_xml(1); sl@0: return 1; sl@0: } sl@0: sl@0: // structure sl@0: sl@0: sl@0: for(i=0; i<=50; i++) sl@0: { sl@0: if(!dbus_message_iter_open_container(&append_iter, DBUS_TYPE_STRUCT, NULL, &sub_iter)) sl@0: { sl@0: std_log(LOG_FILENAME_LINE, "No memory"); sl@0: create_xml(1); sl@0: return 1; sl@0: } sl@0: data.cnt = i; sl@0: if(!dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_INT32, &data.cnt)) sl@0: { sl@0: std_log(LOG_FILENAME_LINE, "No memory"); sl@0: create_xml(1); sl@0: return 1; sl@0: } sl@0: if(!dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_STRING, &data.name)) sl@0: { sl@0: std_log(LOG_FILENAME_LINE, "No memory"); sl@0: create_xml(1); sl@0: return 1; sl@0: } sl@0: if(!dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_STRING, &data.ph_no)) sl@0: { sl@0: std_log(LOG_FILENAME_LINE, "No memory"); sl@0: create_xml(1); sl@0: return 1; sl@0: } sl@0: dbus_message_iter_close_container(&append_iter, &sub_iter); // for 80 structure sl@0: } sl@0: sl@0: sl@0: // send message and get a handle for a reply sl@0: if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout sl@0: std_log(LOG_FILENAME_LINE, "message send error"); sl@0: create_xml(1); sl@0: exit(1); sl@0: } sl@0: if (NULL == pending) { sl@0: std_log(LOG_FILENAME_LINE, "pending is null"); sl@0: create_xml(1); sl@0: exit(1); sl@0: } sl@0: dbus_connection_flush(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: std_log(LOG_FILENAME_LINE, "Reply error"); sl@0: create_xml(1); sl@0: sl@0: exit(1); 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_iter_init(msg1, &return_iter); sl@0: sl@0: dbus_message_iter_get_basic(&return_iter, &return_value); sl@0: std_log(LOG_FILENAME_LINE, "reply = %d",return_value); sl@0: sl@0: if(return_value != 50) sl@0: { sl@0: std_log(LOG_FILENAME_LINE, "return value is not what is sent"); sl@0: create_xml(1); sl@0: return 1; sl@0: } sl@0: dbus_message_unref(msg); sl@0: sl@0: dbus_connection_close(connection); sl@0: dbus_connection_unref(connection); sl@0: dbus_shutdown(); sl@0: std_log(LOG_FILENAME_LINE, "SUCCESS"); sl@0: create_xml(0); sl@0: return 0; sl@0: sl@0: }