HomeAboutMailing ListList Chatter /0/0

dbus Programming in C

2018-03-05 by: DaWorm
From: DaWorm 
Anyone done any dbus programming in C?  I'm looking for how to read a
property, and have zero experience in this.  Specifically, I'm looking to
read the org.bluez.Adapter1.Name property.  Pretty sure my issue is in the
dbus side of things, not the BlueZ side.

I can get a handle to dbus with dbus_bus_get() and were Name a method, I'm
pretty sure I could call it with dbus_message_new_method_call() followed by
dbus_connection_send_with_reply_and_block(), but since Name is a Property,
this isn't how it's done.  Problem is, I can't find any examples in C of
how to read/set a property.  Other languages that I'm not familiar with I
see a few things, such as reading whether a media player is currently
playing or setting the volume control, but I know Python or Lua even less
than I know dbus.  Apparently it involves something to do with getting a
proxy then using a properties manager with that proxy, but I'm having
trouble finding how in C.

Any help would be appreciated.


=============================================================== From: Joe Freeman ------------------------------------------------------ Does this example help- #include #include #include int main(int argc, char **argv) { DBusConnection *conn; DBusMessage *msg, *reply; const char *name; conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); msg = dbus_message_new_method_call( "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter", "GetName"); reply = dbus_connection_send_with_reply_and_block( conn, msg, -1, NULL); dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID); printf("%s ", name); dbus_message_unref(msg); dbus_message_unref(reply); dbus_connection_close(conn); return 0; } Taken from https://www.landley.net/kdocs/ols/2006/ols2006v1-pages-421-426.pdf, page 425. Joe

=============================================================== From: DaWorm ------------------------------------------------------ I've seen this one and it is the base for my test code. Apparently its for the old version of Bluez though. In the latest version the GetName _method_ has now been replaced by the Name _property_. So this no longer works. I have the latest bluez source and what I need is apparently in the bluetoothctl client command code I just have to figure out how to extract it from the 9000 other things that code does. Jeff ", name);

=============================================================== From: DaWorm ------------------------------------------------------ For anyone interested, this series of blog posts has proven very effective for what I'm looking to do. Perhaps a bit on the simplistic side for general purpose usage, but for a purpose built app that is straightforward and easy to digest, this series of posts is great. Post 1 Follow ups are linked at the bottom before comments. Jeff. ", name);