blob: 9c649459d35aaf0b3f424917b602f7ed18f01a10 [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"
24#include "CommandListener.h"
25#include "LoopController.h"
26#include "VpnController.h"
27
28#include "TiwlanWifiController.h"
29
30NetworkManager::NetworkManager() {
31 mListener = new CommandListener(this);
32 mFm = new FrameworkManager(mListener);
33 mControllers = new ControllerCollection();
34}
35
36int NetworkManager::run() {
37 LOGD("NetworkManager::start()");
38
39 // XXX: Factory needed
40 addController(new LoopController());
41 addController(new TiwlanWifiController("/system/lib/modules/wlan.ko", "wlan", ""));
42 addController(new VpnController());
43 //addController(new GenericController("rmnet0"));
44
45 if (startControllers()) {
46 LOGW("Unable to start all controllers (%s)", strerror(errno));
47 }
48 mFm->run();
49 return 0;
50}
51
52void NetworkManager::addController(Controller *c) {
53 mControllers->push_back(c);
54}
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);
63 if (irc && !rc)
64 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);
76 if (irc && !rc)
77 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
92int NetworkManager::onInterfaceCreated(Controller *c, char *name) {
93 LOGD("Interface %s created by controller %s", name, c->getName());
94 return 0;
95}
96
97int NetworkManager::onInterfaceDestroyed(Controller *c, char *name) {
98 LOGD("Interface %s destroyed by controller %s", name, c->getName());
99 return 0;
100}