am d6c67966: nexus: Rename onInterfaceStarted -> onInterfaceConnected and add Dhcp start/stop control

Merge commit 'd6c6796670a5e566977b13d542020fb8cc88e6cf'

* commit 'd6c6796670a5e566977b13d542020fb8cc88e6cf':
  nexus: Rename onInterfaceStarted -> onInterfaceConnected and add Dhcp start/stop control
This commit is contained in:
San Mehat 2009-06-22 10:45:25 -07:00 committed by The Android Open Source Project
commit 715c03a10b
4 changed files with 45 additions and 37 deletions

View File

@ -22,8 +22,8 @@ class InterfaceConfig;
class IControllerHandler {
public:
virtual void onInterfaceStarted(Controller *c, const InterfaceConfig *cfg) = 0;
virtual void onInterfaceStopping(Controller *c, const char *name) = 0;
virtual void onInterfaceConnected(Controller *c, const InterfaceConfig *cfg) = 0;
virtual void onInterfaceDisconnected(Controller *c, const char *name) = 0;
};
#endif

View File

@ -23,6 +23,7 @@
#include "NetworkManager.h"
#include "InterfaceConfig.h"
#include "DhcpClient.h"
NetworkManager *NetworkManager::sInstance = NULL;
@ -36,6 +37,7 @@ NetworkManager::NetworkManager(PropertyManager *propMngr) {
mBroadcaster = NULL;
mControllers = new ControllerCollection();
mPropMngr = propMngr;
mDhcp = new DhcpClient(this);
}
NetworkManager::~NetworkManager() {
@ -89,8 +91,8 @@ Controller *NetworkManager::findController(const char *name) {
return NULL;
}
void NetworkManager::onInterfaceStarted(Controller *c, const InterfaceConfig *cfg) {
LOGD("Interface %s started by controller %s", c->getBoundInterface(), c->getName());
void NetworkManager::onInterfaceConnected(Controller *c, const InterfaceConfig *cfg) {
LOGD("Controller %s interface %s connected", c->getName(), c->getBoundInterface());
// Look up the interface
@ -98,9 +100,9 @@ void NetworkManager::onInterfaceStarted(Controller *c, const InterfaceConfig *cf
}
if (cfg) {
if (cfg->getUseDhcp()) {
// Launch DHCP thread
} else {
if (cfg->getUseDhcp() && mDhcp->start(c->getBoundInterface())) {
LOGE("DHCP start failed");
} else if (!cfg->getUseDhcp()) {
// Static configuration
}
} else {
@ -109,6 +111,11 @@ void NetworkManager::onInterfaceStarted(Controller *c, const InterfaceConfig *cf
}
}
void NetworkManager::onInterfaceStopping(Controller *c, const char *name) {
LOGD("Interface %s stopped by controller %s", name, c->getName());
void NetworkManager::onInterfaceDisconnected(Controller *c, const char *name) {
LOGD("Controller %s interface %s disconnected", c->getName(), name);
// If we have a DHCP request out on this interface then stop it
if (1) {
mDhcp->stop();
}
}

View File

@ -22,10 +22,12 @@
#include "Controller.h"
#include "PropertyManager.h"
#include "IControllerHandler.h"
#include "IDhcpEventHandlers.h"
class InterfaceConfig;
class DhcpClient;
class NetworkManager : public IControllerHandler {
class NetworkManager : public IControllerHandler, public IDhcpEventHandlers {
private:
static NetworkManager *sInstance;
@ -33,6 +35,7 @@ private:
ControllerCollection *mControllers;
SocketListener *mBroadcaster;
PropertyManager *mPropMngr;
DhcpClient *mDhcp;
public:
virtual ~NetworkManager();
@ -55,7 +58,7 @@ private:
NetworkManager(PropertyManager *propMngr);
void onInterfaceStarted(Controller *c, const InterfaceConfig *cfg);
void onInterfaceStopping(Controller *c, const char *name);
void onInterfaceConnected(Controller *c, const InterfaceConfig *cfg);
void onInterfaceDisconnected(Controller *c, const char *name);
};
#endif

View File

@ -279,33 +279,31 @@ void WifiController::onAssociatedEvent(SupplicantAssociatedEvent *evt) {
void WifiController::onConnectedEvent(SupplicantConnectedEvent *evt) {
LOGD("onConnectedEvent(%s, %d)", evt->getBssid(), evt->getReassociated());
if (!evt->getReassociated()) {
SupplicantStatus *ss = mSupplicant->getStatus();
WifiNetwork *wn;
SupplicantStatus *ss = mSupplicant->getStatus();
WifiNetwork *wn;
if (ss->getWpaState() != SupplicantState::COMPLETED) {
char tmp[32];
if (ss->getWpaState() != SupplicantState::COMPLETED) {
char tmp[32];
LOGW("onConnected() with SupplicantState = %s!",
SupplicantState::toString(ss->getWpaState(), tmp,
sizeof(tmp)));
return;
}
if (ss->getId() == -1) {
LOGW("onConnected() with id = -1!");
return;
}
if (!(wn = mSupplicant->lookupNetwork(ss->getId()))) {
LOGW("Error looking up connected network id %d (%s)",
ss->getId(), strerror(errno));
return;
}
delete ss;
mHandlers->onInterfaceStarted(this, wn->getIfaceCfg());
LOGW("onConnected() with SupplicantState = %s!",
SupplicantState::toString(ss->getWpaState(), tmp,
sizeof(tmp)));
return;
}
if (ss->getId() == -1) {
LOGW("onConnected() with id = -1!");
return;
}
if (!(wn = mSupplicant->lookupNetwork(ss->getId()))) {
LOGW("Error looking up connected network id %d (%s)",
ss->getId(), strerror(errno));
return;
}
delete ss;
mHandlers->onInterfaceConnected(this, wn->getIfaceCfg());
}
void WifiController::onScanResultsEvent(SupplicantScanResultsEvent *evt) {
@ -373,7 +371,7 @@ void WifiController::onConnectionTimeoutEvent(SupplicantConnectionTimeoutEvent *
}
void WifiController::onDisconnectedEvent(SupplicantDisconnectedEvent *evt) {
LOGD("onDisconnectedEvent()");
mHandlers->onInterfaceDisconnected(this, getBoundInterface());
}
#if 0