shill: Start assigning service state

Service state is usually controlled by the associated Device.  Devices
select a single Service to reflect current connection state.  All other
Services remain in an idle or whatever Failure state they ended up with
at the end of their last attempt.

When Service state changes, the service notifies the Manager of its new
state.  This will be used by the Manager to update service priority and
selection of default routes.

For unit-tests, add a "State" test for service_unittest which which
tests for state changes and up-calls to the Manager.  Add
"SelectedDevice" test to device_unittest to ensure proper down-calls
to the service.

BUG=chromium-os:19523
TEST=New unit tests

Change-Id: Ic253cc1dd77821a74176346521aff5948ad59660
Reviewed-on: http://gerrit.chromium.org/gerrit/6495
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/device.h b/device.h
index 008d370..cd3aeeb 100644
--- a/device.h
+++ b/device.h
@@ -16,6 +16,7 @@
 #include "shill/ipconfig.h"
 #include "shill/property_store.h"
 #include "shill/refptr_types.h"
+#include "shill/service.h"
 #include "shill/shill_event.h"
 
 namespace shill {
@@ -87,6 +88,7 @@
   FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);
   FRIEND_TEST(DeviceTest, GetProperties);
   FRIEND_TEST(DeviceTest, Save);
+  FRIEND_TEST(DeviceTest, SelectedService);
 
   // If there's an IP configuration in |ipconfig_|, releases the IP address and
   // destroys the configuration instance.
@@ -104,6 +106,17 @@
   // Remove connection state
   void DestroyConnection();
 
+  // Selects a service to be "current" -- i.e. link-state or configuration
+  // events that happen to the device are attributed to this service.
+  void SelectService(const ServiceRefPtr &service);
+
+  // Set the state of the selected service
+  void SetServiceState(Service::ConnectState state);
+
+  // Set the failure of the selected service (implicitly sets the state to
+  // "failure")
+  void SetServiceFailure(Service::ConnectFailure failure_state);
+
   void HelpRegisterDerivedStrings(const std::string &name,
                                   Strings(Device::*get)(void),
                                   bool(Device::*set)(const Strings&));
@@ -146,6 +159,9 @@
 
   scoped_ptr<DeviceAdaptorInterface> adaptor_;
 
+  // Maintain a reference to the connected / connecting service
+  ServiceRefPtr selected_service_;
+
   // Cache singleton pointer for performance and test purposes.
   DHCPProvider *dhcp_provider_;