]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Add DBus helper methods for creating reply messages
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 19 Mar 2014 10:58:42 +0000 (10:58 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 21 Mar 2014 11:26:34 +0000 (11:26 +0000)
The test suites often have to create DBus method reply messages
with payloads. Create two helpers for simplifying the process
of creating replies with payloads.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/libvirt_private.syms
src/util/virdbus.c
src/util/virdbus.h

index 1f70e0e474f58eee9cbe09eb5a62ad82657f684f..fe8461f7a0c568d4aa4f0e7b31bba6b672cf63a9 100644 (file)
@@ -1165,6 +1165,8 @@ virDBusCallMethod;
 virDBusCloseSystemBus;
 virDBusCreateMethod;
 virDBusCreateMethodV;
+virDBusCreateReply;
+virDBusCreateReplyV;
 virDBusGetSessionBus;
 virDBusGetSystemBus;
 virDBusHasSystemBus;
index 2576208eb0e51b4005ab7966fbc8632ea76bf2c5..ecfe9f636418c1c99a040e1939166bb229e46f79 100644 (file)
@@ -1228,6 +1228,66 @@ int virDBusCreateMethod(DBusMessage **call,
 }
 
 
+/**
+ * virDBusCreateReplyV:
+ * @reply: pointer to be filled with a method reply message
+ * @types: type signature for following method arguments
+ * @args: method arguments
+ *
+ * This creates a DBus method reply message and saves a
+ * pointer to it in @reply.
+ *
+ * The @types parameter is a DBus signature describing
+ * the method call parameters which will be provided
+ * as variadic args. See virDBusCreateMethodV for a
+ * description of this parameter.
+ */
+int virDBusCreateReplyV(DBusMessage **reply,
+                        const char *types,
+                        va_list args)
+{
+    int ret = -1;
+
+    if (!(*reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN))) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    if (virDBusMessageEncodeArgs(*reply, types, args) < 0) {
+        dbus_message_unref(*reply);
+        *reply = NULL;
+        goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    return ret;
+}
+
+
+/**
+ * virDBusCreateReply:
+ * @reply: pointer to be filled with a method reply message
+ * @types: type signature for following method arguments
+ * @...: method arguments
+ *
+ * See virDBusCreateReplyV for a description of the
+ * behaviour of this method.
+ */
+int virDBusCreateReply(DBusMessage **reply,
+                       const char *types, ...)
+{
+    va_list args;
+    int ret;
+
+    va_start(args, types);
+    ret = virDBusCreateReplyV(reply, types, args);
+    va_end(args);
+
+    return ret;
+}
+
+
 /**
  * virDBusCall:
  * @conn: a DBus connection
index e191a2853531b5bbeaf88b641e43014f2447e312..4fbda8799b512acf5aa547ff142bbe41e2d0457c 100644 (file)
@@ -53,6 +53,11 @@ int virDBusCreateMethodV(DBusMessage **call,
                          const char *member,
                          const char *types,
                          va_list args);
+int virDBusCreateReply(DBusMessage **reply,
+                       const char *types, ...);
+int virDBusCreateReplyV(DBusMessage **reply,
+                        const char *types,
+                        va_list args);
 
 int virDBusCallMethod(DBusConnection *conn,
                       DBusMessage **reply,