OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DBUS_SCOPED_DBUS_ERROR_H_ | 5 #ifndef DBUS_SCOPED_DBUS_ERROR_H_ |
6 #define DBUS_SCOPED_DBUS_ERROR_H_ | 6 #define DBUS_SCOPED_DBUS_ERROR_H_ |
7 | 7 |
8 #include <dbus/dbus.h> | 8 #include <dbus/dbus.h> |
9 | 9 |
10 namespace dbus { | 10 namespace dbus { |
11 | 11 |
12 // Utility class to ensure that DBusError is freed. | 12 // Utility class to ensure that DBusError is freed. |
13 class ScopedDBusError { | 13 class ScopedDBusError { |
14 public: | 14 public: |
15 ScopedDBusError() { | 15 ScopedDBusError() { |
16 dbus_error_init(&error_); | 16 dbus_error_init(&error_); |
17 } | 17 } |
18 | 18 |
19 ~ScopedDBusError() { | 19 ~ScopedDBusError() { |
20 dbus_error_free(&error_); | 20 dbus_error_free(&error_); |
21 } | 21 } |
22 | 22 |
23 DBusError* get() { return &error_; } | 23 DBusError* get() { return &error_; } |
24 bool is_set() { return dbus_error_is_set(&error_); } | 24 bool is_set() const { return dbus_error_is_set(&error_); } |
25 const char* name() { return error_.name; } | 25 const char* name() { return error_.name; } |
26 const char* message() { return error_.message; } | 26 const char* message() { return error_.message; } |
27 | 27 |
28 private: | 28 private: |
29 DBusError error_; | 29 DBusError error_; |
30 }; | 30 }; |
31 | 31 |
32 } // namespace dbus | 32 } // namespace dbus |
33 | 33 |
34 #endif // DBUS_SCOPED_DBUS_ERROR_H_ | 34 #endif // DBUS_SCOPED_DBUS_ERROR_H_ |
OLD | NEW |