Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
various tiny changes
[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
12 #include <simgrid/s4u/Activity.hpp>
13 #include <simgrid/s4u/forward.hpp>
14 #include <simgrid/s4u/mailbox.hpp>
15
16 namespace simgrid {
17 namespace s4u {
18
19 /** @brief Communication async
20  *
21  * Represents all asynchronous communications, that you can test or wait onto.
22  */
23 XBT_PUBLIC_CLASS Comm : public Activity {
24   Comm() : Activity() {}
25 public:
26   ~Comm() override;
27
28 public:
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);
37
38   void start() override;
39   void wait() override;
40   void wait(double timeout) override;
41
42   /** Sets the maximal communication rate (in byte/sec). Must be done before start */
43   void setRate(double rate);
44
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);
51
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();
58
59   bool test();
60
61
62 private:
63   double rate_ = -1;
64   void *dstBuff_ = nullptr;
65   size_t dstBuffSize_ = 0;
66   void *srcBuff_ = nullptr;
67   size_t srcBuffSize_ = sizeof(void*);
68
69   /* FIXME: expose these elements in the API */
70   int detached_ = 0;
71   int (*matchFunction_)(void *, void *, smx_synchro_t) = nullptr;
72   void (*cleanFunction_)(void *) = nullptr;
73   void (*copyDataFunction_)(smx_synchro_t, void*, size_t) = nullptr;
74
75   smx_process_t sender_ = nullptr;
76   smx_process_t receiver_ = nullptr;
77   Mailbox *mailbox_ = nullptr;
78 };
79
80 }} // namespace simgrid::s4u
81
82 #endif /* SIMGRID_S4U_COMM_HPP */