blob: 93702ce8deda61e9677a89c4d4ca189fe9c84b35 [file] [log] [blame]
San Mehatdc266072009-05-06 11:16:52 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
San Mehat3c5a6f02009-05-22 15:36:13 -070016
San Mehatdc266072009-05-06 11:16:52 -070017#ifndef _NETWORKMANAGER_H
18#define _NETWORKMANAGER_H
19
San Mehatc4a895b2009-06-23 21:10:57 -070020#include <utils/List.h>
San Mehat1441e762009-05-07 11:37:10 -070021#include <sysutils/SocketListener.h>
San Mehatdc266072009-05-06 11:16:52 -070022
San Mehat1441e762009-05-07 11:37:10 -070023#include "Controller.h"
San Mehat3c5a6f02009-05-22 15:36:13 -070024#include "PropertyManager.h"
San Mehat3aff2d12009-06-15 14:10:44 -070025#include "IControllerHandler.h"
San Mehatd6c67962009-06-22 10:39:36 -070026#include "IDhcpEventHandlers.h"
San Mehatdc266072009-05-06 11:16:52 -070027
San Mehat192331d2009-05-22 13:58:06 -070028class InterfaceConfig;
San Mehatd6c67962009-06-22 10:39:36 -070029class DhcpClient;
San Mehat192331d2009-05-22 13:58:06 -070030
San Mehatd6c67962009-06-22 10:39:36 -070031class NetworkManager : public IControllerHandler, public IDhcpEventHandlers {
San Mehat1441e762009-05-07 11:37:10 -070032 static NetworkManager *sInstance;
33
San Mehatc4a895b2009-06-23 21:10:57 -070034 class ControllerBinding {
35 Controller *mController;
36 InterfaceConfig *mCurrentCfg;
37 InterfaceConfig *mBoundCfg;
38
39 public:
40 ControllerBinding(Controller *c);
41 virtual ~ControllerBinding() {}
42
43 InterfaceConfig *getCurrentCfg() { return mCurrentCfg; }
44 InterfaceConfig *getBoundCfg() { return mCurrentCfg; }
45 Controller *getController() { return mController; }
46
47 void setCurrentCfg(InterfaceConfig *cfg);
48 void setBoundCfg(InterfaceConfig *cfg);
49 };
50
51 typedef android::List<ControllerBinding *> ControllerBindingCollection;
52
San Mehat1441e762009-05-07 11:37:10 -070053private:
San Mehatc4a895b2009-06-23 21:10:57 -070054 ControllerBindingCollection *mControllerBindings;
55 SocketListener *mBroadcaster;
56 PropertyManager *mPropMngr;
57 DhcpClient *mDhcp;
58 int mLastDhcpState;
San Mehatdc266072009-05-06 11:16:52 -070059
60public:
San Mehat3c5a6f02009-05-22 15:36:13 -070061 virtual ~NetworkManager();
San Mehatdc266072009-05-06 11:16:52 -070062
63 int run();
64
San Mehat1441e762009-05-07 11:37:10 -070065 int attachController(Controller *controller);
66
67 Controller *findController(const char *name);
68
69 void setBroadcaster(SocketListener *sl) { mBroadcaster = sl; }
70 SocketListener *getBroadcaster() { return mBroadcaster; }
San Mehat3c5a6f02009-05-22 15:36:13 -070071 PropertyManager *getPropMngr() { return mPropMngr; }
San Mehat1441e762009-05-07 11:37:10 -070072
73 static NetworkManager *Instance();
74
San Mehatdc266072009-05-06 11:16:52 -070075private:
San Mehatdc266072009-05-06 11:16:52 -070076 int startControllers();
77 int stopControllers();
San Mehat48765672009-05-20 15:28:43 -070078
San Mehat3c5a6f02009-05-22 15:36:13 -070079 NetworkManager(PropertyManager *propMngr);
San Mehatc4a895b2009-06-23 21:10:57 -070080 ControllerBinding *lookupBinding(Controller *c);
San Mehatdc266072009-05-06 11:16:52 -070081
San Mehatc4a895b2009-06-23 21:10:57 -070082 void onInterfaceConnected(Controller *c);
83 void onInterfaceDisconnected(Controller *c);
84 void onControllerSuspending(Controller *c);
85 void onControllerResumed(Controller *c);
86
87 void onDhcpStateChanged(Controller *c, int state);
88 void onDhcpEvent(Controller *c, int event);
89 void onDhcpLeaseUpdated(Controller *c,
90 struct in_addr *addr, struct in_addr *net,
91 struct in_addr *brd,
92 struct in_addr *gw, struct in_addr *dns1,
93 struct in_addr *dns2);
San Mehatdc266072009-05-06 11:16:52 -070094};
95#endif