Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/ethernet_eap_provider.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include "shill/ethernet_eap_service.h" |
| 10 | #include "shill/manager.h" |
| 11 | |
| 12 | using std::string; |
| 13 | |
| 14 | namespace shill { |
| 15 | |
| 16 | EthernetEapProvider::EthernetEapProvider(ControlInterface *control_interface, |
| 17 | EventDispatcher *dispatcher, |
| 18 | Metrics *metrics, |
| 19 | Manager *manager) |
| 20 | : control_interface_(control_interface), |
| 21 | dispatcher_(dispatcher), |
| 22 | metrics_(metrics), |
| 23 | manager_(manager) {} |
| 24 | |
Paul Stewart | 93e00f4 | 2013-04-19 15:45:23 -0700 | [diff] [blame] | 25 | EthernetEapProvider::~EthernetEapProvider() {} |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 26 | |
| 27 | void EthernetEapProvider::Start() { |
| 28 | if (!service_) { |
| 29 | service_ = new EthernetEapService(control_interface_, |
| 30 | dispatcher_, |
| 31 | metrics_, |
| 32 | manager_); |
| 33 | } |
| 34 | manager_->RegisterService(service_); |
| 35 | } |
| 36 | |
| 37 | void EthernetEapProvider::Stop() { |
| 38 | if (service_) { |
| 39 | manager_->DeregisterService(service_); |
| 40 | } |
| 41 | // Do not destroy the service, since devices may or may not have been |
| 42 | // removed as the provider is stopped, and we'd like them to continue |
| 43 | // to refer to the same service on restart. |
| 44 | } |
| 45 | |
| 46 | void EthernetEapProvider::SetCredentialChangeCallback( |
| 47 | Ethernet *device, CredentialChangeCallback callback) { |
| 48 | callback_map_[device] = callback; |
| 49 | } |
| 50 | |
| 51 | void EthernetEapProvider::ClearCredentialChangeCallback(Ethernet *device) { |
| 52 | CallbackMap::iterator it = callback_map_.find(device); |
| 53 | if (it != callback_map_.end()) { |
| 54 | callback_map_.erase(it); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void EthernetEapProvider::OnCredentialsChanged() const { |
| 59 | CallbackMap::const_iterator it; |
| 60 | for (it = callback_map_.begin(); it != callback_map_.end(); ++it) { |
| 61 | CHECK(!it->second.is_null()); |
| 62 | it->second.Run(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | } // namespace shill |