CommandListener.h 4.95 KB
Newer Older
San Mehat's avatar
San Mehat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _COMMANDLISTENER_H__
#define _COMMANDLISTENER_H__

#include <sysutils/FrameworkListener.h>
San Mehat's avatar
San Mehat committed
21

San Mehat's avatar
San Mehat committed
22
#include "NetdCommand.h"
23
#include "NetworkController.h"
24
#include "TetherController.h"
San Mehat's avatar
San Mehat committed
25
#include "NatController.h"
26
#include "PppController.h"
27
#include "SoftapController.h"
28
#include "BandwidthController.h"
29
#include "IdletimerController.h"
30
#include "InterfaceController.h"
Mattias Falk's avatar
Mattias Falk committed
31
#include "ResolverController.h"
32
#include "FirewallController.h"
Daniel Drown's avatar
Daniel Drown committed
33
#include "ClatdController.h"
34
#include "StrictController.h"
San Mehat's avatar
San Mehat committed
35 36

class CommandListener : public FrameworkListener {
37
    static TetherController *sTetherCtrl;
San Mehat's avatar
San Mehat committed
38
    static NatController *sNatCtrl;
39
    static PppController *sPppCtrl;
40
    static SoftapController *sSoftapCtrl;
41
    static BandwidthController *sBandwidthCtrl;
42
    static IdletimerController *sIdletimerCtrl;
43
    static InterfaceController *sInterfaceCtrl;
Mattias Falk's avatar
Mattias Falk committed
44
    static ResolverController *sResolverCtrl;
45
    static FirewallController *sFirewallCtrl;
Daniel Drown's avatar
Daniel Drown committed
46
    static ClatdController *sClatdCtrl;
47
    static StrictController *sStrictCtrl;
48

San Mehat's avatar
San Mehat committed
49
public:
50 51 52
    static NetworkController *sNetCtrl;

    CommandListener();
San Mehat's avatar
San Mehat committed
53 54 55 56
    virtual ~CommandListener() {}

private:

57 58 59 60 61 62 63
    class SoftapCmd : public NetdCommand {
    public:
        SoftapCmd();
        virtual ~SoftapCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

64
    class InterfaceCmd : public NetdCommand {
San Mehat's avatar
San Mehat committed
65
    public:
66 67
        InterfaceCmd();
        virtual ~InterfaceCmd() {}
San Mehat's avatar
San Mehat committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class IpFwdCmd : public NetdCommand {
    public:
        IpFwdCmd();
        virtual ~IpFwdCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class TetherCmd : public NetdCommand {
    public:
        TetherCmd();
        virtual ~TetherCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class NatCmd : public NetdCommand {
    public:
        NatCmd();
        virtual ~NatCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    };
91 92 93 94 95 96 97 98 99 100 101 102 103 104

    class ListTtysCmd : public NetdCommand {
    public:
        ListTtysCmd();
        virtual ~ListTtysCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

    class PppdCmd : public NetdCommand {
    public:
        PppdCmd();
        virtual ~PppdCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    };
105

106 107 108 109 110
    class BandwidthControlCmd : public NetdCommand {
    public:
        BandwidthControlCmd();
        virtual ~BandwidthControlCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
111 112 113 114
    protected:
        void sendGenericOkFail(SocketClient *cli, int cond);
        void sendGenericOpFailed(SocketClient *cli, const char *errMsg);
        void sendGenericSyntaxError(SocketClient *cli, const char *usageMsg);
115
    };
116

117 118 119 120 121 122 123
    class IdletimerControlCmd : public NetdCommand {
    public:
        IdletimerControlCmd();
        virtual ~IdletimerControlCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    };

Mattias Falk's avatar
Mattias Falk committed
124 125 126 127 128 129
    class ResolverCmd : public NetdCommand {
    public:
        ResolverCmd();
        virtual ~ResolverCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    };
130 131 132 133 134 135 136 137 138 139

    class FirewallCmd: public NetdCommand {
    public:
        FirewallCmd();
        virtual ~FirewallCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    protected:
        int sendGenericOkFail(SocketClient *cli, int cond);
        static FirewallRule parseRule(const char* arg);
    };
Daniel Drown's avatar
Daniel Drown committed
140 141 142 143 144 145 146

    class ClatdCmd : public NetdCommand {
    public:
        ClatdCmd();
        virtual ~ClatdCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    };
147

148 149 150 151 152 153 154 155 156 157
    class StrictCmd : public NetdCommand {
    public:
        StrictCmd();
        virtual ~StrictCmd() {}
        int runCommand(SocketClient *c, int argc, char ** argv);
    protected:
        int sendGenericOkFail(SocketClient *cli, int cond);
        static StrictPenalty parsePenalty(const char* arg);
    };

158
    class NetworkCommand : public NetdCommand {
159
    public:
160 161 162
        NetworkCommand();
        virtual ~NetworkCommand() {}
        int runCommand(SocketClient* client, int argc, char** argv);
163 164
    private:
        int syntaxError(SocketClient* cli, const char* message);
165
        int operationError(SocketClient* cli, const char* message, int ret);
166
        int success(SocketClient* cli);
167
    };
San Mehat's avatar
San Mehat committed
168 169 170
};

#endif