shill: Update Error to support all existing error types and default messages.

Also, added unit tests and a default Error::kSuccess error type to indicate a
default setting to lack of error.

BUG=chromium-os:19555
TEST=unit tests

Change-Id: Ib8a728f3a2363a654ad01219f6987f3a66944440
Reviewed-on: http://gerrit.chromium.org/gerrit/6594
Reviewed-by: Darin Petkov <petkov@chromium.org>
Tested-by: Darin Petkov <petkov@chromium.org>
diff --git a/error.h b/error.h
index cf04a3b..dc2ab19 100644
--- a/error.h
+++ b/error.h
@@ -18,6 +18,8 @@
 class Error {
  public:
   enum Type {
+    kSuccess = 0,  // No error.
+    kAlreadyConnected,
     kAlreadyExists,
     kInProgress,
     kInternalError,
@@ -25,22 +27,50 @@
     kInvalidNetworkName,
     kInvalidPassphrase,
     kInvalidProperty,
+    kNoCarrier,
+    kNotConnected,
     kNotFound,
+    kNotImplemented,
+    kNotOnHomeNetwork,
+    kNotRegistered,
     kNotSupported,
+    kOperationAborted,
+    kOperationTimeout,
+    kPassphraseRequired,
     kPermissionDenied,
-    kPinError,
     kNumErrors
   };
-  static const char * const kErrorNames[kNumErrors];
 
-  Error(Type type, const std::string& message);
-  virtual ~Error();
+  Error();  // Success by default.
+  explicit Error(Type type);  // Uses the default message for |type|.
+  Error(Type type, const std::string &message);
+  ~Error();
 
-  void Populate(Type type, const std::string& message);
+  void Populate(Type type);  // Uses the default message for |type|.
+  void Populate(Type type, const std::string &message);
 
-  void ToDBusError(::DBus::Error *error);
+  // Sets the DBus |error| to this error if it's failure. Leaves |error|
+  // unchanged otherwise.
+  void ToDBusError(::DBus::Error *error) const;
+
+  Type type() const { return type_; }
+  const std::string &message() const { return message_; }
+
+  bool IsSuccess() const { return type_ == kSuccess; }
+  bool IsFailure() const { return !IsSuccess(); }
+
+  static std::string GetName(Type type);
+  static std::string GetDefaultMessage(Type type);
 
  private:
+  struct Info {
+    const char *name;  // Error type name.
+    const char *message;  // Default Error type message.
+  };
+
+  static const Info kInfos[kNumErrors];
+  static const char kInterfaceName[];
+
   Type type_;
   std::string message_;