Repository :
http://git.fedorahosted.org/cgit/firewalld-recode.git
On branch : master
---------------------------------------------------------------
commit 8a1e1fed1466f41f7007c161fef5d3d1988ceed5
Author: Daniel Kopecek <dkopecek(a)redhat.com>
Date: Tue Oct 14 14:45:51 2014 +0200
Added Transaction class implementation
---------------------------------------------------------------
src/Daemon/Firewall/Transaction.cpp | 80 +++++++++++++++++++++++++++++++++++
src/Daemon/Firewall/Transaction.hpp | 60 ++++++++++++++++++++++++++
2 files changed, 140 insertions(+), 0 deletions(-)
diff --git a/src/Daemon/Firewall/Transaction.cpp b/src/Daemon/Firewall/Transaction.cpp
new file mode 100644
index 0000000..1505e69
--- /dev/null
+++ b/src/Daemon/Firewall/Transaction.cpp
@@ -0,0 +1,80 @@
+//
+// Copyright (C) 2014 Red Hat, Inc.
+//
+// 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 2 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/>.
+//
+// Authors: Daniel Kopecek <dkopecek(a)redhat.com>
+//
+#include "Transaction.hpp"
+#include <stdexcept>
+
+namespace firewalld
+{
+
+ Transaction::Transaction(const String& identifier)
+ {
+ _identifier = identifier;
+ }
+
+ const UStringList& Transaction::operation(size_t index) const
+ {
+ return _operations.at(index);
+ }
+
+ size_t Transaction::countOperations() const
+ {
+ return _operations.size();
+ }
+
+ size_t Transaction::appendOperation(const UStringList& op)
+ {
+ _operations.push_back(op);
+ return (_operations.size() - 1);
+ }
+
+ void Transaction::removeOperation(size_t index)
+ {
+ if (index > (_operations.size() - 1)) {
+ throw std::out_of_range("removeOperation range check failed");
+ }
+ _operations.erase(_operations.begin() + index);
+ }
+
+ TransactionError::TransactionError(Pointer<Transaction> transaction, size_t
failed_op_index, const UString& message)
+ : std::runtime_error("Transaction error")
+ {
+ _transaction = transaction;
+ _failed_op_index = failed_op_index;
+ _message = message;
+ }
+
+ const UString& TransactionError::message() const
+ {
+ return _message;
+ }
+
+ bool TransactionError::rollbackNeeded() const
+ {
+ if (_transaction->countOperations() > 0) {
+ return (_failed_op_index > 0);
+ }
+ return false;
+ }
+
+ size_t TransactionError::rollbackFromIndex() const
+ {
+ return (_failed_op_index > 0 ? _failed_op_index - 1 : 0);
+ }
+
+} /* namespace firewalld */
diff --git a/src/Daemon/Firewall/Transaction.hpp b/src/Daemon/Firewall/Transaction.hpp
new file mode 100644
index 0000000..2978039
--- /dev/null
+++ b/src/Daemon/Firewall/Transaction.hpp
@@ -0,0 +1,60 @@
+//
+// Copyright (C) 2014 Red Hat, Inc.
+//
+// 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 2 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/>.
+//
+// Authors: Daniel Kopecek <dkopecek(a)redhat.com>
+//
+#ifndef FIREWALLD_FIREWALL_TRANSACTION_HPP
+#define FIREWALLD_FIREWALL_TRANSACTION_HPP
+
+#include "Common/Types.hpp"
+#include <stdexcept>
+#include <cstddef>
+
+namespace firewalld
+{
+
+ class Transaction
+ {
+ public:
+ Transaction(const String& identifier);
+
+ const UStringList& operation(size_t index) const;
+ size_t countOperations() const;
+
+ size_t appendOperation(const UStringList& op);
+ void removeOperation(size_t index);
+
+ private:
+ String _identifier;
+ std::vector<UStringList> _operations;
+ };
+
+ class TransactionError : public std::runtime_error
+ {
+ public:
+ TransactionError(Pointer<Transaction> transaction, size_t failed_op_index,
const UString& message);
+ const UString& message() const;
+ bool rollbackNeeded() const;
+ size_t rollbackFromIndex() const;
+ private:
+ Pointer<Transaction> _transaction;
+ size_t _failed_op_index;
+ UString _message;
+ };
+
+} /* namespace firewalld */
+
+#endif /* FIREWALLD_FIREWALL_TRANSACTION_HPP */