<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Santiago,<br>
    <br>
    Thank you very much for your reply.&nbsp; I've already spent a decent
    amount of time on this; the thought of digging deep into DBus and
    dbus-java isn't very appealing, not to mention my qualifications to
    do so.&nbsp;&nbsp; The requirement for Java comes from the ability to
    seamlessly integrate with the wealth of Java back-end software.&nbsp;&nbsp;
    Just curious if you or anyone on this alias has an opinion on the
    notion of taking the Python HDP code and running it in a Jython
    environment.&nbsp; This would rehost the software to a Java Virtual
    Machine and make Java back-end integration straightforward.<br>
    <br>
    Thanks,<br>
    -- Jim C<br>
    <br>
    On 7/15/2011 3:38 AM, Santiago Perez wrote:
    <blockquote cite="mid:DUB101-W59775A085BDD2E779916D9E0490@phx.gbl"
      type="cite">
      <style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
      <div dir="ltr">
        Hi Jim.<br>
        I have tried to develop a X73 Manager for a Blood Pressure
        Monitor with BT HDP and Java, but&nbsp;nowadays the Java binding
        doesn't support the datatype "File Descriptor".&nbsp;<br>
        &nbsp;<br>
        A file descriptor is needed because is the way in&nbsp;which the
        device sends data to the manager. It is defined in the "health
        API" doc of bluez, the <span lang="ES-MODERN">org.bluez.HealthChannel
          interface has the method "<span lang="ES-MODERN">fd Acquire()"
            (fd: file descriptor).</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">The Java binding's
            author (Matthew Johnson <a moz-do-not-send="true"
              href="mailto:dbus@matthew.ath.cx">dbus@matthew.ath.cx</a>)
            said to me that&nbsp;he&nbsp;cannot to incorporate that datatype at
            the moment. I tried it, but it isn't easy...</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">Anyway, related to
            your code I see a few things:</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">- You have to work
            with a dBus connection for the current Session, no with the
            dBus system... way? I don't know. I just know that the
            Bluetooth HDP only creates the HealthManager in the&nbsp;dBus
            Session, not in the&nbsp;dBus System...</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">- You don't need
            to get the remote object for the dBus connection! </span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">This is my code
            and&nbsp;it works, I hope it is useful for you:</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">Cheers,</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">Santiago</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">-------------</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">&nbsp;<br>
            <strong>//Getting a DBus connection<br>
            </strong>try {<br>
            &nbsp;dbusConn = DBusConnection.getConnection(<strong>DBusConnection.SESSION</strong>);<br>
            } catch (DBusException e) {&nbsp;&nbsp;&nbsp;<br>
            &nbsp;throw new
            BusinessRuleException(BusinessRuleError.ERROR_CONNECTION_DBUS,
errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_CONNECTION_DBUS)));<br>
            }<br>
            if(dbusConn == null)<br>
            {<br>
            &nbsp;throw new
            BusinessRuleException(BusinessRuleError.ERROR_CONNECTION_DBUS,
errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_CONNECTION_DBUS)));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
            }<br>
            &nbsp;&nbsp;</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"><strong>//Getting
              the HealthManager object<br>
            </strong>try {<br>
            &nbsp;bluezHealthManager = dbusConn.getRemoteObject("org.bluez",
            "/org/bluez", org.bluez.HealthManager.class);<br>
            } catch (DBusException e) {<br>
            &nbsp;throw new
            BusinessRuleException(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ,
errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ)));<br>
            }<br>
            if(bluezHealthManager == null)<br>
            {<br>
            &nbsp;throw new
            BusinessRuleException(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ,
errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ)));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
            }<br>
            &nbsp;&nbsp;<br>
            <strong>//Registering the X73 Manager for a Blood Pressure
              Monitor in dBus<br>
            </strong></span></span><span lang="ES-MODERN"><span
            lang="ES-MODERN">Map&lt;String, Variant&gt; dictionary = new
            HashMap&lt;String, Variant&gt;();</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">UInt16 managerType
            = new UInt16(0x1007);&nbsp;<br>
          </span></span><span lang="ES-MODERN"><span lang="ES-MODERN">dictionary.put("DataType",
            new Variant(managerType));&nbsp;<br>
            dictionary.put("Role",new Variant(strRole));<br>
            dictionary.put("Description",new Variant(strDescription));<br>
            dictionary.put("ChannelType",new Variant(strChannelType));<br>
            &nbsp;&nbsp;<br>
            Path managerPath = null;<br>
            managerPath =
            bluezHealthManager.CreateApplication(dictionary);<br>
            if(managerPath == null)<br>
            {<br>
            &nbsp;throw new
            BusinessRuleException(BusinessRuleError.ERROR_REGISTER_X73MANAGER_DBUS,
errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_REGISTER_X73MANAGER_DBUS)));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
            }</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"><strong>The
              HealthManager interface in Java is defined as:</strong></span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">package org.bluez;</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">import
            java.util.Map;</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"><br>
            import org.freedesktop.dbus.DBusInterface;<br>
            import org.freedesktop.dbus.Path;<br>
            import org.freedesktop.dbus.Variant;</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">public interface
            HealthManager extends DBusInterface<br>
            {</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">&nbsp; public Path
            CreateApplication(Map&lt;String,Variant&gt; dic);<br>
            &nbsp; public void DestroyApplication(Path o);</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN">}</span></span><br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"><br>
          </span></span>&nbsp;<br>
        <span lang="ES-MODERN"><span lang="ES-MODERN"></span></span>&nbsp;<br>
        ---------------<br>
        <br>
        &nbsp;<br>
        <div>
          &gt; Date: Thu, 14 Jul 2011 17:21:46 -0400<br>
          &gt; From: <a class="moz-txt-link-abbreviated" href="mailto:james.connors@oracle.com">james.connors@oracle.com</a><br>
          &gt; To: <a class="moz-txt-link-abbreviated" href="mailto:dbus@lists.freedesktop.org">dbus@lists.freedesktop.org</a><br>
          &gt; Subject: dbus-java for Bluetooth HDP<br>
          &gt; <br>
          &gt; Hello,<br>
          &gt; <br>
          &gt; I'm trying to use dbus-java to communicate with a
          bluetooth Heathcare <br>
          &gt; Device Profile (HDP) cpmpliant pulse oxymiter. There has
          been some work <br>
          &gt; demonstrating this capability with the Python dbus
          binding, but next to <br>
          &gt; nothing on the Java front from what I see. Not being a
          Python <br>
          &gt; aficionado, trying to map the Python stuff over to Java
          isn't working <br>
          &gt; out too well. The example below attempts to make a remote
          invocation <br>
          &gt; on a method called CreateApplication() as specified by
          the following <br>
          &gt; interface:<br>
          &gt; <br>
          &gt; package org.bluez;<br>
          &gt; import java.util.Map;<br>
          &gt; import org.freedesktop.dbus.DBusInterface;<br>
          &gt; import org.freedesktop.dbus.Variant;<br>
          &gt; <br>
          &gt; public interface HealthManager extends DBusInterface<br>
          &gt; {<br>
          &gt; public DBusInterface
          CreateApplication(Map&lt;String,Variant&gt; a);<br>
          &gt; public void DestroyApplication(DBusInterface a);<br>
          &gt; }<br>
          &gt; <br>
          &gt; The simple application below throws a DBusExecution
          exception when <br>
          &gt; reaching the CreateApplication() method call:<br>
          &gt; <br>
          &gt; package testhdp;<br>
          &gt; <br>
          &gt; import java.util.Map;<br>
          &gt; import java.util.HashMap;<br>
          &gt; import org.freedesktop.DBus;<br>
          &gt; import org.freedesktop.dbus.DBusConnection;<br>
          &gt; import org.freedesktop.dbus.DBusInterface;<br>
          &gt; import org.freedesktop.dbus.Variant;<br>
          &gt; import org.freedesktop.dbus.UInt16;<br>
          &gt; import org.bluez.Manager;<br>
          &gt; import org.bluez.HealthManager;<br>
          &gt; import org.freedesktop.DBus.Introspectable;<br>
          &gt; <br>
          &gt; class TestHDP {<br>
          &gt; <br>
          &gt; public static void main(String[] args) throws<br>
          &gt; org.freedesktop.dbus.exceptions.DBusException {<br>
          &gt; <br>
          &gt; DBusConnection conn =<br>
          &gt; DBusConnection.getConnection(DBusConnection.SYSTEM);<br>
          &gt; <br>
          &gt; DBus dbus = conn.getRemoteObject(<br>
          &gt; "org.freedesktop.DBus", "/org/freedesktop/DBus", <br>
          &gt; DBus.class);<br>
          &gt; <br>
          &gt; String ORG_BLUEZ = "org.bluez";<br>
          &gt; System.out.print("Searching dbus.ListNames() return for "
          +<br>
          &gt; "\"" + ORG_BLUEZ + "\": ");<br>
          &gt; String[] names = dbus.ListNames();<br>
          &gt; boolean bluezFound = false;<br>
          &gt; for (String name: names)<br>
          &gt; if (name.equals(ORG_BLUEZ)) {<br>
          &gt; bluezFound = true;<br>
          &gt; break;<br>
          &gt; }<br>
          &gt; if (bluezFound)<br>
          &gt; System.out.println(ORG_BLUEZ + " found.");<br>
          &gt; else<br>
          &gt; System.out.println(ORG_BLUEZ + " not found.");<br>
          &gt; <br>
          &gt; Manager m = (Manager) conn.getRemoteObject("org.bluez",
          "/",<br>
          &gt; Manager.class);<br>
          &gt; System.out.println(m.toString());<br>
          &gt; Map&lt;String, Variant&gt; props = m.GetProperties();<br>
          &gt; <br>
          &gt; HealthManager hm = (HealthManager) conn.getRemoteObject(<br>
          &gt; "org.bluez", "/org/bluez", HealthManager.class);<br>
          &gt; System.out.println(hm.toString());<br>
          &gt; <br>
          &gt; Map&lt;String, Variant&gt; config = new
          HashMap&lt;String, Variant&gt;();<br>
          &gt; config.put("DataType", new Variant&lt;UInt16&gt;(new
          UInt16(0x1004)));<br>
          &gt; config.put("Role", new Variant&lt;String&gt;("Sink"));<br>
          &gt; config.put("Description", new
          Variant&lt;String&gt;("Oximeter Sink"));<br>
          &gt; <br>
          &gt; DBusInterface app = hm.CreateApplication(config);<br>
          &gt; <br>
          &gt; conn.disconnect();<br>
          &gt; }<br>
          &gt; }<br>
          &gt; <br>
          &gt; Output is as follows:<br>
          &gt; <br>
          &gt; Searching dbus.ListNames() return for "org.bluez":
          org.bluez found.<br>
          &gt; org.bluez:/:interface org.bluez.Manager<br>
          &gt; org.bluez:/org/bluez:interface org.bluez.HealthManager<br>
          &gt; Exception in thread "main" <br>
          &gt; org.freedesktop.dbus.exceptions.DBusExecutionException:
          Wrong return <br>
          &gt; type (failed to de-serialize correct types: Failed to
          create proxy <br>
          &gt; object for /org/bluez/health_app_30 exported by :1.51.
          Reason: Could not <br>
          &gt; find an interface to cast to )<br>
          &gt; at
          org.freedesktop.dbus.RemoteInvocationHandler.convertRV(Unknown
          <br>
          &gt; Source)<br>
          &gt; at <br>
          &gt;
          org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(Unknown
          <br>
          &gt; Source)<br>
          &gt; at
          org.freedesktop.dbus.RemoteInvocationHandler.invoke(Unknown
          Source)<br>
          &gt; at $Proxy2.CreateApplication(Unknown Source)<br>
          &gt; at testhdp.TestHDP.main(TestHDP.java:66)<br>
          &gt; <br>
          &gt; <br>
          &gt; <br>
          &gt; Any guidance would be greatly appreciated.<br>
          &gt; <br>
          &gt; Thanks,<br>
          &gt; Jim Connors<br>
          &gt; <br>
          &gt; _______________________________________________<br>
          &gt; dbus mailing list<br>
          &gt; <a class="moz-txt-link-abbreviated" href="mailto:dbus@lists.freedesktop.org">dbus@lists.freedesktop.org</a><br>
          &gt; <a class="moz-txt-link-freetext" href="http://lists.freedesktop.org/mailman/listinfo/dbus">http://lists.freedesktop.org/mailman/listinfo/dbus</a><br>
        </div>
      </div>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
dbus mailing list
<a class="moz-txt-link-abbreviated" href="mailto:dbus@lists.freedesktop.org">dbus@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freedesktop.org/mailman/listinfo/dbus">http://lists.freedesktop.org/mailman/listinfo/dbus</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>