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