Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c0eaf9a5e323c153db52e5fde07c00e14cbefa34
[simgrid.git] / include / simgrid / s4u / Mess.hpp
1 /* Copyright (c) 2023. 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_MESS_HPP
7 #define SIMGRID_S4U_MESS_HPP
8
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Activity.hpp>
11
12 #include <string>
13 #include <vector>
14
15 namespace simgrid::s4u {
16
17 class XBT_PUBLIC Mess : public Activity_T<Mess> {
18 #ifndef DOXYGEN
19   friend MessageQueue; // Factory of messages
20   friend kernel::activity::MessImpl;
21 #endif
22   MessageQueue* queue_  = nullptr;
23   void* payload_        = nullptr;
24   size_t dst_buff_size_ = 0;
25   void* dst_buff_       = nullptr;
26   kernel::activity::ActivityImplPtr pimpl_;
27
28   Mess() = default;
29   Mess* do_start() override;
30
31   static xbt::signal<void(Mess const&)> on_send;
32   xbt::signal<void(Mess const&)> on_this_send;
33   static xbt::signal<void(Mess const&)> on_recv;
34   xbt::signal<void(Mess const&)> on_this_recv;
35
36   /* These ensure that the on_completion signals are really thrown */
37   void fire_on_completion_for_real() const { Activity_T<Mess>::fire_on_completion(); }
38   void fire_on_this_completion_for_real() const { Activity_T<Mess>::fire_on_this_completion(); }
39
40 public:
41 #ifndef DOXYGEN
42   Mess(Mess const&) = delete;
43   Mess& operator=(Mess const&) = delete;
44 #endif
45
46   MessPtr set_queue(MessageQueue* queue);
47   MessageQueue* get_queue() const { return queue_; }
48
49   /** Retrieve the payload associated to the communication. You can only do that once the comm is (gracefully)
50    * terminated */
51   void* get_payload() const { return payload_; }
52   MessPtr set_payload(void* data);
53   MessPtr set_dst_data(void** buff, size_t size);
54   Actor* get_sender() const;
55   Actor* get_receiver() const;
56
57   bool is_assigned() const override { return true; };
58
59   Mess* wait_for(double timeout) override;
60
61   kernel::actor::ActorImpl* sender_   = nullptr;
62   kernel::actor::ActorImpl* receiver_ = nullptr;
63 };
64 } // namespace simgrid::s4u
65
66 #endif /* SIMGRID_S4U_MESS_HPP */