os/ossrv/ofdbus/dbus/tsrc/testapps/exes1/src/file_writecontact0.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ofdbus/dbus/tsrc/testapps/exes1/src/file_writecontact0.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,189 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include<stdio.h> 
    1.23 +#include <dbus/dbus.h>
    1.24 +#include <stdlib.h>
    1.25 +#include <string.h>
    1.26 +
    1.27 +#define LOG_FILE "c:\\logs\\file_writecontact0_log1.txt"
    1.28 +#include "std_log_result.h"
    1.29 +#define LOG_FILENAME_LINE __FILE__, __LINE__
    1.30 +
    1.31 +void create_xml(int result)
    1.32 +{
    1.33 +	if(result)
    1.34 +		assert_failed = 1;
    1.35 +	
    1.36 +	testResultXml("file_writecontact0");
    1.37 +	close_log_file();
    1.38 +}
    1.39 +
    1.40 +int main()
    1.41 +{
    1.42 + 		DBusConnection* connection;
    1.43 +	DBusError error;
    1.44 +	DBusMessage* msg;
    1.45 +	DBusMessage* msg1;
    1.46 +	DBusMessageIter append_iter;
    1.47 +	DBusMessageIter return_iter;
    1.48 +	DBusMessageIter sub_iter;
    1.49 +	DBusPendingCall* pending;
    1.50 +	char error_name[40];
    1.51 +	char error_msg[40];
    1.52 +	dbus_int32_t return_value;
    1.53 +	char ret_msg[20]; 
    1.54 +	int i;
    1.55 +	
    1.56 +	
    1.57 +	char* arg_str = "DBus Testing";
    1.58 +	char* arg_obj_path = "\Test\Object\Path";
    1.59 +	int size;
    1.60 +	struct data_contact
    1.61 +	{
    1.62 +		char *name;
    1.63 +		char *ph_no;
    1.64 +		dbus_int32_t cnt;
    1.65 +	}data;
    1.66 +	size = sizeof(struct data_contact);
    1.67 +	std_log(LOG_FILENAME_LINE, "size of struct is %d",size);
    1.68 +	  
    1.69 +	 
    1.70 +	
    1.71 +	data.name = "DBus";
    1.72 +	data.ph_no = "+91234455";
    1.73 +	//cnt=0;
    1.74 +	
    1.75 +	
    1.76 +	dbus_error_init(&error);
    1.77 +	
    1.78 +	connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
    1.79 +	if(!connection)
    1.80 +	{
    1.81 +		
    1.82 +		std_log(LOG_FILENAME_LINE, "error_name",error.name);
    1.83 +		std_log(LOG_FILENAME_LINE, "error_msg",error.message);
    1.84 +		create_xml(1);
    1.85 +		return 1;
    1.86 +	}  
    1.87 +	msg = dbus_message_new_method_call("Test.Method.Call1", "/Test/Method/Object", "test.Method.Call", "file_writecontact");
    1.88 +	if(msg == NULL)
    1.89 +		{ 
    1.90 +			std_log(LOG_FILENAME_LINE, "message error");
    1.91 +		create_xml(1);
    1.92 +		return 1;
    1.93 +		}
    1.94 +		std_log(LOG_FILENAME_LINE, "message created successfully");
    1.95 +	 
    1.96 +	
    1.97 +	dbus_message_iter_init_append(msg, &append_iter);
    1.98 +	
    1.99 +	if(!dbus_message_iter_append_basic(&append_iter, DBUS_TYPE_STRING, &arg_str))
   1.100 +		{
   1.101 +		std_log(LOG_FILENAME_LINE, "No memory");
   1.102 +		create_xml(1);
   1.103 +		return 1;
   1.104 +		}
   1.105 +	
   1.106 +	// structure 
   1.107 +	
   1.108 +		 
   1.109 +	for(i=0; i<=50; i++)  
   1.110 +	{
   1.111 +	if(!dbus_message_iter_open_container(&append_iter, DBUS_TYPE_STRUCT, NULL, &sub_iter))
   1.112 +		{
   1.113 +		std_log(LOG_FILENAME_LINE, "No memory");
   1.114 +		create_xml(1); 
   1.115 +		return 1;
   1.116 +		}	     
   1.117 +		data.cnt = i; 
   1.118 +		if(!dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_INT32, &data.cnt))
   1.119 +		{ 
   1.120 +			std_log(LOG_FILENAME_LINE, "No memory");
   1.121 +			create_xml(1);
   1.122 +			return 1;  
   1.123 +		} 
   1.124 +		if(!dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_STRING, &data.name))
   1.125 +		{ 
   1.126 +			std_log(LOG_FILENAME_LINE, "No memory");
   1.127 +			create_xml(1);
   1.128 +			return 1;  
   1.129 +		} 
   1.130 +		if(!dbus_message_iter_append_basic(&sub_iter, DBUS_TYPE_STRING, &data.ph_no))
   1.131 +		{ 
   1.132 +			std_log(LOG_FILENAME_LINE, "No memory");
   1.133 +			create_xml(1);
   1.134 +			return 1;  
   1.135 +		} 
   1.136 +		dbus_message_iter_close_container(&append_iter, &sub_iter);  // for 80 structure
   1.137 +	}
   1.138 +	
   1.139 +	
   1.140 +	// send message and get a handle for a reply
   1.141 +	   if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout
   1.142 +	   	std_log(LOG_FILENAME_LINE, "message send error");
   1.143 +	   		create_xml(1);
   1.144 +	   		exit(1);
   1.145 +	   }   
   1.146 +	   if (NULL == pending) {
   1.147 +	   	std_log(LOG_FILENAME_LINE, "pending is null");
   1.148 +	   		create_xml(1);
   1.149 +	      exit(1);
   1.150 +	   }
   1.151 +	   dbus_connection_flush(connection);
   1.152 +	   
   1.153 +	   // free message
   1.154 +	   dbus_message_unref(msg); 
   1.155 +	  
   1.156 +	   // block until we recieve a reply
   1.157 +	   dbus_pending_call_block(pending);
   1.158 +	
   1.159 +	   // get the reply message
   1.160 +	   msg1 = dbus_pending_call_steal_reply(pending);
   1.161 +	   if (NULL == msg1) {
   1.162 +	   	std_log(LOG_FILENAME_LINE, "Reply error"); 
   1.163 +	   create_xml(1);
   1.164 +	 
   1.165 +	      exit(1);
   1.166 +	   } 
   1.167 +	   
   1.168 +	   // free the pending message handle
   1.169 +	   dbus_pending_call_unref(pending);
   1.170 +		 
   1.171 +		dbus_error_init (&error);
   1.172 +		dbus_message_iter_init(msg1, &return_iter);
   1.173 +
   1.174 +		dbus_message_iter_get_basic(&return_iter, &return_value);
   1.175 +		std_log(LOG_FILENAME_LINE, "reply = %d",return_value);
   1.176 +		 
   1.177 +			if(return_value != 50)
   1.178 +			{
   1.179 +			std_log(LOG_FILENAME_LINE, "return value is not what is sent");
   1.180 +			create_xml(1);
   1.181 +			return 1;
   1.182 +			} 
   1.183 +			dbus_message_unref(msg);  
   1.184 +	   
   1.185 +	   dbus_connection_close(connection);
   1.186 +	   dbus_connection_unref(connection);
   1.187 +	   dbus_shutdown();
   1.188 +	   std_log(LOG_FILENAME_LINE, "SUCCESS");
   1.189 + 		   create_xml(0);
   1.190 +		    return 0;  
   1.191 +
   1.192 +}