blob: e8564cae58949e12429098e7f1d921d66b3f4339 [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#ifndef _NETWORKMANAGER_H
17#define _NETWORKMANAGER_H
18
San Mehat1441e762009-05-07 11:37:10 -070019#include <sysutils/SocketListener.h>
San Mehatdc266072009-05-06 11:16:52 -070020
San Mehat1441e762009-05-07 11:37:10 -070021#include "Controller.h"
San Mehat48765672009-05-20 15:28:43 -070022#include "PropertyCollection.h"
San Mehatdc266072009-05-06 11:16:52 -070023
San Mehat192331d2009-05-22 13:58:06 -070024class InterfaceConfig;
25
San Mehatdc266072009-05-06 11:16:52 -070026class NetworkManager {
27private:
San Mehat1441e762009-05-07 11:37:10 -070028 static NetworkManager *sInstance;
29
30private:
San Mehatdc266072009-05-06 11:16:52 -070031 ControllerCollection *mControllers;
San Mehat1441e762009-05-07 11:37:10 -070032 SocketListener *mBroadcaster;
San Mehat48765672009-05-20 15:28:43 -070033 PropertyCollection *mProperties;
San Mehatdc266072009-05-06 11:16:52 -070034
35public:
San Mehatdc266072009-05-06 11:16:52 -070036 virtual ~NetworkManager() {}
37
38 int run();
39
San Mehat1441e762009-05-07 11:37:10 -070040 int attachController(Controller *controller);
41
42 Controller *findController(const char *name);
43
San Mehat48765672009-05-20 15:28:43 -070044 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 Mehat1441e762009-05-07 11:37:10 -070048 void setBroadcaster(SocketListener *sl) { mBroadcaster = sl; }
49 SocketListener *getBroadcaster() { return mBroadcaster; }
50
51 static NetworkManager *Instance();
52
San Mehatdc266072009-05-06 11:16:52 -070053private:
San Mehatdc266072009-05-06 11:16:52 -070054 int startControllers();
55 int stopControllers();
San Mehat48765672009-05-20 15:28:43 -070056 int registerProperty(const char *name);
57 int unregisterProperty(const char *name);
58
San Mehat1441e762009-05-07 11:37:10 -070059 NetworkManager();
San Mehatdc266072009-05-06 11:16:52 -070060
61public:
San Mehat192331d2009-05-22 13:58:06 -070062 /*
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 Mehatdc266072009-05-06 11:16:52 -070067
San Mehat192331d2009-05-22 13:58:06 -070068 /*
69 * Called from a controller when an interface should be shut down
70 */
71 int onInterfaceStop(Controller *c, const char *name);
San Mehatdc266072009-05-06 11:16:52 -070072};
73#endif