Module: check_mk
Branch: master
Commit: 15a7aee42c72bd8d3cbf8c30f3d97c71aece7666
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=15a7aee42c72bd…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Aug 9 10:00:54 2017 +0200
Encapsulation 101: Restrict access to current configuration (World::_config)
* Do not directly access fields of other classes.
* Avoid "train wrecks", see
http://wiki.c2.com/?TrainWreck.
* Improve const-correctness.
This commit is part of a series, trying to statically ensure that Livestatus
threads access the rest of the system in a read-only way.
Change-Id: Id3ada2bfa2fd6a58a16d4d53bbf99dc6d0e2850f
---
livestatus/src/AndingFilter.cc | 2 +-
livestatus/src/Column.h | 5 +++--
livestatus/src/HostListColumn.h | 2 +-
livestatus/src/HostListStateColumn.h | 2 +-
livestatus/src/ServiceListColumn.h | 2 +-
livestatus/src/ServiceListStateColumn.h | 2 +-
livestatus/src/Store.h | 2 +-
7 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/livestatus/src/AndingFilter.cc b/livestatus/src/AndingFilter.cc
index d67c092..ee47e52 100644
--- a/livestatus/src/AndingFilter.cc
+++ b/livestatus/src/AndingFilter.cc
@@ -52,7 +52,7 @@ bool AndingFilter::optimizeBitmask(const string &column_name,
uint32_t *mask,
const string *AndingFilter::findValueForIndexing(
const string &column_name) const {
for (const auto &filter : _subfilters) {
- if (const string *value = filter->valueForIndexing(column_name)) {
+ if (auto value = filter->valueForIndexing(column_name)) {
return value;
}
}
diff --git a/livestatus/src/Column.h b/livestatus/src/Column.h
index 7e41930..81a735d 100644
--- a/livestatus/src/Column.h
+++ b/livestatus/src/Column.h
@@ -38,8 +38,9 @@ class Logger;
class RowRenderer;
template <typename T>
-T *offset_cast(void *ptr, size_t offset) {
- return reinterpret_cast<T *>(reinterpret_cast<char *>(ptr) + offset);
+const T *offset_cast(const void *ptr, size_t offset) {
+ return reinterpret_cast<const T *>(reinterpret_cast<const char *>(ptr) +
+ offset);
}
enum class ColumnType { int_, double_, string, list, time, dict, blob, null };
diff --git a/livestatus/src/HostListColumn.h b/livestatus/src/HostListColumn.h
index 28f7000..f603e9d 100644
--- a/livestatus/src/HostListColumn.h
+++ b/livestatus/src/HostListColumn.h
@@ -58,7 +58,7 @@ public:
std::unique_ptr<Filter> createFilter(RelationalOperator relOp,
const std::string &value) override;
#ifdef CMC
- std::unordered_set<Host *> *getMembers(Row row);
+ const std::unordered_set<Host *> *getMembers(Row row);
#else
hostsmember *getMembers(Row row);
#endif
diff --git a/livestatus/src/HostListStateColumn.h b/livestatus/src/HostListStateColumn.h
index 87093b4..c00b698 100644
--- a/livestatus/src/HostListStateColumn.h
+++ b/livestatus/src/HostListStateColumn.h
@@ -84,7 +84,7 @@ public:
, _logictype(logictype) {}
int32_t getValue(Row row, contact *auth_user) override;
#ifdef CMC
- std::unordered_set<Host *> *getMembers(Row row);
+ const std::unordered_set<Host *> *getMembers(Row row);
#else
hostsmember *getMembers(Row row);
#endif
diff --git a/livestatus/src/ServiceListColumn.h b/livestatus/src/ServiceListColumn.h
index 8edaad2..519cb9d 100644
--- a/livestatus/src/ServiceListColumn.h
+++ b/livestatus/src/ServiceListColumn.h
@@ -61,7 +61,7 @@ public:
std::unique_ptr<Filter> createFilter(RelationalOperator relOp,
const std::string &value) override;
#ifdef CMC
- Host::services_t *getMembers(Row row);
+ const Host::services_t *getMembers(Row row);
#else
servicesmember *getMembers(Row row);
#endif
diff --git a/livestatus/src/ServiceListStateColumn.h
b/livestatus/src/ServiceListStateColumn.h
index d960850..deae10e 100644
--- a/livestatus/src/ServiceListStateColumn.h
+++ b/livestatus/src/ServiceListStateColumn.h
@@ -69,7 +69,7 @@ public:
int32_t getValue(Row row, contact *auth_user) override;
#ifdef CMC
static int32_t getValue(MonitoringCore *mc, Type logictype,
- Host::services_t *mem, contact *auth_user);
+ const Host::services_t *mem, contact *auth_user);
#else
static int32_t getValue(MonitoringCore *mc, Type logictype,
servicesmember *mem, contact *auth_user);
diff --git a/livestatus/src/Store.h b/livestatus/src/Store.h
index dc1ac0f..d6cc658 100644
--- a/livestatus/src/Store.h
+++ b/livestatus/src/Store.h
@@ -142,7 +142,7 @@ private:
void addTable(Table *table);
Table *findTable(const std::string &name);
#ifdef CMC
- Config *config() const;
+ const Config *config() const;
uint32_t horizon() const;
#else
void logRequest(const std::string &line,