<br>Hi all,<br><div class="gmail_quote"><br>I am newbie in DBus programming using java. I am trying to call a method "myfun" on an object class "Demo" in a simple java program (TestDBus.java) from another java program (TestDBus1.java) using DBus Connection. I am able to connecct both these applications to DBus but my code is not able to call method "myfun" and I got some exception. My code and run time exception are as below :<br>
<-------------------------------------------- <b>Demo.java </b>-----------------------------------------------------------------><br><br>package pack;<br>import org.freedesktop.DBus;<br>import org.freedesktop.dbus.DBusConnection;<br>
import org.freedesktop.dbus.exceptions.DBusException;<br>import org.freedesktop.dbus.DBusInterface;<br><br>interface TestDBusInt extends DBusInterface{<br>public void myfun();<br>}<br><br>public class Demo implements TestDBusInt{<br>
public Demo(){}<br> public boolean isRemote(){return false;}<br> public void myfun(){<br> System.out.println("Within myfun of Demo class within TestDBus.class");<br> } <br>}<br><br><br> <----------------------------------------- <b>TestDBus.java</b> ----------------------------------------------------------><br>
<br>import org.freedesktop.DBus;<br>import org.freedesktop.dbus.exceptions.DBusException;<br>import org.freedesktop.dbus.*;<br>import pack.Demo;<br><br>public class TestDBus{<br><br> public static void main(String[] args) throws org.freedesktop.dbus.exceptions.DBusException {<br>
DBusConnection bus = null;<br><br> // Getting the Bus Connection.<br><br> System.out.println("Connecting Bus........");<br><br> bus = DBusConnection.getConnection(DBusConnection.SESSION);<br>
<br> System.out.println("Bus Connection Established.");<br><br> //Getting Unique name of this connection.<br> String conName=bus.getUniqueName();<br> System.out.println("Unique Name of this Bus Connection => "+conName);<br>
<br> <br> //Requesting Bus Name.<br> bus.requestBusName("My.FirstBus");<br><br> <br> //Getting the names owned by this connection.<br> System.out.println("Names owned by this Bus Connection are =>");<br>
String []bnames1=bus.getNames();<br> for(int i=0;i<bnames1.length;i++)<br> System.out.println(bnames1[i]);<br> <br><br> //exporting the Demo class object on the path “/Test”<br>
<br>
<b> DBusInterface db1=new Demo();<br> bus.exportObject("/Test", db1);</b><br> <br> while(true){}<br> <br> } <br>}<br><br clear="all"> <----------------------------------------- <b>TestDBus1.java</b> ----------------------------------------------------------><br>
<br>import org.freedesktop.DBus;<br>import org.freedesktop.dbus.*;<br>import java.lang.reflect.*;<br>import org.freedesktop.DBus.Introspectable;<br>import org.freedesktop.*;<br>import pack.Demo;<br><br><br>public class TestDBus1 {<br>
<br> public static void main(String[] args) throws org.freedesktop.dbus.exceptions.DBusException {<br> DBusConnection bus1 = null;<br> DBusConnection bus2=null;<br> <br> System.out.println("Establishing Bus Connection.......");<br>
<br> bus1 = DBusConnection.getConnection(DBusConnection.SESSION);<br> <br> System.out.println("Bus Connection Established.");<br><br> //Getting Unique name of this connection.<br>
String conName1=bus1.getUniqueName();<br> System.out.println("Unique Name of this Bus Connection => "+conName1);<br> <br><br> // Getting and Displaying Introspection data on Remote Object.<br>
<b> Introspectable intro = (Introspectable) bus1.getRemoteObject(<br> "My.FirstBus", "/Test",<br> Introspectable.class);<br><br> String data = intro.Introspect();</b><br>
<br> <br><br> <br> //System.out.println(db.myfun());<br><br><br> System.out.println("<--------------------------- Introspection Data Start ----------------------------------->");<br>
System.out.println(data);<br> System.out.println("<--------------------------- Introspection Data End ----------------------------------->");<br> <br><br> //Getting the remote object and calling a method of that object.<br>
<b>DBusInterface db =bus1.getPeerRemoteObject("</b><b>My.FirstBus","/Test");<br> DBusAsyncReply<Boolean> stuffreply =bus1.callMethodAsync(db,"</b><b>myfun");</b><br> <br>
<br> while(true){}<br>
<br> }<br>}<br><br><--------------------------------------------------<b>End Of Code</b> --------------------------------------------------------------------------------------><br><br><br><br>
<br><--------------------------------------------<b>Console Output on running TestDBus.java </b>---------------------------------------><br><br>Connecting Bus........<br>Bus Connection Established.<br>Unique Name of this Bus Connection => :1.37<br>
Names owned by this Bus Connection are =><br>:1.37<br>My.FirstBus<br>^Cshivnath@cmk-kbcs-shivnath:~/jdk1.6.0_07/bin/dbusex2$ java TestDBus<br>Connecting Bus........<br>Bus Connection Established.<br>Unique Name of this Bus Connection => :1.39<br>
Names owned by this Bus Connection are =><br>:1.39<br>My.FirstBus<br><br><br><br><------------------------------------- <b>Console Output
on running TestDBus1.java</b> ---------------------------------------><br><br>Establishing Bus Connection.......<br>Bus Connection Established.<br>Unique Name of this Bus Connection => :1.40<br><--------------------------- Introspection Data Start -----------------------------------><br>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "<a href="http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" target="_blank">http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd</a>"><br>
<node name="/Test"><br> <interface name="pack.TestDBusInt"><br> <method name="myfun" ><br> </method><br> </interface><br> <interface name="org.freedesktop.DBus.Introspectable"><br>
<method name="Introspect"><br> <arg type="s" direction="out"/><br> </method><br> </interface><br> <interface name="org.freedesktop.DBus.Peer"><br>
<method name="Ping"><br> </method><br> </interface><br></node><br><--------------------------- Introspection Data End -----------------------------------><br>Exception in thread "main" org.freedesktop.dbus.exceptions.DBusExecutionException: $Proxy2.myfun()<br>
at org.freedesktop.dbus.AbstractConnection.callMethodAsync(AbstractConnection.java:683)<br> at TestDBus1.main(TestDBus1.java:48)<br><------------------------------------------------------<b>End of Console Output</b>--------------------------------------------------------------><br>
<br>I am not sure, if I am missing something obvious here and would appreciate any advice on this. Plz, help me if I am going wrong in some way. Plz suggest me what to do to fix such exception and call the method as I want. <br>
Waiting for your reply.<br><br>Thanks in Advance !!<br><br></div>-- <br>Regards,<br>Shiv Nath Kumar<br>