Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f8cfd8f0cc162b5367df1e746b4dd09a9a7181c0
[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_srcBuff = NULL;
49         size_t p_srcBuffSize = sizeof(void*);
50 public:
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);
57
58 private: /* FIXME: expose these elements in the API */
59         int p_detached = 0;
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;
63
64
65
66
67 private:
68         Actor *p_sender = NULL;
69         Mailbox *p_mailbox = NULL;
70 };
71
72 }} // namespace simgrid::s4u
73
74 #endif /* SIMGRID_S4U_COMM_HPP */