Add async support for shill client calls.

Many of the modem manager method invocations performed by the
shill cellular support have been converted to be asynchronous,
based on the dbus-c++ support for asynchronous proxies.
I've also hooked this up with the mechanism that was recently
introduced that allows adaptor methods to defer returning
results to callers of shill methods, so that we now have
an end-to-end asynchronous solution.

Adaptor methods that want to be non-blocking create a Returner
object, which will later be used to send back the result
of the operation. The cellular device code that implements
the method (or the cellular service code, depending on the
method), wraps the Returner in an AsyncCallHandler object,
which is passed to the proxy methods as the "data" argument.
When the reply callback for the method occurs, it can pull
the Returner object out of the AsyncCallHandler and use it
to return the result.

In the case of an operation like Enable that involves multiple
client method invocations, the object that wraps the returner
is a MultiStepAsyncCallHandler, a subclass of AsyncCallHandler,
that also wraps a list of Tasks comprising the compound
operation.

In either case, a callback indicates that the handling of
the method is complete by calling Complete() on the AsyncCallHandler.
This is an overloaded method - without any argument, it returns
a success result to the caller of the shill method. With an
Error argument, it returns the DBus::Error equivalent of that
error to the caller. For a MultiStepAsyncCallHandler, calling
Complete() with no argument removes the next Task from the
list and posts it to the main loop, unless there are no
remaining tasks, in which case it returns the result to
the caller of the original shill method.

I've converted the following operations to work asynchronously
end-to-end:
Enable, Register, EnterPIN, RequirePIN, ChangePIN, UnblockPIN,
Activate.
Connect and Scan have been changed to be asynchronous on the
proxy side, but not yet on the adaptor side. For Enable, all of
the individual proxy operations are now done asynchronously,
except for fetching of individual properties.

I've moved all the ModemProxy and ModemSimpleProxy method
invocations from Cellular into CellularCapability. Now all
operations to the modem are done through a Capability interface.

There is a memory leak issue noted in the file async_call_handler.h

BUG=chromium-os:23433,chromium-os:22732
TEST=unit tests, testing on device

Change-Id: I54254dd36d116a1e9089bc9b1a60fa06a3098bd5
Reviewed-on: https://gerrit.chromium.org/gerrit/12564
Commit-Ready: Eric Shienbrood <ers@chromium.org>
Reviewed-by: Eric Shienbrood <ers@chromium.org>
Tested-by: Eric Shienbrood <ers@chromium.org>
diff --git a/async_call_handler.h b/async_call_handler.h
new file mode 100644
index 0000000..af88be0
--- /dev/null
+++ b/async_call_handler.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_ASYNC_CALL_HANDLER_
+#define SHILL_ASYNC_CALL_HANDLER_
+
+#include <base/basictypes.h>
+
+namespace shill {
+
+class Error;
+class ReturnerInterface;
+
+// TODO(ers): An AsyncCallHandler object for an in-flight operation can leak if
+// an ObjectProxy disappears before the object is deleted. This can probably
+// be handled by changing dbus-c++ to allow registering a user-supplied
+// 'free' function for the 'data' argument passed to proxy methods. In that
+// case, the objects will be freed when pending dbus calls are canceled.
+//
+// The same issue appears to be relevant to Returner objects as well.
+
+
+// This class implements reply handling for code that makes asynchronous
+// client calls. The default behavior, embodied in this class, is to
+// return a result or error to the pending adaptor method invocation,
+// if any. This behavior may be overridden or extended by specializations
+// of this class.
+//
+// <external-client> --- [method call] ---> shill adaptor
+class AsyncCallHandler {
+ public:
+  AsyncCallHandler();
+  explicit AsyncCallHandler(ReturnerInterface *returner);
+  virtual ~AsyncCallHandler() { }
+
+  // Signal successful completion of the handling of a reply to a
+  // single asynchronous client operation. Returns true if a terminal
+  // state has been reached, i.e., the AsyncCallHandler is no longer
+  // needed. The base class always returns true.
+  bool Complete();
+  // Signal completion of the handling of a reply to a single
+  // asynchronous client operation which resulted in an error.
+  // Returns true if a terminal state has been reached, i.e.,
+  // the AsyncCallHandler is no longer needed. The base class always
+  // returns true.
+  bool Complete(const Error &error);
+
+ protected:
+  ReturnerInterface *returner() const { return returner_; }
+
+  virtual bool CompleteOperation();
+  virtual bool CompleteOperationWithError(const Error &error);
+
+  void DoReturn();
+
+ private:
+  // scoped_ptr not used here because Returners delete themselves
+  ReturnerInterface *returner_;
+
+  DISALLOW_COPY_AND_ASSIGN(AsyncCallHandler);
+};
+
+}  // namespace shill
+
+#endif  // SHILL_ASYNC_CALL_HANDLER_