blob: 237438c6e4a399c8eefbfe539794d763d39c96a0 [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_DRIVER_
6#define SHILL_VPN_DRIVER_
7
Paul Stewartca6abd42012-03-01 15:45:29 -08008#include <string>
9
Darin Petkov33af05c2012-02-28 10:10:30 +010010#include <base/basictypes.h>
Darin Petkov0e9735d2012-04-24 12:33:45 +020011#include <gtest/gtest_prod.h> // for FRIEND_TEST
Darin Petkov33af05c2012-02-28 10:10:30 +010012
Darin Petkovb451d6e2012-04-23 11:56:41 +020013#include "shill/accessor_interface.h"
14#include "shill/key_value_store.h"
Darin Petkov79d74c92012-03-07 17:20:32 +010015#include "shill/refptr_types.h"
16
Darin Petkov33af05c2012-02-28 10:10:30 +010017namespace shill {
18
19class Error;
Darin Petkov0e9735d2012-04-24 12:33:45 +020020class Manager;
Paul Stewartebd38562012-03-23 13:06:40 -070021class PropertyStore;
Darin Petkovf3c71d72012-03-21 12:32:15 +010022class StoreInterface;
Darin Petkov33af05c2012-02-28 10:10:30 +010023
24class VPNDriver {
25 public:
Darin Petkovb451d6e2012-04-23 11:56:41 +020026 virtual ~VPNDriver();
Darin Petkov33af05c2012-02-28 10:10:30 +010027
Paul Stewartca6abd42012-03-01 15:45:29 -080028 virtual bool ClaimInterface(const std::string &link_name,
29 int interface_index) = 0;
Darin Petkov79d74c92012-03-07 17:20:32 +010030 virtual void Connect(const VPNServiceRefPtr &service, Error *error) = 0;
Darin Petkov6aa21872012-03-09 16:10:19 +010031 virtual void Disconnect() = 0;
Paul Stewart39964fa2012-04-04 09:50:25 -070032 virtual std::string GetProviderType() const = 0;
Darin Petkovb451d6e2012-04-23 11:56:41 +020033
34 virtual void InitPropertyStore(PropertyStore *store);
35
36 virtual bool Load(StoreInterface *storage, const std::string &storage_id);
37 virtual bool Save(StoreInterface *storage, const std::string &storage_id);
38
39 KeyValueStore *args() { return &args_; }
40
41 protected:
42 struct Property {
43 enum Flags {
44 kEphemeral = 1 << 0,
45 kCrypted = 1 << 1,
46 };
47
48 const char *property;
49 int flags;
50 };
51
Darin Petkov0e9735d2012-04-24 12:33:45 +020052 VPNDriver(Manager *manager,
53 const Property *properties,
54 size_t property_count);
55
56 Manager *manager() const { return manager_; }
57
Darin Petkovb451d6e2012-04-23 11:56:41 +020058 private:
59 Stringmap GetProvider(Error *error);
60 void ClearMappedProperty(const size_t &index, Error *error);
61 std::string GetMappedProperty(const size_t &index, Error *error);
62 void SetMappedProperty(
63 const size_t &index, const std::string &value, Error *error);
64
Darin Petkov0e9735d2012-04-24 12:33:45 +020065 Manager *manager_;
Darin Petkovb451d6e2012-04-23 11:56:41 +020066 const Property * const properties_;
67 const size_t property_count_;
68 KeyValueStore args_;
69
70 DISALLOW_COPY_AND_ASSIGN(VPNDriver);
Darin Petkov33af05c2012-02-28 10:10:30 +010071};
72
73} // namespace shill
74
75#endif // SHILL_VPN_DRIVER_