Re: [libvirt] [PATCH 1/2] Introduce virDBusCallMethod virDBusMessageRead methods

2013-07-24 Thread Daniel P. Berrange
On Tue, Jul 23, 2013 at 05:02:54PM -0600, Eric Blake wrote:
 On 07/18/2013 07:27 AM, Daniel P. Berrange wrote:
  From: Daniel P. Berrange berra...@redhat.com
  
  Doing DBus method calls using libdbus.so is tedious in the
  extreme. systemd developers came up with a nice high level
  API for DBus method calls (sd_bus_call_method). While
  systemd doesn't use libdbus.so, their API design can easily
  be ported to libdbus.so.
  
  This patch thus introduces methods virDBusCallMethod 
  virDBusMessageRead, which are based on the code used for
  sd_bus_call_method and sd_bus_message_read. This code in
  systemd is under the LGPLv2+, so we're license compatible.
  
  This code is probably pretty unintelligible unless you are
  familiar with the DBus type system. So I added some API
  docs trying to explain how to use them, as well as test
  cases to validate that I didn't screw up the adaptation
  from the original systemd code.
  
  Signed-off-by: Daniel P. Berrange berra...@redhat.com
  ---
 
  +static const char virDBusBasicTypes[] = {
  +DBUS_TYPE_BYTE,
  +DBUS_TYPE_BOOLEAN,
  +DBUS_TYPE_INT16,
  +DBUS_TYPE_UINT16,
  +DBUS_TYPE_INT32,
  +DBUS_TYPE_UINT32,
  +DBUS_TYPE_INT64,
  +DBUS_TYPE_UINT64,
  +DBUS_TYPE_DOUBLE,
  +DBUS_TYPE_STRING,
  +DBUS_TYPE_OBJECT_PATH,
  +DBUS_TYPE_SIGNATURE,
  +DBUS_TYPE_UNIX_FD
  +};
 
 This fails to build on RHEL 6.4:
 
   CC libvirt_util_la-virdbus.lo
 util/virdbus.c:242: error: 'DBUS_TYPE_UNIX_FD' undeclared here (not in a
 function)
 cc1: warnings being treated as errors
 
 
 DBUS_TYPE_UNIX_FD was added sometime after dbus-devel-1.2.24 and before
 1.6.12; we'll have to make the code conditional and error out if a
 client tries to pass an fd when using an older version of dbus.

Ok, I'll add an #ifdef

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/2] Introduce virDBusCallMethod virDBusMessageRead methods

2013-07-23 Thread Eric Blake
On 07/18/2013 07:27 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 Doing DBus method calls using libdbus.so is tedious in the
 extreme. systemd developers came up with a nice high level
 API for DBus method calls (sd_bus_call_method). While
 systemd doesn't use libdbus.so, their API design can easily
 be ported to libdbus.so.
 
 This patch thus introduces methods virDBusCallMethod 
 virDBusMessageRead, which are based on the code used for
 sd_bus_call_method and sd_bus_message_read. This code in
 systemd is under the LGPLv2+, so we're license compatible.
 
 This code is probably pretty unintelligible unless you are
 familiar with the DBus type system. So I added some API
 docs trying to explain how to use them, as well as test
 cases to validate that I didn't screw up the adaptation
 from the original systemd code.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---

 +static const char virDBusBasicTypes[] = {
 +DBUS_TYPE_BYTE,
 +DBUS_TYPE_BOOLEAN,
 +DBUS_TYPE_INT16,
 +DBUS_TYPE_UINT16,
 +DBUS_TYPE_INT32,
 +DBUS_TYPE_UINT32,
 +DBUS_TYPE_INT64,
 +DBUS_TYPE_UINT64,
 +DBUS_TYPE_DOUBLE,
 +DBUS_TYPE_STRING,
 +DBUS_TYPE_OBJECT_PATH,
 +DBUS_TYPE_SIGNATURE,
 +DBUS_TYPE_UNIX_FD
 +};

This fails to build on RHEL 6.4:

  CC libvirt_util_la-virdbus.lo
util/virdbus.c:242: error: 'DBUS_TYPE_UNIX_FD' undeclared here (not in a
function)
cc1: warnings being treated as errors


DBUS_TYPE_UNIX_FD was added sometime after dbus-devel-1.2.24 and before
1.6.12; we'll have to make the code conditional and error out if a
client tries to pass an fd when using an older version of dbus.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/2] Introduce virDBusCallMethod virDBusMessageRead methods

