ctdb-protocol: Add utility function ctdb_sock_addr_to_string
[Samba.git] / ctdb / common / srvid.h
blobf048b5c6cbfc8c58dbcaf9e0c78628240bee437d
1 /*
2 Message handler database based on srvid
4 Copyright (C) Amitay Isaacs 2015
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef __CTDB_SRVID_H__
21 #define __CTDB_SRVID_H__
23 #include <talloc.h>
24 #include <tdb.h>
26 /**
27 * @file srvid.h
29 * @brief Database of message handlers based on srvid
31 * CTDB can be used to send messages between clients across nodes using
32 * CTDB_REQ_MESSAGE. Clients register for mesages based on srvid. CTDB itself
33 * uses a small set of srvid messages. A large range (2^56) of srvid messages
34 * is reserved for Samba.
37 /**
38 * @brief Message handler function
40 * To receive messages for a specific srvid, register a message handler function
41 * for the srvid.
43 typedef void (*srvid_handler_fn)(uint64_t srvid, TDB_DATA data,
44 void *private_data);
46 /**
47 * @brief Abstract struct to store srvid message handler database
49 struct srvid_context;
51 /**
52 * @brief Initialize srvid message handler database
54 * This returns a new srvid message handler database context. Freeing
55 * this context will free all the memory associated with the hash table.
57 * @param[in] mem_ctx Talloc memory context
58 * @param[out] result The new db_hash_context structure
59 * @return 0 on success, errno on failure
61 int srvid_init(TALLOC_CTX *mem_ctx, struct srvid_context **result);
63 /**
64 * @brief Register a message handler for a srvid
66 * The message handler is allocated using the specified talloc context. Freeing
67 * this talloc context, removes the message handler.
69 * @param[in] srv The srvid message handler database context
70 * @param[in] mem_ctx Talloc memory context for message handler
71 * @param[in] srvid The srvid
72 * @param[in] handler The message handler function for srvid
73 * @param[in] private_data Private data for message handler function
74 * @return 0 on success, errno on failure
76 int srvid_register(struct srvid_context *srv, TALLOC_CTX *mem_ctx,
77 uint64_t srvid, srvid_handler_fn handler,
78 void *private_data);
80 /**
81 * @brief Unregister a message handler for a srvid
83 * @param[in] srv The srvid message handler database context
84 * @param[in] srvid The srvid
85 * @param[in] private_data Private data of message handler function
86 * @return 0 on success, errno on failure
88 int srvid_deregister(struct srvid_context *srv, uint64_t srvid,
89 void *private_data);
91 /**
92 * @brief Check if any message handler is registered for srvid
94 * @param[in] srv The srvid message handler database context
95 * @param[in] srvid The srvid
96 * @return 0 on success, errno on failure
98 int srvid_exists(struct srvid_context *srv, uint64_t srvid);
101 * @brief Call message handlers for given srvid
103 * @param[in] srv The srvid message handler database context
104 * @param[in] srvid The srvid
105 * @param[in] srvid_all The srvid that gets all messages
106 * @param[in] data The data passed to each message handler
107 * @return 0 on success, errno on failure
109 * If srvid_all passed is 0, the message is not sent to message handlers
110 * registered with special srvid to receive all messages.
112 int srvid_dispatch(struct srvid_context *srv, uint64_t srvid,
113 uint64_t srvid_all, TDB_DATA data);
115 #endif /* __CTDB_SRVID_H__ */