blob: 63bfd8f6f907c993b0b6eb409c56306867cc63fa [file] [log] [blame]
Paul Stewart1062d9d2012-04-27 10:42:27 -07001// 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_STATIC_IP_PARAMETERS_
6#define SHILL_STATIC_IP_PARAMETERS_
7
8#include <string>
9#include <vector>
10
11#include <base/memory/ref_counted.h>
12
13#include "shill/ipconfig.h"
14#include "shill/key_value_store.h"
15#include "shill/property_store.h"
16
17namespace shill {
18class StoreInterface;
19
20// Holder for static IP parameters. Includes methods for reading and
21// displaying values over a control API, methods for loading and
22// storing this to a persistent store, as well as applying these
23// parameters to an IPConfig object.
24class StaticIPParameters {
25 public:
26 StaticIPParameters();
27 virtual ~StaticIPParameters();
28
29 // Take a property store and add static IP parameters to them.
30 void PlumbPropertyStore(PropertyStore *store);
31
32 // Load static IP parameters from a persistent store with id |storage_id|.
33 void Load(StoreInterface *storage, const std::string &storage_id);
34
35 // Save static IP parameters to a persistent store with id |storage_id|.
36 void Save(StoreInterface *storage, const std::string &storage_id);
37
38 // Apply static IP parameters to an IPConfig properties object.
39 void ApplyTo(IPConfig::Properties *props) const;
40
41 // Return whether configuration parameters contain an address property.
42 bool ContainsAddress() const;
43
44 private:
45 friend class StaticIPParametersTest;
mukesh agrawalcc0fded2012-05-09 13:40:58 -070046 FRIEND_TEST(DeviceTest, IPConfigUpdatedFailureWithStatic);
Paul Stewart1062d9d2012-04-27 10:42:27 -070047
48 struct Property {
49 enum Type {
50 kTypeInt32,
51 kTypeString,
52 // Properties of type "Strings" are stored as a comma-separated list
53 // in the control interface and in the profile, but are stored as a
54 // vector of strings in the IPConfig properties.
55 kTypeStrings
56 };
57
58 const char *name;
59 Type type;
60 };
61
62 static const char kConfigKeyPrefix[];
63 static const Property kProperties[];
64
65 // These functions try to retrieve the argument |property| out of the
66 // KeyValueStore in |args_|. If that value exists, overwrite |value_out|
67 // with its contents.
68 void ApplyInt(const std::string &property, int32 *value_out) const;
69 void ApplyString(const std::string &property, std::string *value_out) const;
70 void ApplyStrings(const std::string &property,
71 std::vector<std::string> *value_out) const;
72
73 void ClearMappedProperty(const size_t &index, Error *error);
74 int32 GetMappedInt32Property(const size_t &index, Error *error);
75 std::string GetMappedStringProperty(const size_t &index, Error *error);
76 void SetMappedInt32Property(
77 const size_t &index, const int32 &value, Error *error);
78 void SetMappedStringProperty(
79 const size_t &index, const std::string &value, Error *error);
80
81 KeyValueStore args_;
82
83 DISALLOW_COPY_AND_ASSIGN(StaticIPParameters);
84};
85
86} // namespace shill
87
88#endif // SHILL_STATIC_IP_PARAMETERS_