24 #include "eclipse_thread.h" 25 #include "externals/blackboard.h" 26 #include "externals/fawkes_logger.h" 27 #include "externals/eclipse_path.h" 28 #include "externals/eclipseclp_config.h" 30 #include <interfaces/TestInterface.h> 31 #include <core/threading/mutex_locker.h> 32 #include <core/exception.h> 33 #include <eclipseclass.h> 53 extern "C" int ec_external( dident,
int (*) (...), dident );
60 m_initialized( false )
80 char* eclipse_dir = NULL;
83 eclipse_dir = strdup(
config->
get_string(
"/eclipse-clp/eclipse_dir" ).c_str() );
85 ec_set_option_ptr( EC_OPTION_ECLIPSEDIR, (
void*) eclipse_dir );
96 ec_set_option_ptr(EC_OPTION_DEFAULT_MODULE, (
void*) agent.c_str());
103 if ( 0 != ec_init() )
109 m_initialized =
true;
116 for (
size_t i = 0; i < paths.size(); ++i) {
127 if (filepath_path.empty()) {
128 throw Exception(
"Failed to determine path to filepath module");
130 load_file(filepath_path.c_str());
134 if (agent_path.empty()) {
135 throw Exception(
"Failed to determine path to agent module");
137 load_file( agent_path.c_str() );
140 if (
config->
get_bool( (
"/eclipse-clp/"+agent+
"/use_graph").c_str() )){
141 graph_path = CONFDIR +
config->
get_string( (
"/eclipse-clp/"+agent+
"/rel_graph_path").c_str());
144 post_goal( term(EC_functor(
"load_graph",1), graph_path.c_str()) );
145 if ( EC_succeed != EC_resume() )
146 {
throw Exception(
"Error loading graph config to agent" ); }
150 if ( EC_succeed != ec_external( ec_did(
"log", 2 ), p_log, ec_did( agent.c_str(), 0 ) ) )
151 {
throw Exception(
"Registering external predicate log/2 failed" ); }
167 int res = EC_resume();
171 if ( EC_succeed != res) {
180 bool EclipseAgentThread::running()
212 if ( !m_initialized ) {
return; }
215 char* atom = strdup( event );
226 EclipseAgentThread::load_file(
const char* filename )
228 if ( !m_initialized ) {
return false; }
230 char* ensure_loaded = strdup(
"ensure_loaded" );
231 post_goal( term( EC_functor( ensure_loaded, 1 ), filename ) );
232 free( ensure_loaded );
234 if ( EC_succeed != ec_resume() )
235 {
throw Exception(
"File %s could not be loaded", filename ); }
257 {
throw Exception(
"No instance of type EclipseThread instantiated" ); }
EclipseAgentThread()
Constructor.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
void apply_regexes()
Apply the regexes to all paths.
virtual void finalize()
Finalize the thread.
void add_regex(boost::regex re, std::string str)
Add a regex.
static EclipsePath * instance()
Get the EclipsePath instance.
fawkes::Logger * get_logger()
Get the logger.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
virtual ~EclipseAgentThread()
Destructor.
Logger * logger
This is the Logger member used to access the logger.
static void cleanup_instance()
Delete the current EclExternalBlackBoard instance and set it to NULL.
static void create_initial_object(BlackBoard *bb)
Creates the initial EclExternalBlackBoard object.
void post_event(const char *)
Post an event to the ECLiPSe context.
void print_all_paths()
Debug method to print all path to the command line.
static EclipseAgentThread * instance()
Get the EclipseAgentThread instance.
Base class for exceptions in Fawkes.
Wrapper class for using the blackboard in the implementation of the external predicates.
const char * name() const
Get name of thread.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
This thread creates an ECLiPSe context in which the ECLiPSe interpreter and the program are loaded...
virtual void init()
Initialize the thread.
static void create_initial_object(Configuration *config)
Creates the initial EclExternalConfig object.
virtual std::vector< std::string > get_strings(const char *path)=0
Get list of values from configuration which is of type string.
virtual void once()
Execute an action exactly once.
static void create_initial_object()
Create the initial EclipsePath object.
std::string locate_file(std::string filename)
Locate a file by filename.
Mutex mutual exclusion lock.
Configuration * config
This is the Configuration member used to access the configuration.
void add_path(std::string path)
Add a new path.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.