[Chugalug] dbus Programming in C

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Chugalug] dbus Programming in C

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.

Thanks,
  Jeff.

_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
Reply | Threaded
Open this post in threaded view
|

Re: [Chugalug] dbus Programming in C

Joe Freeman
Does this example help-

#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus.h>

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\n", name);
dbus_message_unref(msg);
dbus_message_unref(reply);
dbus_connection_close(conn);

return 0;
}


Joe

On Mon, Feb 26, 2018 at 4:04 PM, DaWorm <[hidden email]> wrote:
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.

Thanks,
  Jeff.

_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug



_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
Reply | Threaded
Open this post in threaded view
|

Re: [Chugalug] dbus Programming in C

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 

On Feb 26, 2018 7:22 PM, "Joe Freeman" <[hidden email]> wrote:
Does this example help-

#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus.h>

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\n", name);
dbus_message_unref(msg);
dbus_message_unref(reply);
dbus_connection_close(conn);

return 0;
}


Joe

On Mon, Feb 26, 2018 at 4:04 PM, DaWorm <[hidden email]> wrote:
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.

Thanks,
  Jeff.

_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug



_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug


_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug
Reply | Threaded
Open this post in threaded view
|

Re: [Chugalug] dbus Programming in C

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.


Follow ups are linked at the bottom before comments.

Jeff.

On Mon, Feb 26, 2018 at 9:23 PM, DaWorm <[hidden email]> wrote:
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 

On Feb 26, 2018 7:22 PM, "Joe Freeman" <[hidden email]> wrote:
Does this example help-

#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus.h>

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\n", name);
dbus_message_unref(msg);
dbus_message_unref(reply);
dbus_connection_close(conn);

return 0;
}


Joe

On Mon, Feb 26, 2018 at 4:04 PM, DaWorm <[hidden email]> wrote:
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.

Thanks,
  Jeff.

_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug



_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug



_______________________________________________
Chugalug mailing list
[hidden email]
http://chugalug.org/cgi-bin/mailman/listinfo/chugalug