diff options
| author | Johan Hedberg <johan.hedberg@nokia.com> | 2007-05-09 22:12:20 +0000 | 
|---|---|---|
| committer | Johan Hedberg <johan.hedberg@nokia.com> | 2007-05-09 22:12:20 +0000 | 
| commit | 86477ad9060c5456a394af462e17247ee51779ed (patch) | |
| tree | 0f7931b8583d6d9d7765c975d705a17d7281a689 | |
| parent | c7ff83efffd73e9ca82aa29990faaa38c90bd826 (diff) | |
Use dbus_connection_emit_signal for sending signals
| -rw-r--r-- | audio/headset.c | 52 | ||||
| -rw-r--r-- | audio/manager.c | 54 | 
2 files changed, 52 insertions, 54 deletions
diff --git a/audio/headset.c b/audio/headset.c index 7b043af3..23c1410e 100644 --- a/audio/headset.c +++ b/audio/headset.c @@ -272,7 +272,6 @@ static gboolean headset_open_input(struct headset *hs, const char *input)  static void hs_signal_gain_setting(struct headset *hs, const char *buf)  {  	const char *name; -	DBusMessage *signal;  	dbus_uint16_t gain;  	if (strlen(buf) < 6) { @@ -292,31 +291,12 @@ static void hs_signal_gain_setting(struct headset *hs, const char *buf)  		return;  	} -	signal = dbus_message_new_signal(hs->object_path, "org.bluez.audio.Headset", name); -	if (!signal) { -		error("Unable to allocate new GainChanged signal"); -		return; -	} -  	gain = (dbus_uint16_t) strtol(&buf[5], NULL, 10); -	dbus_message_append_args(signal, DBUS_TYPE_UINT16, &gain, +	dbus_connection_emit_signal(connection, hs->object_path, +					AUDIO_HEADSET_INTERFACE, name, +					DBUS_TYPE_UINT16, &gain,  					DBUS_TYPE_INVALID); - -	send_message_and_unref(connection, signal); -} - -static void hs_signal(struct headset *hs, const char *name) -{ -	DBusMessage *signal; - -	signal = dbus_message_new_signal(hs->object_path, "org.bluez.audio.Headset", name); -	if (!signal) { -		error("Unable to allocate new AnswerRequested signal"); -		return; -	} - -	send_message_and_unref(connection, signal);  }  static headset_event_t parse_headset_event(const char *buf, char *rsp, int rsp_len) @@ -354,7 +334,9 @@ static void close_sco(struct headset *hs)  		headset_close_input(hs);  	assert(hs->rfcomm);  	hs->state = HEADSET_STATE_CONNECTED; -	hs_signal(hs, "Stopped"); +	dbus_connection_emit_signal(connection, hs->object_path, +					AUDIO_HEADSET_INTERFACE, "Stopped", +					DBUS_TYPE_INVALID);  } @@ -414,7 +396,10 @@ static gboolean rfcomm_io_cb(GIOChannel *chan, GIOCondition cond,  			hs->ring_timer = 0;  		} -		hs_signal(hs, "AnswerRequested"); +		dbus_connection_emit_signal(connection, hs->object_path, +						AUDIO_HEADSET_INTERFACE, +						"AnswerRequested", +						DBUS_TYPE_INVALID);  		break;  	case HEADSET_EVENT_INVALID: @@ -503,7 +488,10 @@ static void auth_callback(DBusPendingCall *call, void *data)  		debug("Accepted connection from %s for %s", hs_address, hs->object_path);  		hs->state = HEADSET_STATE_CONNECTED; -		hs_signal(hs, "Connected"); +		dbus_connection_emit_signal(connection, hs->object_path, +						AUDIO_HEADSET_INTERFACE, +						"Connected", +						DBUS_TYPE_INVALID);  	}  	dbus_message_unref(reply); @@ -649,7 +637,9 @@ static gboolean sco_connect_cb(GIOChannel *chan, GIOCondition cond,  	hs->pending_connect = NULL;  	hs->state = HEADSET_STATE_PLAYING; -	hs_signal(hs, "Playing"); +	dbus_connection_emit_signal(connection, hs->object_path, +					AUDIO_HEADSET_INTERFACE, +					"Playing", DBUS_TYPE_INVALID);  	return FALSE; @@ -701,7 +691,9 @@ static gboolean rfcomm_connect_cb(GIOChannel *chan, GIOCondition cond, struct he  	hs->pending_connect->io = NULL;  	hs->state = HEADSET_STATE_CONNECTED; -	hs_signal(hs, "Connected"); +	dbus_connection_emit_signal(connection, hs->object_path, +					AUDIO_HEADSET_INTERFACE, +					"Connected", DBUS_TYPE_INVALID);  	debug("Connected to %s", hs_address); @@ -1197,7 +1189,9 @@ static DBusHandlerResult hs_disconnect(DBusConnection *conn, DBusMessage *msg,  	ba2str(&hs->bda, hs_address);  	info("Disconnected from %s, %s", &hs_address, hs->object_path); -	hs_signal(hs, "Disconnected"); +	dbus_connection_emit_signal(connection, hs->object_path, +					AUDIO_HEADSET_INTERFACE, +					"Disconnected", DBUS_TYPE_INVALID);  	hs->data_start = 0;  	hs->data_length = 0; diff --git a/audio/manager.c b/audio/manager.c index 19a02150..5d381972 100644 --- a/audio/manager.c +++ b/audio/manager.c @@ -87,25 +87,6 @@ static DBusHandlerResult err_invalid_args(DBusConnection *conn, DBusMessage *msg  			descr ? descr : "Invalid arguments in method call");  } -static void manager_signal(DBusConnection *conn, const char *name, -				const char *param) -{ -	DBusMessage *signal; - -	signal = dbus_message_new_signal("/org/bluez/audio", -						"org.bluez.audio.Manager", -						name); -	if (!signal) { -		error("Unable to create new D-Bus signal"); -		return; -	} - -	dbus_message_append_args(signal, DBUS_TYPE_STRING, ¶m, -					DBUS_TYPE_INVALID); - -	send_message_and_unref(conn, signal); -} -  static gboolean unix_event(GIOChannel *chan, GIOCondition cond, gpointer data)  {  	struct sockaddr_un addr; @@ -141,11 +122,19 @@ void manager_add_headset(const char *path)  	headsets = g_slist_append(headsets, my_path); -	manager_signal(connection, "HeadsetCreated", my_path); +	dbus_connection_emit_signal(connection, AUDIO_MANAGER_PATH, +					AUDIO_MANAGER_INTERFACE, +					"HeadsetCreated", +					DBUS_TYPE_STRING, &my_path, +					DBUS_TYPE_INVALID);  	if (!default_hs) {  		default_hs = my_path; -		manager_signal(connection, "DefaultHeadsetChanged", my_path); +		dbus_connection_emit_signal(connection, AUDIO_MANAGER_PATH, +						AUDIO_MANAGER_INTERFACE, +						"DefaultHeadsetChanged", +						DBUS_TYPE_STRING, &my_path, +						DBUS_TYPE_INVALID);  	}  } @@ -235,16 +224,27 @@ static DBusHandlerResult am_remove_headset(DBusConnection *conn, DBusMessage *ms  	headsets = g_slist_remove(headsets, path);  	if (default_hs == path) { +		const char *param; +  		if (!headsets)  			default_hs = NULL;  		else  			default_hs = headsets->data; -		manager_signal(connection, "DefaultHeadsetChanged", -				default_hs ? default_hs : ""); +		param = default_hs ? default_hs : ""; + +		dbus_connection_emit_signal(conn, AUDIO_MANAGER_PATH, +						AUDIO_MANAGER_INTERFACE, +						"DefaultHeadsetChanged", +						DBUS_TYPE_STRING, ¶m, +						DBUS_TYPE_INVALID);  	} -	manager_signal(connection, "HeadsetRemoved", path); +	dbus_connection_emit_signal(conn, AUDIO_MANAGER_PATH, +					AUDIO_MANAGER_INTERFACE, +					"HeadsetRemoved", +					DBUS_TYPE_STRING, &path, +					DBUS_TYPE_INVALID);  	headset_remove(path); @@ -332,7 +332,11 @@ static DBusHandlerResult am_change_default_headset(DBusConnection *conn, DBusMes  	default_hs = match->data; -	manager_signal(connection, "DefaultHeadsetChanged", default_hs); +	dbus_connection_emit_signal(conn, AUDIO_MANAGER_PATH, +					AUDIO_MANAGER_INTERFACE, +					"DefaultHeadsetChanged", +					DBUS_TYPE_STRING, &default_hs, +					DBUS_TYPE_INVALID);  	return send_message_and_unref(connection, reply);  }  | 
