[shill] Begin wiring SetProperty
Create a PropertyStoreInterface that can be implemented by Device,
Service, Manager, etc to handle getting/setting of properties. The
various DBusAdaptor subclasses can dispatch incoming calls to their
associated implementation object based on the names of the properties
and/or the types of the arguments.
BUG=chromium-os:16343
TEST=unit tests
Change-Id: If7abb0ffa623e59288943b4ed1f49832a92524ea
Reviewed-on: http://gerrit.chromium.org/gerrit/2408
Reviewed-by: Chris Masone <cmasone@chromium.org>
Tested-by: Chris Masone <cmasone@chromium.org>
diff --git a/error.cc b/error.cc
new file mode 100644
index 0000000..c9a6a51
--- /dev/null
+++ b/error.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "shill/error.h"
+
+#include <string>
+
+#include <base/logging.h>
+#include <dbus-c++/error.h>
+
+#include "shill/dbus_adaptor.h"
+
+namespace shill {
+
+// static
+const char * const Error::kErrorNames[Error::kNumErrors] = {
+ SHILL_INTERFACE ".Error.AlreadyExists",
+ SHILL_INTERFACE ".Error.InProgress",
+ SHILL_INTERFACE ".Error.InternalError",
+ SHILL_INTERFACE ".Error.InvalidArguments",
+ SHILL_INTERFACE ".Error.InvalidNetworkName",
+ SHILL_INTERFACE ".Error.InvalidPassphrase",
+ SHILL_INTERFACE ".Error.InvalidProperty",
+ SHILL_INTERFACE ".Error.NotFound",
+ SHILL_INTERFACE ".Error.NotSupported",
+ SHILL_INTERFACE ".Error.PermissionDenied",
+ SHILL_INTERFACE ".Error.PinError"
+};
+
+Error::Error(Type type, const std::string& message)
+ : type_(type),
+ message_(message) {
+ CHECK(type_ < Error::kNumErrors) << "Error type out of range: " << type;
+}
+
+Error::~Error() {}
+
+void Error::Populate(Type type, const std::string& message) {
+ CHECK(type_ < Error::kNumErrors) << "Error type out of range: " << type;
+ type_ = type;
+ message_ = message;
+}
+
+void Error::ToDBusError(::DBus::Error *error) {
+ if (type_ < Error::kNumErrors)
+ *error = ::DBus::Error(kErrorNames[type_], message_.c_str());
+}
+
+} // namespace shill