am 78828ff4: nexus: Use interface for handling Supplicant events

Merge commit '78828ff4f5f959fcf8066ecb6a6b689d2a3c5985'

* commit '78828ff4f5f959fcf8066ecb6a6b689d2a3c5985':
  nexus: Use interface for handling Supplicant events
  nexus: Remove dependancy on libutil
This commit is contained in:
San Mehat 2009-06-02 10:32:12 -07:00 committed by The Android Open Source Project
commit e085355735
5 changed files with 70 additions and 32 deletions

View file

@ -32,7 +32,7 @@ LOCAL_C_INCLUDES := $(KERNEL_HEADERS) -I../../../frameworks/base/include/
LOCAL_CFLAGS :=
LOCAL_SHARED_LIBRARIES := libsysutils libwpa_client libutils
LOCAL_SHARED_LIBRARIES := libsysutils libwpa_client
include $(BUILD_EXECUTABLE)
@ -46,7 +46,7 @@ LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
LOCAL_CFLAGS :=
LOCAL_SHARED_LIBRARIES := libutils
LOCAL_SHARED_LIBRARIES := libcutils
include $(BUILD_EXECUTABLE)

View 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

View file

@ -30,8 +30,9 @@ class WifiController;
#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 @@ public:
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 @@ public:
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

View file

@ -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 @@ bool SupplicantListener::onDataAvailable(SocketClient *cli) {
// 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");
}

View file

@ -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