diff options
| -rw-r--r-- | hcid/dbus-manager.c | 29 | ||||
| -rw-r--r-- | hcid/dbus-service.c | 32 | ||||
| -rw-r--r-- | hcid/dbus-service.h | 2 | 
3 files changed, 43 insertions, 20 deletions
| diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index ae180cc6..21587575 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -245,6 +245,34 @@ static DBusHandlerResult list_services(DBusConnection *conn,  	return send_message_and_unref(conn, reply);  } +static DBusHandlerResult activate_service(DBusConnection *conn, +						DBusMessage *msg, void *data) +{ +	const char *pattern, *path; +	struct service *service; + +	if (!dbus_message_get_args(msg, NULL, +				DBUS_TYPE_STRING, &pattern, +				DBUS_TYPE_INVALID)) +		return error_invalid_arguments(conn, msg); + +	path = search_service(conn, pattern); +	if (!path) +		return error_no_such_service(conn, msg); + +	if (!dbus_connection_get_object_path_data(conn, path, +						(void *) &service)) +		return error_no_such_service(conn, msg); + +	if (service_start(service, conn) < 0) +		return error_failed(conn, msg, ENOEXEC); + +	service->action = dbus_message_ref(msg); + +	return DBUS_HANDLER_RESULT_HANDLED; +} + +  static sdp_buf_t *service_record_extract(DBusMessageIter *iter)  {  	sdp_buf_t *sdp_buf; @@ -507,6 +535,7 @@ static struct service_data methods[] = {  	{ "ListAdapters",		list_adapters			},  	{ "FindService",		find_service			},  	{ "ListServices",		list_services			}, +	{ "ActivateService",		activate_service		},  	{ "AddServiceRecord",		add_service_record		},  	{ "AddServiceRecordFromXML", 	add_service_record_xml		},  	{ "RemoveServiceRecord",	remove_service_record		}, diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index c390fc39..08b39d87 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -365,8 +365,10 @@ static DBusHandlerResult service_filter(DBusConnection *conn,  	if (service->action) {  		msg = dbus_message_new_method_return(service->action);  		if (msg) { -			dbus_message_append_args(msg, DBUS_TYPE_STRING, &new, -						DBUS_TYPE_INVALID); +			if (dbus_message_is_method_call(msg, MANAGER_INTERFACE, +							"ActivateService")) +				dbus_message_append_args(msg, DBUS_TYPE_STRING, &new, +							DBUS_TYPE_INVALID);  			send_message_and_unref(conn, msg);  		} @@ -490,7 +492,7 @@ static gboolean service_startup_timeout(gpointer data)  	return FALSE;  } -static int start_service(struct service *service, DBusConnection *conn) +int service_start(struct service *service, DBusConnection *conn)  {  	GError *err = NULL;  	DBusError derr; @@ -551,7 +553,7 @@ static DBusHandlerResult start(DBusConnection *conn,  	if (service->pid)  		return error_failed(conn, msg, EALREADY); -	if (start_service(service, conn) < 0) +	if (service_start(service, conn) < 0)  		return error_failed(conn, msg, ENOEXEC);  	service->action = dbus_message_ref(msg); @@ -858,23 +860,13 @@ void release_services(DBusConnection *conn)  const char *search_service(DBusConnection *conn, const char *pattern)  { -	GSList *l = services; -	struct service *service; -	const char *path; - -	while (l) { -		path = l->data; - -		l = l->next; - -		if (!dbus_connection_get_object_path_data(conn, path, (void *) &service)) -			continue; +	GSList *l; -		if (!service) -			continue; +	for (l = services; l != NULL; l = l->next) { +		struct service *service = l->data;  		if (service->ident && !strcmp(service->ident, pattern)) -			return path; +			return service->object_path;  	}  	return NULL; @@ -1011,7 +1003,7 @@ static void service_notify(int action, const char *name, void *user_data)  		}  		if (service->autostart) -			start_service(service, get_dbus_connection()); +			service_start(service, get_dbus_connection());  		break;  	case NOTIFY_DELETE: @@ -1038,7 +1030,7 @@ static gboolean startup_services(gpointer user_data)  		struct service *service = l->data;  		if (service->autostart) -			start_service(service, get_dbus_connection()); +			service_start(service, get_dbus_connection());  	} diff --git a/hcid/dbus-service.h b/hcid/dbus-service.h index 7fdfd933..d01278fa 100644 --- a/hcid/dbus-service.h +++ b/hcid/dbus-service.h @@ -78,6 +78,8 @@ struct service_call *service_call_new(DBusConnection *conn, DBusMessage *msg,  					struct service *service);  void service_call_free(void *data); +int service_start(struct service *service, DBusConnection *conn); +  int init_services(const char *path);  #endif /* __BLUEZ_DBUS_SERVICE_H */ | 
