nexus: Use interface for handling Supplicant events
Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
parent
37629255e9
commit
78828ff4f5
4 changed files with 68 additions and 30 deletions
38
nexus/ISupplicantEventHandler.h
Normal file
38
nexus/ISupplicantEventHandler.h
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ISUPPLICANT_EVENT_HANDLER_H
|
||||||
|
#define _ISUPPLICANT_EVENT_HANDLER_H
|
||||||
|
|
||||||
|
class ISupplicantEventHandler {
|
||||||
|
public:
|
||||||
|
virtual int onConnectedEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onDisconnectedEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onTerminatingEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onPasswordChangedEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onEapNotificationEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onEapStartedEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onEapMethodEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onEapSuccessEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onEapFailureEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onScanResultsEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onStateChangeEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onLinkSpeedEvent(SupplicantEvent *evt) = 0;
|
||||||
|
virtual int onDriverStateEvent(SupplicantEvent *evt) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -30,8 +30,9 @@ class WifiController;
|
||||||
#include "ScanResult.h"
|
#include "ScanResult.h"
|
||||||
#include "WifiNetwork.h"
|
#include "WifiNetwork.h"
|
||||||
#include "IPropertyProvider.h"
|
#include "IPropertyProvider.h"
|
||||||
|
#include "ISupplicantEventHandler.h"
|
||||||
|
|
||||||
class Supplicant : public IPropertyProvider {
|
class Supplicant : public IPropertyProvider, public ISupplicantEventHandler {
|
||||||
private:
|
private:
|
||||||
struct wpa_ctrl *mCtrl;
|
struct wpa_ctrl *mCtrl;
|
||||||
struct wpa_ctrl *mMonitor;
|
struct wpa_ctrl *mMonitor;
|
||||||
|
|
@ -77,9 +78,13 @@ public:
|
||||||
int set(const char *name, const char *value);
|
int set(const char *name, const char *value);
|
||||||
const char *get(const char *name, char *buffer, size_t max);
|
const char *get(const char *name, char *buffer, size_t max);
|
||||||
|
|
||||||
// XXX: Extract these into an interface
|
private:
|
||||||
// handlers for SupplicantListener
|
int connectToSupplicant();
|
||||||
public:
|
int sendCommand(const char *cmd, char *reply, size_t *reply_len);
|
||||||
|
int setupConfig();
|
||||||
|
int retrieveInterfaceName();
|
||||||
|
|
||||||
|
// ISupplicantEventHandler methods
|
||||||
virtual int onConnectedEvent(SupplicantEvent *evt);
|
virtual int onConnectedEvent(SupplicantEvent *evt);
|
||||||
virtual int onDisconnectedEvent(SupplicantEvent *evt);
|
virtual int onDisconnectedEvent(SupplicantEvent *evt);
|
||||||
virtual int onTerminatingEvent(SupplicantEvent *evt);
|
virtual int onTerminatingEvent(SupplicantEvent *evt);
|
||||||
|
|
@ -93,12 +98,6 @@ public:
|
||||||
virtual int onStateChangeEvent(SupplicantEvent *evt);
|
virtual int onStateChangeEvent(SupplicantEvent *evt);
|
||||||
virtual int onLinkSpeedEvent(SupplicantEvent *evt);
|
virtual int onLinkSpeedEvent(SupplicantEvent *evt);
|
||||||
virtual int onDriverStateEvent(SupplicantEvent *evt);
|
virtual int onDriverStateEvent(SupplicantEvent *evt);
|
||||||
|
|
||||||
private:
|
|
||||||
int connectToSupplicant();
|
|
||||||
int sendCommand(const char *cmd, char *reply, size_t *reply_len);
|
|
||||||
int setupConfig();
|
|
||||||
int retrieveInterfaceName();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,14 @@
|
||||||
|
|
||||||
#include "libwpa_client/wpa_ctrl.h"
|
#include "libwpa_client/wpa_ctrl.h"
|
||||||
|
|
||||||
#include "Supplicant.h"
|
|
||||||
#include "SupplicantListener.h"
|
#include "SupplicantListener.h"
|
||||||
#include "SupplicantEvent.h"
|
#include "SupplicantEvent.h"
|
||||||
|
#include "ISupplicantEventHandler.h"
|
||||||
|
|
||||||
SupplicantListener::SupplicantListener(Supplicant *supplicant, struct wpa_ctrl *monitor) :
|
SupplicantListener::SupplicantListener(ISupplicantEventHandler *handlers,
|
||||||
|
struct wpa_ctrl *monitor) :
|
||||||
SocketListener(wpa_ctrl_get_fd(monitor), false) {
|
SocketListener(wpa_ctrl_get_fd(monitor), false) {
|
||||||
mSupplicant = supplicant;
|
mHandlers = handlers;
|
||||||
mMonitor = monitor;
|
mMonitor = monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,29 +59,29 @@ bool SupplicantListener::onDataAvailable(SocketClient *cli) {
|
||||||
// XXX: Instead of calling Supplicant directly
|
// XXX: Instead of calling Supplicant directly
|
||||||
// extract an Interface and use that instead
|
// extract an Interface and use that instead
|
||||||
if (evt->getType() == SupplicantEvent::EVENT_CONNECTED)
|
if (evt->getType() == SupplicantEvent::EVENT_CONNECTED)
|
||||||
rc = mSupplicant->onConnectedEvent(evt);
|
rc = mHandlers->onConnectedEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_DISCONNECTED)
|
else if (evt->getType() == SupplicantEvent::EVENT_DISCONNECTED)
|
||||||
rc = mSupplicant->onDisconnectedEvent(evt);
|
rc = mHandlers->onDisconnectedEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_TERMINATING)
|
else if (evt->getType() == SupplicantEvent::EVENT_TERMINATING)
|
||||||
rc = mSupplicant->onTerminatingEvent(evt);
|
rc = mHandlers->onTerminatingEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_PASSWORD_CHANGED)
|
else if (evt->getType() == SupplicantEvent::EVENT_PASSWORD_CHANGED)
|
||||||
rc = mSupplicant->onPasswordChangedEvent(evt);
|
rc = mHandlers->onPasswordChangedEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_EAP_NOTIFICATION)
|
else if (evt->getType() == SupplicantEvent::EVENT_EAP_NOTIFICATION)
|
||||||
rc = mSupplicant->onEapNotificationEvent(evt);
|
rc = mHandlers->onEapNotificationEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_EAP_STARTED)
|
else if (evt->getType() == SupplicantEvent::EVENT_EAP_STARTED)
|
||||||
rc = mSupplicant->onEapStartedEvent(evt);
|
rc = mHandlers->onEapStartedEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_EAP_SUCCESS)
|
else if (evt->getType() == SupplicantEvent::EVENT_EAP_SUCCESS)
|
||||||
rc = mSupplicant->onEapSuccessEvent(evt);
|
rc = mHandlers->onEapSuccessEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_EAP_FAILURE)
|
else if (evt->getType() == SupplicantEvent::EVENT_EAP_FAILURE)
|
||||||
rc = mSupplicant->onEapFailureEvent(evt);
|
rc = mHandlers->onEapFailureEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_SCAN_RESULTS)
|
else if (evt->getType() == SupplicantEvent::EVENT_SCAN_RESULTS)
|
||||||
rc = mSupplicant->onScanResultsEvent(evt);
|
rc = mHandlers->onScanResultsEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_STATE_CHANGE)
|
else if (evt->getType() == SupplicantEvent::EVENT_STATE_CHANGE)
|
||||||
rc = mSupplicant->onStateChangeEvent(evt);
|
rc = mHandlers->onStateChangeEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_LINK_SPEED)
|
else if (evt->getType() == SupplicantEvent::EVENT_LINK_SPEED)
|
||||||
rc = mSupplicant->onLinkSpeedEvent(evt);
|
rc = mHandlers->onLinkSpeedEvent(evt);
|
||||||
else if (evt->getType() == SupplicantEvent::EVENT_DRIVER_STATE)
|
else if (evt->getType() == SupplicantEvent::EVENT_DRIVER_STATE)
|
||||||
rc = mSupplicant->onDriverStateEvent(evt);
|
rc = mHandlers->onDriverStateEvent(evt);
|
||||||
else {
|
else {
|
||||||
LOGW("Ignoring unknown event");
|
LOGW("Ignoring unknown event");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,22 +22,22 @@
|
||||||
struct wpa_ctrl;
|
struct wpa_ctrl;
|
||||||
class Supplicant;
|
class Supplicant;
|
||||||
class SocketClient;
|
class SocketClient;
|
||||||
|
class ISupplicantEventHandler;
|
||||||
|
|
||||||
class SupplicantListener: public SocketListener {
|
class SupplicantListener: public SocketListener {
|
||||||
private:
|
private:
|
||||||
struct wpa_ctrl *mMonitor;
|
struct wpa_ctrl *mMonitor;
|
||||||
Supplicant *mSupplicant;
|
ISupplicantEventHandler *mHandlers;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SupplicantListener(Supplicant *supplicant, struct wpa_ctrl *monitor);
|
SupplicantListener(ISupplicantEventHandler *handlers,
|
||||||
|
struct wpa_ctrl *monitor);
|
||||||
virtual ~SupplicantListener() {}
|
virtual ~SupplicantListener() {}
|
||||||
|
|
||||||
struct wpa_ctrl *getMonitor() { return mMonitor; }
|
struct wpa_ctrl *getMonitor() { return mMonitor; }
|
||||||
Supplicant *getSupplicant() { return mSupplicant; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool onDataAvailable(SocketClient *c);
|
virtual bool onDataAvailable(SocketClient *c);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue