]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- extended proxy classes
authorArvin Schnell <aschnell@suse.de>
Mon, 29 Oct 2018 09:31:14 +0000 (10:31 +0100)
committerArvin Schnell <aschnell@suse.de>
Mon, 29 Oct 2018 09:31:14 +0000 (10:31 +0100)
client/commands.cc
client/commands.h
client/errors.cc
client/errors.h
client/proxy-dbus.cc
client/proxy-dbus.h
client/proxy-lib.h
client/proxy.h
client/types.cc
client/types.h

index 61ced87aaad9f597c0f502d18ec8b80b39051e3d..ecb7ef0a408a040d1b7ef18b4bf69110e7b4e7af 100644 (file)
@@ -24,6 +24,7 @@
 #include <iostream>
 
 #include "commands.h"
+#include "errors.h"
 #include "utils/text.h"
 #include "snapper/AppUtil.h"
 
@@ -296,13 +297,13 @@ command_delete_snapshots(DBus::Connection& conn, const string& config_name,
 std::pair<bool, unsigned int>
 command_get_default_snapshot(DBus::Connection& conn, const string& config_name)
 {
-    DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetDefaultSnapshot");
-
-    DBus::Hoho hoho(call);
-    hoho << config_name;
-
     try
     {
+       DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetDefaultSnapshot");
+
+       DBus::Hoho hoho(call);
+       hoho << config_name;
+
        DBus::Message reply = conn.send_with_reply_and_block(call);
 
        bool valid;
@@ -315,13 +316,7 @@ command_get_default_snapshot(DBus::Connection& conn, const string& config_name)
     }
     catch (const DBus::ErrorException& e)
     {
-       SN_CAUGHT(e);
-
-       if (strcmp(e.name(), "error.unsupported") == 0)
-           SN_THROW(UnsupportedException());
-
-       SN_RETHROW(e);
-       __builtin_unreachable();
+       convert_exception(e);
     }
 }
 
@@ -329,13 +324,13 @@ command_get_default_snapshot(DBus::Connection& conn, const string& config_name)
 std::pair<bool, unsigned int>
 command_get_active_snapshot(DBus::Connection& conn, const string& config_name)
 {
-    DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetActiveSnapshot");
-
-    DBus::Hoho hoho(call);
-    hoho << config_name;
-
     try
     {
+       DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetActiveSnapshot");
+
+       DBus::Hoho hoho(call);
+       hoho << config_name;
+
        DBus::Message reply = conn.send_with_reply_and_block(call);
 
        bool valid;
@@ -348,13 +343,7 @@ command_get_active_snapshot(DBus::Connection& conn, const string& config_name)
     }
     catch (const DBus::ErrorException& e)
     {
-       SN_CAUGHT(e);
-
-       if (strcmp(e.name(), "error.unsupported") == 0)
-           SN_THROW(UnsupportedException());
-
-       SN_RETHROW(e);
-       __builtin_unreachable();
+       convert_exception(e);
     }
 }
 
@@ -362,23 +351,18 @@ command_get_active_snapshot(DBus::Connection& conn, const string& config_name)
 void
 command_calculate_used_space(DBus::Connection& conn, const string& config_name)
 {
-    DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "CalculateUsedSpace");
-
-    DBus::Hoho hoho(call);
-    hoho << config_name;
-
     try
     {
+       DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "CalculateUsedSpace");
+
+       DBus::Hoho hoho(call);
+       hoho << config_name;
+
        conn.send_with_reply_and_block(call);
     }
     catch (const DBus::ErrorException& e)
     {
-       SN_CAUGHT(e);
-
-       if (strcmp(e.name(), "error.quota") == 0)
-           SN_THROW(QuotaException(e.message()));
-
-       SN_RETHROW(e);
+       convert_exception(e);
     }
 }
 
@@ -525,31 +509,71 @@ command_setup_quota(DBus::Connection& conn, const string& config_name)
 void
 command_prepare_quota(DBus::Connection& conn, const string& config_name)
 {
-    DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "PrepareQuota");
+    try
+    {
+       DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "PrepareQuota");
 
