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