Hi All,<br>I am using dbus glib binding. I have a code where i am trying to transfer a 5 MB file over dbus. I am getting an error which is <br><br>"Failed to write file 'copy-client.JK5K5T': fwrite() failed: Bad address"<br><br>However for small file ( about 10-20 k), I am not getting the same problem. I looked up the dbus specs and that says that the max message size is 2 pow 27. I am not able to understand the reason of failure. I am attaching my code for your reference.<br><br>--------------- server-code------------<br>/* some-object.h */<br>#ifndef __SOME_OBJECT_H__<br>#define __SOME_OBJECT_H__<br><br>#include <glib-object.h><br><br>typedef struct _SomeObject SomeObject;<br>struct _SomeObject<br>{<br> GObject parent_obj;<br> gint m_a;<br> gchar* m_b;<br> gfloat
m_c;<br>};<br><br>typedef struct _SomeObjectClass SomeObjectClass;<br>struct _SomeObjectClass<br>{<br> GObjectClass parent_class;<br><br> /* Some useful methods may follow. */<br> gboolean (*method1) (SomeObject *self, gint x,gchar **y,gint *z,GError **error);<br> void (*method2) (SomeObject *self, gchar*);<br>};<br><br>GType some_object_get_type ();<br><br>gboolean some_object_method1 (SomeObject *self, gint x,gchar**y,gint *z,GError **); /* virtual */<br>void some_object_method2 (SomeObject *self, gchar*); /* virtual */<br>void some_object_method3 (SomeObject *self, gfloat); /* non-virtual */<br><br><br>/* Handy macros */<br>#define SOME_OBJECT_TYPE
(some_object_get_type ())<br>#define SOME_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOME_OBJECT_TYPE, SomeObject))<br>#define SOME_OBJECT_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), SOME_OBJECT_TYPE, SomeObjectClass))<br>#define SOME_IS_OBJECT(obj) (G_TYPE_CHECK_TYPE ((obj), SOME_OBJECT_TYPE))<br>#define SOME_IS_OBJECT_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), SOME_OBJECT_TYPE))<br>#define SOME_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOME_OBJECT_TYPE, SomeObjectClass))<br><br>#endif<br><br><br><br>/* some-object.c */<br><br>#include "some-object.h"<br>#include "some-object-glue.h"<br>#include <dbus/dbus-glib-bindings.h><br>#include <string.h><br>#include <sys/stat.h><br><br>static GObjectClass *parent_class = ((void *)0);<br>static void some_object_init
(SomeObject *self);<br><br>char *FILENAME = NULL;<br><br>gboolean some_object_method1_impl (SomeObject *self, gint a, gchar **y,gint *z,GError **error)<br>{<br> struct stat stat_buf;<br> self->m_a = a;<br> g_print ("Method1: %i\n", self->m_a);<br>/* <br> *y = (char *)g_malloc0(6);<br> strcpy(*y,"sumit");<br>*/ <br> stat(FILENAME,&stat_buf);<br> *y = g_malloc(stat_buf.st_size + 100);<br> if(g_file_get_contents(FILENAME,y,z,error))<br> {<br> g_print("Contents read\n");<br> if(g_file_set_contents("copy-server",*y,*z,NULL))<br> g_print("Contents written\n");<br> }<br>
else<br> g_print("Contents reading failed... %s \n",(*error)->message);<br><br> return TRUE;<br>}<br><br>void some_object_method2_impl (SomeObject *self, gchar* b)<br>{<br> self->m_b = b;<br> g_print ("Method2: %s\n", self->m_b);<br>}<br><br><br>/* Public methods. */<br>gboolean some_object_method1 (SomeObject *self, gint a,gchar **y,gint *z,GError **error)<br>{<br> return SOME_OBJECT_GET_CLASS (self)->method1 (self, a,y,z,error);<br>}<br><br>void some_object_method2 (SomeObject *self, gchar* b)<br>{<br> SOME_OBJECT_GET_CLASS (self)->method2 (self, b);<br>}<br><br>void some_object_method3 (SomeObject *self, gfloat c)<br>{<br> self->m_c = c;<br> g_print ("Method3: %f\n", self->m_c);<br>}<br><br><br>void some_object_dispose (GObject
*self)<br>{<br> static gboolean first_run = TRUE;<br><br> if (first_run)<br> {<br> first_run = FALSE;<br> <br> /* Call g_object_unref on any GObjects that we hold, but don't break the object */<br><br> parent_class-> dispose (self);<br> }<br>}<br><br>void some_object_finalize (GObject *self)<br>{<br> parent_class-> finalize (self);<br>}<br><br>/* Here is where we override any functions. Since we have no properties or even fields, none of the below are needed. */<br>void some_object_class_init (gpointer g_class, gpointer class_data)<br>{<br> GObjectClass *object_class = G_OBJECT_CLASS
(g_class);<br> SomeObjectClass *this_class = SOME_OBJECT_CLASS (g_class);<br> <br> //assign value to parent class<br> parent_class = g_type_class_peek_parent (g_class);<br> <br> //assing pointer values to the base class members<br> object_class-> dispose = &some_object_dispose;<br> object_class-> finalize = &some_object_finalize;<br> <br> //assign value to derived class members<br> this_class->method1 = &some_object_method1_impl;<br> this_class->method2 = &some_object_method2_impl;<br><br> dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(this_class),&dbus_glib__object_info);<br>}<br><br>void some_object_init (SomeObject *self)<br>{<br> self->m_a =
1;<br> self->m_c = 1.03f;<br> self->m_b = "sumit";<br>}<br><br>GType some_object_get_type () <br>{<br> static GType g_define_type_id = 0; <br> if ((g_define_type_id == 0)) <br> { <br> static const GTypeInfo g_define_type_info = <br> { <br> sizeof (SomeObjectClass), <br> (GBaseInitFunc) ((void *)0), <br> (GBaseFinalizeFunc) ((void *)0), <br> (GClassInitFunc) some_object_class_init, <br> (GClassFinalizeFunc) ((void *)0), <br> ((void *)0), <br>
sizeof (SomeObject), <br> 0, <br> (GInstanceInitFunc) some_object_init, <br> }; <br><br> g_define_type_id = g_type_register_static <br> (<br> G_TYPE_OBJECT, <br> "SomeObject", <br> &g_define_type_info, <br> (GTypeFlags) 0<br> );<br> <br> } <br><br> return g_define_type_id; <br>}<br><br>int main(int argc,char *argv[])<br>{<br> SomeObject *so =
NULL;<br> DBusGConnection *bus;<br> g_type_init();<br> GMainLoop *mainLoop = NULL;<br> int request_ret;<br> GError *error = NULL;<br><br> DBusGProxy *proxy = NULL;<br> char *x;<br><br> FILENAME = argv[1];<br><br> so = g_object_new(SOME_OBJECT_TYPE,NULL);<br><br> bus = dbus_g_bus_get(DBUS_BUS_SESSION,NULL);<br><br> proxy = dbus_g_proxy_new_for_name(bus,DBUS_SERVICE_DBUS,DBUS_PATH_DBUS,DBUS_INTERFACE_DBUS);<br><br> dbus_g_connection_register_g_object(bus,"/com/example/SomeObject",G_OBJECT(so));<br><br> if(!org_freedesktop_DBus_request_name(proxy,"com.example.SomeObject",0,&request_ret,&error))<br> {<br> g_print("Unable to register service\n");<br>
return 1;<br> }<br><br> mainLoop = g_main_loop_new(NULL,FALSE);<br> g_main_loop_run(mainLoop);<br> <br> return 0;<br>}<br>------------------- End server code --------------<br><br>---------- Client code -------------------<br>#define DBUS_API_SUBJECT_TO_CHANGE<br><br>#include <dbus/dbus.h><br>#include <dbus/dbus-glib.h><br>#include <stdlib.h><br>#include <stdio.h><br>#include "some-object-bindings.h"<br><br>int main (int argc, char **argv)<br>{<br> DBusGConnection *connection;<br> GError *error;<br> DBusGProxy *proxy;<br> gchar *x;<br> gint length;<br> <br> g_type_init ();<br><br> error = NULL;<br> connection = dbus_g_bus_get
(DBUS_BUS_SESSION,<br> &error);<br> if (connection == NULL)<br> {<br> g_printerr ("Failed to open connection to bus: %s\n",<br> error->message);<br> g_error_free (error);<br> exit (1);<br> }<br><br> proxy = dbus_g_proxy_new_for_name (connection,<br>
"com.example.SomeObject",<br> "/com/example/SomeObject",<br> "com.example.SomeObject");<br><br> error = NULL;<br><br> if(!com_example_SomeObject_method1(proxy,10,&x,&length,&error))<br> {<br> printf("Error --- %s\n",error->message);<br> return 1;<br> }<br><br> printf("File details... length = %d\n",length);<br> error = NULL;<br> if(!g_file_set_contents("copy-client",x,length,&error))<br> printf("Error message =
%s\n",error->message);<br> <br> return 0;<br>}<br>------------ End Client code -------------<br><br>--------- Introspection XML ------------<br><?xml version="1.0" encoding="UTF-8" ?><br><br><node name="/com/example/SomeObject"><br><br> <interface name="com.example.SomeObject"><br> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="some_object"/><br> <method name="Method1"><br> <!-- This is optional, and in this case is redunundant --><br> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="some_object_method1"/><br> <arg type="u" name="x" direction="in" /><br> <arg type="s" name="y" direction="out" /><br> <arg type="u" name="z" direction="out" /><br>
</method><br> </interface><br></node><br>--------- End Introspection XML ------------<br><br><br>Please help.<br><br>Regads,<br>Sumit<br><p> 
<!--5--><hr size=1></hr> Now you can chat without downloading messenger. <a href="http://in.rd.yahoo.com/tagline_webmessenger_5/*http://in.messenger.yahoo.com/webmessengerpromo.php">Click here</a> to know how.