Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c2d3a59e17bfe5eb312c5261df09a405ed38d7b7
[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 "simgrid/s4u/async.hpp"
11 #include "simgrid/s4u/mailbox.hpp"
12
13 namespace simgrid {
14 namespace s4u {
15
16 class Mailbox;
17
18 /** @brief Communication async
19  *
20  * Represents all asynchronous communications, that you can test or wait onto.
21  */
22 class Comm : public Async {
23         Comm() : Async() {}
24 public:
25         virtual ~Comm();
26
27 public:
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);
36
37         void start() override;
38         void wait() override;
39         void wait(double timeout) override;
40
41 private:
42         double p_rate=-1;
43 public:
44         /** Sets the maximal communication rate (in byte/sec). Must be done before start */
45         void setRate(double rate);
46
47 private:
48         void *p_dstBuff = NULL;
49         size_t p_dstBuffSize = 0;
50         void *p_srcBuff = NULL;
51         size_t p_srcBuffSize = sizeof(void*);
52 public:
53         /** Specify the data to send */
54         void setSrcData(void * buff);
55         /** Specify the size of the data to send */
56         void setSrcDataSize(size_t size);
57         /** Specify the data to send and its size */
58         void setSrcData(void * buff, size_t size);
59
60         /** Specify where to receive the data */
61         void setDstData(void ** buff);
62         /** Specify the buffer in which the data should be received */
63         void setDstData(void ** buff, size_t size);
64         /** Retrieve the size of the received data */
65         size_t getDstDataSize();
66
67
68 private: /* FIXME: expose these elements in the API */
69         int p_detached = 0;
70     int (*p_matchFunction)(void *, void *, smx_synchro_t) = NULL;
71     void (*p_cleanFunction)(void *) = NULL;
72     void (*p_copyDataFunction)(smx_synchro_t, void*, size_t) = NULL;
73
74
75
76
77 private:
78         Actor *p_sender = NULL;
79         Mailbox *p_mailbox = NULL;
80 };
81
82 }} // namespace simgrid::s4u
83
84 #endif /* SIMGRID_S4U_COMM_HPP */