Commit e1b7d7de authored by Patrick Chen's avatar Patrick Chen

support condition in service

parent 27aa4d58
...@@ -32,6 +32,7 @@ namespace xs { namespace test ...@@ -32,6 +32,7 @@ namespace xs { namespace test
public: public:
std::string name_; std::string name_;
boost::optional<nlohmann::json> condition_;
boost::optional<nlohmann::json> response_; boost::optional<nlohmann::json> response_;
}; };
} } } }
......
...@@ -14,6 +14,10 @@ namespace xs { namespace test ...@@ -14,6 +14,10 @@ namespace xs { namespace test
{ {
if (object.count("command")) { if (object.count("command")) {
response_ = object["response"]; response_ = object["response"];
if (object.count("condition")) {
condition_ = object["condition"];
}
} }
} }
...@@ -23,9 +27,18 @@ namespace xs { namespace test ...@@ -23,9 +27,18 @@ namespace xs { namespace test
return false; return false;
} }
static const auto isStringOrObject = [](const nlohmann::json& object) {
return object.is_string() || object.is_object();
};
if (object.count("command")) { if (object.count("command")) {
if (object.count("condition")) {
if (!isStringOrObject(object["condition"])) {
return false;
}
}
return object["command"].is_string() return object["command"].is_string()
&& (object["response"].is_string() || object["response"].is_object()) && isStringOrObject(object["response"])
; ;
} else if (object.count("event")) { } else if (object.count("event")) {
return object["event"].is_string(); return object["event"].is_string();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment