Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
docs: try to add a doxygene xample, but breathe does not handle this yet
[simgrid.git] / include / simgrid / s4u / Mailbox.hpp
1 /* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_S4U_MAILBOX_HPP
7 #define SIMGRID_S4U_MAILBOX_HPP
8
9 #include <xbt/string.hpp>
10 #include <simgrid/s4u/Actor.hpp>
11
12 #include <string>
13
14 namespace simgrid {
15 namespace s4u {
16
17 /** @brief Mailboxes: Network rendez-vous points. */
18 class XBT_PUBLIC Mailbox {
19   friend simgrid::s4u::Comm;
20   friend simgrid::kernel::activity::MailboxImpl;
21
22   simgrid::kernel::activity::MailboxImpl* pimpl_;
23
24   explicit Mailbox(kernel::activity::MailboxImpl * mbox) : pimpl_(mbox) {}
25
26   /** private function to manage the mailboxes' lifetime (see @ref s4u_raii) */
27   friend void intrusive_ptr_add_ref(Mailbox*) {}
28   /** private function to manage the mailboxes' lifetime (see @ref s4u_raii) */
29   friend void intrusive_ptr_release(Mailbox*) {}
30 public:
31   /** private function, do not use. FIXME: make me protected */
32   kernel::activity::MailboxImpl* get_impl() { return pimpl_; }
33
34   /** @brief Retrieves the name of that mailbox as a C++ string */
35   const simgrid::xbt::string& get_name() const;
36   /** @brief Retrieves the name of that mailbox as a C string */
37   const char* get_cname() const;
38
39   /** Retrieve the mailbox associated to the given name */
40   static MailboxPtr by_name(std::string name);
41
42   /** Returns whether the mailbox contains queued communications */
43   bool empty();
44
45   /** Check if there is a communication going on in a mailbox. */
46   bool listen();
47
48   /** Check if there is a communication ready to be consumed from a mailbox. */
49   bool ready();
50
51   /** Gets the first element in the queue (without dequeuing it), or nullptr if none is there */
52   smx_activity_t front();
53
54   /** Declare that the specified actor is a permanent receiver on that mailbox
55    *
56    * It means that the communications sent to this mailbox will start flowing to
57    * its host even before he does a recv(). This models the real behavior of TCP
58    * and MPI communications, amongst other. It will improve the accuracy of
59    * predictions, in particular if your application exhibits swarms of small messages.
60    *
61    * SimGrid does not enforces any kind of ownership over the mailbox. Even if a receiver
62    * was declared, any other actors can still get() data from the mailbox. The timings
63    * will then probably be off tracks, so you should strive on your side to not get data
64    * from someone else's mailbox.
65    */
66   void set_receiver(ActorPtr actor);
67
68   /** Return the actor declared as permanent receiver, or nullptr if none **/
69   ActorPtr get_receiver();
70
71   /** Creates (but don't start) a data emission to that mailbox */
72   CommPtr put_init();
73   /** Creates (but don't start) a data emission to that mailbox */
74   CommPtr put_init(void* data, uint64_t simulated_size_in_bytes);
75   /** Creates and start a data emission to that mailbox */
76   CommPtr put_async(void* data, uint64_t simulated_size_in_bytes);
77
78   /** Blocking data emission */
79   void put(void* payload, uint64_t simulated_size_in_bytes);
80   /** Blocking data emission with timeout */
81   void put(void* payload, uint64_t simulated_size_in_bytes, double timeout);
82
83   /** Creates (but don't start) a data reception onto that mailbox */
84   CommPtr get_init();
85   /** Creates and start an async data reception to that mailbox */
86   CommPtr get_async(void** data);
87
88   /** Blocking data reception */
89   void* get(); // FIXME: make a typed template version
90   /** Blocking data reception with timeout */
91   void* get(double timeout);
92
93   // Deprecated functions
94   /** @deprecated Mailbox::set_receiver() */
95   XBT_ATTRIB_DEPRECATED_v323("Please use Mailbox::set_receiver()") void setReceiver(ActorPtr actor)
96   {
97     set_receiver(actor);
98   }
99   /** @deprecated Mailbox::get_receiver() */
100   XBT_ATTRIB_DEPRECATED_v323("Please use Mailbox::get_receiver()") ActorPtr getReceiver() { return get_receiver(); }
101   /** @deprecated Mailbox::get_name() */
102   XBT_ATTRIB_DEPRECATED_v323("Please use Mailbox::get_name()") const simgrid::xbt::string& getName() const
103   {
104     return get_name();
105   }
106   /** @deprecated Mailbox::get_cname() */
107   XBT_ATTRIB_DEPRECATED_v323("Please use Mailbox::get_cname()") const char* getCname() const { return get_cname(); }
108   /** @deprecated Mailbox::get_impl() */
109   XBT_ATTRIB_DEPRECATED_v323("Please use Mailbox::get_impl()") kernel::activity::MailboxImpl* getImpl()
110   {
111     return get_impl();
112   }
113   /** @deprecated Mailbox::by_name() */
114   XBT_ATTRIB_DEPRECATED_v323("Please use Mailbox::by_name()") static MailboxPtr byName(const char* name)
115   {
116     return by_name(name);
117   }
118   /** @deprecated Mailbox::by_name() */
119   XBT_ATTRIB_DEPRECATED_v323("Please use Mailbox::by_name()") static MailboxPtr byName(std::string name)
120   {
121     return by_name(name);
122   }
123 };
124
125 }} // namespace simgrid::s4u
126
127 #endif /* SIMGRID_S4U_MAILBOX_HPP */