blob: 21708f18ca3174a2127150c929048acce2394d02 [file] [log] [blame]
// Copyright (c) 2013 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.
#ifndef SHILL_ETHERNET_EAP_PROVIDER_H_
#define SHILL_ETHERNET_EAP_PROVIDER_H_
#include <map>
#include <base/callback.h>
#include "shill/provider_interface.h"
#include "shill/refptr_types.h"
namespace shill {
class ControlInterface;
class Error;
class Ethernet;
class EventDispatcher;
class KeyValueStore;
class Manager;
class Metrics;
class EthernetEapProvider : public ProviderInterface {
public:
typedef base::Callback<void()> CredentialChangeCallback;
EthernetEapProvider(ControlInterface *control_interface,
EventDispatcher *dispatcher,
Metrics *metrics,
Manager *manager);
virtual ~EthernetEapProvider();
// Called by Manager as a part of the Provider interface.
virtual void CreateServicesFromProfile(const ProfileRefPtr &profile) override;
virtual ServiceRefPtr GetService(const KeyValueStore &args,
Error *error) override;
virtual ServiceRefPtr FindSimilarService(
const KeyValueStore &args, Error *error) const override;
virtual ServiceRefPtr CreateTemporaryService(
const KeyValueStore &args, Error *error) override;
virtual void Start() override;
virtual void Stop() override;
virtual const ServiceRefPtr &service() const { return service_; }
// Notify |device| via |callback| when EAP credentials have changed.
// Any previous callbacks for |device| are removed. |device| is
// only used a key to a map and is never dereferenced.
virtual void SetCredentialChangeCallback(Ethernet *device,
CredentialChangeCallback callback);
// Clear any previously registered callback for |device|.
virtual void ClearCredentialChangeCallback(Ethernet *device);
// Called by |service_| when EAP credentials are changed. Notify all
// listening Ethernet devices.
virtual void OnCredentialsChanged() const;
private:
friend class EthernetEapProviderTest;
friend class EthernetTest;
friend class ManagerTest;
// Used only in Ethernet and Manager unit tests.
// TODO(gauravsh): Remove this and allow mocks to work correctly
// crbug.com/232134
void set_service(const ServiceRefPtr &service) { service_ = service; }
typedef std::map<Ethernet *, CredentialChangeCallback> CallbackMap;
// Representative service on which EAP credentials are configured.
ServiceRefPtr service_;
// Keyed set of notifiers to call when the EAP credentials for |service_|
// have changed.
CallbackMap callback_map_;
ControlInterface *control_interface_;
EventDispatcher *dispatcher_;
Metrics *metrics_;
Manager *manager_;
};
} // namespace shill
#endif // SHILL_ETHERNET_EAP_PROVIDER_H_