nexus: Use interface for handling Supplicant events
Signed-off-by: San Mehat <san@google.com>
diff --git a/nexus/ISupplicantEventHandler.h b/nexus/ISupplicantEventHandler.h
new file mode 100644
index 0000000..7e1bd5a
--- /dev/null
+++ b/nexus/ISupplicantEventHandler.h
@@ -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
+
diff --git a/nexus/Supplicant.h b/nexus/Supplicant.h
index 34ecdcf..42f2f79 100644
--- a/nexus/Supplicant.h
+++ b/nexus/Supplicant.h
@@ -30,8 +30,9 @@
#include "ScanResult.h"
#include "WifiNetwork.h"
#include "IPropertyProvider.h"
+#include "ISupplicantEventHandler.h"
-class Supplicant : public IPropertyProvider {
+class Supplicant : public IPropertyProvider, public ISupplicantEventHandler {
private:
struct wpa_ctrl *mCtrl;
struct wpa_ctrl *mMonitor;
@@ -77,9 +78,13 @@
int set(const char *name, const char *value);
const char *get(const char *name, char *buffer, size_t max);
-// XXX: Extract these into an interface
-// handlers for SupplicantListener
-public:
+private:
+ int connectToSupplicant();
+ int sendCommand(const char *cmd, char *reply, size_t *reply_len);
+ int setupConfig();
+ int retrieveInterfaceName();
+
+ // ISupplicantEventHandler methods
virtual int onConnectedEvent(SupplicantEvent *evt);
virtual int onDisconnectedEvent(SupplicantEvent *evt);
virtual int onTerminatingEvent(SupplicantEvent *evt);
@@ -93,12 +98,6 @@
virtual int onStateChangeEvent(SupplicantEvent *evt);
virtual int onLinkSpeedEvent(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
diff --git a/nexus/SupplicantListener.cpp b/nexus/SupplicantListener.cpp
index 852eeb2..b94648b 100644
--- a/nexus/SupplicantListener.cpp
+++ b/nexus/SupplicantListener.cpp
@@ -23,13 +23,14 @@
#include "libwpa_client/wpa_ctrl.h"
-#include "Supplicant.h"
#include "SupplicantListener.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) {
- mSupplicant = supplicant;
+ mHandlers = handlers;
mMonitor = monitor;
}
@@ -58,29 +59,29 @@
// XXX: Instead of calling Supplicant directly
// extract an Interface and use that instead
if (evt->getType() == SupplicantEvent::EVENT_CONNECTED)
- rc = mSupplicant->onConnectedEvent(evt);
+ rc = mHandlers->onConnectedEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_DISCONNECTED)
- rc = mSupplicant->onDisconnectedEvent(evt);
+ rc = mHandlers->onDisconnectedEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_TERMINATING)
- rc = mSupplicant->onTerminatingEvent(evt);
+ rc = mHandlers->onTerminatingEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_PASSWORD_CHANGED)
- rc = mSupplicant->onPasswordChangedEvent(evt);
+ rc = mHandlers->onPasswordChangedEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_EAP_NOTIFICATION)
- rc = mSupplicant->onEapNotificationEvent(evt);
+ rc = mHandlers->onEapNotificationEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_EAP_STARTED)
- rc = mSupplicant->onEapStartedEvent(evt);
+ rc = mHandlers->onEapStartedEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_EAP_SUCCESS)
- rc = mSupplicant->onEapSuccessEvent(evt);
+ rc = mHandlers->onEapSuccessEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_EAP_FAILURE)
- rc = mSupplicant->onEapFailureEvent(evt);
+ rc = mHandlers->onEapFailureEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_SCAN_RESULTS)
- rc = mSupplicant->onScanResultsEvent(evt);
+ rc = mHandlers->onScanResultsEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_STATE_CHANGE)
- rc = mSupplicant->onStateChangeEvent(evt);
+ rc = mHandlers->onStateChangeEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_LINK_SPEED)
- rc = mSupplicant->onLinkSpeedEvent(evt);
+ rc = mHandlers->onLinkSpeedEvent(evt);
else if (evt->getType() == SupplicantEvent::EVENT_DRIVER_STATE)
- rc = mSupplicant->onDriverStateEvent(evt);
+ rc = mHandlers->onDriverStateEvent(evt);
else {
LOGW("Ignoring unknown event");
}
diff --git a/nexus/SupplicantListener.h b/nexus/SupplicantListener.h
index 680a523..3d186ad 100644
--- a/nexus/SupplicantListener.h
+++ b/nexus/SupplicantListener.h
@@ -22,22 +22,22 @@
struct wpa_ctrl;
class Supplicant;
class SocketClient;
+class ISupplicantEventHandler;
class SupplicantListener: public SocketListener {
private:
- struct wpa_ctrl *mMonitor;
- Supplicant *mSupplicant;
+ struct wpa_ctrl *mMonitor;
+ ISupplicantEventHandler *mHandlers;
public:
- SupplicantListener(Supplicant *supplicant, struct wpa_ctrl *monitor);
+ SupplicantListener(ISupplicantEventHandler *handlers,
+ struct wpa_ctrl *monitor);
virtual ~SupplicantListener() {}
struct wpa_ctrl *getMonitor() { return mMonitor; }
- Supplicant *getSupplicant() { return mSupplicant; }
protected:
virtual bool onDataAvailable(SocketClient *c);
-
};
#endif