1// 2// Copyright (C) 2013 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16 17#include "shill/ethernet/ethernet_eap_provider.h" 18 19#include <string> 20 21#include "shill/ethernet/ethernet_eap_service.h" 22#include "shill/manager.h" 23 24using std::string; 25 26namespace shill { 27 28EthernetEapProvider::EthernetEapProvider(ControlInterface* control_interface, 29 EventDispatcher* dispatcher, 30 Metrics* metrics, 31 Manager* manager) 32 : control_interface_(control_interface), 33 dispatcher_(dispatcher), 34 metrics_(metrics), 35 manager_(manager) {} 36 37EthernetEapProvider::~EthernetEapProvider() {} 38 39void EthernetEapProvider::CreateServicesFromProfile( 40 const ProfileRefPtr& profile) { 41 // Since the EthernetEapProvider's service is created during Start(), 42 // there is no need to do anything in this method. 43} 44 45ServiceRefPtr EthernetEapProvider::FindSimilarService(const KeyValueStore& args, 46 Error* error) const { 47 CHECK_EQ(kTypeEthernetEap, args.LookupString(kTypeProperty, "")) 48 << "Service type must be Ethernet EAP!"; 49 return service(); 50} 51 52ServiceRefPtr EthernetEapProvider::GetService(const KeyValueStore& args, 53 Error* error) { 54 return FindSimilarService(args, error); 55} 56 57ServiceRefPtr EthernetEapProvider::CreateTemporaryService( 58 const KeyValueStore& args, 59 Error* error) { 60 return new EthernetEapService(control_interface_, 61 dispatcher_, 62 metrics_, 63 manager_); 64} 65 66ServiceRefPtr EthernetEapProvider::CreateTemporaryServiceFromProfile( 67 const ProfileRefPtr& profile, const std::string& entry_name, Error* error) { 68 return new EthernetEapService(control_interface_, 69 dispatcher_, 70 metrics_, 71 manager_); 72} 73 74void EthernetEapProvider::Start() { 75 if (!service_) { 76 service_ = new EthernetEapService(control_interface_, 77 dispatcher_, 78 metrics_, 79 manager_); 80 } 81 manager_->RegisterService(service_); 82} 83 84void EthernetEapProvider::Stop() { 85 if (service_) { 86 manager_->DeregisterService(service_); 87 } 88 // Do not destroy the service, since devices may or may not have been 89 // removed as the provider is stopped, and we'd like them to continue 90 // to refer to the same service on restart. 91} 92 93void EthernetEapProvider::SetCredentialChangeCallback( 94 Ethernet* device, CredentialChangeCallback callback) { 95 callback_map_[device] = callback; 96} 97 98void EthernetEapProvider::ClearCredentialChangeCallback(Ethernet* device) { 99 CallbackMap::iterator it = callback_map_.find(device); 100 if (it != callback_map_.end()) { 101 callback_map_.erase(it); 102 } 103} 104 105void EthernetEapProvider::OnCredentialsChanged() const { 106 CallbackMap::const_iterator it; 107 for (it = callback_map_.begin(); it != callback_map_.end(); ++it) { 108 CHECK(!it->second.is_null()); 109 it->second.Run(); 110 } 111} 112 113} // namespace shill 114