blob: af03d2e59df3e2430869bec349128879ddef72f0 [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 */
San Mehat3c5a6f02009-05-22 15:36:13 -070016
San Mehatdc266072009-05-06 11:16:52 -070017#ifndef _CONTROLLER_H
18#define _CONTROLLER_H
19
San Mehat48765672009-05-20 15:28:43 -070020#include <unistd.h>
21#include <sys/types.h>
22
San Mehat3c5a6f02009-05-22 15:36:13 -070023#include <utils/List.h>
San Mehatdc266072009-05-06 11:16:52 -070024
San Mehat3c5a6f02009-05-22 15:36:13 -070025class PropertyManager;
San Mehat3aff2d12009-06-15 14:10:44 -070026class IControllerHandler;
San Mehat48765672009-05-20 15:28:43 -070027
San Mehat3c5a6f02009-05-22 15:36:13 -070028#include "PropertyManager.h"
29#include "IPropertyProvider.h"
30
31class Controller : public IPropertyProvider {
San Mehat3c5a6f02009-05-22 15:36:13 -070032 /*
33 * Name of this controller - WIFI/VPN/USBNET/BTNET/BTDUN/LOOP/etc
34 */
35 char *mName;
36
37 /*
38 * Name of the system ethernet interface which this controller is
39 * bound to.
40 */
41 char *mBoundInterface;
42
43protected:
44 PropertyManager *mPropMngr;
San Mehat3aff2d12009-06-15 14:10:44 -070045 IControllerHandler *mHandlers;
San Mehatdc266072009-05-06 11:16:52 -070046
47public:
San Mehat3aff2d12009-06-15 14:10:44 -070048 Controller(const char *name, PropertyManager *propMngr,
49 IControllerHandler *handlers);
San Mehat3c5a6f02009-05-22 15:36:13 -070050 virtual ~Controller();
San Mehatdc266072009-05-06 11:16:52 -070051
52 virtual int start();
53 virtual int stop();
54
San Mehat48765672009-05-20 15:28:43 -070055 const char *getName() { return mName; }
San Mehat3c5a6f02009-05-22 15:36:13 -070056 const char *getBoundInterface() { return mBoundInterface; }
57
58 /* IPropertyProvider methods */
59 virtual int set(const char *name, const char *value);
60 virtual const char *get(const char *name, char *buffer, size_t maxsize);
San Mehatdc266072009-05-06 11:16:52 -070061
62protected:
63 int loadKernelModule(char *modpath, const char *args);
64 bool isKernelModuleLoaded(const char *modtag);
65 int unloadKernelModule(const char *modtag);
San Mehat3c5a6f02009-05-22 15:36:13 -070066 int bindInterface(const char *ifname);
67 int unbindInterface(const char *ifname);
San Mehat48765672009-05-20 15:28:43 -070068
San Mehatdc266072009-05-06 11:16:52 -070069private:
70 void *loadFile(char *filename, unsigned int *_size);
San Mehatdc266072009-05-06 11:16:52 -070071};
72
73typedef android::List<Controller *> ControllerCollection;
74#endif