Avi Drissman | f75e37f | 2022-09-13 19:40:31 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
satorux@chromium.org | 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_ |
satorux@chromium.org | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 7 | |
| 8 | #include <dbus/dbus.h> |
| 9 | |
Hidehiko Abe | 3afb59a | 2023-07-06 07:34:38 | [diff] [blame] | 10 | namespace dbus::internal { |
satorux@chromium.org | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 11 | |
| 12 | // Utility class to ensure that DBusError is freed. |
Hidehiko Abe | 3afb59a | 2023-07-06 07:34:38 | [diff] [blame] | 13 | class ScopedDBusError { |
satorux@chromium.org | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 14 | public: |
avakulenko | 7c5b40c | 2014-09-24 18:47:52 | [diff] [blame] | 15 | // Do not inline methods that call dbus_error_xxx() functions. |
| 16 | // See http://crbug.com/416628 |
| 17 | ScopedDBusError(); |
| 18 | ~ScopedDBusError(); |
satorux@chromium.org | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 19 | |
| 20 | DBusError* get() { return &error_; } |
avakulenko | 7c5b40c | 2014-09-24 18:47:52 | [diff] [blame] | 21 | bool is_set() const; |
Hidehiko Abe | ac7a3c5 | 2023-07-06 11:18:10 | [diff] [blame] | 22 | const char* name() const { return error_.name; } |
| 23 | const char* message() const { return error_.message; } |
satorux@chromium.org | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 24 | |
| 25 | private: |
| 26 | DBusError error_; |
| 27 | }; |
| 28 | |
Hidehiko Abe | 3afb59a | 2023-07-06 07:34:38 | [diff] [blame] | 29 | } // namespace dbus::internal |
satorux@chromium.org | a5107611 | 2011-08-17 20:58:12 | [diff] [blame] | 30 | |
| 31 | #endif // DBUS_SCOPED_DBUS_ERROR_H_ |