Skip to content

Commit

Permalink
Add pImpl to libdnf5::base::transaction_* classes
Browse files Browse the repository at this point in the history
This includes package, group, environment and module.
  • Loading branch information
kontura authored and jan-kolarik committed Jan 26, 2024
1 parent 4859807 commit 4d1aaf3
Show file tree
Hide file tree
Showing 10 changed files with 493 additions and 101 deletions.
35 changes: 15 additions & 20 deletions include/libdnf5/base/transaction_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef LIBDNF5_BASE_TRANSACTION_ENVIRONMENT_HPP
#define LIBDNF5_BASE_TRANSACTION_ENVIRONMENT_HPP

#include "libdnf5/base/goal_elements.hpp"
#include "libdnf5/base/transaction.hpp"
#include "libdnf5/comps/environment/environment.hpp"
#include "libdnf5/transaction/transaction_item_action.hpp"
Expand All @@ -36,46 +35,42 @@ class TransactionEnvironment {
using Reason = transaction::TransactionItemReason;
using State = transaction::TransactionItemState;
using Action = transaction::TransactionItemAction;
using PackageType = libdnf5::comps::PackageType;

/// @return the underlying environment.
libdnf5::comps::Environment get_environment() const { return environment; }
libdnf5::comps::Environment get_environment() const;

/// @return the action being performed on the transaction environment.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getAction()
Action get_action() const noexcept { return action; }
Action get_action() const noexcept;

/// @return the state of the environment in the transaction.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getState()
State get_state() const noexcept { return state; }
State get_state() const noexcept;

/// @return the reason of the action being performed on the transaction environment.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getReason()
Reason get_reason() const noexcept { return reason; }
Reason get_reason() const noexcept;

/// @return package types requested to be installed with the group.
bool get_with_optional() const noexcept { return with_optional; }
bool get_with_optional() const noexcept;

~TransactionEnvironment();

TransactionEnvironment(const TransactionEnvironment & mpkg);
TransactionEnvironment & operator=(const TransactionEnvironment & mpkg);
TransactionEnvironment(TransactionEnvironment && mpkg) noexcept;
TransactionEnvironment & operator=(TransactionEnvironment && mpkg) noexcept;

private:
friend class Transaction::Impl;

TransactionEnvironment(
const libdnf5::comps::Environment & grp, Action action, Reason reason, const bool with_optional)
: environment(grp),
action(action),
reason(reason),
with_optional(with_optional) {}

void set_state(State value) noexcept { state = value; }
TransactionEnvironment(const libdnf5::comps::Environment & grp, Action action, Reason reason, bool with_optional);

libdnf5::comps::Environment environment;
Action action;
Reason reason;
State state{State::STARTED};
bool with_optional;
class Impl;
std::unique_ptr<Impl> p_impl;
};

} // namespace libdnf5::base
Expand Down
35 changes: 15 additions & 20 deletions include/libdnf5/base/transaction_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef LIBDNF5_BASE_TRANSACTION_GROUP_HPP
#define LIBDNF5_BASE_TRANSACTION_GROUP_HPP

#include "libdnf5/base/goal_elements.hpp"
#include "libdnf5/base/transaction.hpp"
#include "libdnf5/comps/group/group.hpp"
#include "libdnf5/comps/group/package.hpp"
Expand All @@ -30,8 +29,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "libdnf5/transaction/transaction_item_reason.hpp"
#include "libdnf5/transaction/transaction_item_state.hpp"

#include <optional>


