- // It's not started yet. Do it in one simcall
- if (srcBuff_ != nullptr) {
- simcall_comm_send(sender_, mailbox_->getInferior(), remains_, rate_,
- srcBuff_, srcBuffSize_,
- matchFunction_, copyDataFunction_,
- userData_, timeout);
- } else { // Receiver
- simcall_comm_recv(receiver_, mailbox_->getInferior(), dstBuff_, &dstBuffSize_,
- matchFunction_, copyDataFunction_,
- userData_, timeout, rate_);
+/** @brief Block the calling actor until the communication is finished, or until timeout
+ *
+ * On timeout, an exception is thrown.
+ *
+ * @param timeout the amount of seconds to wait for the comm termination.
+ * Negative values denote infinite wait times. 0 as a timeout returns immediately. */
+Activity* Comm::wait(double timeout)
+{
+ switch (state_) {
+ case State::finished:
+ return this;
+
+ case State::inited: // It's not started yet. Do it in one simcall
+ if (srcBuff_ != nullptr) {
+ simcall_comm_send(sender_, mailbox_->get_impl(), remains_, rate_, srcBuff_, srcBuffSize_, matchFunction_,
+ copyDataFunction_, user_data_, timeout);
+ } else { // Receiver
+ simcall_comm_recv(receiver_, mailbox_->get_impl(), dstBuff_, &dstBuffSize_, matchFunction_, copyDataFunction_,
+ user_data_, timeout, rate_);
+ }
+ state_ = State::finished;
+ return this;
+
+ case State::started:
+ simcall_comm_wait(pimpl_, timeout);
+ state_ = State::finished;
+ return this;
+
+ default:
+ THROW_IMPOSSIBLE;