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/modem_gsm_network_proxy_interface.h b/modem_gsm_network_proxy_interface.h
index 6c1cbaf..e3ab494 100644
--- a/modem_gsm_network_proxy_interface.h
+++ b/modem_gsm_network_proxy_interface.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// 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.
 
@@ -14,37 +14,56 @@
 
 namespace shill {
 
+class AsyncCallHandler;
+class Error;
+
+typedef DBus::Struct<unsigned int, std::string, std::string>
+    GSMRegistrationInfo;
+typedef std::map<std::string, std::string> GSMScanResult;
+typedef std::vector<GSMScanResult> GSMScanResults;
+
 // These are the methods that a ModemManager.Modem.Gsm.Network proxy must
 // support. The interface is provided so that it can be mocked in tests.
+// All calls are made asynchronously. Call completion is signalled through
+// the corresponding 'OnXXXCallback' method in the ProxyDelegate interface.
 class ModemGSMNetworkProxyInterface {
  public:
-  typedef DBus::Struct<uint32, std::string, std::string> RegistrationInfo;
-  typedef std::map<std::string, std::string> ScanResult;
-  typedef std::vector<ScanResult> ScanResults;
-
   virtual ~ModemGSMNetworkProxyInterface() {}
 
-  virtual RegistrationInfo GetRegistrationInfo() = 0;
+  virtual void GetRegistrationInfo(AsyncCallHandler *call_handler,
+                                   int timeout) = 0;
   virtual uint32 GetSignalQuality() = 0;
-  virtual void Register(const std::string &network_id) = 0;
-  virtual ScanResults Scan() = 0;
+  virtual void Register(const std::string &network_id,
+                        AsyncCallHandler *call_handler, int timeout) = 0;
+  virtual void Scan(AsyncCallHandler *call_handler, int timeout) = 0;
 
   // Properties.
   virtual uint32 AccessTechnology() = 0;
 };
 
-// ModemManager.Modem.Gsm.Network signal delegate to be associated with the
-// proxy.
+// ModemManager.Modem.Gsm.Network method reply callback and signal
+// delegate to be associated with the proxy.
 class ModemGSMNetworkProxyDelegate {
  public:
   virtual ~ModemGSMNetworkProxyDelegate() {}
 
   virtual void OnGSMNetworkModeChanged(uint32 mode) = 0;
+  // The following callback handler is used for both the
+  // RegistrationInfo signal and the GetRegistrationInfo
+  // method reply. For the signal case, the |call_handler|
+  // is NULL.
   virtual void OnGSMRegistrationInfoChanged(
       uint32 status,
       const std::string &operator_code,
-      const std::string &operator_name) = 0;
+      const std::string &operator_name,
+      const Error &error,
+      AsyncCallHandler *call_handler) = 0;
   virtual void OnGSMSignalQualityChanged(uint32 quality) = 0;
+  virtual void OnScanCallback(const GSMScanResults &results,
+                              const Error &error,
+                              AsyncCallHandler *call_handler) = 0;
+  virtual void OnRegisterCallback(const Error &error,
+                                  AsyncCallHandler *call_handler) = 0;
 };
 
 }  // namespace shill