2013-07-18 Thread Eric Blake
On 07/18/2013 07:27 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 Doing DBus method calls using libdbus.so is tedious in the
 extreme. systemd developers came up with a nice high level
 API for DBus method calls (sd_bus_call_method). While
 systemd doesn't use libdbus.so, their API design can easily
 be ported to libdbus.so.
 
 This patch thus introduces methods virDBusCallMethod 
 virDBusMessageRead, which are based on the code used for
 sd_bus_call_method and sd_bus_message_read. This code in
 systemd is under the LGPLv2+, so we're license compatible.
 
 This code is probably pretty unintelligible unless you are
 familiar with the DBus type system. So I added some API
 docs trying to explain how to use them, as well as test
 cases to validate that I didn't screw up the adaptation
 from the original systemd code.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com

Failed to build.

util/virdbus.c:1119:9: error: implicit declaration of function
'virReportDBusServiceError' [-Werror=implicit-function-declaration]
 virReportDBusServiceError(error.message ? error.message :
unknown error,
 ^
util/virdbus.c:1119:9: error: nested extern declaration of
'virReportDBusServiceError' [-Werror=nested-externs]

 ---
  .gitignore   |   1 +
  src/libvirt_private.syms |   4 +
  src/util/virdbus.c   | 966 
 ++-
  src/util/virdbus.h   |  11 +
  src/util/virdbuspriv.h   |  45 +++
  tests/Makefile.am|  13 +
  tests/virdbustest.c  | 389 +++
  7 files changed, 1428 insertions(+), 1 deletion(-)
  create mode 100644 src/util/virdbuspriv.h
  create mode 100644 tests/virdbustest.c

 +++ b/.gitignore
 @@ -191,6 +191,7 @@
  /tests/virbitmaptest
  /tests/virbuftest
  /tests/vircgrouptest
 +/tests/virdbustest

Yay - an added test is reassuring (although I didn't actually run it,
due to the compile error).

 +
 +if (virDBusSignatureLengthInternal(s + 1, true, arrayDepth+1, 
 structDepth, t)  0)

Inconsistent spacing around '+'.

 +
 +while (*p != DBUS_STRUCT_END_CHAR) {
 +size_t t;
 +
 +if (virDBusSignatureLengthInternal(p, false, arrayDepth, 
 structDepth+1, t)  0)

and again, probably also a long line worth wrapping.


 +
 +if (virDBusSignatureLengthInternal(p, false, arrayDepth, 
 structDepth+1, t)  0)

Recurring theme on '+'; I'll quit pointing them out.

 +
 +/* Ideally, we'd just call ourselves recursively on every
 + * complex type. However, the state of a va_list that is
 + * passed to a function is undefined after that function
 + * returns. This means we need to docode the va_list linearly

d/docode/decode/

 + * in a single stackframe. We hence implement our own
 + * home-grown stack in an array. */

Is it also possible to use va_copy, or is that risking stack explosion
because we'd have to copy the list for each recursion?

 +/**
 + * @conn: a DBus connection

Missing the method name 'virDBusCallMethod:' before the parameters.

 + * @replyout: pointer to receive reply message, or NULL
 + * @destination: bus identifier of the target service
 + * @path: object path of the target service
 + * @interface: the interface of the object
 + * @member: the name of the method in the interface
 + * @types: type signature for following method arguments
 + * @...: method arguments

 + * 'd' - 8-byte floating point, passed as a 'double'
 + * 's' - NULL terminated string, in UTF-8
 + * 'o' - NULL terminated string, representing a valid object path
 + * 'g' - NULL terminated string, representing a valid type signature

Technically, it's NUL-terminated (terminated by the one-byte character
NUL, not by the 4/8 byte pointer NULL), but we're inconsistent on this
so I don't care if you leave it.

 + * Example signatures, with their corresponding variadic
 + * args:

Thanks; this helps.

 + *
 + * - a{sv} - a hash table (aka array + dict entry)
 + *
 + * (3, email, s, j...@blogs.com, age, i, 35,
 + *  address, as, 3, Some house, Some road, some city)

Wow, that adds up fast.

 +ret = -1;
 +
 +if (!(reply = dbus_connection_send_with_reply_and_block(conn,
 +call,
 +30 * 1000,

Worth a symbolic name for this magic number?

 +
 +/**
 + * virDBusMessageRead:
 + * @msg: the reply to decode
 + * @types: type signature for following return values
 + * @...: pointers in which to store return values
 + *
 + * The @types type signature is the same format as
 + * that used for the virDBusCallMethod. The difference
 + * is that each variadic parameter must be a pointer to
 + * be filled with the values. eg instead of passing an
 + * 'int', pass an 'int *'.

Are variants/structs/dicts allowed on decoding?  If so, an example of
how to interleave intermediate types alongside pointers for receiving
contents may make sense.

 +++