public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* dbus of c program for adapter get/set properties
@ 2009-04-21  1:27 yesir yao
  2009-04-21  2:50 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 3+ messages in thread
From: yesir yao @ 2009-04-21  1:27 UTC (permalink / raw)
  To: linux-bluetooth

hi, all:

I need to use dbus api to control my bluetooth adapter in my C program.
After I had read doc/adapter-api.txt and writed the codes, It can't work.

my question is:
what is the different between:
dbus_connection_send_with_reply_and_block
and
dbus_connection_send_with_reply ?

in src/adapter.c, I found two methods defined:
static GDBusMethodTable adapter_methods[] = {
{ "GetProperties", "",	"a{sv}",  get_properties  },
{ "SetProperty", "sv", "",   set_property,
	G_DBUS_METHOD_FLAG_ASYNC },

For Methods dict GetProperties(), we should use
dbus_connection_send_with_reply_and_block ?
For Methods void SetProperty(..), we should use
dbus_connection_send_with_reply ?
is it right or not? (because of the flag: G_DBUS_METHOD_FLAG_ASYNC ?

===================================
static LRESULT OnAdapterSetDiscov()
{
	DBusConnection *conn;
	DBusMessage *dmsg, *reply;
	DBusError err;
	int bOn = TRUE;
	const char *PropName = "Discoverable";

	conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
	if (!conn) {
		print("Can't get on session bus");
		exit(1);
	}

	dmsg = dbus_message_new_method_call("org.bluez", "/org/bluez/hci0",
					"org.bluez.Adapter", "SetProperty");
	if (!dmsg) {
		print("Can't allocate new method call");
		return -1;
	}

	dbus_message_append_args(dmsg, DBUS_TYPE_STRING, &PropName,
					DBUS_TYPE_BOOLEAN, &bOn,
					DBUS_TYPE_INVALID);
#if 1
// can't SetProperty of Discoverable
	if (dbus_connection_send_with_reply(conn, dmsg, NULL, -1) == FALSE) {
		print("D-Bus send failed");
		return (LRESULT)0;
	}

#else
// print error: Method "SetProperty" with signature "sb" on interface
" org.bluez.Adapter" doesn't exist

	dbus_error_init(&err);
	reply = dbus_connection_send_with_reply_and_block(conn, dmsg, -1, &err);	
	if (!reply) {
		if (dbus_error_is_set(&err)) {
			print("%s", err.message);
			dbus_error_free(&err);
		}
		return (LRESULT)0;
	}
#endif

	dbus_message_unref(dmsg);
	dbus_message_unref(reply);
	dbus_connection_flush(conn);

	return (LRESULT)0;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-04-23  4:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-21  1:27 dbus of c program for adapter get/set properties yesir yao
2009-04-21  2:50 ` Luiz Augusto von Dentz
2009-04-23  4:52   ` yesir yao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox