libchromeos: Add support for async D-Bus method handlers

Changed DBusObject implementation infrastructure in libchromeos
to add support for registering asynchronous D-Bus method handlers.

Also changed the simple synchronous method handler signature to
eliminate the confusion when a handler returning a value throws
an error.

Currently, there are four kinds of D-Bus method handlers:
- SimpleMethodHandler - has one of the following signatures:

    RetVal Handler(Args... args)
    void Handler(Args... args)

  The first one takes only input parameters (by value or const
  reference) and returns a single value as a function return.
  The second handler can mix both input (value/const reference)
  and output (pointer) values.

  This handler is synchronous (response is sent as soon as the
  handler returns) and does not provide any error returns
  (it always succeeds).

- SimpleMethodHanderWithError
  This is similar to SimpleMethodHandler but provides a way
  to return an error. The handler signature is as follows:

    bool Handler(ErrorPtr* error, Args... args)

  The parameters can include both IN and OUT arguments.

  If the handler succeeds, it must return true. On failures,
  it returns false and provides error details in |error|.

- MethodHandler - a generic (possibly asynchronous) handler
  that has the following signature:

    void Handler(scoped_ptr<DBusMethodResponse> response,
                 Args... args)

  The parameters include only IN arguments and the method
  sends back any return values using the |response| object.

  The handler owns the |response| so it can start an
  asynchronous operation (that holds on to the response) and
  exit immediately. The D-Bus method response is sent only
  when the handler provides the reply using the response
  object.

- RawMethodHandler
  This is the low-level method handler that does not go through
  any of the parameter/return value parsing. It is provided
  with the raw method call D-Bus message and is expected to
  provide the response manually. The handler signtaure is:

    void Handler(dbus::MethodCall* method_call,
                 ResponseSender sender)

  This type of handler is useful to implement D-Bus methods
  with variable number of parameters or those which
  can accept a number of different types of arguments.

BUG=chromium:428390
TEST=FEATURES=test emerge-link libchromeos peerd buffet attestation
CQ-DEPEND=CL:227281

Change-Id: I1dde6b279ada9d350a4d0e6743c56d3b12cc38cf
Reviewed-on: https://chromium-review.googlesource.com/226666
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
6 files changed
tree: 7ad765941f83f6e7c08aa1c65eae1a345923e477
  1. buffet/