Make Enable/Disable work using new callbacks for async support.

Use new-style callbacks to implement the Manager EnableTechnology
and DisableTechnology operations asynchronously. This allows
devices to be enabled and disabled from the UI ,and for the UI
to display available networks once the device is enabled.

Removed the behavior whereby setting the Device.Powered property
had the side effect of enabling or disabling the device. To
replace this, I added new Device.Enable and Device.Disable calls
for enabling and disabling individual devices.

Also separated the in-memory value of the Powered property from
the persisted value. Whenever a client requests that a device
be enabled or disabled, the desired power state is immediately
saved in the profile, but the in-memory value isn't updated until
the operation completes. On startup, shill now automatically
starts any devices for which the persistent Powered property
is set, and does not start devices for which it is not set.

BUG=chromium-os:23319,chromium-os:27814
TEST=Manual testing on device + unit tests passing.

Change-Id: Id676be3fc662cfd5efb730c67687edfd16b2dc6b
Reviewed-on: https://gerrit.chromium.org/gerrit/18123
Commit-Ready: Eric Shienbrood <ers@chromium.org>
Reviewed-by: Eric Shienbrood <ers@chromium.org>
Tested-by: Eric Shienbrood <ers@chromium.org>
diff --git a/mm1_modem_proxy.h b/mm1_modem_proxy.h
index 3758423..f7da74d 100644
--- a/mm1_modem_proxy.h
+++ b/mm1_modem_proxy.h
@@ -12,48 +12,58 @@
 #include "shill/mm1_modem_proxy_interface.h"
 
 namespace shill {
-class AsyncCallHandler;
-
 namespace mm1 {
 
 class ModemProxy : public ModemProxyInterface {
  public:
   // Constructs a org.freedesktop.ModemManager1.Modem DBus object
-  // proxy at |path| owned by |service|. Caught signals and
-  // asynchronous method replies will be dispatched to |delegate|.
-  ModemProxy(ModemProxyDelegate *delegate,
-             DBus::Connection *connection,
+  // proxy at |path| owned by |service|.
+  ModemProxy(DBus::Connection *connection,
              const std::string &path,
              const std::string &service);
   virtual ~ModemProxy();
 
   // Inherited methods from ModemProxyInterface.
-  virtual void Enable(const bool &enable,
-                      AsyncCallHandler *call_handler,
+  virtual void Enable(bool enable,
+                      Error *error,
+                      const ResultCallback &callback,
                       int timeout);
-  virtual void ListBearers(AsyncCallHandler *call_handler, int timeout);
-  virtual void CreateBearer(
-      const DBusPropertiesMap &properties,
-      AsyncCallHandler *call_handler,
-      int timeout);
+  virtual void ListBearers(Error *error,
+                           const DBusPathsCallback &callback,
+                           int timeout);
+  virtual void CreateBearer(const DBusPropertiesMap &properties,
+                            Error *error,
+                            const DBusPathCallback &callback,
+                            int timeout);
   virtual void DeleteBearer(const ::DBus::Path &bearer,
-                            AsyncCallHandler *call_handler,
+                            Error *error,
+                            const ResultCallback &callback,
                             int timeout);
-  virtual void Reset(AsyncCallHandler *call_handler, int timeout);
+  virtual void Reset(Error *error,
+                     const ResultCallback &callback,
+                     int timeout);
   virtual void FactoryReset(const std::string &code,
-                            AsyncCallHandler *call_handler,
+                            Error *error,
+                            const ResultCallback &callback,
                             int timeout);
-  virtual void SetAllowedModes(const uint32_t &modes, const uint32_t &preferred,
-                               AsyncCallHandler *call_handler,
+  virtual void SetAllowedModes(const uint32_t &modes,
+                               const uint32_t &preferred,
+                               Error *error,
+                               const ResultCallback &callback,
                                int timeout);
   virtual void SetBands(const std::vector< uint32_t > &bands,
-                        AsyncCallHandler *call_handler,
+                        Error *error,
+                        const ResultCallback &callback,
                         int timeout);
   virtual void Command(const std::string &cmd,
                        const uint32_t &user_timeout,
-                       AsyncCallHandler *call_handler,
+                       Error *error,
+                       const StringCallback &callback,
                        int timeout);
 
+  virtual void set_state_changed_callback(
+      const ModemStateChangedSignalCallback &callback);
+
   // Inherited properties from ModemProxyInterface.
   virtual const ::DBus::Path Sim();
   virtual uint32_t ModemCapabilities();
@@ -83,12 +93,14 @@
   class Proxy : public org::freedesktop::ModemManager1::Modem_proxy,
                 public DBus::ObjectProxy {
    public:
-    Proxy(ModemProxyDelegate *delegate,
-          DBus::Connection *connection,
+    Proxy(DBus::Connection *connection,
           const std::string &path,
           const std::string &service);
     virtual ~Proxy();
 
+    void set_state_changed_callback(
+        const ModemStateChangedSignalCallback &callback);
+
    private:
     // Signal callbacks inherited from Proxy
     // handle signals
@@ -114,7 +126,7 @@
                                  const ::DBus::Error &dberror,
                                  void *data);
 
-    ModemProxyDelegate *delegate_;
+    ModemStateChangedSignalCallback state_changed_callback_;
 
     DISALLOW_COPY_AND_ASSIGN(Proxy);
   };