Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Remove s4u::Task, use xbt::Task instead
[simgrid.git] / include / simgrid / s4u / comm.hpp
1 /* Copyright (c) 2006-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef SIMGRID_S4U_COMM_HPP
8 #define SIMGRID_S4U_COMM_HPP
9
10 #include <xbt/base.h>
11 #include <simgrid/s4u/Activity.hpp>
12 #include <simgrid/s4u/forward.hpp>
13 #include <simgrid/s4u/mailbox.hpp>
14
15 namespace simgrid {
16 namespace s4u {
17
18 /** @brief Communication async
19  *
20  * Represents all asynchronous communications, that you can test or wait onto.
21  */
22 XBT_PUBLIC_CLASS Comm : public Activity {
23   Comm() : Activity() {}
24 public:
25   ~Comm() override;
26
27 public:
28   /** Creates (but don't start) an async send to the mailbox @p dest */
29   static Comm &send_init(Mailbox &dest);
30   /** Creates and start an async send to the mailbox @p dest */
31   static Comm &send_async(Mailbox &dest, void *data, int simulatedByteAmount);
32     /** Creates (but don't start) an async recv onto the mailbox @p from */
33   static Comm &recv_init(Mailbox &from);
34   /** Creates and start an async recv to the mailbox @p from */
35   static Comm &recv_async(Mailbox &from, void **data);
36
37   void start() override;
38   void wait() override;
39   void wait(double timeout) override;
40
41   /** Sets the maximal communication rate (in byte/sec). Must be done before start */
42   void setRate(double rate);
43
44   /** Specify the data to send */
45   void setSrcData(void * buff);
46   /** Specify the size of the data to send */
47   void setSrcDataSize(size_t size);
48   /** Specify the data to send and its size */
49   void setSrcData(void * buff, size_t size);
50
51   /** Specify where to receive the data */
52   void setDstData(void ** buff);
53   /** Specify the buffer in which the data should be received */
54   void setDstData(void ** buff, size_t size);
55   /** Retrieve the size of the received data */
56   size_t getDstDataSize();
57
58
59 private:
60   double rate_ = -1;
61   void *dstBuff_ = nullptr;
62   size_t dstBuffSize_ = 0;
63   void *srcBuff_ = nullptr;
64   size_t srcBuffSize_ = sizeof(void*);
65
66   /* FIXME: expose these elements in the API */
67   int detached_ = 0;
68   int (*matchFunction_)(void *, void *, smx_synchro_t) = nullptr;
69   void (*cleanFunction_)(void *) = nullptr;
70   void (*copyDataFunction_)(smx_synchro_t, void*, size_t) = nullptr;
71
72   smx_process_t sender_ = nullptr;
73   smx_process_t receiver_ = nullptr;
74   Mailbox *mailbox_ = nullptr;
75 };
76
77 }} // namespace simgrid::s4u
78
79 #endif /* SIMGRID_S4U_COMM_HPP */