namespace libdnf5::base {

Expand All @@ -43,42 +40,40 @@ class TransactionGroup {
using PackageType = libdnf5::comps::PackageType;

/// @return the underlying group.
libdnf5::comps::Group get_group() const { return group; }
libdnf5::comps::Group get_group() const;

/// @return the action being performed on the transaction group.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getAction()
Action get_action() const noexcept { return action; }
Action get_action() const noexcept;

/// @return the state of the group in the transaction.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getState()
State get_state() const noexcept { return state; }
State get_state() const noexcept;

/// @return the reason of the action being performed on the transaction group.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getReason()
Reason get_reason() const noexcept { return reason; }
Reason get_reason() const noexcept;

/// @return package types requested to be installed with the group.
PackageType get_package_types() const noexcept { return package_types; }
PackageType get_package_types() const noexcept;

~TransactionGroup();

TransactionGroup(const TransactionGroup & mpkg);
TransactionGroup & operator=(const TransactionGroup & mpkg);
TransactionGroup(TransactionGroup && mpkg) noexcept;
TransactionGroup & operator=(TransactionGroup && mpkg) noexcept;

private:
friend class Transaction::Impl;

TransactionGroup(const libdnf5::comps::Group & grp, Action action, Reason reason, const PackageType types)
: group(grp),
action(action),
reason(reason),
package_types(types) {}

void set_state(State value) noexcept { state = value; }
TransactionGroup(const libdnf5::comps::Group & grp, Action action, Reason reason, const PackageType & types);

libdnf5::comps::Group group;
Action action;
Reason reason;
State state{State::STARTED};
PackageType package_types;
class Impl;
std::unique_ptr<Impl> p_impl;
};

} // namespace libdnf5::base
Expand Down
36 changes: 15 additions & 21 deletions include/libdnf5/base/transaction_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef LIBDNF5_BASE_TRANSACTION_MODULE_HPP
#define LIBDNF5_BASE_TRANSACTION_MODULE_HPP

#include "libdnf5/base/goal_elements.hpp"
#include "libdnf5/base/transaction.hpp"
#include "libdnf5/module/module_item.hpp"
#include "libdnf5/transaction/transaction_item_action.hpp"
#include "libdnf5/transaction/transaction_item_reason.hpp"
#include "libdnf5/transaction/transaction_item_state.hpp"

#include <optional>


namespace libdnf5::base {

Expand All @@ -40,42 +36,40 @@ class TransactionModule {
using Action = transaction::TransactionItemAction;

/// @return the module name.
std::string get_module_name() const { return module_name; }
std::string get_module_name() const;

/// @return the module stream.
std::string get_module_stream() const { return module_stream; }
std::string get_module_stream() const;

/// @return the action being performed on the transaction module.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getAction()
Action get_action() const noexcept { return action; }
Action get_action() const noexcept;

/// @return the state of the module item in the transaction.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getState()
State get_state() const noexcept { return state; }
State get_state() const noexcept;

/// @return the reason of the action being performed on the transaction module.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getReason()
Reason get_reason() const noexcept { return reason; }
Reason get_reason() const noexcept;

~TransactionModule();

TransactionModule(const TransactionModule & mpkg);
TransactionModule & operator=(const TransactionModule & mpkg);
TransactionModule(TransactionModule && mpkg) noexcept;
TransactionModule & operator=(TransactionModule && mpkg) noexcept;

private:
friend class Transaction::Impl;

TransactionModule(const std::string & module_name, const std::string & module_stream, Action action, Reason reason)
: module_name(module_name),
module_stream(module_stream),
action(action),
reason(reason) {}

void set_state(State value) noexcept { state = value; }
TransactionModule(const std::string & module_name, const std::string & module_stream, Action action, Reason reason);

std::string module_name;
std::string module_stream;
Action action;
Reason reason;
State state{State::STARTED};
class Impl;
std::unique_ptr<Impl> p_impl;
};

} // namespace libdnf5::base
Expand Down
56 changes: 20 additions & 36 deletions include/libdnf5/base/transaction_package.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#ifndef LIBDNF5_BASE_TRANSACTION_PACKAGE_HPP
#define LIBDNF5_BASE_TRANSACTION_PACKAGE_HPP

