9#include "roo_collections/flat_small_hash_set.h"
10#include "roo_scheduler.h"
46 roo_scheduler::Scheduler& scheduler);
102 void setPassword(
const std::string& ssid,
const std::string& passwd);
108 bool connect(
const std::string& ssid,
const std::string& passwd);
114 void forget(
const std::string& ssid);
119 WifiListener(
Controller& wifi) : wifi_(wifi) {}
124 wifi_.onScanCompleted();
128 wifi_.onConnectionStateChanged(type);
142 void periodicRefreshCurrentNetwork();
144 void refreshCurrentNetwork();
146 void updateCurrentNetwork(
const std::string& ssid,
bool open, int8_t rssi,
149 void onScanCompleted();
155 int16_t current_network_index_;
157 std::vector<Network> all_networks_;
159 roo_collections::FlatSmallHashSet<Listener*> model_listeners_;
162 roo_scheduler::SingletonTask start_scan_;
163 roo_scheduler::SingletonTask refresh_current_network_;
Listener for controller events.
virtual ~Listener()=default
virtual void onCurrentNetworkChanged()
virtual void onEnableChanged(bool enabled)
virtual void onScanStarted()
virtual void onConnectionStateChanged(Interface::EventType type)
virtual void onScanCompleted()
High-level Wi-Fi controller that manages scanning and connections.
const Network & currentNetwork() const
Returns the current network (may be empty if disconnected).
void pause()
Temporarily disables periodic refresh and event processing.
ConnectionStatus currentNetworkStatus() const
Returns the connection status of the current network.
void toggleEnabled()
Toggles the enabled/disabled state and persists it in the store.
void begin()
Initializes the controller and registers for interface events.
void resume()
Resumes periodic refresh and event processing.
bool isEnabled() const
Returns true when the interface is enabled.
bool isConnecting() const
Returns true when a connection is in progress.
bool connect()
Connects using stored SSID/password values.
void removeListener(Listener *listener)
Removes a previously added listener.
void forget(const std::string &ssid)
Forgets the password and SSID association.
bool startScan()
Starts a scan. Returns false if a scan could not be started.
void disconnect()
Disconnects the current connection.
~Controller()
Destroys the controller and detaches listeners.
bool getStoredPassword(const std::string &ssid, std::string &passwd) const
Looks up a stored password for the given SSID.
friend class WifiListener
void setPassword(const std::string &ssid, const std::string &passwd)
Stores a password for the given SSID.
bool isScanCompleted() const
Returns true when the current scan has completed.
int otherScannedNetworksCount() const
Returns the number of non-current networks in the scan list.
void addListener(Listener *listener)
Adds a listener for controller events.
const Network * lookupNetwork(const std::string &ssid) const
Returns a network by SSID, or nullptr if not found.
void notifyEnableChanged()
Notifies listeners that enable state changed.
const Network & otherNetwork(int idx) const
Returns the ith non-current network in the scan list.
Listener for interface events.
Abstraction for interacting with the hardware Wi-Fi interface.
EventType
Interface event types.
virtual bool scanCompleted() const =0
Returns true if the last scan has completed.
Abstraction for persistently storing Wi-Fi controller data.
ConnectionStatus
Wi-Fi connection status.
Summary of a scanned network.