CommandListener.h revision db7da58e8d2aa021060098057f944ef754be06e3
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
17#ifndef _COMMANDLISTENER_H__
18#define _COMMANDLISTENER_H__
19
20#include <sysutils/FrameworkListener.h>
21
22#include "NetdCommand.h"
23#include "TetherController.h"
24#include "NatController.h"
25#include "PppController.h"
26#include "PanController.h"
27#include "SoftapController.h"
28#include "BandwidthController.h"
29#include "ResolverController.h"
30
31class CommandListener : public FrameworkListener {
32    static TetherController *sTetherCtrl;
33    static NatController *sNatCtrl;
34    static PppController *sPppCtrl;
35    static PanController *sPanCtrl;
36    static SoftapController *sSoftapCtrl;
37    static BandwidthController *sBandwidthCtrl;
38    static ResolverController *sResolverCtrl;
39
40public:
41    CommandListener();
42    virtual ~CommandListener() {}
43
44private:
45
46    static int readInterfaceCounters(const char *iface, unsigned long *rx, unsigned long *tx);
47
48    class SoftapCmd : public NetdCommand {
49    public:
50        SoftapCmd();
51        virtual ~SoftapCmd() {}
52        int runCommand(SocketClient *c, int argc, char ** argv);
53    };
54
55    class InterfaceCmd : public NetdCommand {
56    public:
57        InterfaceCmd();
58        virtual ~InterfaceCmd() {}
59        int runCommand(SocketClient *c, int argc, char ** argv);
60    };
61
62    class IpFwdCmd : public NetdCommand {
63    public:
64        IpFwdCmd();
65        virtual ~IpFwdCmd() {}
66        int runCommand(SocketClient *c, int argc, char ** argv);
67    };
68
69    class TetherCmd : public NetdCommand {
70    public:
71        TetherCmd();
72        virtual ~TetherCmd() {}
73        int runCommand(SocketClient *c, int argc, char ** argv);
74    };
75
76    class NatCmd : public NetdCommand {
77    public:
78        NatCmd();
79        virtual ~NatCmd() {}
80        int runCommand(SocketClient *c, int argc, char ** argv);
81    };
82
83    class ListTtysCmd : public NetdCommand {
84    public:
85        ListTtysCmd();
86        virtual ~ListTtysCmd() {}
87        int runCommand(SocketClient *c, int argc, char ** argv);
88    };
89
90    class PppdCmd : public NetdCommand {
91    public:
92        PppdCmd();
93        virtual ~PppdCmd() {}
94        int runCommand(SocketClient *c, int argc, char ** argv);
95    };
96
97    class PanCmd : public NetdCommand {
98    public:
99        PanCmd();
100        virtual ~PanCmd() {}
101        int runCommand(SocketClient *c, int argc, char ** argv);
102    };
103
104    class BandwidthControlCmd : public NetdCommand {
105    public:
106        BandwidthControlCmd();
107        virtual ~BandwidthControlCmd() {}
108        int runCommand(SocketClient *c, int argc, char ** argv);
109    protected:
110        void sendGenericOkFail(SocketClient *cli, int cond);
111        void sendGenericOpFailed(SocketClient *cli, const char *errMsg);
112        void sendGenericSyntaxError(SocketClient *cli, const char *usageMsg);
113    };
114
115    class ResolverCmd : public NetdCommand {
116    public:
117        ResolverCmd();
118        virtual ~ResolverCmd() {}
119        int runCommand(SocketClient *c, int argc, char ** argv);
120    };
121};
122
123#endif
124