Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enforce "Rule-of-Three/Five".
[simgrid.git] / examples / s4u / dht-kademlia / message.hpp
1 /* Copyright (c) 2012-2019. 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 _KADEMLIA_TASK_HPP_
8 #define _KADEMLIA_TASK_HPP_
9 #include "s4u-dht-kademlia.hpp"
10 #include "simgrid/s4u.hpp"
11
12 namespace kademlia {
13
14 class Message {
15 public:
16   unsigned int sender_id_             = 0;       // Id of the guy who sent the task
17   unsigned int destination_id_        = 0;       // Id we are trying to find, if needed.
18   Answer* answer_                     = nullptr; // Answer to the request made, if needed.
19   simgrid::s4u::MailboxPtr answer_to_ = nullptr; // mailbox to send the answer to (if not an answer).
20   char* issuer_host_name_             = nullptr; // used for logging
21
22   explicit Message(unsigned int sender_id, unsigned int destination_id, Answer* answer,
23                    simgrid::s4u::MailboxPtr mailbox, const char* hostname)
24       : sender_id_(sender_id)
25       , destination_id_(destination_id)
26       , answer_(answer)
27       , answer_to_(mailbox)
28       , issuer_host_name_(xbt_strdup(hostname))
29   {
30   }
31   explicit Message(unsigned int sender_id, unsigned int destination_id, simgrid::s4u::MailboxPtr mailbox,
32                    const char* hostname)
33       : Message(sender_id, destination_id, nullptr, mailbox, hostname)
34   {
35   }
36   Message(const Message&) = delete;
37   Message& operator=(const Message&) = delete;
38   ~Message()
39   {
40     if (issuer_host_name_)
41       xbt_free(issuer_host_name_);
42   }
43 };
44 }
45 #endif