22 #include "clips-rest-api.h"
24 #include <clips/clips.h>
25 #include <core/threading/mutex_locker.h>
26 #include <webview/rest_api_manager.h>
51 std::bind(&ClipsRestApi::cb_get_facts,
53 std::placeholders::_1));
55 WebRequest::METHOD_GET,
"/", std::bind(&ClipsRestApi::cb_list_environments,
this));
128 CLIPS::Fact::pointer & fact,
135 CLIPS::Template::pointer fact_template = fact->get_template();
145 OpenStringDestination(clips->cobj(), (
char *)
"ProcPPForm", tmp, 16383);
146 PrintFact(clips->cobj(), (
char *)
"ProcPPForm", (
struct fact *)fact->cobj(), FALSE, FALSE);
147 CloseStringDestination(clips->cobj(), (
char *)
"ProcPPForm");
150 std::vector<std::string> slots = fact->slot_names();
151 for (
const auto &s : slots) {
152 CLIPS::Values fval = fact->slot_value(s);
156 : (fval.size() > 1));
157 for (
const auto &v : fval) {
159 case CLIPS::TYPE_FLOAT: sval.
addto_values(std::to_string(v.as_float()));
break;
160 case CLIPS::TYPE_INTEGER: sval.
addto_values(std::to_string(v.as_integer()));
break;
161 case CLIPS::TYPE_SYMBOL:
162 case CLIPS::TYPE_STRING:
163 case CLIPS::TYPE_INSTANCE_NAME: sval.
addto_values(v.as_string());
break;
177 bool formatted = (params.
query_arg(
"formatted") ==
"true");
182 std::map<std::string, LockPtr<CLIPS::Environment>> envs =
clips_env_mgr->environments();
183 if (envs.find(params.
path_arg(
"env")) == envs.end()) {
185 "Environment '%s' is unknown",
189 auto clips = envs[params.
path_arg(
"env")];
192 CLIPS::Fact::pointer fact = clips->get_facts();
194 CLIPS::Template::pointer tmpl = fact->get_template();
195 rv.
push_back(std::move(gen_fact(clips, fact, formatted)));
203 ClipsRestApi::cb_list_environments()
208 std::map<std::string, LockPtr<CLIPS::Environment>> envs =
clips_env_mgr->environments();
210 for (
const auto &e : envs) {
212 env.set_kind(
"Environment");
214 env.set_name(e.first);