]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - src/server_id.h
forb: Update forb_server_id_to_string() documentation
[frescor/forb.git] / src / server_id.h
1 #ifndef FORB_SERVER_ID_H
2 #define FORB_SERVER_ID_H
3
4 #include <forb/uuid.h>
5 #include <forb/types.h>
6
7 void
8 forb_server_id_init(forb_server_id *serer);
9
10 /** 
11  * Compares to server IDs.
12  * 
13  * @param id1 
14  * @param id2 
15  * 
16  * @return -1, 0 or 1 if the @a id1 is less, equal on greated to @a id2 respectively.
17  */
18 static inline int forb_server_id_cmp(const forb_server_id *id1, const forb_server_id *id2)
19 {
20         return memcmp(id1, id2, sizeof(forb_server_id));
21 }
22
23 /** 
24  * Converts a server ID to string.
25  * 
26  * @param dest Where to store the converted string.
27  * @param server_id Server ID to convert.
28  * @param n The size of @a dest memory buffer.
29  * 
30  * @return Same value as @a dest.
31  */
32 static inline char *
33 forb_server_id_to_string(char *dest, const forb_server_id *server_id, size_t n)
34 {
35         return forb_uuid_to_string(dest, (forb_uuid_t*)server_id->uuid, n);
36 }
37
38 /** 
39  * Initializes server ID from string.
40  * 
41  * @param server_id Initialized server ID.
42  * @param string String form of server ID.
43  * 
44  * @return Same value as @a server_id, NULL in the case of error.
45  */
46 static inline forb_server_id * 
47 forb_server_id_from_string(forb_server_id *server_id, const char *string)
48 {
49         return (forb_server_id *)forb_uuid_from_string((forb_uuid_t*)&server_id->uuid, string);
50 }
51
52
53 static inline bool
54 forb_server_id_empty(const forb_server_id *server_id)
55 {
56         unsigned i;
57         for (i=0; i<sizeof(server_id); i++) {
58                 if (server_id->uuid[i] != 0)
59                         return false;
60         }
61         return true;
62 }
63
64 #endif