From 51a05a5d56fdeed675ae02e0ecbb6fbae9cf9a37 Mon Sep 17 00:00:00 2001 From: mquinson Date: Tue, 16 May 2006 08:42:28 +0000 Subject: [PATCH] Some (trivial) helping functions around xbt_host_t git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2209 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/xbt/host.h | 30 ++++++++++++++++++++++++++++++ src/xbt/xbt_host.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 include/xbt/host.h create mode 100644 src/xbt/xbt_host.c diff --git a/include/xbt/host.h b/include/xbt/host.h new file mode 100644 index 0000000000..97ee335e7c --- /dev/null +++ b/include/xbt/host.h @@ -0,0 +1,30 @@ +/* $Id$ */ + +/* host.h - host management functions */ + +/* Copyright (c) 2006 Arnaud Legrand. */ +/* All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef XBT_HOST_H +#define XBT_HOST_H + +#include "xbt/misc.h" + +SG_BEGIN_DECL() + +typedef struct { + char *name; + int port; +} s_xbt_host_t, *xbt_host_t; + +xbt_host_t xbt_host_new(char *name, int port); +void xbt_host_free(xbt_host_t host); +void xbt_host_free_voidp(void *d); + +SG_END_DECL() + + +#endif /* XBT_MISC_H */ diff --git a/src/xbt/xbt_host.c b/src/xbt/xbt_host.c new file mode 100644 index 0000000000..c66892617b --- /dev/null +++ b/src/xbt/xbt_host.c @@ -0,0 +1,35 @@ +/* $Id$ */ + +/* xbt_host_t management functions */ + +/* Copyright (c) 2006 Martin Quinson. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "xbt/sysdep.h" +#include "xbt/log.h" +#include "xbt/host.h" + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host,xbt,"Host management"); + +/** \brief constructor */ +xbt_host_t xbt_host_new(char *name, int port) { + xbt_host_t res=xbt_new(s_xbt_host_t, 1); + res->name = name; + res->port = port; + return res; +} + +/** \brief destructor */ +void xbt_host_free(xbt_host_t host) { + if (host) { + if (host->name) free(host->name); + free(host); + } +} + +/** \brief Freeing function for dynars of xbt_host_t */ +void xbt_host_free_voidp(void *d) { + xbt_host_free( (xbt_host_t) *(void**)d ); +} -- 2.20.1