blob: ae5fee85ee64d44e6c28ad4e8b06b4edd548f9a4 [file] [log] [blame]
// Copyright 2020 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_SUPPLICANT_SUPPLICANT_MANAGER_H_
#define SHILL_SUPPLICANT_SUPPLICANT_MANAGER_H_
#include <memory>
#include <vector>
#include <base/bind.h>
#include <base/callback.h>
namespace shill {
class ControlInterface;
class EventDispatcher;
class Manager;
class SupplicantProcessProxyInterface;
class SupplicantManager {
public:
using SupplicantListenerCallback = base::Callback<void(bool)>;
class ScopedSupplicantListener {
public:
ScopedSupplicantListener(SupplicantManager* supplicant_manager,
const SupplicantListenerCallback& callback);
~ScopedSupplicantListener();
private:
SupplicantListenerCallback callback_;
SupplicantManager* const supplicant_manager_;
DISALLOW_COPY_AND_ASSIGN(ScopedSupplicantListener);
};
explicit SupplicantManager(Manager* manager);
~SupplicantManager();
void Start();
SupplicantProcessProxyInterface* proxy() const { return proxy_.get(); }
private:
friend class WiFiObjectTest;
friend class EthernetTest;
friend class SupplicantManagerTest;
void AddSupplicantListener(
const SupplicantListenerCallback& present_callback);
void RemoveSupplicantListener(
const SupplicantListenerCallback& present_callback);
void OnSupplicantPresence(bool present);
// Used by tests to set a mock SupplicantProcessProxy. Takes ownership of
// |proxy|.
void set_proxy(SupplicantProcessProxyInterface* proxy);
ControlInterface* control_interface_;
EventDispatcher* dispatcher_;
std::unique_ptr<SupplicantProcessProxyInterface> proxy_;
std::vector<SupplicantListenerCallback> listeners_;
bool present_ = false;
DISALLOW_COPY_AND_ASSIGN(SupplicantManager);
};
} // namespace shill
#endif // SHILL_SUPPLICANT_SUPPLICANT_MANAGER_H_