CommandListener.h revision 12f6baf16328cdeea8f079616c2c44ac28f82496
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 "NetworkController.h"
24#include "TetherController.h"
25#include "NatController.h"
26#include "PppController.h"
27#include "SoftapController.h"
28#include "BandwidthController.h"
29#include "IdletimerController.h"
30#include "InterfaceController.h"
31#include "ResolverController.h"
32#include "FirewallController.h"
33#include "ClatdController.h"
34#include "StrictController.h"
35
36class CommandListener : public FrameworkListener {
37    static TetherController *sTetherCtrl;
38    static NatController *sNatCtrl;
39    static PppController *sPppCtrl;
40    static SoftapController *sSoftapCtrl;
41    static BandwidthController *sBandwidthCtrl;
42    static IdletimerController *sIdletimerCtrl;
43    static InterfaceController *sInterfaceCtrl;
44    static ResolverController *sResolverCtrl;
45    static FirewallController *sFirewallCtrl;
46    static ClatdController *sClatdCtrl;
47    static StrictController *sStrictCtrl;
48
49public:
50    static NetworkController *sNetCtrl;
51
52    CommandListener();
53    virtual ~CommandListener() {}
54
55private:
56
57    class SoftapCmd : public NetdCommand {
58    public:
59        SoftapCmd();
60        virtual ~SoftapCmd() {}
61        int runCommand(SocketClient *c, int argc, char ** argv);
62    };
63
64    class InterfaceCmd : public NetdCommand {
65    public:
66        InterfaceCmd();
67        virtual ~InterfaceCmd() {}
68        int runCommand(SocketClient *c, int argc, char ** argv);
69    };
70
71    class IpFwdCmd : public NetdCommand {
72    public:
73        IpFwdCmd();
74        virtual ~IpFwdCmd() {}
75        int runCommand(SocketClient *c, int argc, char ** argv);
76    };
77
78    class TetherCmd : public NetdCommand {
79    public:
80        TetherCmd();
81        virtual ~TetherCmd() {}
82        int runCommand(SocketClient *c, int argc, char ** argv);
83    };
84
85    class NatCmd : public NetdCommand {
86    public:
87        NatCmd();
88        virtual ~NatCmd() {}
89        int runCommand(SocketClient *c, int argc, char ** argv);
90    };
91
92    class ListTtysCmd : public NetdCommand {
93    public:
94        ListTtysCmd();
95        virtual ~ListTtysCmd() {}
96        int runCommand(SocketClient *c, int argc, char ** argv);
97    };
98
99    class PppdCmd : public NetdCommand {
100    public:
101        PppdCmd();
102        virtual ~PppdCmd() {}
103        int runCommand(SocketClient *c, int argc, char ** argv);
104    };
105
106    class BandwidthControlCmd : public NetdCommand {
107    public:
108        BandwidthControlCmd();
109        virtual ~BandwidthControlCmd() {}
110        int runCommand(SocketClient *c, int argc, char ** argv);
111    protected:
112        void sendGenericOkFail(SocketClient *cli, int cond);
113        void sendGenericOpFailed(SocketClient *cli, const char *errMsg);
114        void sendGenericSyntaxError(SocketClient *cli, const char *usageMsg);
115    };
116
117    class IdletimerControlCmd : public NetdCommand {
118    public:
119        IdletimerControlCmd();
120        virtual ~IdletimerControlCmd() {}
121        int runCommand(SocketClient *c, int argc, char ** argv);
122    };
123
124    class ResolverCmd : public NetdCommand {
125    public:
126        ResolverCmd();
127        virtual ~ResolverCmd() {}
128        int runCommand(SocketClient *c, int argc, char ** argv);
129
130    private:
131        bool parseAndExecuteSetNetDns(int netId, int argc, const char** argv);
132    };
133
134    class FirewallCmd: public NetdCommand {
135    public:
136        FirewallCmd();
137        virtual ~FirewallCmd() {}
138        int runCommand(SocketClient *c, int argc, char ** argv);
139    protected:
140        int sendGenericOkFail(SocketClient *cli, int cond);
141        static FirewallRule parseRule(const char* arg);
142        static FirewallType parseFirewallType(const char* arg);
143        static ChildChain parseChildChain(const char* arg);
144    };
145
146    class ClatdCmd : public NetdCommand {
147    public:
148        ClatdCmd();
149        virtual ~ClatdCmd() {}
150        int runCommand(SocketClient *c, int argc, char ** argv);
151    };
152
153    class StrictCmd : public NetdCommand {
154    public:
155        StrictCmd();
156        virtual ~StrictCmd() {}
157        int runCommand(SocketClient *c, int argc, char ** argv);
158    protected:
159        int sendGenericOkFail(SocketClient *cli, int cond);
160        static StrictPenalty parsePenalty(const char* arg);
161    };
162
163    class NetworkCommand : public NetdCommand {
164    public:
165        NetworkCommand();
166        virtual ~NetworkCommand() {}
167        int runCommand(SocketClient* client, int argc, char** argv);
168    private:
169        int syntaxError(SocketClient* cli, const char* message);
170        int operationError(SocketClient* cli, const char* message, int ret);
171        int success(SocketClient* cli);
172    };
173};
174
175#endif
176