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