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