Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_OPENVPN_MANAGEMENT_SERVER_ |
| 6 | #define SHILL_OPENVPN_MANAGEMENT_SERVER_ |
| 7 | |
| 8 | #include <base/basictypes.h> |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame^] | 9 | #include <base/cancelable_callback.h> |
| 10 | #include <base/memory/weak_ptr.h> |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 11 | |
| 12 | namespace shill { |
| 13 | |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame^] | 14 | class EventDispatcher; |
| 15 | class InputData; |
| 16 | class IOHandler; |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 17 | class OpenVPNDriver; |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame^] | 18 | class Sockets; |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 19 | |
| 20 | class OpenVPNManagementServer { |
| 21 | public: |
| 22 | OpenVPNManagementServer(OpenVPNDriver *driver); |
| 23 | virtual ~OpenVPNManagementServer(); |
| 24 | |
| 25 | // Returns true on success, false on failure. |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame^] | 26 | bool Start(EventDispatcher *dispatcher, Sockets *sockets); |
| 27 | |
| 28 | void Stop(); |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 29 | |
| 30 | private: |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame^] | 31 | // IO handler callbacks. |
| 32 | void OnReady(int fd); |
| 33 | void OnInput(InputData *data); |
| 34 | |
| 35 | void Send(const std::string &data); |
| 36 | void SendState(const std::string &state); |
| 37 | |
| 38 | void ProcessMessage(const std::string &message); |
| 39 | |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 40 | OpenVPNDriver *driver_; |
Darin Petkov | 78f6326 | 2012-03-26 01:30:24 +0200 | [diff] [blame^] | 41 | base::WeakPtrFactory<OpenVPNManagementServer> weak_ptr_factory_; |
| 42 | base::Callback<void(int)> ready_callback_; |
| 43 | base::Callback<void(InputData *)> input_callback_; |
| 44 | |
| 45 | Sockets *sockets_; |
| 46 | int socket_; |
| 47 | scoped_ptr<IOHandler> ready_handler_; |
| 48 | EventDispatcher *dispatcher_; |
| 49 | int connected_socket_; |
| 50 | scoped_ptr<IOHandler> input_handler_; |
Darin Petkov | 1c11520 | 2012-03-22 15:35:47 +0100 | [diff] [blame] | 51 | |
| 52 | DISALLOW_COPY_AND_ASSIGN(OpenVPNManagementServer); |
| 53 | }; |
| 54 | |
| 55 | } // namespace shill |
| 56 | |
| 57 | #endif // SHILL_OPENVPN_MANAGEMENT_SERVER_ |