Skip to content

Commit

Permalink
Reduce construction core interface objects, part 2
Browse files Browse the repository at this point in the history
Change-Id: I27870810deabc2c1976b76480dc939d00b134820
  • Loading branch information
spt29 committed Nov 22, 2024
1 parent 642f496 commit 11b631c
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/livestatus/include/livestatus/ICore.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ICore {
const std::string &name) const = 0;
[[nodiscard]] virtual const IHostGroup *find_hostgroup(
const std::string &name) const = 0;
[[nodiscard]] virtual std::unique_ptr<const IHost> getHostByDesignation(
[[nodiscard]] virtual const IHost *getHostByDesignation(
const std::string &designation) const = 0;
virtual bool all_of_hosts(
const std::function<bool(const IHost &)> &pred) const = 0;
Expand Down
4 changes: 2 additions & 2 deletions packages/livestatus/include/livestatus/TableEventConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include <vector>

#include "livestatus/IntColumn.h"
#include "livestatus/Interface.h"
#include "livestatus/ListColumn.h"
#include "livestatus/Table.h"

class ColumnOffsets;
template <typename T>
class DoubleColumn;
class ICore;
class IHost;
class Query;
template <typename T>
class StringColumn;
Expand Down Expand Up @@ -57,7 +57,7 @@ class ECRow {

private:
std::map<std::string, std::string> map_;
std::unique_ptr<const IHost> host_;
const IHost *host_;

[[nodiscard]] std::string get(const std::string &column_name,
const std::string &default_value) const;
Expand Down
3 changes: 2 additions & 1 deletion packages/livestatus/src/TableEventConsole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "livestatus/EventConsoleConnection.h"
#include "livestatus/Filter.h"
#include "livestatus/ICore.h"
#include "livestatus/Interface.h"
#include "livestatus/Query.h"
#include "livestatus/Row.h"
#include "livestatus/StringColumn.h"
Expand Down Expand Up @@ -269,7 +270,7 @@ std::string ECRow::get(const std::string &column_name,
return it == map_.end() ? default_value : it->second;
}

const IHost *ECRow::host() const { return host_ ? host_.get() : nullptr; }
const IHost *ECRow::host() const { return host_; }

namespace {
std::function<bool(const row_type &)> get_authorizer(const Table &table,
Expand Down
2 changes: 1 addition & 1 deletion packages/livestatus/test/test_Table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class DummyMonitoringCore : public ICore {
const std::string & /* name */) const override {
return nullptr;
}
[[nodiscard]] std::unique_ptr<const IHost> getHostByDesignation(
[[nodiscard]] const IHost *getHostByDesignation(
const std::string & /*designation*/) const override {
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/neb/include/neb/NebCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class NebCore : public ICore {
const std::string &name) const override;
[[nodiscard]] const IHostGroup *find_hostgroup(
const std::string &name) const override;
[[nodiscard]] std::unique_ptr<const IHost> getHostByDesignation(
[[nodiscard]] const IHost *getHostByDesignation(
const std::string &designation) const override;
bool all_of_hosts(
const std::function<bool(const IHost &)> &pred) const override;
Expand Down
6 changes: 2 additions & 4 deletions packages/neb/src/NebCore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,10 @@ bool NebCore::all_of_services(
[pred](const auto &entry) { return pred(*entry.second); });
}

std::unique_ptr<const IHost> NebCore::getHostByDesignation(
const IHost *NebCore::getHostByDesignation(
const std::string &designation) const {
auto it = _hosts_by_designation.find(mk::unsafe_tolower(designation));
return it == _hosts_by_designation.end()
? nullptr
: std::make_unique<NebHost>(*it->second);
return it == _hosts_by_designation.end() ? nullptr : ihost(it->second);
}

const IService *NebCore::iservice(const ::service *handle) const {
Expand Down

0 comments on commit 11b631c

Please sign in to comment.