Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78828ff4 authored by San Mehat's avatar San Mehat
Browse files

nexus: Use interface for handling Supplicant events



Signed-off-by: default avatarSan Mehat <san@google.com>
parent 37629255
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
/*
 * 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
+9 −10
Original line number Diff line number Diff line
@@ -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
+16 −15
Original line number Diff line number Diff line
@@ -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");
    }
+5 −5
Original line number Diff line number Diff line
@@ -22,22 +22,22 @@
struct wpa_ctrl;
class Supplicant;
class SocketClient;
class ISupplicantEventHandler;

class SupplicantListener: public SocketListener {
private:
    struct wpa_ctrl         *mMonitor;
    Supplicant      *mSupplicant;
    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