blob: 3b823d15d0f1dd6d7dc5e940d71622ceb1c3d9a8 [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 */
16#include <stdio.h>
17#include <errno.h>
18
19#define LOG_TAG "Nexus"
20
21#include <cutils/log.h>
22
23#include "NetworkManager.h"
San Mehatdc266072009-05-06 11:16:52 -070024
San Mehat1441e762009-05-07 11:37:10 -070025NetworkManager *NetworkManager::sInstance = NULL;
26
27NetworkManager *NetworkManager::Instance() {
28 if (!sInstance)
29 sInstance = new NetworkManager();
30 return sInstance;
31}
San Mehatdc266072009-05-06 11:16:52 -070032
33NetworkManager::NetworkManager() {
San Mehat1441e762009-05-07 11:37:10 -070034 mBroadcaster = NULL;
San Mehatdc266072009-05-06 11:16:52 -070035 mControllers = new ControllerCollection();
36}
37
38int NetworkManager::run() {
San Mehatdc266072009-05-06 11:16:52 -070039 if (startControllers()) {
40 LOGW("Unable to start all controllers (%s)", strerror(errno));
41 }
San Mehatdc266072009-05-06 11:16:52 -070042 return 0;
43}
44
San Mehat1441e762009-05-07 11:37:10 -070045int NetworkManager::attachController(Controller *c) {
San Mehatdc266072009-05-06 11:16:52 -070046 mControllers->push_back(c);
San Mehat1441e762009-05-07 11:37:10 -070047 return 0;
San Mehatdc266072009-05-06 11:16:52 -070048}
49
50int NetworkManager::startControllers() {
51 int rc = 0;
52 ControllerCollection::iterator i;
53
54 for (i = mControllers->begin(); i != mControllers->end(); ++i) {
55 int irc = (*i)->start();
56 LOGD("Controller '%s' start rc = %d", (*i)->getName(), irc);
57 if (irc && !rc)
58 rc = irc;
59 }
60 return rc;
61}
62
63int NetworkManager::stopControllers() {
64 int rc = 0;
65 ControllerCollection::iterator i;
66
67 for (i = mControllers->begin(); i != mControllers->end(); ++i) {
68 int irc = (*i)->stop();
69 LOGD("Controller '%s' stop rc = %d", (*i)->getName(), irc);
70 if (irc && !rc)
71 rc = irc;
72 }
73 return rc;
74}
75
76Controller *NetworkManager::findController(const char *name) {
77 ControllerCollection::iterator i;
78 for (i = mControllers->begin(); i != mControllers->end(); ++i) {
79 if (!strcmp((*i)->getName(), name))
80 return *i;
81 }
82 LOGW("Controller '%s' not found", name);
83 return NULL;
84}
85
86int NetworkManager::onInterfaceCreated(Controller *c, char *name) {
87 LOGD("Interface %s created by controller %s", name, c->getName());
88 return 0;
89}
90
91int NetworkManager::onInterfaceDestroyed(Controller *c, char *name) {
92 LOGD("Interface %s destroyed by controller %s", name, c->getName());
93 return 0;
94}