50 #include <nsAutoPtr.h>
66 const char* aDestination,
68 const char* aInterface,
72 NS_ENSURE_ARG_POINTER(aMessage);
76 NS_ENSURE_TRUE(message, NS_ERROR_OUT_OF_MEMORY);
79 DBusMessage* baseMessage = dbus_message_new_method_call(aDestination,
83 NS_ENSURE_TRUE(baseMessage, NS_ERROR_OUT_OF_MEMORY);
84 message->Assign(baseMessage);
87 *aMessage = message.forget();
103 dbus_message_unref(mBaseMessage);
106 mBaseMessage = aMessage;
123 va_start(varArgs, aFirstArgType);
124 dbus_message_get_args_valist(mBaseMessage, &error, aFirstArgType, varArgs);
141 dbus_message_unref(mBaseMessage);
158 DBusBusType aBusType,
159 const char* aDestination,
161 const char* aInterface)
164 NS_ENSURE_ARG_POINTER(aConnection);
171 NS_ENSURE_TRUE(connection, NS_ERROR_OUT_OF_MEMORY);
172 rv = connection->Initialize(aBusType, aDestination, aPath, aInterface);
173 NS_ENSURE_SUCCESS(rv, rv);
176 *aConnection = connection.forget();
188 sbDBusConnection::Initialize(DBusBusType aBusType,
189 const char* aDestination,
191 const char* aInterface)
196 mBaseConnection = dbus_bus_get(aBusType, &error);
201 mDestination.Assign(aDestination);
205 mInterface.Assign(aInterface);
223 NS_ENSURE_ARG_POINTER(aMethod);
231 nsAutoPtr<sbDBusMessage> dBusMessage;
237 NS_ENSURE_SUCCESS(rv, rv);
240 dbus_message_set_auto_start(dBusMessage->get(), TRUE);
243 if (aFirstArgType != DBUS_TYPE_INVALID) {
245 va_start(varArgs, aFirstArgType);
246 success = dbus_message_append_args_valist(dBusMessage->get(),
250 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
257 NS_ENSURE_TRUE(reply, NS_ERROR_OUT_OF_MEMORY);
260 DBusMessage* baseReply;
261 baseReply = dbus_connection_send_with_reply_and_block(mBaseConnection,
263 sMethodCallTimeoutMS,
266 reply->Assign(baseReply);
269 *aReply = reply.forget();
273 success = dbus_connection_send(mBaseConnection, dBusMessage->get(), NULL);
274 NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
286 sbDBusConnection::sbDBusConnection() :
287 mBaseConnection(NULL)
301 dbus_connection_unref(mBaseConnection);
319 dbus_error_init(
this);
331 dbus_error_free(
this);
nsresult GetArgs(int aFirstArgType,...)
static nsresult New(sbDBusConnection **aConnection, DBusBusType aBusType, const char *aDestination, const char *aPath, const char *aInterface)
nsresult InvokeMethod(const char *aMethod, sbDBusMessage **aReply, int aFirstArgType,...)
static nsresult NewMethodCall(sbDBusMessage **aMessage, const char *aDestination, const char *aPath, const char *aInterface, const char *aMethod)
sbDBusMessage(DBusMessage *aMessage=NULL)
Songbird D-Bus Service Definitions.
#define SB_DBUS_ENSURE_SUCCESS(aError, aReturnValue)
void Assign(DBusMessage *aMessage)
virtual ~sbDBusConnection()