diff --git a/include/villas/hook.hpp b/include/villas/hook.hpp index 3a91eaf96..e8a88a72b 100644 --- a/include/villas/hook.hpp +++ b/include/villas/hook.hpp @@ -64,8 +64,8 @@ protected: enum State state; int flags; - int priority; /**< A priority to change the order of execution within one type of hook. */ - int enabled; /**< Is this hook active? */ + unsigned priority; /**< A priority to change the order of execution within one type of hook. */ + bool enabled; /**< Is this hook active? */ struct vpath *path; struct vnode *node; @@ -141,7 +141,7 @@ public: return Reason::OK; }; - int getPriority() const + unsigned getPriority() const { return priority; } @@ -199,7 +199,7 @@ public: virtual Hook * make(struct vpath *p, struct vnode *n) = 0; virtual int getFlags() const = 0; - virtual int getPriority() const = 0; + virtual unsigned getPriority() const = 0; virtual std::string @@ -207,7 +207,7 @@ public: { return "hook"; } }; -template +template class HookPlugin : public HookFactory { public: @@ -234,7 +234,7 @@ public: getFlags() const { return flags; } - virtual int + virtual unsigned getPriority() const { return prio; } }; diff --git a/lib/hook.cpp b/lib/hook.cpp index 86a82119d..16f02afc7 100644 --- a/lib/hook.cpp +++ b/lib/hook.cpp @@ -86,13 +86,22 @@ void Hook::parse(json_t *json) assert(state != State::STARTED); + int prio; + int en; + ret = json_unpack_ex(json, &err, 0, "{ s?: i, s?: b }", - "priority", &priority, - "enabled", &enabled + "priority", &prio, + "enabled", &en ); if (ret) throw ConfigError(json, err, "node-config-hook"); + if (prio < 0) + throw ConfigError(json, "node-config-hook", "Priority must be equal or larger than zero"); + + priority = prio; + enabled = en; + config = json; state = State::PARSED;