Home AMX User Forum Duet/Cafe Duet

getAllServiceReferences() for multiple devices

Let's say I have multiple DVD players in one system, 41001 and 41002, and I want to grab a reference to 41002 specifically, is there an easy way to do this? I imagine I could call
getAllServiceReferences("com.amx.duet.devicesdk.DiscDevice", null)
and iterate over the results, looking for a reference where the DUET_DEVICE property has a device number of 41002, but that seems a bit cumbersome.

Would something like
getAllServiceReferences("com.amx.duet.devicesdk.DiscDevice", "(Duet-Device=41002:*)")
work? From the OSGi documentation, it seems it should.

Comments

  • PhreaKPhreaK Posts: 966
    Yep. You got it. In fact you can search on any of the properties that are defined in your module manifest so you may find there is something more applicable that the virtual device number / you can define something more logical than a virtual device number. Those filters are LDAP format so you can start combining different properties in all sorts of useful ways.

    Also, you may want to consider using getServiceReferences(..) as a opposed to getAllServiceReferences(..). This one only returns service references guaranteed to be classloader compatible with your bundle so will protect you against class cast exceptions when you try to start using it.
  • mstocummstocum Posts: 120
    PhreaK wrote: »
    Yep. You got it. In fact you can search on any of the properties that are defined in your module manifest so you may find there is something more applicable that the virtual device number / you can define something more logical than a virtual device number. Those filters are LDAP format so you can start combining different properties in all sorts of useful ways.

    Do you have an example you can post? No matter what I try, if I specify any filter, I get nothing back. If I pass null for the filter, I get an array of every module of that type, which I can iterate over.
Sign In or Register to comment.