1 /* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef PAX_MSG_H
24 #define PAX_MSG_H
25 
26 #include "xcom/site_struct.h"
27 #include "xdr_gen/xcom_vp.h"
28 
29 #ifdef PAX_MSG_SANITY_CHECK
30 #define PAX_MSG_SANITY_CHECK(p)                      \
31   {                                                  \
32     if ((p) && !(p)->a && (p)->msg_type == normal) { \
33       assert((p)->op != client_msg);                 \
34       assert((p)->op != ack_prepare_op);             \
35       assert((p)->op != accept_op);                  \
36       assert((p)->op != learn_op);                   \
37     }                                                \
38   }
39 #else
40 #define PAX_MSG_SANITY_CHECK(p)
41 #endif
42 
43 #define CLONE_PAX_MSG(target, msg) \
44   replace_pax_msg((&target), clone_pax_msg_no_app(msg))
45 
46 int eq_ballot(ballot x, ballot y);
47 int gt_ballot(ballot x, ballot y);
48 int ref_msg(pax_msg *p);
49 int unref_msg(pax_msg **pp);
50 pax_msg *clone_pax_msg_no_app(pax_msg *msg);
51 pax_msg *clone_pax_msg(pax_msg *msg);
52 ballot *init_ballot(ballot *bal, int cnt, node_no node);
53 pax_msg *pax_msg_new(synode_no synode, site_def const *site);
54 pax_msg *pax_msg_new_0(synode_no synode);
55 void dbg_ballot(ballot const *p, char *s);
56 void add_ballot_event(ballot const bal);
57 char *dbg_pax_msg(pax_msg const *p);
58 void delete_pax_msg(pax_msg *p);
59 /* void replace_pax_msg(pax_msg **target, pax_msg *p); */
60 void unchecked_replace_pax_msg(pax_msg **target, pax_msg *p);
61 
62 #define replace_pax_msg(target, p)        \
63   {                                       \
64     PAX_MSG_SANITY_CHECK(p);              \
65     unchecked_replace_pax_msg(target, p); \
66   }
67 
68 #endif
69