CommandListener.h revision 2eab1f762badb7ba46b95716e62ea4548a979903
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 "IdletimerController.h"
30#include "InterfaceController.h"
31#include "ResolverController.h"
32#include "SecondaryTableController.h"
33#include "FirewallController.h"
34
35class CommandListener : public FrameworkListener {
36    static TetherController *sTetherCtrl;
37    static NatController *sNatCtrl;
38    static PppController *sPppCtrl;
39    static PanController *sPanCtrl;
40    static SoftapController *sSoftapCtrl;
41    static BandwidthController *sBandwidthCtrl;
42    static IdletimerController *sIdletimerCtrl;
43    static InterfaceController *sInterfaceCtrl;
44    static ResolverController *sResolverCtrl;
45    static SecondaryTableController *sSecondaryTableCtrl;
46    static FirewallController *sFirewallCtrl;
47
48public:
49    CommandListener();
50    virtual ~CommandListener() {}
51
52private:
53
54    static int writeFile(const char *path, const char *value, int size);
55
56    static int readInterfaceCounters(const char *iface, unsigned long *rx, unsigned long *tx);
57
58    class SoftapCmd : public NetdCommand {
59    public:
60        SoftapCmd();
61        virtual ~SoftapCmd() {}
62        int runCommand(SocketClient *c, int argc, char ** argv);
63    };
64
65    class InterfaceCmd : public NetdCommand {
66    public:
67        InterfaceCmd();
68        virtual ~InterfaceCmd() {}
69        int runCommand(SocketClient *c, int argc, char ** argv);
70    };
71
72    class IpFwdCmd : public NetdCommand {
73    public:
74        IpFwdCmd();
75        virtual ~IpFwdCmd() {}
76        int runCommand(SocketClient *c, int argc, char ** argv);
77    };
78
79    class TetherCmd : public NetdCommand {
80    public:
81        TetherCmd();
82        virtual ~TetherCmd() {}
83        int runCommand(SocketClient *c, int argc, char ** argv);
84    };
85
86    class NatCmd : public NetdCommand {
87    public:
88        NatCmd();
89        virtual ~NatCmd() {}
90        int runCommand(SocketClient *c, int argc, char ** argv);
91    };
92
93    class ListTtysCmd : public NetdCommand {
94    public:
95        ListTtysCmd();
96        virtual ~ListTtysCmd() {}
97        int runCommand(SocketClient *c, int argc, char ** argv);
98    };
99
100    class PppdCmd : public NetdCommand {
101    public:
102        PppdCmd();
103        virtual ~PppdCmd() {}
104        int runCommand(SocketClient *c, int argc, char ** argv);
105    };
106
107    class PanCmd : public NetdCommand {
108    public:
109        PanCmd();
110        virtual ~PanCmd() {}
111        int runCommand(SocketClient *c, int argc, char ** argv);
112    };
113
114    class BandwidthControlCmd : public NetdCommand {
115    public:
116        BandwidthControlCmd();
117        virtual ~BandwidthControlCmd() {}
118        int runCommand(SocketClient *c, int argc, char ** argv);
119    protected:
120        void sendGenericOkFail(SocketClient *cli, int cond);
121        void sendGenericOpFailed(SocketClient *cli, const char *errMsg);
122        void sendGenericSyntaxError(SocketClient *cli, const char *usageMsg);
123    };
124
125    class IdletimerControlCmd : public NetdCommand {
126    public:
127        IdletimerControlCmd();
128        virtual ~IdletimerControlCmd() {}
129        int runCommand(SocketClient *c, int argc, char ** argv);
130    };
131
132    class ResolverCmd : public NetdCommand {
133    public:
134        ResolverCmd();
135        virtual ~ResolverCmd() {}
136        int runCommand(SocketClient *c, int argc, char ** argv);
137    };
138
139    class FirewallCmd: public NetdCommand {
140    public:
141        FirewallCmd();
142        virtual ~FirewallCmd() {}
143        int runCommand(SocketClient *c, int argc, char ** argv);
144    protected:
145        int sendGenericOkFail(SocketClient *cli, int cond);
146        static FirewallRule parseRule(const char* arg);
147    };
148};
149
150#endif
151