From: Arvin Schnell Date: Tue, 5 Jun 2012 14:11:12 +0000 (+0200) Subject: - work on dbus interface X-Git-Tag: v0.1.3~223 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=026b5b8b62dc9dce69398591d0f0bc41e4cf9c8c;p=thirdparty%2Fsnapper.git - work on dbus interface --- diff --git a/client/snapper.cc b/client/snapper.cc index 8bb981bc..b5a324ef 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -1212,9 +1212,23 @@ main(int argc, char** argv) exit(EXIT_FAILURE); } - DBus::Connection conn(DBUS_BUS_SYSTEM); + try + { + DBus::Connection conn(DBUS_BUS_SYSTEM); - (*cmd->second)(conn); + (*cmd->second)(conn); + } + catch (const DBus::ErrorException& e) + { + if (strcmp(e.name(), "error.no_permissions") == 0) + cerr << "failed (no permissions)" << endl; + else + cerr << "failed (" << e.what() << ")" << endl; + } + catch (const DBus::FatalException& e) + { + cerr << "failed (" << e.what() << ")" << endl; + } exit(EXIT_SUCCESS); } diff --git a/dbus/DBusConnection.cc b/dbus/DBusConnection.cc index bcf4359a..ef492eca 100644 --- a/dbus/DBusConnection.cc +++ b/dbus/DBusConnection.cc @@ -102,8 +102,7 @@ namespace DBus 0x7fffffff, &err); if (dbus_error_is_set(&err)) { - dbus_error_free(&err); - throw FatalException(); + throw ErrorException(err); } Message reply(tmp); diff --git a/dbus/DBusMessage.h b/dbus/DBusMessage.h index e5a40c08..b8f3ea48 100644 --- a/dbus/DBusMessage.h +++ b/dbus/DBusMessage.h @@ -47,6 +47,17 @@ namespace DBus }; + struct ErrorException : public Exception + { + explicit ErrorException(const DBusError err) throw() : err(err) {} + ~ErrorException() throw() { dbus_error_free(&err); } + virtual const char* what() const throw() { return "dbus error exception"; } + virtual const char* name() const throw() { return err.name; } + virtual const char* message() const throw() { return err.message; } + DBusError err; + }; + + struct MarshallingException : public Exception { explicit MarshallingException() throw() {}