- // It's not started yet. Do it in one simcall
- if (p_srcBuff != NULL) {
- simcall_comm_send(p_sender->getInferior(), p_mailbox->getInferior(), p_remains, p_rate,
- p_srcBuff, p_srcBuffSize,
- p_matchFunction, p_copyDataFunction,
- p_userData, timeout);
- } else { // Receiver
- simcall_comm_recv(p_receiver->getInferior(), p_mailbox->getInferior(), p_dstBuff, &p_dstBuffSize,
- p_matchFunction, p_copyDataFunction,
- p_userData, timeout, p_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 finished:
+ return this;
+
+ case inited: // It's not started yet. Do it in one simcall
+ if (srcBuff_ != nullptr) {
+ simcall_comm_send(sender_, mailbox_->getImpl(), remains_, rate_, srcBuff_, srcBuffSize_, matchFunction_,
+ copyDataFunction_, userData_, timeout);
+ } else { // Receiver
+ simcall_comm_recv(receiver_, mailbox_->getImpl(), dstBuff_, &dstBuffSize_, matchFunction_, copyDataFunction_,
+ userData_, timeout, rate_);
+ }
+ state_ = finished;
+ return this;
+
+ case started:
+ simcall_comm_wait(pimpl_, timeout);
+ state_ = finished;
+ return this;
+
+ default:
+ THROW_IMPOSSIBLE;