blob: c15c44397b91c59e21d871228b048f64c241ac55 [file] [log] [blame]
adamk@chromium.org35c0eef2012-02-11 06:45:23 +09001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
satorux@chromium.org163f1cb2011-08-18 05:58:12 +09002// 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.org163f1cb2011-08-18 05:58:12 +09007
8#include <dbus/dbus.h>
9
10namespace dbus {
11
12// Utility class to ensure that DBusError is freed.
13class ScopedDBusError {
14 public:
15 ScopedDBusError() {
16 dbus_error_init(&error_);
17 }
18
19 ~ScopedDBusError() {
20 dbus_error_free(&error_);
21 }
22
23 DBusError* get() { return &error_; }
tfarina@chromium.org56cc3fc2012-10-30 01:43:26 +090024 bool is_set() const { return dbus_error_is_set(&error_); }
adamk@chromium.org35c0eef2012-02-11 06:45:23 +090025 const char* name() { return error_.name; }
satorux@chromium.org163f1cb2011-08-18 05:58:12 +090026 const char* message() { return error_.message; }
27
28 private:
29 DBusError error_;
30};
31
32} // namespace dbus
33
34#endif // DBUS_SCOPED_DBUS_ERROR_H_