CommandListener.h revision ddf2d5bc87fe6de7cae2b73a17dbaf35033565ca
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#include "utils/RWLock.h" 22 23#include "NetdCommand.h" 24#include "NetdConstants.h" 25#include "NetworkController.h" 26#include "TetherController.h" 27#include "NatController.h" 28#include "PppController.h" 29#include "SoftapController.h" 30#include "BandwidthController.h" 31#include "IdletimerController.h" 32#include "InterfaceController.h" 33#include "ResolverController.h" 34#include "FirewallController.h" 35#include "ClatdController.h" 36#include "StrictController.h" 37 38class CommandListener : public FrameworkListener { 39public: 40 CommandListener(); 41 virtual ~CommandListener() {} 42 43private: 44 void registerLockingCmd(FrameworkCommand *cmd, android::RWLock& lock); 45 void registerLockingCmd(FrameworkCommand *cmd) { 46 registerLockingCmd(cmd, android::net::gBigNetdLock); 47 } 48 49 class SoftapCmd : public NetdCommand { 50 public: 51 SoftapCmd(); 52 virtual ~SoftapCmd() {} 53 int runCommand(SocketClient *c, int argc, char ** argv); 54 }; 55 56 class InterfaceCmd : public NetdCommand { 57 public: 58 InterfaceCmd(); 59 virtual ~InterfaceCmd() {} 60 int runCommand(SocketClient *c, int argc, char ** argv); 61 }; 62 63 class IpFwdCmd : public NetdCommand { 64 public: 65 IpFwdCmd(); 66 virtual ~IpFwdCmd() {} 67 int runCommand(SocketClient *c, int argc, char ** argv); 68 }; 69 70 class TetherCmd : public NetdCommand { 71 public: 72 TetherCmd(); 73 virtual ~TetherCmd() {} 74 int runCommand(SocketClient *c, int argc, char ** argv); 75 }; 76 77 class NatCmd : public NetdCommand { 78 public: 79 NatCmd(); 80 virtual ~NatCmd() {} 81 int runCommand(SocketClient *c, int argc, char ** argv); 82 }; 83 84 class ListTtysCmd : public NetdCommand { 85 public: 86 ListTtysCmd(); 87 virtual ~ListTtysCmd() {} 88 int runCommand(SocketClient *c, int argc, char ** argv); 89 }; 90 91 class PppdCmd : public NetdCommand { 92 public: 93 PppdCmd(); 94 virtual ~PppdCmd() {} 95 int runCommand(SocketClient *c, int argc, char ** argv); 96 }; 97 98 class BandwidthControlCmd : public NetdCommand { 99 public: 100 BandwidthControlCmd(); 101 virtual ~BandwidthControlCmd() {} 102 int runCommand(SocketClient *c, int argc, char ** argv); 103 protected: 104 void sendGenericOkFail(SocketClient *cli, int cond); 105 void sendGenericOpFailed(SocketClient *cli, const char *errMsg); 106 void sendGenericSyntaxError(SocketClient *cli, const char *usageMsg); 107 }; 108 109 class IdletimerControlCmd : public NetdCommand { 110 public: 111 IdletimerControlCmd(); 112 virtual ~IdletimerControlCmd() {} 113 int runCommand(SocketClient *c, int argc, char ** argv); 114 }; 115 116 class ResolverCmd : public NetdCommand { 117 public: 118 ResolverCmd(); 119 virtual ~ResolverCmd() {} 120 int runCommand(SocketClient *c, int argc, char ** argv); 121 }; 122 123 class FirewallCmd: public NetdCommand { 124 public: 125 FirewallCmd(); 126 virtual ~FirewallCmd() {} 127 int runCommand(SocketClient *c, int argc, char ** argv); 128 protected: 129 int sendGenericOkFail(SocketClient *cli, int cond); 130 static FirewallRule parseRule(const char* arg); 131 static FirewallType parseFirewallType(const char* arg); 132 static ChildChain parseChildChain(const char* arg); 133 }; 134 135 class ClatdCmd : public NetdCommand { 136 public: 137 ClatdCmd(); 138 virtual ~ClatdCmd() {} 139 int runCommand(SocketClient *c, int argc, char ** argv); 140 }; 141 142 class StrictCmd : public NetdCommand { 143 public: 144 StrictCmd(); 145 virtual ~StrictCmd() {} 146 int runCommand(SocketClient *c, int argc, char ** argv); 147 protected: 148 int sendGenericOkFail(SocketClient *cli, int cond); 149 static StrictPenalty parsePenalty(const char* arg); 150 }; 151 152 class NetworkCommand : public NetdCommand { 153 public: 154 NetworkCommand(); 155 virtual ~NetworkCommand() {} 156 int runCommand(SocketClient* client, int argc, char** argv); 157 private: 158 int syntaxError(SocketClient* cli, const char* message); 159 int operationError(SocketClient* cli, const char* message, int ret); 160 int success(SocketClient* cli); 161 }; 162}; 163 164#endif 165