Module: check_mk
Branch: master
Commit: 3e6e484d4b640ae1f7fc660a3306193031f4c71e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3e6e484d4b640a…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Sep 1 09:35:17 2017 +0200
Make access of column data const-correct.
This is an important step: The compiler statically verifies that the
Livestatus threads don't accidentally modify the contents of table columns.
Change-Id: Ib5a21f41b49fbb6c793f2c007d222de474c8a6f7
---
livestatus/src/Column.h | 4 ++--
livestatus/src/CommentColumn.cc | 5 +++--
livestatus/src/DowntimeColumn.cc | 5 +++--
livestatus/src/OffsetStringHostMacroColumn.cc | 4 ++--
livestatus/src/OffsetStringHostMacroColumn.h | 4 ++--
livestatus/src/OffsetStringServiceMacroColumn.cc | 4 ++--
livestatus/src/OffsetStringServiceMacroColumn.h | 4 ++--
livestatus/src/TableColumns.cc | 4 ++--
livestatus/src/TableColumns.h | 4 ++--
9 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/livestatus/src/Column.h b/livestatus/src/Column.h
index 1d51a10..a1494dc 100644
--- a/livestatus/src/Column.h
+++ b/livestatus/src/Column.h
@@ -55,8 +55,8 @@ public:
std::string description() const { return _description; }
template <typename T>
- T *columnData(Row row) const {
- return static_cast<T *>(shiftPointer(row));
+ const T *columnData(Row row) const {
+ return static_cast<const T *>(shiftPointer(row));
}
virtual ColumnType type() const = 0;
diff --git a/livestatus/src/CommentColumn.cc b/livestatus/src/CommentColumn.cc
index 914ffb9..f7074f7 100644
--- a/livestatus/src/CommentColumn.cc
+++ b/livestatus/src/CommentColumn.cc
@@ -87,9 +87,10 @@ vector<CommentData> CommentColumn::comments_for_row(Row row)
const {
if (auto data = columnData<void>(row)) {
return _is_service
? _mc->comments_for_service(
- reinterpret_cast<MonitoringCore::Service *>(data))
+ reinterpret_cast<const MonitoringCore::Service *>(
+ data))
: _mc->comments_for_host(
- reinterpret_cast<MonitoringCore::Host *>(data));
+ reinterpret_cast<const MonitoringCore::Host *>(data));
}
return {};
}
diff --git a/livestatus/src/DowntimeColumn.cc b/livestatus/src/DowntimeColumn.cc
index 8c096e6..a36d0cc 100644
--- a/livestatus/src/DowntimeColumn.cc
+++ b/livestatus/src/DowntimeColumn.cc
@@ -81,9 +81,10 @@ vector<DowntimeData> DowntimeColumn::downtimes_for_row(Row row)
const {
if (auto data = columnData<void>(row)) {
return _is_service
? _mc->downtimes_for_service(
- reinterpret_cast<MonitoringCore::Service *>(data))
+ reinterpret_cast<const MonitoringCore::Service *>(
+ data))
: _mc->downtimes_for_host(
- reinterpret_cast<MonitoringCore::Host *>(data));
+ reinterpret_cast<const MonitoringCore::Host *>(data));
}
return {};
}
diff --git a/livestatus/src/OffsetStringHostMacroColumn.cc
b/livestatus/src/OffsetStringHostMacroColumn.cc
index a079a08..34efd80 100644
--- a/livestatus/src/OffsetStringHostMacroColumn.cc
+++ b/livestatus/src/OffsetStringHostMacroColumn.cc
@@ -25,10 +25,10 @@
#include "OffsetStringHostMacroColumn.h"
#include "Row.h"
-host *OffsetStringHostMacroColumn::getHost(Row row) const {
+const host *OffsetStringHostMacroColumn::getHost(Row row) const {
return columnData<host>(row);
}
-service *OffsetStringHostMacroColumn::getService(Row /*unused*/) const {
+const service *OffsetStringHostMacroColumn::getService(Row /*unused*/) const {
return nullptr;
}
diff --git a/livestatus/src/OffsetStringHostMacroColumn.h
b/livestatus/src/OffsetStringHostMacroColumn.h
index f144f9e..32eef88 100644
--- a/livestatus/src/OffsetStringHostMacroColumn.h
+++ b/livestatus/src/OffsetStringHostMacroColumn.h
@@ -39,8 +39,8 @@ public:
int extra_extra_offset)
: OffsetStringMacroColumn(name, description, offset, indirect_offset,
extra_offset, extra_extra_offset) {}
- host *getHost(Row row) const override;
- service *getService(Row row) const override;
+ const host *getHost(Row row) const override;
+ const service *getService(Row row) const override;
};
#endif // OffsetStringHostMacroColumn_h
diff --git a/livestatus/src/OffsetStringServiceMacroColumn.cc
b/livestatus/src/OffsetStringServiceMacroColumn.cc
index f5c53ae..865774d 100644
--- a/livestatus/src/OffsetStringServiceMacroColumn.cc
+++ b/livestatus/src/OffsetStringServiceMacroColumn.cc
@@ -25,13 +25,13 @@
#include "OffsetStringServiceMacroColumn.h"
#include "Row.h"
-host *OffsetStringServiceMacroColumn::getHost(Row row) const {
+const host *OffsetStringServiceMacroColumn::getHost(Row row) const {
if (auto svc = getService(row)) {
return svc->host_ptr;
}
return nullptr;
}
-service *OffsetStringServiceMacroColumn::getService(Row row) const {
+const service *OffsetStringServiceMacroColumn::getService(Row row) const {
return columnData<service>(row);
}
diff --git a/livestatus/src/OffsetStringServiceMacroColumn.h
b/livestatus/src/OffsetStringServiceMacroColumn.h
index 9e31e08..0a162fc 100644
--- a/livestatus/src/OffsetStringServiceMacroColumn.h
+++ b/livestatus/src/OffsetStringServiceMacroColumn.h
@@ -39,8 +39,8 @@ public:
int extra_extra_offset)
: OffsetStringMacroColumn(name, description, offset, indirect_offset,
extra_offset, extra_extra_offset) {}
- host *getHost(Row row) const override;
- service *getService(Row row) const override;
+ const host *getHost(Row row) const override;
+ const service *getService(Row row) const override;
};
#endif // OffsetStringServiceMacroColumn_h
diff --git a/livestatus/src/TableColumns.cc b/livestatus/src/TableColumns.cc
index 49fc726..a26d409 100644
--- a/livestatus/src/TableColumns.cc
+++ b/livestatus/src/TableColumns.cc
@@ -62,7 +62,7 @@ void TableColumns::answerQuery(Query *query) {
}
}
-string TableColumns::getValue(Column *column,
+string TableColumns::getValue(const Column *column,
ColumnsColumn::Type colcol) const {
static const char *typenames[8] = {"int", "float",
"string", "list",
"time", "dict",
"blob", "null"};
@@ -80,7 +80,7 @@ string TableColumns::getValue(Column *column,
return "";
}
-string TableColumns::tableNameOf(Column *column) const {
+string TableColumns::tableNameOf(const Column *column) const {
for (auto table : _tables) {
if (table->any_column(
[&](shared_ptr<Column> c) { return c.get() == column; })) {
diff --git a/livestatus/src/TableColumns.h b/livestatus/src/TableColumns.h
index 750a8ef..ef4b5f0 100644
--- a/livestatus/src/TableColumns.h
+++ b/livestatus/src/TableColumns.h
@@ -45,8 +45,8 @@ public:
void answerQuery(Query *query) override;
void addTable(Table *);
- std::string getValue(Column *column, ColumnsColumn::Type colcol) const;
- std::string tableNameOf(Column *column) const;
+ std::string getValue(const Column *column, ColumnsColumn::Type colcol) const;
+ std::string tableNameOf(const Column *column) const;
};
#endif // TableColumns_h