OSDN Git Service

ada79ebfc501ee407d727ffa6230d2b6df2cd57d
[android-x86/system-netd.git] / server / CommandListener.h
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 "SecondaryTableController.h"
33 #include "FirewallController.h"
34 #include "ClatdController.h"
35
36 class PermissionsController;
37 class RouteController;
38
39 class CommandListener : public FrameworkListener {
40     static TetherController *sTetherCtrl;
41     static NatController *sNatCtrl;
42     static PppController *sPppCtrl;
43     static SoftapController *sSoftapCtrl;
44     static BandwidthController *sBandwidthCtrl;
45     static IdletimerController *sIdletimerCtrl;
46     static InterfaceController *sInterfaceCtrl;
47     static ResolverController *sResolverCtrl;
48     static SecondaryTableController *sSecondaryTableCtrl;
49     static FirewallController *sFirewallCtrl;
50     static ClatdController *sClatdCtrl;
51     static RouteController* sRouteController;
52
53 public:
54     static NetworkController *sNetCtrl;
55     static PermissionsController* sPermissionsController;
56
57     CommandListener();
58     virtual ~CommandListener() {}
59
60 private:
61
62     class SoftapCmd : public NetdCommand {
63     public:
64         SoftapCmd();
65         virtual ~SoftapCmd() {}
66         int runCommand(SocketClient *c, int argc, char ** argv);
67     };
68
69     class InterfaceCmd : public NetdCommand {
70     public:
71         InterfaceCmd();
72         virtual ~InterfaceCmd() {}
73         int runCommand(SocketClient *c, int argc, char ** argv);
74     };
75
76     class IpFwdCmd : public NetdCommand {
77     public:
78         IpFwdCmd();
79         virtual ~IpFwdCmd() {}
80         int runCommand(SocketClient *c, int argc, char ** argv);
81     };
82
83     class TetherCmd : public NetdCommand {
84     public:
85         TetherCmd();
86         virtual ~TetherCmd() {}
87         int runCommand(SocketClient *c, int argc, char ** argv);
88     };
89
90     class NatCmd : public NetdCommand {
91     public:
92         NatCmd();
93         virtual ~NatCmd() {}
94         int runCommand(SocketClient *c, int argc, char ** argv);
95     };
96
97     class ListTtysCmd : public NetdCommand {
98     public:
99         ListTtysCmd();
100         virtual ~ListTtysCmd() {}
101         int runCommand(SocketClient *c, int argc, char ** argv);
102     };
103
104     class PppdCmd : public NetdCommand {
105     public:
106         PppdCmd();
107         virtual ~PppdCmd() {}
108         int runCommand(SocketClient *c, int argc, char ** argv);
109     };
110
111     class BandwidthControlCmd : public NetdCommand {
112     public:
113         BandwidthControlCmd();
114         virtual ~BandwidthControlCmd() {}
115         int runCommand(SocketClient *c, int argc, char ** argv);
116     protected:
117         void sendGenericOkFail(SocketClient *cli, int cond);
118         void sendGenericOpFailed(SocketClient *cli, const char *errMsg);
119         void sendGenericSyntaxError(SocketClient *cli, const char *usageMsg);
120     };
121
122     class IdletimerControlCmd : public NetdCommand {
123     public:
124         IdletimerControlCmd();
125         virtual ~IdletimerControlCmd() {}
126         int runCommand(SocketClient *c, int argc, char ** argv);
127     };
128
129     class ResolverCmd : public NetdCommand {
130     public:
131         ResolverCmd();
132         virtual ~ResolverCmd() {}
133         int runCommand(SocketClient *c, int argc, char ** argv);
134     };
135
136     class FirewallCmd: public NetdCommand {
137     public:
138         FirewallCmd();
139         virtual ~FirewallCmd() {}
140         int runCommand(SocketClient *c, int argc, char ** argv);
141     protected:
142         int sendGenericOkFail(SocketClient *cli, int cond);
143         static FirewallRule parseRule(const char* arg);
144     };
145
146     class ClatdCmd : public NetdCommand {
147     public:
148         ClatdCmd();
149         virtual ~ClatdCmd() {}
150         int runCommand(SocketClient *c, int argc, char ** argv);
151     };
152
153     class NetworkCommand : public NetdCommand {
154     public:
155         NetworkCommand();
156         virtual ~NetworkCommand() {}
157         int runCommand(SocketClient* client, int argc, char** argv);
158     private:
159         int syntaxError(SocketClient* cli, const char* message);
160         int paramError(SocketClient* cli, const char* message);
161         int operationError(SocketClient* cli, const char* message);
162         int success(SocketClient* cli);
163     };
164 };
165
166 #endif