• 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,
33     const brillo::Error* error);
34 
35 // AddDBusError() is the opposite of GetDBusError(). It de-serializes the Error
36 // object received over D-Bus.
37 BRILLO_EXPORT void AddDBusError(brillo::ErrorPtr* error,
38                                 const std::string& dbus_error_name,
39                                 const std::string& dbus_error_message);
40 
41 }  // namespace dbus_utils
42 }  // namespace brillo
43 
44 #endif  // LIBBRILLO_BRILLO_DBUS_UTILS_H_
45