| San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 1 | /* | 
 | 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 Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 16 |  | 
| San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 17 | #include <stdlib.h> | 
 | 18 | #include <errno.h> | 
 | 19 |  | 
 | 20 | #define LOG_TAG "Nexus" | 
 | 21 |  | 
 | 22 | #include "cutils/log.h" | 
 | 23 | #include "NetworkManager.h" | 
| San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 24 | #include "CommandListener.h" | 
 | 25 |  | 
 | 26 | #include "LoopController.h" | 
| San Mehat | 94447ca | 2009-05-13 11:54:16 -0700 | [diff] [blame] | 27 | #include "OpenVpnController.h" | 
| San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 28 | #include "TiwlanWifiController.h" | 
| San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 29 |  | 
 | 30 | int main() { | 
| Steve Block | 4163b45 | 2012-01-04 19:19:03 +0000 | [diff] [blame] | 31 |     ALOGI("Nexus version 0.1 firing up"); | 
| San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 32 |  | 
| San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 33 |     CommandListener *cl = new CommandListener(); | 
 | 34 |  | 
 | 35 |     NetworkManager *nm; | 
 | 36 |     if (!(nm = NetworkManager::Instance())) { | 
| Steve Block | 8aeb6e2 | 2012-01-06 14:13:42 +0000 | [diff] [blame] | 37 |         ALOGE("Unable to create NetworkManager"); | 
| San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 38 |         exit (-1); | 
 | 39 |     }; | 
 | 40 |  | 
| San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 41 |     nm->setBroadcaster((SocketListener *) cl); | 
 | 42 |  | 
| San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 43 |     nm->attachController(new LoopController(nm->getPropMngr(), nm)); | 
 | 44 |     nm->attachController(new TiwlanWifiController(nm->getPropMngr(), nm, "/system/lib/modules/wlan.ko", "wlan", "")); | 
 | 45 | //    nm->attachController(new AndroidL2TPVpnController(nm->getPropMngr(), nm)); | 
 | 46 |     nm->attachController(new OpenVpnController(nm->getPropMngr(), nm)); | 
| San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 47 |  | 
 | 48 |  | 
 | 49 |     if (NetworkManager::Instance()->run()) { | 
| Steve Block | 8aeb6e2 | 2012-01-06 14:13:42 +0000 | [diff] [blame] | 50 |         ALOGE("Unable to Run NetworkManager (%s)", strerror(errno)); | 
| San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 51 |         exit (1); | 
 | 52 |     } | 
 | 53 |  | 
| San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 54 |     if (cl->startListener()) { | 
| Steve Block | 8aeb6e2 | 2012-01-06 14:13:42 +0000 | [diff] [blame] | 55 |         ALOGE("Unable to start CommandListener (%s)", strerror(errno)); | 
| San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 56 |         exit (1); | 
 | 57 |     } | 
 | 58 |  | 
| San Mehat | 94447ca | 2009-05-13 11:54:16 -0700 | [diff] [blame] | 59 |     // XXX: we'll use the main thread for the NetworkManager eventually | 
| San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 60 |  | 
| San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 61 |     while(1) { | 
 | 62 |         sleep(1000); | 
 | 63 |     } | 
 | 64 |  | 
| Steve Block | 4163b45 | 2012-01-04 19:19:03 +0000 | [diff] [blame] | 65 |     ALOGI("Nexus exiting"); | 
| San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 66 |     exit(0); | 
 | 67 | } |