blob: 9bd4f43f0e47f27d558de46e3b3a713f36d12078 [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;
Darin Petkov5eb05422012-05-11 15:45:25 +020032 virtual void OnConnectionDisconnected() = 0;
Paul Stewart39964fa2012-04-04 09:50:25 -070033 virtual std::string GetProviderType() const = 0;
Darin Petkovb451d6e2012-04-23 11:56:41 +020034
35 virtual void InitPropertyStore(PropertyStore *store);
36
37 virtual bool Load(StoreInterface *storage, const std::string &storage_id);
Darin Petkovcb715292012-04-25 13:04:37 +020038 virtual bool Save(StoreInterface *storage,
39 const std::string &storage_id,
40 bool save_credentials);
41 virtual void UnloadCredentials();
Darin Petkovb451d6e2012-04-23 11:56:41 +020042
43 KeyValueStore *args() { return &args_; }
44
45 protected:
46 struct Property {
47 enum Flags {
Darin Petkovcb715292012-04-25 13:04:37 +020048 kEphemeral = 1 << 0, // Never load or save.
49 kCredential = 1 << 1, // Save if saving credentials (crypted).
50 kWriteOnly = 1 << 2, // Never read over RPC.
Darin Petkovb451d6e2012-04-23 11:56:41 +020051 };
52
53 const char *property;
54 int flags;
55 };
56
Darin Petkov0e9735d2012-04-24 12:33:45 +020057 VPNDriver(Manager *manager,
58 const Property *properties,
59 size_t property_count);
60
61 Manager *manager() const { return manager_; }
62
Darin Petkovb536a742012-04-26 11:31:28 +020063 virtual KeyValueStore GetProvider(Error *error);
64
Darin Petkovb451d6e2012-04-23 11:56:41 +020065 private:
Darin Petkovb451d6e2012-04-23 11:56:41 +020066 void ClearMappedProperty(const size_t &index, Error *error);
67 std::string GetMappedProperty(const size_t &index, Error *error);
68 void SetMappedProperty(
69 const size_t &index, const std::string &value, Error *error);
70
Darin Petkov0e9735d2012-04-24 12:33:45 +020071 Manager *manager_;
Darin Petkovb451d6e2012-04-23 11:56:41 +020072 const Property * const properties_;
73 const size_t property_count_;
74 KeyValueStore args_;
75
76 DISALLOW_COPY_AND_ASSIGN(VPNDriver);
Darin Petkov33af05c2012-02-28 10:10:30 +010077};
78
79} // namespace shill
80
81#endif // SHILL_VPN_DRIVER_