Darin Petkov | 33af05c | 2012-02-28 10:10:30 +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_VPN_PROVIDER_ |
| 6 | #define SHILL_VPN_PROVIDER_ |
| 7 | |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 11 | #include <base/basictypes.h> |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 12 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 13 | |
| 14 | #include "shill/refptr_types.h" |
| 15 | |
| 16 | namespace shill { |
| 17 | |
| 18 | class ControlInterface; |
| 19 | class Error; |
| 20 | class EventDispatcher; |
| 21 | class KeyValueStore; |
| 22 | class Manager; |
| 23 | class Metrics; |
| 24 | |
| 25 | class VPNProvider { |
| 26 | public: |
| 27 | VPNProvider(ControlInterface *control_interface, |
| 28 | EventDispatcher *dispatcher, |
| 29 | Metrics *metrics, |
| 30 | Manager *manager); |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 31 | virtual ~VPNProvider(); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 32 | |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 33 | virtual void Start(); |
| 34 | virtual void Stop(); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 35 | |
| 36 | VPNServiceRefPtr GetService(const KeyValueStore &args, Error *error); |
| 37 | |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 38 | // Offers an unclaimed interface to VPN services. Returns true if this |
| 39 | // device has been accepted by a service. |
Paul Stewart | 8c116a9 | 2012-05-02 18:30:03 -0700 | [diff] [blame] | 40 | virtual bool OnDeviceInfoAvailable(const std::string &link_name, |
| 41 | int interface_index); |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 42 | |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 43 | // Clean up a VPN services that has been unloaded and will be deregistered. |
| 44 | // This removes the VPN provider's reference to this service in its |
| 45 | // services_ vector. |
| 46 | void RemoveService(VPNServiceRefPtr service); |
| 47 | |
Paul Stewart | 6681533 | 2012-04-09 18:09:36 -0700 | [diff] [blame] | 48 | void CreateServicesFromProfile(ProfileRefPtr profile); |
| 49 | |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 50 | // Returns true if any of the managed VPN services is connecting or connected. |
| 51 | virtual bool HasActiveService() const; |
| 52 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 53 | private: |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 54 | friend class VPNProviderTest; |
Darin Petkov | 9d1bbe7 | 2012-04-25 10:58:59 +0200 | [diff] [blame] | 55 | FRIEND_TEST(VPNProviderTest, CreateService); |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 56 | FRIEND_TEST(VPNProviderTest, OnDeviceInfoAvailable); |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 57 | FRIEND_TEST(VPNProviderTest, RemoveService); |
Darin Petkov | a0e645e | 2012-04-25 11:38:59 +0200 | [diff] [blame] | 58 | FRIEND_TEST(VPNServiceTest, Unload); |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 59 | |
Paul Stewart | 6681533 | 2012-04-09 18:09:36 -0700 | [diff] [blame] | 60 | // Create a service of type |type| and storage identifier |storage_id| |
| 61 | // and initial parameters |args|. Returns a service reference pointer |
| 62 | // to the newly created service, or popuplates |error| with an the error |
| 63 | // that caused this to fail. |
| 64 | VPNServiceRefPtr CreateService(const std::string &type, |
Paul Stewart | 451aa7f | 2012-04-11 19:07:58 -0700 | [diff] [blame] | 65 | const std::string &name, |
Paul Stewart | 6681533 | 2012-04-09 18:09:36 -0700 | [diff] [blame] | 66 | const std::string &storage_id, |
Paul Stewart | 6681533 | 2012-04-09 18:09:36 -0700 | [diff] [blame] | 67 | Error *error); |
| 68 | |
Darin Petkov | 9c6e981 | 2013-03-26 13:49:07 +0100 | [diff] [blame] | 69 | // Finds a service of type |type| with its Name property set to |name| and its |
| 70 | // Provider.Host property set to |host|. |
Paul Stewart | 6681533 | 2012-04-09 18:09:36 -0700 | [diff] [blame] | 71 | VPNServiceRefPtr FindService(const std::string &type, |
Darin Petkov | 9c6e981 | 2013-03-26 13:49:07 +0100 | [diff] [blame] | 72 | const std::string &name, |
| 73 | const std::string &host); |
Paul Stewart | 6681533 | 2012-04-09 18:09:36 -0700 | [diff] [blame] | 74 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 75 | ControlInterface *control_interface_; |
| 76 | EventDispatcher *dispatcher_; |
| 77 | Metrics *metrics_; |
| 78 | Manager *manager_; |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 79 | std::vector<VPNServiceRefPtr> services_; |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 80 | |
| 81 | DISALLOW_COPY_AND_ASSIGN(VPNProvider); |
| 82 | }; |
| 83 | |
| 84 | } // namespace shill |
| 85 | |
| 86 | #endif // SHILL_VPN_PROVIDER_ |