• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 #ifndef LIBBRILLO_BRILLO_DBUS_UTILS_H_
6 #define LIBBRILLO_BRILLO_DBUS_UTILS_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include <brillo/brillo_export.h>
12 #include <brillo/errors/error.h>
13 #include <dbus/exported_object.h>
14 #include <dbus/message.h>
15 #include <dbus/scoped_dbus_error.h>
16 
17 namespace brillo {
18 namespace dbus_utils {
19 
20 // A helper function to create a D-Bus error response object as unique_ptr<>.
21 BRILLO_EXPORT std::unique_ptr<::dbus::Response> CreateDBusErrorResponse(
22     ::dbus::MethodCall* method_call,
23     const std::string& error_name,
24     const std::string& error_message);
25 
26 // Create a D-Bus error response object from brillo::Error. If the last
27 // error in the error chain belongs to "dbus" error domain, its error code
28 // and message are directly translated to D-Bus error code and message.
29 // Any inner errors are formatted as "domain/code:message" string and appended
30 // to the D-Bus error message, delimited by semi-colons.
31 BRILLO_EXPORT std::unique_ptr<::dbus::Response> GetDBusError(
32     ::dbus::MethodCall* method_call, const brillo::Error* error);
33 
34 // AddDBusError() is the opposite of GetDBusError(). It de-serializes the Error
35 // object received over D-Bus.
36 BRILLO_EXPORT void AddDBusError(brillo::ErrorPtr* error,
37                                 const std::string& dbus_error_name,
38                                 const std::string& dbus_error_message);
39 
40 }  // namespace dbus_utils
41 }  // namespace brillo
42 
43 #endif  // LIBBRILLO_BRILLO_DBUS_UTILS_H_
44