Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix: correct trace mask checking
[simgrid.git] / src / xbt / xbt_peer.c
1 /* $Id$ */
2
3 /* xbt_peer_t management functions                                          */
4
5 /* Copyright (c) 2006 Martin Quinson. All rights reserved.                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include "xbt/sysdep.h"
11 #include "xbt/log.h"
12 #include "xbt/peer.h"
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(peer, xbt, "peer management");
15
16 /** \brief constructor */
17 xbt_peer_t xbt_peer_new(const char *name, int port)
18 {
19   xbt_peer_t res = xbt_new(s_xbt_peer_t, 1);
20   res->name = xbt_strdup(name);
21   res->port = port;
22   return res;
23 }
24
25 xbt_peer_t xbt_peer_copy(xbt_peer_t h)
26 {
27   return xbt_peer_new(h->name, h->port);
28 }
29
30 /** \brief constructor. Argument should be of form '(peername):(port)'. */
31 xbt_peer_t xbt_peer_from_string(const char *peerport)
32 {
33   xbt_peer_t res = xbt_new(s_xbt_peer_t, 1);
34   char *name = xbt_strdup(peerport);
35   char *port_str = strchr(name, ':');
36   xbt_assert1(port_str,
37               "argument of xbt_peer_from_string should be of form <peername>:<port>, it's '%s'",
38               peerport);
39   *port_str = '\0';
40   port_str++;
41
42   res->name = xbt_strdup(name); /* it will be shorter now that we cut the port */
43   res->port = atoi(port_str);
44   free(name);
45   return res;
46 }
47
48 /** \brief destructor */
49 void xbt_peer_free(xbt_peer_t peer)
50 {
51   if (peer) {
52     if (peer->name)
53       free(peer->name);
54     free(peer);
55   }
56 }
57
58 /** \brief Freeing function for dynars of xbt_peer_t */
59 void xbt_peer_free_voidp(void *d)
60 {
61   xbt_peer_free((xbt_peer_t) * (void **) d);
62 }