#include "libdnf5/base/goal_elements.hpp"
#include "libdnf5/base/transaction.hpp"
#include "libdnf5/rpm/package.hpp"
#include "libdnf5/transaction/transaction_item_action.hpp"
Expand All @@ -43,70 +42,55 @@ class TransactionPackage {
using State = transaction::TransactionItemState;

/// @return the underlying package.
libdnf5::rpm::Package get_package() const { return package; }
libdnf5::rpm::Package get_package() const;

/// @return the action being performed on the transaction package.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getAction()
Action get_action() const noexcept { return action; }
Action get_action() const noexcept;

/// @return the state of the package in the transaction.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getState()
State get_state() const noexcept { return state; }
State get_state() const noexcept;

/// @return the reason of the action being performed on the transaction package.
//
// @replaces libdnf:transaction/TransactionItem.hpp:method:TransactionItemBase.getReason()
Reason get_reason() const noexcept { return reason; }
Reason get_reason() const noexcept;

/// @return packages replaced by this transaction package.
const std::vector<rpm::Package> get_replaces() const noexcept { return replaces; }
std::vector<rpm::Package> get_replaces() const noexcept;

/// @return packages that replace this transaction package (for transaction
/// packages that are leaving the system).
const std::vector<rpm::Package> & get_replaced_by() const noexcept { return replaced_by; }
const std::vector<rpm::Package> & get_replaced_by() const noexcept;

/// The REASON_CHANGE action requires group id in case the reason is changed to GROUP
/// @return id of group the package belongs to
const std::string * get_reason_change_group_id() const noexcept {
return reason_change_group_id ? &reason_change_group_id.value() : nullptr;
}
const std::string * get_reason_change_group_id() const noexcept;

~TransactionPackage();

TransactionPackage(const TransactionPackage & mpkg);
TransactionPackage & operator=(const TransactionPackage & mpkg);
TransactionPackage(TransactionPackage && mpkg) noexcept;
TransactionPackage & operator=(TransactionPackage && mpkg) noexcept;

private:
friend class Transaction::Impl;
friend class ::BaseGoalTest;
friend class ::RpmTransactionTest;

TransactionPackage(const libdnf5::rpm::Package & pkg, Action action, Reason reason)
: package(pkg),
action(action),
reason(reason) {}
TransactionPackage(const libdnf5::rpm::Package & pkg, Action action, Reason reason);

TransactionPackage(const libdnf5::rpm::Package & pkg, Action action, Reason reason, State state)
: package(pkg),
action(action),
reason(reason),
state(state) {}
TransactionPackage(const libdnf5::rpm::Package & pkg, Action action, Reason reason, State state);

TransactionPackage(
const libdnf5::rpm::Package & pkg, Action action, Reason reason, std::optional<std::string> group_id)
: package(pkg),
action(action),
reason(reason),
reason_change_group_id(group_id) {}

void set_reason(Reason value) noexcept { reason = value; }
void set_state(State value) noexcept { state = value; }

libdnf5::rpm::Package package;
Action action;
Reason reason;
State state{State::STARTED};
std::optional<std::string> reason_change_group_id;

std::vector<rpm::Package> replaces;
std::vector<rpm::Package> replaced_by;
const libdnf5::rpm::Package & pkg, Action action, Reason reason, const std::optional<std::string> & group_id);

class Impl;
std::unique_ptr<Impl> p_impl;
};

} // namespace libdnf5::base
Expand Down
9 changes: 5 additions & 4 deletions libdnf5/base/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "solver_problems_internal.hpp"
#include "transaction/transaction_sr.hpp"
#include "transaction_impl.hpp"
#include "transaction_package_impl.hpp"
#include "utils/locker.hpp"
#include "utils/string.hpp"

Expand Down Expand Up @@ -409,7 +410,7 @@ void Transaction::Impl::set_transaction(
rpm::Package obsoleted(base, rpm::PackageId(replaced_id));
TransactionPackage tspkg(obsoleted, TransactionPackage::Action::REPLACED, obsoleted.get_reason());
for (auto id : replaced_by_ids) {
tspkg.replaced_by.emplace_back(rpm::Package(base, rpm::PackageId(id)));
tspkg.p_impl->replaced_by_append(rpm::Package(base, rpm::PackageId(id)));
}
packages.emplace_back(std::move(tspkg));
}
Expand Down Expand Up @@ -462,7 +463,7 @@ void Transaction::Impl::set_transaction(
pkg.get_action() == transaction::TransactionItemAction::REMOVE ||
(reason_override->second > pkg.get_reason() &&
pkg.get_action() != transaction::TransactionItemAction::REASON_CHANGE)) {
pkg.reason = reason_override->second;
pkg.p_impl->set_reason(reason_override->second);
}
}
}
Expand Down Expand Up @@ -504,10 +505,10 @@ TransactionPackage Transaction::Impl::make_transaction_package(
for (auto replaced_id : obs) {
rpm::Package replaced_pkg(base, rpm::PackageId(replaced_id));
reason = std::max(reason, replaced_pkg.get_reason());
tspkg.replaces.emplace_back(std::move(replaced_pkg));
tspkg.p_impl->replaces_append(std::move(replaced_pkg));
replaced[replaced_id].push_back(id);
}
tspkg.set_reason(reason);
tspkg.p_impl->set_reason(reason);

return tspkg;
}
Expand Down
Loading

0 comments on commit 4d1aaf3

Please sign in to comment.