12 : id_ (id), context_ (context)
26 Knowledge::Update & data)
32 long long value = data.value;
36 DLINFO "SpliceDataReaderListener::handle_assignment:" \
37 " waiting to process assignment\n"));
53 data.quality, data.clock,
false);
61 DLINFO "SpliceDataReaderListener::handle_assignment:" \
62 " received data[%s]=%q from %s.\n",
63 key.c_str (), value, data.originator.val ()));
69 DLINFO "SpliceDataReaderListener::handle_assignment:" \
70 " discarded data[%s]=%q from %s as the value was already set.\n",
71 key.c_str (), value, data.originator.val ()));
73 else if (result == -1)
76 DLINFO "SpliceDataReaderListener::handle_assignment:" \
77 " discarded data due to null key.\n"));
79 else if (result == -2)
82 DLINFO "SpliceDataReaderListener::handle_assignment:" \
83 " discarded data[%s]=%q due to lower quality (%u vs %u).\n",
84 key.c_str (), value, cur_quality, data.quality));
86 else if (result == -3)
89 DLINFO "SpliceDataReaderListener::handle_assignment:" \
90 " discarded data[%s]=%q due to older timestamp (%Q vs %Q).\n",
91 key.c_str (), value, cur_clock, data.clock));
97 Knowledge::Update & data)
104 std::stringstream stream (data.key.val ());
107 DLINFO "SpliceDataReaderListener::multiassignment:" \
108 " waiting to process multiassignment\n"));
113 DLINFO "SpliceDataReaderListener::multiassignment:" \
114 " processing multiassignment (%s).\n",
117 while (!stream.eof ())
119 stream >> key >> symbol >> value >> symbol;
130 data.quality, data.clock,
false);
136 DLINFO "SpliceDataReaderListener::handle_multiassignment:" \
137 " received data[%s]=%q from %s.\n",
138 key.c_str (), value, data.originator.val ()));
141 else if (result == 0)
144 DLINFO "SpliceDataReaderListener::handle_multiassignment:" \
145 " discarded data[%s]=%q from %s as the value was already set.\n",
146 key.c_str (), value, data.originator.val ()));
148 else if (result == -1)
151 DLINFO "SpliceDataReaderListener::handle_multiassignment:" \
152 " discarded data due to null key.\n"));
154 else if (result == -2)
157 DLINFO "SpliceDataReaderListener::handle_multiassignment:" \
158 " discarded data[%s]=%q due to lower quality (%u vs %u).\n",
159 key.c_str (), value, cur_quality, data.quality));
161 else if (result == -3)
164 DLINFO "SpliceDataReaderListener::handle_multiassignment:" \
165 " discarded data[%s]=%q due to older timestamp (%Q vs %Q).\n",
166 key.c_str (), value, cur_clock, data.clock));
176 DDS::DataReader_ptr,
const DDS::SampleLostStatus &status)
182 DDS::DataReader_ptr,
const DDS::SampleRejectedStatus &status)
188 DDS::DataReader_ptr,
const DDS::RequestedIncompatibleQosStatus &status)
194 DDS::DataReader_ptr reader,
const DDS::RequestedDeadlineMissedStatus & status)
200 DDS::DataReader_ptr reader,
const DDS::LivelinessChangedStatus & status)
206 DDS::DataReader_ptr reader,
const DDS::SubscriptionMatchedStatus & status)
213 DDS::DataReader_ptr reader)
215 DDS::SampleInfoSeq_var infoList =
new DDS::SampleInfoSeq;
216 DDS::ReturnCode_t dds_result;
218 DDS::Boolean result =
false;
219 Knowledge::UpdateSeq_var update_data_list_ =
new Knowledge::UpdateSeq;
221 Knowledge::UpdateDataReader_ptr update_reader =
222 dynamic_cast<Knowledge::UpdateDataReader_ptr
> (reader);
224 if (update_reader == 0)
227 "\nSpliceDataReaderListener::on_data_available:" \
228 " Unable to create specialized reader. Leaving callback...\n"));
232 dds_result = update_reader->take (update_data_list_, infoList, 1,
233 DDS::ANY_SAMPLE_STATE, DDS::ANY_VIEW_STATE, DDS::ANY_INSTANCE_STATE);
235 amount = update_data_list_->length ();
242 for (
int i = 0; i < amount; ++i)
247 if (!update_data_list_[i].originator.val () ||
248 id_ == update_data_list_[i].originator.val ())
253 DLINFO "\nSpliceDataReaderListener::on_data_available:" \
254 " discarding null originator event.\n"));
262 DLINFO "\nSpliceDataReaderListener::on_data_available:" \
263 " processing %s=%q from %s with time %Q and quality %u.\n",
264 update_data_list_[i].key.val (), update_data_list_[i].value,
265 update_data_list_[i].originator.val (),
266 update_data_list_[i].clock, update_data_list_[i].quality));
273 DLINFO "\nSpliceDataReaderListener::on_data_available:" \
274 " processing multassignment from %s with time %Q and quality %u.\n",
275 update_data_list_[i].originator.val (),
276 update_data_list_[i].clock, update_data_list_[i].quality));
284 dds_result = update_reader->return_loan (update_data_list_, infoList);
uint32_t get_quality(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically gets quality of a variable.
void lock(void) const
Locks the mutex on this context.
This class stores variables and their values for use by any entity needing state information in a thr...
#define MADARA_ERROR(L, X)
knowledge::ThreadSafeContext & context_
#define MADARA_LOG_MAJOR_DEBUG_INFO
Used to display important configuration information that impacts major MADARA events.
#define MADARA_LOG_MAJOR_EVENT
Used to indicate that a ``significant'' MADARA event has completed.
void on_requested_incompatible_qos(DDS::DataReader_ptr, const DDS::RequestedIncompatibleQosStatus &status)
DDS callback for incompatible qos.
void handle_assignment(Knowledge::Update &data)
void unlock(void) const
Unlocks the mutex on this context.
int set_if_unequal(const std::string &key, madara::knowledge::KnowledgeRecord::Integer value, uint32_t quality, uint64_t clock, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets if the variable value will be different.
#define MADARA_DEBUG(L, X)
void on_sample_lost(DDS::DataReader_ptr, const DDS::SampleLostStatus &status)
DDS callback for sample lost.
void set_changed(void)
Force a change to be registered, waking up anyone waiting on entry.
void handle_multiassignment(Knowledge::Update &data)
void on_requested_deadline_missed(DDS::DataReader_ptr, const DDS::RequestedDeadlineMissedStatus &status)
DDS callback for deadline being missed.
void on_data_available(DDS::DataReader_ptr reader)
void on_subscription_matched(DDS::DataReader_ptr reader, const DDS::SubscriptionMatchedStatus &status)
DDS callback for subscription matched.
uint64_t get_clock(void) const
Atomically gets the Lamport clock.
SpliceDataReaderListener(const std::string &id, knowledge::ThreadSafeContext &context)
Container for DDS-related callbacks (deprecated and unused)
void on_liveliness_changed(DDS::DataReader_ptr, const DDS::LivelinessChangedStatus &status)
DDS callback for sample rejected.
#define MADARA_LOG_MINOR_EVENT
Used to inficate a ``minor'' MADARA event has completed.
~SpliceDataReaderListener()
#define MADARA_LOG_EVENT_TRACE
Used to trace significant actions within major/minor events.
void on_sample_rejected(DDS::DataReader_ptr, const DDS::SampleRejectedStatus &status)
DDS callback for sample rejected.
#define MADARA_LOG_TERMINAL_ERROR
Used for MADARA errors at the point the error exits the process in question, or when a decision is ma...