blob: 610a31b943c542b2ffce50ef2572019043b18184 [file] [log] [blame]
Darin Petkov33af05c2012-02-28 10:10:30 +01001// 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 Stewartca6abd42012-03-01 15:45:29 -08008#include <string>
9#include <vector>
10
Darin Petkov33af05c2012-02-28 10:10:30 +010011#include <base/basictypes.h>
Paul Stewartca6abd42012-03-01 15:45:29 -080012#include <gtest/gtest_prod.h> // for FRIEND_TEST
Darin Petkov33af05c2012-02-28 10:10:30 +010013
14#include "shill/refptr_types.h"
15
16namespace shill {
17
18class ControlInterface;
19class Error;
20class EventDispatcher;
21class KeyValueStore;
22class Manager;
23class Metrics;
24
25class VPNProvider {
26 public:
27 VPNProvider(ControlInterface *control_interface,
28 EventDispatcher *dispatcher,
29 Metrics *metrics,
30 Manager *manager);
Paul Stewart8c116a92012-05-02 18:30:03 -070031 virtual ~VPNProvider();
Darin Petkov33af05c2012-02-28 10:10:30 +010032
Paul Stewart8c116a92012-05-02 18:30:03 -070033 virtual void Start();
34 virtual void Stop();
Darin Petkov33af05c2012-02-28 10:10:30 +010035
36 VPNServiceRefPtr GetService(const KeyValueStore &args, Error *error);
37
Paul Stewartca6abd42012-03-01 15:45:29 -080038 // Offers an unclaimed interface to VPN services. Returns true if this
39 // device has been accepted by a service.
Paul Stewart8c116a92012-05-02 18:30:03 -070040 virtual bool OnDeviceInfoAvailable(const std::string &link_name,
41 int interface_index);
Paul Stewartca6abd42012-03-01 15:45:29 -080042
Paul Stewart65512e12012-03-26 18:01:08 -070043 // 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 Stewart66815332012-04-09 18:09:36 -070048 void CreateServicesFromProfile(ProfileRefPtr profile);
49
Darin Petkov33af05c2012-02-28 10:10:30 +010050 private:
Darin Petkov9d1bbe72012-04-25 10:58:59 +020051 FRIEND_TEST(VPNProviderTest, CreateService);
Paul Stewartca6abd42012-03-01 15:45:29 -080052 FRIEND_TEST(VPNProviderTest, OnDeviceInfoAvailable);
Paul Stewart65512e12012-03-26 18:01:08 -070053 FRIEND_TEST(VPNProviderTest, RemoveService);
Darin Petkova0e645e2012-04-25 11:38:59 +020054 FRIEND_TEST(VPNServiceTest, Unload);
Paul Stewartca6abd42012-03-01 15:45:29 -080055
Paul Stewart66815332012-04-09 18:09:36 -070056 // Create a service of type |type| and storage identifier |storage_id|
57 // and initial parameters |args|. Returns a service reference pointer
58 // to the newly created service, or popuplates |error| with an the error
59 // that caused this to fail.
60 VPNServiceRefPtr CreateService(const std::string &type,
Paul Stewart451aa7f2012-04-11 19:07:58 -070061 const std::string &name,
Paul Stewart66815332012-04-09 18:09:36 -070062 const std::string &storage_id,
Paul Stewart66815332012-04-09 18:09:36 -070063 Error *error);
64
65 // Find a service of type |type| whose storage identifier is |storage_id|.
66 VPNServiceRefPtr FindService(const std::string &type,
67 const std::string &storage_id);
68
Darin Petkov33af05c2012-02-28 10:10:30 +010069 ControlInterface *control_interface_;
70 EventDispatcher *dispatcher_;
71 Metrics *metrics_;
72 Manager *manager_;
Paul Stewartca6abd42012-03-01 15:45:29 -080073 std::vector<VPNServiceRefPtr> services_;
Darin Petkov33af05c2012-02-28 10:10:30 +010074
75 DISALLOW_COPY_AND_ASSIGN(VPNProvider);
76};
77
78} // namespace shill
79
80#endif // SHILL_VPN_PROVIDER_