-    DBus::Hoho hoho(call);
-    hoho << config_name;
+       DBus::Hoho hoho(call);
+       hoho << config_name;
 
-    conn.send_with_reply_and_block(call);
+        conn.send_with_reply_and_block(call);
+    }
+    catch (const DBus::ErrorException& e)
+    {
+       convert_exception(e);
+    }
 }
 
 
 QuotaData
 command_query_quota(DBus::Connection& conn, const string& config_name)
 {
-    DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "QueryQuota");
+    try
+    {
+       DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "QueryQuota");
 
-    DBus::Hoho hoho(call);
-    hoho << config_name;
+       DBus::Hoho hoho(call);
+       hoho << config_name;
 
-    DBus::Message reply = conn.send_with_reply_and_block(call);
+       DBus::Message reply = conn.send_with_reply_and_block(call);
 
-    QuotaData quota_data;
+       QuotaData quota_data;
 
-    DBus::Hihi hihi(reply);
-    hihi >> quota_data;
+       DBus::Hihi hihi(reply);
+       hihi >> quota_data;
+
+       return quota_data;
+    }
+    catch (const DBus::ErrorException& e)
+    {
+       convert_exception(e);
+    }
+}
 
-    return quota_data;
+
+FreeSpaceData
+command_query_free_space(DBus::Connection& conn, const string& config_name)
+{
+    try
+    {
+       DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "QueryFreeSpace");
+
+       DBus::Hoho hoho(call);
+       hoho << config_name;
+
+       DBus::Message reply = conn.send_with_reply_and_block(call);
+
+       FreeSpaceData free_space_data;
+
+       DBus::Hihi hihi(reply);
+       hihi >> free_space_data;
+
+       return free_space_data;
+    }
+    catch (const DBus::ErrorException& e)
+    {
+       convert_exception(e);
+    }
 }
 
 
index dfd3f0e9739f07ef79048ef611ace01f5507821e..11cbc0e6b42b7d4c946e1f047cb3517686c89640 100644 (file)
@@ -135,6 +135,9 @@ command_prepare_quota(DBus::Connection& conn, const string& config_name);
 QuotaData
 command_query_quota(DBus::Connection& conn, const string& config_name);
 
+FreeSpaceData
+command_query_free_space(DBus::Connection& conn, const string& config_name);
+
 void
 command_sync(DBus::Connection& conn, const string& config_name);
 
index ff16a8d0b9d57bc146dfd2c7a526db285c5e52f0..1b630ea7315bf368c686a6bd8707dd535485950e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2016] SUSE LLC
+ * Copyright (c) [2016,2018] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -22,6 +22,7 @@
 
 
 #include <snapper/AppUtil.h>
+#include <snapper/Snapper.h>
 
 #include "utils/text.h"
 
@@ -32,6 +33,27 @@ using namespace std;
 using namespace snapper;
 
 
+void
+convert_exception(const DBus::ErrorException& e)
+{
+    SN_CAUGHT(e);
+
+    string name = e.name();
+
+    if (name == "error.unsupported")
+       SN_THROW(UnsupportedException());
+
+    if (name == "error.quota")
+       SN_THROW(QuotaException(e.message()));
+
+    if (name == "error.free_space")
+       SN_THROW(FreeSpaceException(e.message()));
+
+    SN_RETHROW(e);
+    __builtin_unreachable();
+}
+
+
 string
 error_description(const DBus::ErrorException& e)
 {
@@ -86,7 +108,10 @@ error_description(const DBus::ErrorException& e)
        return _("ACL error.");
 
     if (name == "error.quota")
-       return sformat(_("Quota failure (%s)."), e.message());
+       return sformat(_("Quota error (%s)."), e.message());
+
+    if (name == "error.free_space")
+       return sformat(_("Free space error (%s)."), e.message());
 
     return sformat(_("Failure (%s)."), name.c_str());
 }
index a56d6d4fa0d1782f2c731b1d5a38320fd1e9a43f..44f465cabc646beedd00424622ccf32d7d3bc5f9 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
+ * Copyright (c) 2018 SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -27,6 +28,19 @@ using std::string;
 #include "dbus/DBusConnection.h"
 
 
