blob: dfaf0fbebc848121071ca1ac29d56bf86a732856 [file] [log] [blame]
Chris Masone3bd3c8c2011-06-13 08:20:26 -07001// Copyright (c) 2011 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_ACCESSOR_INTERFACE_
6#define SHILL_ACCESSOR_INTERFACE_
7
8#include <map>
9#include <string>
10#include <tr1/memory>
Chris Masoneb925cc82011-06-22 15:39:57 -070011#include <vector>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070012
13#include <base/basictypes.h>
14
15namespace shill {
16
17// A templated abstract base class for objects that can be used to access
18// properties stored in objects that are meant to be made available over RPC.
19// The intended usage is that an object stores a maps of strings to
20// AccessorInterfaces of the appropriate type, and then uses
21// map[name]->Get() and map[name]->Set(value) to get and set the properties.
22template <class T>
23class AccessorInterface {
24 public:
25 AccessorInterface() {}
26 virtual ~AccessorInterface() {}
27
28 // Provides read-only access.
29 virtual const T &Get() = 0;
30 // Attempts to set the wrapped value. Returns true upon success.
31 virtual bool Set(const T &value) = 0;
32
33 private:
34 DISALLOW_COPY_AND_ASSIGN(AccessorInterface);
35};
36
Chris Masonea8a2c252011-06-27 22:16:30 -070037typedef std::vector<std::string> Strings;
38typedef std::map<std::string, std::string> Stringmap;
39
Chris Masone3bd3c8c2011-06-13 08:20:26 -070040// Using a smart pointer here allows pointers to classes derived from
41// AccessorInterface<> to be stored in maps and other STL container types.
42typedef std::tr1::shared_ptr<AccessorInterface<bool> > BoolAccessor;
Chris Masoneb925cc82011-06-22 15:39:57 -070043typedef std::tr1::shared_ptr<AccessorInterface<int16> > Int16Accessor;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070044typedef std::tr1::shared_ptr<AccessorInterface<int32> > Int32Accessor;
Chris Masoneb925cc82011-06-22 15:39:57 -070045typedef std::tr1::shared_ptr<AccessorInterface<std::string> > StringAccessor;
Chris Masonea8a2c252011-06-27 22:16:30 -070046typedef std::tr1::shared_ptr<AccessorInterface<Stringmap> > StringmapAccessor;
47typedef std::tr1::shared_ptr<AccessorInterface<Strings> > StringsAccessor;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070048typedef std::tr1::shared_ptr<AccessorInterface<uint8> > Uint8Accessor;
49typedef std::tr1::shared_ptr<AccessorInterface<uint16> > Uint16Accessor;
Chris Masoneb925cc82011-06-22 15:39:57 -070050typedef std::tr1::shared_ptr<AccessorInterface<uint32> > Uint32Accessor;
Chris Masone3bd3c8c2011-06-13 08:20:26 -070051
52} // namespace shill
53
54#endif // SHILL_ACCESSOR_INTERFACE_