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
35class CommandListener : public FrameworkListener {
36    static TetherController *sTetherCtrl;
37    static NatController *sNatCtrl;
38    static PppController *sPppCtrl;
39    static SoftapController *sSoftapCtrl;
40    static BandwidthController *sBandwidthCtrl;
41    static IdletimerController *sIdletimerCtrl;
42    static InterfaceController *sInterfaceCtrl;
43    static ResolverController *sResolverCtrl;
44    static FirewallController *sFirewallCtrl;
45    static ClatdController *sClatdCtrl;
46
47public:
48    static NetworkController *sNetCtrl;
49
50    CommandListener();
51    virtual ~CommandListener() {}
52
53private:
54
55    class SoftapCmd : public NetdCommand {
56    public:
57        SoftapCmd();
58        virtual ~SoftapCmd() {}
59        int runCommand(SocketClient *c, int argc, char ** argv);
60    };
61
62    class InterfaceCmd : public NetdCommand {
63    public:
64        InterfaceCmd();
65        virtual ~InterfaceCmd() {}
66        int runCommand(SocketClient *c, int argc, char ** argv);
67    };
68
69    class IpFwdCmd : public NetdCommand {
70    public:
71        IpFwdCmd();
72        virtual ~IpFwdCmd() {}
73        int runCommand(SocketClient *c, int argc, char ** argv);
74    };
75
76    class TetherCmd : public NetdCommand {
77    public:
78        TetherCmd();
79        virtual ~TetherCmd() {}
80        int runCommand(SocketClient *c, int argc, char ** argv);
81    };
82
83    class NatCmd : public NetdCommand {
84    public:
85        NatCmd();
86        virtual ~NatCmd() {}
87        int runCommand(SocketClient *c, int argc, char ** argv);
88    };
89
90    class ListTtysCmd : public NetdCommand {
91    public:
92        ListTtysCmd();
93        virtual ~ListTtysCmd() {}
94        int runCommand(SocketClient *c, int argc, char ** argv);
95    };
96
97    class PppdCmd : public NetdCommand {
98    public:
99        PppdCmd();
100        virtual ~PppdCmd() {}
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 IdletimerControlCmd : public NetdCommand {
116    public:
117        IdletimerControlCmd();
118        virtual ~IdletimerControlCmd() {}
119        int runCommand(SocketClient *c, int argc, char ** argv);
120    };
121
122    class ResolverCmd : public NetdCommand {
123    public:
124        ResolverCmd();
125        virtual ~ResolverCmd() {}
126        int runCommand(SocketClient *c, int argc, char ** argv);
127    };
128
129    class FirewallCmd: public NetdCommand {
130    public:
131        FirewallCmd();
132        virtual ~FirewallCmd() {}
133        int runCommand(SocketClient *c, int argc, char ** argv);
134    protected:
135        int sendGenericOkFail(SocketClient *cli, int cond);
136        static FirewallRule parseRule(const char* arg);
137    };
138
139    class ClatdCmd : public NetdCommand {
140    public:
141        ClatdCmd();
142        virtual ~ClatdCmd() {}
143        int runCommand(SocketClient *c, int argc, char ** argv);
144    };
145
146    class NetworkCommand : public NetdCommand {
147    public:
148        NetworkCommand();
149        virtual ~NetworkCommand() {}
150        int runCommand(SocketClient* client, int argc, char** argv);
151    private:
152        int syntaxError(SocketClient* cli, const char* message);
153        int operationError(SocketClient* cli, const char* message, int ret);
154        int success(SocketClient* cli);
155    };
156};
157
158#endif
159