1 /* Copyright (c) 2006-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SIMGRID_S4U_COMM_HPP
8 #define SIMGRID_S4U_COMM_HPP
10 #include "simgrid/s4u/async.hpp"
11 #include "simgrid/s4u/mailbox.hpp"
18 /** @brief Communication async
20 * Represents all asynchronous communications, that you can test or wait onto.
22 class Comm : public Async {
28 /** Creates (but don't start) an async send to the mailbox #dest */
29 static Comm &send_init(Actor *sender, Mailbox &dest);
30 /** Creates and start an async send to the mailbox #dest */
31 static Comm &send_async(s4u::Actor *sender, Mailbox &dest, void *data, int simulatedByteAmount);
32 /** Creates (but don't start) an async recv onto the mailbox #from */
33 //static Comm &recv_init(Mailbox &from);
34 /** Creates and start an async recv to the mailbox #from */
35 //static Comm &recv_async(Mailbox &from, void *data);
37 void start() override;
39 void wait(double timeout) override;
44 /** Sets the maximal communication rate (in byte/sec). Must be done before start */
45 void setRate(double rate);
48 void *p_srcBuff = NULL;
49 size_t p_srcBuffSize = sizeof(void*);
51 /** Specify the data to send */
52 void setSrcData(void * buff);
53 /** Specify the size of the data to send */
54 void setSrcDataSize(size_t size);
55 /** Specify the data to send and its size */
56 void setSrcData(void * buff, size_t size);
58 private: /* FIXME: expose these elements in the API */
60 int (*p_matchFunction)(void *, void *, smx_synchro_t) = NULL;
61 void (*p_cleanFunction)(void *) = NULL;
62 void (*p_copyDataFunction)(smx_synchro_t, void*, size_t) = NULL;
68 Actor *p_sender = NULL;
69 Mailbox *p_mailbox = NULL;
72 }} // namespace simgrid::s4u
74 #endif /* SIMGRID_S4U_COMM_HPP */