shill: Implement write-only properties

Certain properties (e.g. WIFI Passphrase) are write only and must
not be returned when Service.GetProperties() is called over D-Bus.

This CL implements WriteOnlyProperties, a write-only analog of the
read-only ConstProperties.

Also add a ReadablePropertyConstIterator which only returns the
readable properties. Switch over DBus adaptor and PropertyStore
to use that.

BUG=chromium-os:21196
TEST=Added 2 new unittests.

Change-Id: I52815cc395650e0b49e1acac8d4954deeebcee5d
Reviewed-on: https://gerrit.chromium.org/gerrit/11402
Commit-Ready: Gaurav Shah <gauravsh@chromium.org>
Reviewed-by: Gaurav Shah <gauravsh@chromium.org>
Tested-by: Gaurav Shah <gauravsh@chromium.org>
diff --git a/property_iterator.h b/property_iterator.h
index 8851b20..c1c47de 100644
--- a/property_iterator.h
+++ b/property_iterator.h
@@ -9,28 +9,37 @@
 #include <string>
 
 #include "shill/accessor_interface.h"
+#include "shill/error.h"
+
+class Error;
 
 namespace shill {
 
 // An iterator wrapper class to hide the details of what kind of data structure
 // we're using to store key/value pairs for properties.
 // Intended for use with PropertyStore.
+
+// TODO(gauravsh): Consider getting rid of PropertyConstIterator, and just
+// keeping ReadablePropertyConstIterator since it doesn't look like the caller
+// is ever interested in anything but readable properties.
 template <class V>
 class PropertyConstIterator {
  public:
   virtual ~PropertyConstIterator() {}
 
-  void Advance() { ++it_; }
+  virtual void Advance() {
+    if (!AtEnd())
+      ++it_;
+  }
 
   bool AtEnd() { return it_ == collection_.end(); }
 
   const std::string &Key() const { return it_->first; }
 
-  const V &Value() const { return it_->second->Get(); }
+  V Value(Error *error) const { return it_->second->Get(error); }
 
- private:
-  friend class PropertyStore;
 
+ protected:
   typedef std::tr1::shared_ptr<AccessorInterface<V> > VAccessorPtr;
 
   explicit PropertyConstIterator(
@@ -39,11 +48,50 @@
         it_(collection_.begin()) {
   }
 
+ private:
+  friend class PropertyStore;
+
   const typename std::map<std::string, VAccessorPtr> &collection_;
   typename std::map<std::string, VAccessorPtr>::const_iterator it_;
 };
 
+// A version of the iterator that always advances to the next readable
+// property.
+template <class V>
+class ReadablePropertyConstIterator : public PropertyConstIterator<V> {
+ public:
+  virtual ~ReadablePropertyConstIterator() {}
 
+  virtual void Advance() {
+    Error error;
+    while (!PropertyConstIterator<V>::AtEnd()) {
+      PropertyConstIterator<V>::Advance();
+      if (PropertyConstIterator<V>::AtEnd())
+        return;
+      error.Reset();
+      PropertyConstIterator<V>::Value(&error);
+      if (error.IsSuccess())
+        break;
+    }
+  }
+
+ private:
+  friend class PropertyStore;
+
+  typedef std::tr1::shared_ptr<AccessorInterface<V> > VAccessorPtr;
+
+  explicit ReadablePropertyConstIterator(
+      const typename std::map<std::string, VAccessorPtr> &collection)
+      : PropertyConstIterator<V>(collection) {
+    if (PropertyConstIterator<V>::AtEnd())
+      return;
+    Error error;
+    PropertyConstIterator<V>::Value(&error);
+    // Start at the next readable property (if any).
+    if (!error.IsSuccess())
+      Advance();
+  }
+};
 
 }  // namespace shill