Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rewrite the s4u_launching example
[simgrid.git] / include / simgrid / s4u / mailbox.hpp
1 /* Copyright (c) 2006-2015. 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 <string>
10
11 #include <xbt/base.h>
12
13 #include <simgrid/s4u/forward.hpp>
14 #include <simgrid/s4u/Actor.hpp>
15
16 namespace simgrid {
17 namespace s4u {
18
19 /** @brief Mailboxes
20  *
21  * Rendez-vous point for network communications, similar to URLs on which you could post and retrieve data.
22  * They are not network locations: you can post and retrieve on a given mailbox from anywhere on the network.
23  * You can access any mailbox without any latency. The network delay are only related to the location of the
24  * sender and receiver.
25  */
26 XBT_PUBLIC_CLASS Mailbox {
27   friend Comm;
28   friend simgrid::s4u::Engine;
29   friend simgrid::simix::Mailbox;
30
31   simgrid::simix::Mailbox *pimpl_;
32
33   Mailbox(smx_mailbox_t mbox): pimpl_(mbox) {}
34
35 public:
36   smx_mailbox_t getImpl() { return pimpl_; } // FIXME: make me protected
37
38   // We don't have to manage the lifetime of mailboxes:
39   friend void intrusive_ptr_add_ref(Mailbox*) {}
40   friend void intrusive_ptr_release(Mailbox*) {}
41
42   /** Get the name of that mailbox */
43   const char *getName();
44
45   /** Retrieve the mailbox associated to the given string */
46   static MailboxPtr byName(const char *name);
47
48   /** Returns whether the mailbox contains queued communications */
49   bool empty();
50
51   /** Returns the first element in the queue, or nullptr if none is there */
52   smx_activity_t front();
53
54   /** Declare that the specified process is a permanent receiver on that mailbox
55    *
56    * It means that the communications sent to this mailbox will start flowing to its host even before he does a recv().
57    * This models the real behavior of TCP and MPI communications, amongst other.
58    */
59   void setReceiver(ActorPtr process);
60
61   /** Return the process declared as permanent receiver, or nullptr if none **/
62   ActorPtr receiver();
63 };
64
65 }} // namespace simgrid::s4u
66
67 XBT_PUBLIC(sg_mbox_t) sg_mbox_by_name(const char*name);
68 XBT_PUBLIC(int) sg_mbox_is_empty(sg_mbox_t mbox);
69 XBT_PUBLIC(void)sg_mbox_setReceiver(sg_mbox_t mbox, smx_process_t process);
70
71 #endif /* SIMGRID_S4U_MAILBOX_HPP */