File: DBusException.hh

package info (click to toggle)
workrave 1.10.54-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,992 kB
  • sloc: cpp: 46,596; ansic: 9,760; sh: 2,754; javascript: 1,935; makefile: 1,452; python: 973; xml: 672; objc: 455; perl: 113; cs: 70; sed: 16
file content (148 lines) | stat: -rw-r--r-- 4,834 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// DBusException.hh --- DBUS interface
//
// Copyright (C) 2007, 2012, 2013 Rob Caelers <robc@krandor.nl>
// All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#ifndef WORKRAVE_DBUS_DBUSEXCEPTION_HH
#define WORKRAVE_DBUS_DBUSEXCEPTION_HH

#include <boost/exception/all.hpp>
#include <iostream>

#include "Exception.hh"

namespace workrave
{
  namespace dbus
  {
    extern const char *DBUS_ERROR_FAILED;
    extern const char *DBUS_ERROR_NOT_SUPPORTED;
    extern const char *DBUS_ERROR_INVALID_ARGS;
    extern const char *DBUS_ERROR_UNKNOWN_METHOD;

    class DBusException : public Exception
    {
    public:
      explicit DBusException(const std::string &detail)
        : Exception(detail)
      {
      }

      ~DBusException() override = default;
    };

    using message_info = boost::error_info<struct tag_message_info, std::string>;
    using error_code_info = boost::error_info<struct tag_error_code_info, std::string>;
    using object_info = boost::error_info<struct tag_oject_info, std::string>;
    using interface_info = boost::error_info<struct tag_interface_info, std::string>;
    using method_info = boost::error_info<struct tag_method_info, std::string>;
    using argument_info = boost::error_info<struct tag_argument_info, std::string>;
    using actual_type_info = boost::error_info<struct tag_type_info, std::string>;
    using expected_type_info = boost::error_info<struct tag_expected_type_info, std::string>;
    using field_info = boost::error_info<struct tag_field_info, std::string>;
    using parameter_info = boost::error_info<struct tag_parameter_info, std::string>;
    using field_path_info = boost::error_info<struct tag_field_path_info, std::string>;

    class DBusRemoteException
      : public virtual boost::exception
      , public virtual std::exception
    {
    public:
      std::string error()
      {
        std::string ret;
        if (const std::string *msg = boost::get_error_info<error_code_info>(*this))
          {
            ret = *msg;
          }
        return ret;
      }

      DBusRemoteException &operator<<(const field_info &rhs)
      {
        if (const std::string *msg = boost::get_error_info<field_path_info>(*this))
          {
            *this << field_path_info(rhs.value() + "." + *msg);
          }
        else
          {
            *this << field_path_info(rhs.value());
          }

        return *this;
      }

      void prepend_field(const std::string &field)
      {
        if (const std::string *msg = boost::get_error_info<field_path_info>(*this))
          {
            *this << field_path_info(field + "." + *msg);
          }
        else
          {
            *this << field_path_info(field);
          }
      }

      std::string diag()
      {
        std::string ret;

        if (const std::string *msg = boost::get_error_info<message_info>(*this))
          {
            ret += *msg;
          }
        if (const std::string *msg = boost::get_error_info<object_info>(*this))
          {
            ret += " object path=" + *msg;
          }
        if (const std::string *msg = boost::get_error_info<interface_info>(*this))
          {
            ret += " interface=" + *msg;
          }
        if (const std::string *msg = boost::get_error_info<method_info>(*this))
          {
            ret += " method=" + *msg;
          }
        if (const std::string *msg = boost::get_error_info<argument_info>(*this))
          {
            ret += " argument=" + *msg;
          }
        if (const std::string *msg = boost::get_error_info<actual_type_info>(*this))
          {
            ret += " type=" + *msg;
          }
        if (const std::string *msg = boost::get_error_info<expected_type_info>(*this))
          {
            ret += " expected_type=" + *msg;
          }
        if (const std::string *msg = boost::get_error_info<field_path_info>(*this))
          {
            ret += " fieldpath=" + *msg;
          }
        if (const std::string *msg = boost::get_error_info<parameter_info>(*this))
          {
            ret += " parameter=" + *msg;
          }

        return ret;
      }
    };
  } // namespace dbus
} // namespace workrave

#endif // WORKRAVE_DBUS_DBUSEXCEPTION_HH