Module: check_mk
Branch: master
Commit: ca1550efe4693398311b9e2570bd1293380a31e1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ca1550efe46933…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Fri Mar 23 16:37:53 2018 +0100
Win-agent: use strongly typed enums, part 4
Convert script_execution_mode and script_async_execution in
SectionPluginGroup.*.
---
agents/windows/build_version | 2 +-
agents/windows/sections/SectionPluginGroup.cc | 24 +++++++++++++-----------
agents/windows/sections/SectionPluginGroup.h | 22 ++++++++++++++++------
3 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 3771b21..fa4988d 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3206
+3208
diff --git a/agents/windows/sections/SectionPluginGroup.cc
b/agents/windows/sections/SectionPluginGroup.cc
index 60b61de..53a485e 100644
--- a/agents/windows/sections/SectionPluginGroup.cc
+++ b/agents/windows/sections/SectionPluginGroup.cc
@@ -258,8 +258,9 @@ void SectionPluginGroup::runContainer(script_container *cont) {
0, // use default creation flags
nullptr), // returns the thread identifier
_winapi};
- if (cont->execution_mode == SYNC ||
- (cont->execution_mode == ASYNC && *_async_execution ==
SEQUENTIAL))
+ if (cont->execution_mode == script_execution_mode::SYNC ||
+ (cont->execution_mode == script_execution_mode::ASYNC &&
+ *_async_execution == script_async_execution::SEQUENTIAL))
_winapi.WaitForSingleObject(cont->worker_thread.get(), INFINITE);
Debug(_logger) << "finished with status " <<
cont->status
@@ -381,9 +382,10 @@ SectionPluginGroup::SectionPluginGroup(
, _type(type)
, _user(user)
, _collection_thread(_winapi)
- , _default_execution_mode(config, "global", "caching_method",
SYNC, _winapi)
- , _async_execution(config, "global", "async_script_execution",
SEQUENTIAL,
- _winapi)
+ , _default_execution_mode(config, "global", "caching_method",
+ script_execution_mode::SYNC, _winapi)
+ , _async_execution(config, "global", "async_script_execution",
+ script_async_execution::SEQUENTIAL, _winapi)
, _execute_suffixes(config, "global", "execute", _winapi)
, _timeout(config, typeToSection(type), "timeout", _winapi)
, _cache_age(config, typeToSection(type), "cache_age", _winapi)
@@ -395,7 +397,7 @@ SectionPluginGroup::~SectionPluginGroup() { _containers.clear(); }
void SectionPluginGroup::startIfAsync() {
updateScripts();
- collectData(ASYNC);
+ collectData(script_execution_mode::ASYNC);
}
void SectionPluginGroup::waitForCompletion() {
@@ -424,7 +426,7 @@ bool SectionPluginGroup::produceOutputInner(
std::ostream &out, const std::optional<std::string> &) {
Debug(_logger) << "SectionPluginGroup::produceOutputInner";
// gather the data for the sync sections
- collectData(SYNC);
+ collectData(script_execution_mode::SYNC);
if (_type == PLUGIN) {
// prevent errors from plugins missing their section header
out << "<<<>>>\n";
@@ -616,7 +618,7 @@ DataCollectionThread(LPVOID lpParam) {
do {
self->_data_collection_retriggered = false;
for (const auto &kv : self->_containers) {
- if (kv.second->execution_mode == ASYNC) {
+ if (kv.second->execution_mode == script_execution_mode::ASYNC) {
self->runContainer(kv.second.get());
}
}
@@ -626,13 +628,13 @@ DataCollectionThread(LPVOID lpParam) {
void SectionPluginGroup::collectData(script_execution_mode mode) {
const std::string typeName = _type == PLUGIN ? "plugin" :
"local";
- if (mode == SYNC) {
+ if (mode == script_execution_mode::SYNC) {
Debug(_logger) << "Collecting sync " << typeName <<
" data";
for (const auto &kv : _containers) {
- if (kv.second->execution_mode == SYNC)
+ if (kv.second->execution_mode == script_execution_mode::SYNC)
runContainer(kv.second.get());
}
- } else if (mode == ASYNC) {
+ } else if (mode == script_execution_mode::ASYNC) {
// If the thread is still running, just tell it to do another cycle
DWORD dwExitCode = 0;
if (_winapi.GetExitCodeThread(_collection_thread.get(), &dwExitCode)) {
diff --git a/agents/windows/sections/SectionPluginGroup.h
b/agents/windows/sections/SectionPluginGroup.h
index 9012ad2..893f0e7 100644
--- a/agents/windows/sections/SectionPluginGroup.h
+++ b/agents/windows/sections/SectionPluginGroup.h
@@ -38,21 +38,31 @@ class Environment;
class SectionPlugin;
// How single scripts are executed
-enum script_execution_mode {
+enum class script_execution_mode {
SYNC, // inline
ASYNC // delayed
};
+inline std::ostream &operator<<(std::ostream &os,
+ const script_execution_mode mode) {
+ return os << static_cast<unsigned>(mode);
+}
+
// How delayed scripts are executed
-enum script_async_execution { PARALLEL, SEQUENTIAL };
+enum class script_async_execution { PARALLEL, SEQUENTIAL };
+
+inline std::ostream &operator<<(std::ostream &os,
+ const script_async_execution async) {
+ return os << static_cast<unsigned>(async);
+}
template <>
inline script_execution_mode from_string<script_execution_mode>(
const WinApiAdaptor &, const std::string &value) {
if (value == "async")
- return ASYNC;
+ return script_execution_mode::ASYNC;
else if (value == "sync")
- return SYNC;
+ return script_execution_mode::SYNC;
throw std::runtime_error("invalid execution mode");
}
@@ -60,9 +70,9 @@ template <>
inline script_async_execution from_string<script_async_execution>(
const WinApiAdaptor &, const std::string &value) {
if (value == "parallel")
- return PARALLEL;
+ return script_async_execution::PARALLEL;
else if (value == "sequential")
- return SEQUENTIAL;
+ return script_async_execution::SEQUENTIAL;
throw std::runtime_error("invalid async mode");
}