problem with executing method using DBUS, why parameters
passing is changed.
Nallammai S
snallammai at novell.com
Mon Mar 12 20:51:12 PDT 2007
Hi,
>Hi
>I have written one server which have one method sum which is exposed to client through DBUS. my client calls this method with 2 input parameters >and one output parameter (collect the sum of 2 input nos), but i am not able to receive any change in my output parameter though the method is >executed.
> Following is my XML file
> <?xml version="1.0" encoding="UTF- 8" ?>
> <node name="/com/example/MyServer">
> <interface name="com.example.MyServer">
> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="my_server"/>
> <method name="NoArgs">
> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="my_server_no_args"/>
> </method>
>
> <method name="Sum">
> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="my_server_sum"/>
> <arg type="i" name="num1" direction="in" />
> <arg type="i" name="num2" direction="in" />
> <arg type="i" name="sum" direction="out" />
> </method>
> </interface>
> </node>
> Following is the implementation of function in server
> gboolean my_server_sum(int num1,int num2,int *sum)
> {
> printf("\n num1 = %d num2 = %d sum = %d \n",num1,num2,sum);
> *sum = num1 + num2;
> return TRUE;
> }
The implementation of the function in server should be like this:
gboolean my_server_sum(SomeObject *obj, int num1,int num2,int *sum,GError *error)
{
*sum = num1 + num2;
printf("\n num1 = %d num2 = %d sum = %d \n",num1,num2,*sum);
return TRUE;
}
The SomeObject is the object through which the methods are exposed. The functions implemented should conform to some rules as:
#1 The function must return a value of type gboolean; TRUE on success, and FALSE otherwise.
#2 The first parameter is a pointer to an instance of the object.
#3 Following the object instance pointer are the method input values.
#4 Following the input values are pointers to return values.
#5 The final parameter must be a GError **. If the function returns FALSE for an error, the error parameter must be initalized with g_set_error
> Following is the call in client
> com_example_MyServer_sum (proxy,num1,num2,ptr,&error);
> where int num1 = 4, num2 = 3
> ptr is integer pointer holding add of integer variable.
> printf on server side prints
> num1 = 134546064 num2 = 4 sum = 3
> why is this happening?
From your printf statement, I found that you are trying to print the value of "sum". Since sum is a pointer variable, it will give the address value. You should first compute the sum and then use "*sum" inorder to print the sum value.
For your reference, you can also look at the examples present in the d-bus source package as well as the D-Bus tutorial present in the D-bus homepage.
Nallammai.S
More information about the dbus
mailing list