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
12 #include <simgrid/s4u/Activity.hpp>
13 #include <simgrid/s4u/forward.hpp>
14 #include <simgrid/s4u/mailbox.hpp>
19 /** @brief Communication async
21 * Represents all asynchronous communications, that you can test or wait onto.
23 XBT_PUBLIC_CLASS Comm : public Activity {
24 Comm() : Activity() {}
29 /** Creates (but don't start) an async send to the mailbox @p dest */
30 static Comm &send_init(Mailbox &dest);
31 /** Creates and start an async send to the mailbox @p dest */
32 static Comm &send_async(Mailbox &dest, void *data, int simulatedByteAmount);
33 /** Creates (but don't start) an async recv onto the mailbox @p from */
34 static Comm &recv_init(Mailbox &from);
35 /** Creates and start an async recv to the mailbox @p from */
36 static Comm &recv_async(Mailbox &from, void **data);
38 void start() override;
40 void wait(double timeout) override;
42 /** Sets the maximal communication rate (in byte/sec). Must be done before start */
43 void setRate(double rate);
45 /** Specify the data to send */
46 void setSrcData(void * buff);
47 /** Specify the size of the data to send */
48 void setSrcDataSize(size_t size);
49 /** Specify the data to send and its size */
50 void setSrcData(void * buff, size_t size);
52 /** Specify where to receive the data */
53 void setDstData(void ** buff);
54 /** Specify the buffer in which the data should be received */
55 void setDstData(void ** buff, size_t size);
56 /** Retrieve the size of the received data */
57 size_t getDstDataSize();
62 void *dstBuff_ = nullptr;
63 size_t dstBuffSize_ = 0;
64 void *srcBuff_ = nullptr;
65 size_t srcBuffSize_ = sizeof(void*);
67 /* FIXME: expose these elements in the API */
69 int (*matchFunction_)(void *, void *, smx_synchro_t) = nullptr;
70 void (*cleanFunction_)(void *) = nullptr;
71 void (*copyDataFunction_)(smx_synchro_t, void*, size_t) = nullptr;
73 smx_process_t sender_ = nullptr;
74 smx_process_t receiver_ = nullptr;
75 Mailbox *mailbox_ = nullptr;
78 }} // namespace simgrid::s4u
80 #endif /* SIMGRID_S4U_COMM_HPP */