+/**
+ * Translate an DBus exception to the corresponding snapper exception
+ * (iff such exists). Unfinished.
+ */
+void
+convert_exception(const DBus::ErrorException& e) __attribute__ ((__noreturn__));
+
+
+/**
+ * Returns a string explaining the DBus exception. Function should
+ * likely be removed once convert_exception is complete and used
+ * everywhere.
+ */
 string
 error_description(const DBus::ErrorException& e);
 
index 1a2a2443dc3295aec6647f874f6f3493e974ccf4..c829c185a1d943ee312572f3e524d14dba946ab6 100644 (file)
@@ -175,6 +175,13 @@ ProxySnapperDbus::queryQuotaData() const
 }
 
 
+FreeSpaceData
+ProxySnapperDbus::queryFreeSpaceData() const
+{
+    return command_query_free_space(conn(), config_name);
+}
+
+
 ProxySnapshots::const_iterator
 ProxySnapperDbus::createSingleSnapshot(const SCD& scd)
 {
index 9bb7f3625e9a8c31757dae90cd57bd60026874d8..b2b6cd33cd3cda6ba2d77c92d3049281cad0dbce 100644 (file)
@@ -147,6 +147,8 @@ public:
 
     virtual QuotaData queryQuotaData() const override;
 
+    virtual FreeSpaceData queryFreeSpaceData() const override;
+
     virtual void calculateUsedSpace() const override;
 
     DBus::Connection& conn() const;
index 2a32d672b42a67ff6a6641847a1c497905a7fa48..5d3db5ad150ab297b81d69b6ee578eeef59a706a 100644 (file)
@@ -130,6 +130,8 @@ public:
 
     virtual QuotaData queryQuotaData() const override { return snapper->queryQuotaData(); }
 
+    virtual FreeSpaceData queryFreeSpaceData() const override { return snapper->queryFreeSpaceData(); }
+
     virtual void calculateUsedSpace() const override { snapper->calculateUsedSpace(); }
 
     std::unique_ptr<Snapper> snapper;
index 2ba22f8cd376ceda78c1a51006a491a75030c73f..d841963d7f220e52a5fc0b358b63cd074cc2e9d5 100644 (file)
@@ -65,8 +65,8 @@ using namespace snapper;
  */
 
 
-// TODO maybe unique error handling, e.g. catch dbus exceptions and throw
-// snapper or new exceptions
+// TODO Maybe unique error handling, e.g. catch dbus exceptions and
+// throw snapper or new exceptions. Partly done, see errors.h.
 
 
 class ProxyConfig
@@ -241,6 +241,8 @@ public:
 
     virtual QuotaData queryQuotaData() const = 0;
 
+    virtual FreeSpaceData queryFreeSpaceData() const = 0;
+
     virtual void calculateUsedSpace() const = 0;
 
 };
index e3acbb8558513fcd78cad530879d8b3638bbb2c8..1196beb6afed263be3ebea82b1950560d6b20c6c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2012 Novell, Inc.
- * Copyright (c) 2016 SUSE LLC
+ * Copyright (c) [2016,2018] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -85,6 +85,16 @@ namespace DBus
     }
 
 
+    Hihi&
+    operator>>(Hihi& hihi, FreeSpaceData& data)
+    {
+       hihi.open_recurse();
+       hihi >> data.size >> data.free;
+       hihi.close_recurse();
+       return hihi;
+    }
+
+
     Hoho&
     operator<<(Hoho& hoho, SnapshotType data)
     {
index de1a5da40aa61dab1210e3f7094b47d4a2c88fa1..9217eacd9d8e51dafd396e16f95df97c81ce52b5 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2012 Novell, Inc.
- * Copyright (c) 2016 SUSE LLC
+ * Copyright (c) [2016,2018] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -113,4 +113,6 @@ namespace DBus
 
     Hihi& operator>>(Hihi& hihi, QuotaData& data);
 
+    Hihi& operator>>(Hihi& hihi, FreeSpaceData& data);
+
 }