22#include "clips_rm_trigger.h"
24#include <core/threading/mutex_locker.h>
26#include <bsoncxx/builder/basic/document.hpp>
30using namespace mongocxx;
44 this->assert_name = assert_name;
45 this->robot_memory = robot_memory;
47 this->logger = logger;
50ClipsRmTrigger::~ClipsRmTrigger()
64 this->trigger = trigger;
76 clips->assert_fact_f(
"( %s)", assert_name.c_str());
77 CLIPS::Template::pointer temp = clips->get_template(
"robmem-trigger");
81 CLIPS::Fact::pointer fact = CLIPS::Fact::create(**clips, temp);
82 fact->set_slot(
"name", assert_name.c_str());
83 CLIPS::Values rcvd_at(2, CLIPS::Value(CLIPS::TYPE_INTEGER));
84 rcvd_at[0] = tv.tv_sec;
85 rcvd_at[1] = tv.tv_usec;
86 fact->set_slot(
"rcvd-at", rcvd_at);
87 using namespace bsoncxx::builder;
88 basic::document *b =
new basic::document();
89 b->append(bsoncxx::builder::concatenate(update));
91 fact->set_slot(
"ptr", CLIPS::Value(ptr));
92 CLIPS::Fact::pointer new_fact = clips->assert_fact(fact);
95 logger->
log_warn(
"CLIPS-RobotMemory",
"Asserting robmem-trigger fact failed");
96 delete static_cast<basic::document *
>(ptr);
99 logger->
log_warn(
"CLIPS-RobotMemory",
"Did not get template, did you load robot-memory.clp?");
ClipsRmTrigger(std::string assert_name, RobotMemory *robot_memory, fawkes::LockPtr< CLIPS::Environment > &clips, fawkes::Logger *logger)
Constructor with references to objects of the plugin.
void callback(const bsoncxx::document::view &update)
Callback function for the trigger.
void set_trigger(EventTrigger *trigger)
Set the trigger object given by the robot memory.
Class holding all information about an EventTrigger.
Access to the robot memory based on mongodb.
void remove_trigger(EventTrigger *trigger)
Remove a previously registered trigger.
Mutex * objmutex_ptr() const
Get object mutex.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
Fawkes library namespace.