blob: f4ae88fd76c203b126ac9a1d4ee30757d31542fc [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#include <stdio.h>
18#include <errno.h>
19
20#define LOG_TAG "Nexus"
21
22#include <cutils/log.h>
23
24#include "NetworkManager.h"
San Mehat192331d2009-05-22 13:58:06 -070025#include "InterfaceConfig.h"
San Mehatdc266072009-05-06 11:16:52 -070026
San Mehat1441e762009-05-07 11:37:10 -070027NetworkManager *NetworkManager::sInstance = NULL;
28
29NetworkManager *NetworkManager::Instance() {
30 if (!sInstance)
San Mehat3c5a6f02009-05-22 15:36:13 -070031 sInstance = new NetworkManager(new PropertyManager());
San Mehat1441e762009-05-07 11:37:10 -070032 return sInstance;
33}
San Mehatdc266072009-05-06 11:16:52 -070034
San Mehat3c5a6f02009-05-22 15:36:13 -070035NetworkManager::NetworkManager(PropertyManager *propMngr) {
San Mehat1441e762009-05-07 11:37:10 -070036 mBroadcaster = NULL;
San Mehatdc266072009-05-06 11:16:52 -070037 mControllers = new ControllerCollection();
San Mehat3c5a6f02009-05-22 15:36:13 -070038 mPropMngr = propMngr;
39}
40
41NetworkManager::~NetworkManager() {
San Mehatdc266072009-05-06 11:16:52 -070042}
43
44int NetworkManager::run() {
San Mehatdc266072009-05-06 11:16:52 -070045 if (startControllers()) {
46 LOGW("Unable to start all controllers (%s)", strerror(errno));
47 }
San Mehatdc266072009-05-06 11:16:52 -070048 return 0;
49}
50
San Mehat1441e762009-05-07 11:37:10 -070051int NetworkManager::attachController(Controller *c) {
San Mehatdc266072009-05-06 11:16:52 -070052 mControllers->push_back(c);
San Mehat1441e762009-05-07 11:37:10 -070053 return 0;
San Mehatdc266072009-05-06 11:16:52 -070054}
55
56int NetworkManager::startControllers() {
57 int rc = 0;
58 ControllerCollection::iterator i;
59
60 for (i = mControllers->begin(); i != mControllers->end(); ++i) {
61 int irc = (*i)->start();
62 LOGD("Controller '%s' start rc = %d", (*i)->getName(), irc);
San Mehat3c5a6f02009-05-22 15:36:13 -070063 if (irc && !rc)
San Mehatdc266072009-05-06 11:16:52 -070064 rc = irc;
65 }
66 return rc;
67}
68
69int NetworkManager::stopControllers() {
70 int rc = 0;
71 ControllerCollection::iterator i;
72
73 for (i = mControllers->begin(); i != mControllers->end(); ++i) {
74 int irc = (*i)->stop();
75 LOGD("Controller '%s' stop rc = %d", (*i)->getName(), irc);
San Mehat3c5a6f02009-05-22 15:36:13 -070076 if (irc && !rc)
San Mehatdc266072009-05-06 11:16:52 -070077 rc = irc;
78 }
79 return rc;
80}
81
82Controller *NetworkManager::findController(const char *name) {
83 ControllerCollection::iterator i;
84 for (i = mControllers->begin(); i != mControllers->end(); ++i) {
85 if (!strcmp((*i)->getName(), name))
86 return *i;
87 }
88 LOGW("Controller '%s' not found", name);
89 return NULL;
90}
91
San Mehat192331d2009-05-22 13:58:06 -070092int NetworkManager::onInterfaceStart(Controller *c, const InterfaceConfig *cfg) {
San Mehat3c5a6f02009-05-22 15:36:13 -070093 LOGD("Interface %s started by controller %s", c->getBoundInterface(), c->getName());
San Mehat192331d2009-05-22 13:58:06 -070094
95 // Look up the interface
96
97 if (0) { // already started?
98 errno = EADDRINUSE;
99 return -1;
100 }
101
102 if (cfg->getUseDhcp()) {
103 } else {
104 }
San Mehatdc266072009-05-06 11:16:52 -0700105 return 0;
106}
107
San Mehat192331d2009-05-22 13:58:06 -0700108int NetworkManager::onInterfaceStop(Controller *c, const char *name) {
109 LOGD("Interface %s stopped by controller %s", name, c->getName());
San Mehatdc266072009-05-06 11:16:52 -0700110 return 0;
111}