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 | */ |
| 16 | #ifndef _NETWORKMANAGER_H |
| 17 | #define _NETWORKMANAGER_H |
| 18 | |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 19 | #include <sysutils/SocketListener.h> |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 20 | |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 21 | #include "Controller.h" |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame] | 22 | #include "PropertyCollection.h" |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 23 | |
San Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame^] | 24 | class InterfaceConfig; |
| 25 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 26 | class NetworkManager { |
| 27 | private: |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 28 | static NetworkManager *sInstance; |
| 29 | |
| 30 | private: |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 31 | ControllerCollection *mControllers; |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 32 | SocketListener *mBroadcaster; |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame] | 33 | PropertyCollection *mProperties; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 34 | |
| 35 | public: |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 36 | virtual ~NetworkManager() {} |
| 37 | |
| 38 | int run(); |
| 39 | |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 40 | int attachController(Controller *controller); |
| 41 | |
| 42 | Controller *findController(const char *name); |
| 43 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame] | 44 | const PropertyCollection &getProperties(); |
| 45 | int setProperty(const char *name, char *value); |
| 46 | const char *getProperty(const char *name, char *buffer, size_t maxsize); |
| 47 | |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 48 | void setBroadcaster(SocketListener *sl) { mBroadcaster = sl; } |
| 49 | SocketListener *getBroadcaster() { return mBroadcaster; } |
| 50 | |
| 51 | static NetworkManager *Instance(); |
| 52 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 53 | private: |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 54 | int startControllers(); |
| 55 | int stopControllers(); |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame] | 56 | int registerProperty(const char *name); |
| 57 | int unregisterProperty(const char *name); |
| 58 | |
San Mehat | 1441e76 | 2009-05-07 11:37:10 -0700 | [diff] [blame] | 59 | NetworkManager(); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 60 | |
| 61 | public: |
San Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame^] | 62 | /* |
| 63 | * Called from a controller when an interface is available/ready for use. |
| 64 | * 'cfg' contains information on how this interface should be configured. |
| 65 | */ |
| 66 | int onInterfaceStart(Controller *c, const InterfaceConfig *cfg); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 67 | |
San Mehat | 192331d | 2009-05-22 13:58:06 -0700 | [diff] [blame^] | 68 | /* |
| 69 | * Called from a controller when an interface should be shut down |
| 70 | */ |
| 71 | int onInterfaceStop(Controller *c, const char *name); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 72 | }; |
| 73 | #endif |