On 20.03.2014 13:28, Daniel P. Berrange wrote:
Split the virDBusMethodCall method into a couple of new methods virDBusCall, virDBusCreateMethod and virDBusCreateMethodV. Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- src/libvirt_private.syms | 3 + src/util/virdbus.c | 207 +++++++++++++++++++++++++++++++++++++++-------- src/util/virdbus.h | 19 +++++ src/util/virdbuspriv.h | 1 - 4 files changed, 195 insertions(+), 35 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3baf766..6091c67 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1155,8 +1155,11 @@ virCryptoHashString; # util/virdbus.h +virDBusCall; virDBusCallMethod; virDBusCloseSystemBus; +virDBusCreateMethod; +virDBusCreateMethodV; virDBusGetSessionBus; virDBusGetSystemBus; virDBusHasSystemBus; diff --git a/src/util/virdbus.c b/src/util/virdbus.c index e3236d8..d4e0381 100644 --- a/src/util/virdbus.c +++ b/src/util/virdbus.c @@ -1049,23 +1049,21 @@ int virDBusMessageDecode(DBusMessage* msg, # define VIR_DBUS_METHOD_CALL_TIMEOUT_MILLIS 30 * 1000 /** - * virDBusCallMethod: - * @conn: a DBus connection - * @replyout: pointer to receive reply message, or NULL + * virDBusCreateMethodV: + * @call: pointer to be filled with a method call message * @destination: bus identifier of the target service * @path: object path of the target service * @iface: the interface of the object * @member: the name of the method in the interface * @types: type signature for following method arguments - * @...: method arguments + * @args: method arguments * - * This invokes a method on a remote service on the - * DBus bus @conn. The @destination, @path, @iface + * This creates a DBus method call message and saves a + * pointer to it in @call. The @destination, @path, @iface * and @member parameters identify the object method to * be invoked. The optional @replyout parameter will be - * filled with any reply to the method call. The - * virDBusMethodReply method can be used to decode the - * return values. + * filled with any reply to the method call. The method + * can be later invoked using virDBusCall. * * The @types parameter is a DBus signature describing * the method call parameters which will be provided @@ -1166,38 +1164,91 @@ int virDBusMessageDecode(DBusMessage* msg, * (3, "email", "s", "joe@xxxxxxxxx", "age", "i", 35, * "address", "as", 3, "Some house", "Some road", "some city") */ - -int virDBusCallMethod(DBusConnection *conn, - DBusMessage **replyout, - const char *destination, - const char *path, - const char *iface, - const char *member, - const char *types, ...) +int virDBusCreateMethodV(DBusMessage **call, + const char *destination, + const char *path, + const char *iface, + const char *member, + const char *types, + va_list args) { - DBusMessage *call = NULL; - DBusMessage *reply = NULL; - DBusError error; int ret = -1; - va_list args; - dbus_error_init(&error); - - if (!(call = dbus_message_new_method_call(destination, - path, - iface, - member))) { + if (!(*call = dbus_message_new_method_call(destination, + path, + iface, + member))) { virReportOOMError(); goto cleanup; } + if (virDBusMessageEncodeArgs(*call, types, args) < 0) { + dbus_message_unref(*call); + *call = NULL; + goto cleanup; + } + + ret = 0; + cleanup:
Indentation's off
+ return ret; +} + + +/** + * virDBusCreateMethod: + * @call: pointer to be filled with a method call message + * @destination: bus identifier of the target service + * @path: object path of the target service + * @iface: the interface of the object + * @member: the name of the method in the interface + * @types: type signature for following method arguments + * @...: method arguments + * + * See virDBusCreateMethodV for a description of the + * behaviour of this method. + */ +int virDBusCreateMethod(DBusMessage **call, + const char *destination, + const char *path, + const char *iface, + const char *member, + const char *types, ...) +{ + va_list args; + int ret; + va_start(args, types); - ret = virDBusMessageEncodeArgs(call, types, args); + ret = virDBusCreateMethodV(call, destination, path, + iface, member, types, args); va_end(args); - if (ret < 0) - goto cleanup; - ret = -1; + return ret; +} + + +/** + * virDBusCall: + * @conn: a DBus connection + * @call: pointer to a message to send + * @replyout: pointer to receive reply message, or NULL + * + * This invokes a method encoded in @call on a remote + * service on the DBus bus @conn. The optional @replyout + * parameter will be filled with any reply to the method + * call. The virDBusMethodReply method can be used to + * decode the return values. + * + * Returns 0 on success, or -1 upon error + */ +int virDBusCall(DBusConnection *conn, + DBusMessage *call, + DBusMessage **replyout) +{ + DBusMessage *reply = NULL; + DBusError error; + int ret = -1; + + dbus_error_init(&error); if (!(reply = dbus_connection_send_with_reply_and_block(conn, call, @@ -1217,10 +1268,8 @@ int virDBusCallMethod(DBusConnection *conn, ret = 0; -cleanup: + cleanup:
And here as well.
dbus_error_free(&error); - if (call) - dbus_message_unref(call); if (reply) { if (ret == 0 && replyout) *replyout = reply;
ACK with that fixed. Michal -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list