blob: c9a6a5139514a5cc1006084a674506b5cec4540a [file] [log] [blame]
Chris Masone8fe2c7e2011-06-09 15:51:19 -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#include "shill/error.h"
6
7#include <string>
8
9#include <base/logging.h>
10#include <dbus-c++/error.h>
11
12#include "shill/dbus_adaptor.h"
13
14namespace shill {
15
16// static
17const char * const Error::kErrorNames[Error::kNumErrors] = {
18 SHILL_INTERFACE ".Error.AlreadyExists",
19 SHILL_INTERFACE ".Error.InProgress",
20 SHILL_INTERFACE ".Error.InternalError",
21 SHILL_INTERFACE ".Error.InvalidArguments",
22 SHILL_INTERFACE ".Error.InvalidNetworkName",
23 SHILL_INTERFACE ".Error.InvalidPassphrase",
24 SHILL_INTERFACE ".Error.InvalidProperty",
25 SHILL_INTERFACE ".Error.NotFound",
26 SHILL_INTERFACE ".Error.NotSupported",
27 SHILL_INTERFACE ".Error.PermissionDenied",
28 SHILL_INTERFACE ".Error.PinError"
29};
30
31Error::Error(Type type, const std::string& message)
32 : type_(type),
33 message_(message) {
34 CHECK(type_ < Error::kNumErrors) << "Error type out of range: " << type;
35}
36
37Error::~Error() {}
38
39void Error::Populate(Type type, const std::string& message) {
40 CHECK(type_ < Error::kNumErrors) << "Error type out of range: " << type;
41 type_ = type;
42 message_ = message;
43}
44
45void Error::ToDBusError(::DBus::Error *error) {
46 if (type_ < Error::kNumErrors)
47 *error = ::DBus::Error(kErrorNames[type_], message_.c_str());
48}
49
50} // namespace shill