Callback support for libhwbinder.

One of the prime differences between HIDL and Binder
is that HIDL allows the server implementation to do
a synchronous callback into the client with response
data. This callback allows the server to respond with
data that is anywhere - on the stack, the heap or globals -
without worrying about the lifetime of the data, since
it can immediately clean up (if necessary) when the callback
returns.

So we go from a chain like this:
IPCThreadState::executeCommand() // Execute BR_TRANSACTION
  BBinder::transact()
    ServerStub::onTransact()
      Server::some_method()
        // Do work, copy data, and return to ServerStub
      // serialize data, and return to BBinder
    // return to IPCThreadState
  IPCThreadState::sendReply()
// done

to a chain like this:
IPCThreadState::executeCommand () // Execute BR_TRANSACTION
  BBinder::transact ()
    ServerStub::onTransact()
      Server::some_method()
        // Do work, send reply
        ServerStub::TransactCallback(reply)
          // Serialize data (until we get scatter-gather)
          BBinder::TransactCallback(serialized_reply)
            IPCThreadState::sendReply(serialized_reply)
              // send reply over binder, return to BBinder
            // return to ServerStub
          // return to Server, server can clean up
        // return to ServerStub
      // return to BBinder
    // return to IPCThreadState
  // IPCThreadState cleanup
// done

To support this, the transact() and onTransact() methods
must support a callback argument, which is added here.

On the proxy side, this callback argument for transact()
can be ignored for now; after all, once the client side gets a
reply, the data is now in the reply Parcel, and the lifetime
of that Parcel is controlled by the Proxy itself. So it
can simply wait for transact() to return, at which point
the reply Parcel is filled.

In the existing Binder model, it would then deserialize
the reply Parcel into arguments that the client had passed
in, and then the Parcel will go out of scope and gets cleaned up.

In HIDL, we deseralize, call the *client* callback, and
then the Parcel goes out of scope and gets cleaned up.

This will change when we get scatter-gather support, but
this allows us to work with the callback-model before that.

Change-Id: If59ee37f68376bc232f3ecbfbe789f7f4d522003
6 files changed