San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 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 | */ |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 16 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 17 | #ifndef _VPN_CONTROLLER_H |
| 18 | #define _VPN_CONTROLLER_H |
| 19 | |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 20 | #include <netinet/in.h> |
| 21 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 22 | #include "Controller.h" |
| 23 | |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 24 | class IControllerHandler; |
| 25 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 26 | class VpnController : public Controller { |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 27 | class VpnIntegerProperty : public IntegerProperty { |
| 28 | protected: |
| 29 | VpnController *mVc; |
| 30 | public: |
| 31 | VpnIntegerProperty(VpnController *c, const char *name, bool ro, |
| 32 | int elements); |
| 33 | virtual ~VpnIntegerProperty() {} |
| 34 | virtual int set(int idx, int value) = 0; |
| 35 | virtual int get(int idx, int *buffer) = 0; |
| 36 | }; |
| 37 | friend class VpnController::VpnIntegerProperty; |
| 38 | |
| 39 | class VpnStringProperty : public StringProperty { |
| 40 | protected: |
| 41 | VpnController *mVc; |
| 42 | public: |
| 43 | VpnStringProperty(VpnController *c, const char *name, bool ro, |
| 44 | int elements); |
| 45 | virtual ~VpnStringProperty() {} |
| 46 | virtual int set(int idx, const char *value) = 0; |
| 47 | virtual int get(int idx, char *buffer, size_t max) = 0; |
| 48 | }; |
| 49 | friend class VpnController::VpnStringProperty; |
| 50 | |
| 51 | class VpnIPV4AddressProperty : public IPV4AddressProperty { |
| 52 | protected: |
| 53 | VpnController *mVc; |
| 54 | public: |
| 55 | VpnIPV4AddressProperty(VpnController *c, const char *name, bool ro, |
| 56 | int elements); |
| 57 | virtual ~VpnIPV4AddressProperty() {} |
| 58 | virtual int set(int idx, struct in_addr *value) = 0; |
| 59 | virtual int get(int idx, struct in_addr *buffer) = 0; |
| 60 | }; |
| 61 | friend class VpnController::VpnIPV4AddressProperty; |
| 62 | |
| 63 | class VpnEnabledProperty : public VpnIntegerProperty { |
| 64 | public: |
| 65 | VpnEnabledProperty(VpnController *c); |
| 66 | virtual ~VpnEnabledProperty() {}; |
| 67 | int set(int idx, int value); |
| 68 | int get(int idx, int *buffer); |
| 69 | }; |
| 70 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 71 | bool mEnabled; |
San Mehat | 5d6d417 | 2009-05-14 15:00:06 -0700 | [diff] [blame] | 72 | /* |
| 73 | * Gateway of the VPN server to connect to |
| 74 | */ |
San Mehat | c4a895b | 2009-06-23 21:10:57 -0700 | [diff] [blame] | 75 | struct in_addr mGateway; |
| 76 | |
| 77 | struct { |
| 78 | VpnEnabledProperty *propEnabled; |
| 79 | } mStaticProperties; |
| 80 | |
| 81 | struct { |
| 82 | IPV4AddressPropertyHelper *propGateway; |
| 83 | } mDynamicProperties; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 84 | |
| 85 | public: |
San Mehat | 3aff2d1 | 2009-06-15 14:10:44 -0700 | [diff] [blame] | 86 | VpnController(PropertyManager *propmngr, IControllerHandler *handlers); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 87 | virtual ~VpnController() {} |
| 88 | |
| 89 | virtual int start(); |
| 90 | virtual int stop(); |
| 91 | |
San Mehat | 3c5a6f0 | 2009-05-22 15:36:13 -0700 | [diff] [blame] | 92 | protected: |
| 93 | virtual int enable() = 0; |
| 94 | virtual int disable() = 0; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | #endif |