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