24 #include "eclipse_thread.h"
26 #include "blackboard_listener_thread.h"
27 #include "externals/blackboard.h"
28 #include "externals/eclipse_path.h"
29 #include "externals/eclipseclp_config.h"
30 #include "externals/fawkes_logger.h"
32 #include <core/exception.h>
33 #include <core/threading/mutex_locker.h>
34 #include <interfaces/TestInterface.h>
54 extern "C" int ec_external(dident,
int (*)(...), dident);
70 if (EclExternalBlackBoard::instance()) {
72 EclExternalBlackBoard::cleanup_instance();
83 char *eclipse_dir = NULL;
85 eclipse_dir = strdup(
config->
get_string(
"/eclipse-clp/eclipse_dir").c_str());
87 ec_set_option_ptr(EC_OPTION_ECLIPSEDIR, (
void *)eclipse_dir);
96 ec_set_option_ptr(EC_OPTION_DEFAULT_MODULE, (
void *)agent.c_str());
102 if (0 != ec_init()) {
108 m_initialized =
true;
115 for (
size_t i = 0; i < paths.size(); ++i) {
126 if (filepath_path.empty()) {
127 throw Exception(
"Failed to determine path to filepath module");
129 load_file(filepath_path.c_str());
130 char *filepath = ::strdup(
"filepath");
131 post_goal(term(EC_functor(
":", 2),
133 term(EC_functor(
"add_library_path", 1),
134 ::list(EC_word(SRCDIR
"/externals"),
135 ::list(EC_word(SRCDIR
"/utils"),
136 ::list(EC_word(SRCDIR
"/consoletool"),
137 ::list(EC_word(SRCDIR
"/interpreter"), nil())))))));
138 if (EC_succeed != EC_resume())
139 throw Exception(
"Failed to add " SRCDIR
"/externals to library path");
142 if (
config->
get_bool((
"/eclipse-clp/" + agent +
"/use_graph").c_str())) {
144 CONFDIR +
config->
get_string((
"/eclipse-clp/" + agent +
"/rel_graph_path").c_str());
147 post_goal(term(EC_functor(
"load_graph", 1), graph_path.c_str()));
148 if (EC_succeed != EC_resume()) {
149 throw Exception(
"Error loading graph config to agent");
155 if (agent_path.empty()) {
156 throw Exception(
"Failed to determine path to agent module");
158 load_file(agent_path.c_str());
161 if (EC_succeed != ec_external(ec_did(
"log", 2), p_log, ec_did(agent.c_str(), 0))) {
162 throw Exception(
"Registering external predicate log/2 failed");
170 if (EclExternalBlackBoard::instance())
178 ec_result = EC_resume(
"init", ec_yield_reason);
184 if (ec_result == EC_status::EC_yield) {
185 EC_word bb_updates(::nil());
186 if (EC_word(ec_yield_reason) == EC_atom(
"exogenous_update")) {
192 ec_result = EC_resume(bb_updates, ec_yield_reason);
194 if (ec_result == EC_status::EC_succeed)
210 if (!m_initialized) {
215 char *atom = strdup(event);
225 EclipseAgentThread::load_file(
const char *filename)
227 if (!m_initialized) {
231 char *ensure_loaded = strdup(
"ensure_loaded");
232 post_goal(term(EC_functor(ensure_loaded, 1), filename));
235 if (EC_succeed != ec_resume()) {
236 throw Exception(
"File %s could not be loaded", filename);
258 throw Exception(
"No instance of type EclipseThread instantiated");