From ce7e8bd40f22e0388a69ba01390443153a084edf Mon Sep 17 00:00:00 2001 From: quasar Date: Thu, 1 Nov 2007 16:06:39 +0000 Subject: [PATCH] gras prop example git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@4953 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- examples/gras/properties/gras_prop.c | 54 +++++++++++++++ examples/gras/properties/gras_prop.mk | 65 +++++++++++++++++++ .../gras/properties/gras_prop_deployment.xml | 10 +++ .../gras/properties/gras_prop_platform.xml | 13 ++++ 4 files changed, 142 insertions(+) create mode 100644 examples/gras/properties/gras_prop.c create mode 100644 examples/gras/properties/gras_prop.mk create mode 100644 examples/gras/properties/gras_prop_deployment.xml create mode 100644 examples/gras/properties/gras_prop_platform.xml diff --git a/examples/gras/properties/gras_prop.c b/examples/gras/properties/gras_prop.c new file mode 100644 index 0000000000..3e03f0a4d5 --- /dev/null +++ b/examples/gras/properties/gras_prop.c @@ -0,0 +1,54 @@ +#include + +XBT_LOG_NEW_DEFAULT_CATEGORY(property,"Simple Property example"); + + +int client(int argc, char *argv[]) { + gras_init(&argc,argv); + + /* Get the properties */ + xbt_dict_t props = gras_process_properties(); + xbt_dict_cursor_t cursor = NULL; + char *key,*data; + + /* Print the properties of the workstation 1 */ + xbt_dict_foreach(props,cursor,key,data) { + INFO2("Process property: %s has value: %s",key,data); + } + + /* Try to get a property that does not exist */ + char *noexist=xbt_strdup("Nonexisent"); + const char *value = gras_process_property_value(noexist); + if ( value == NULL) + INFO1("Process property: %s is undefined", noexist); + else + INFO2("Process property: %s has value: %s", noexist, value); + + gras_exit(); + return 0; +} + +int server(int argc, char *argv[]) { + gras_init(&argc,argv); + + /* Get the properties */ + xbt_dict_t props = gras_os_host_properties(); + xbt_dict_cursor_t cursor = NULL; + char *key,*data; + + /* Print the properties of the workstation 1 */ + xbt_dict_foreach(props,cursor,key,data) { + INFO2("Host property: %s has value: %s",key,data); + } + + /* Try to get a property that does not exist */ + char *noexist=xbt_strdup("Nonexisent"); + const char *value = gras_os_host_property_value(noexist); + if ( value == NULL) + INFO1("Host property: %s is undefined", noexist); + else + INFO2("Host property: %s has value: %s", noexist, value); + + gras_exit(); + return 0; +} diff --git a/examples/gras/properties/gras_prop.mk b/examples/gras/properties/gras_prop.mk new file mode 100644 index 0000000000..4f7c6fd873 --- /dev/null +++ b/examples/gras/properties/gras_prop.mk @@ -0,0 +1,65 @@ + +#### +#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT +#### + + +## Variable declarations +PROJECT_NAME=gras_prop +DISTDIR=gras-$(PROJECT_NAME) + +# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid +# Compilation will fail if you don't do so +GRAS_ROOT?= $(shell echo "\"<<<< GRAS_ROOT undefined !!! >>>>\"") + +# You can fiddle the following to make it fit your taste +INCLUDES = -I$(GRAS_ROOT)/include +CFLAGS ?= -O3 -w -g +LIBS_SIM = -lm -L$(GRAS_ROOT)/lib/ -lsimgrid +LIBS_RL = -lm -L$(GRAS_ROOT)/lib/ -lgras +LIBS = + +PRECIOUS_C_FILES ?= gras_prop.c +GENERATED_C_FILES = _gras_prop_simulator.c _gras_prop_client.c _gras_prop_server.c +OBJ_FILES = $(patsubst %.c,%.o,$(PRECIOUS_C_FILES)) +BIN_FILES = gras_prop_simulator gras_prop_client gras_prop_server + +## By default, build all the binaries +all: $(BIN_FILES) + + +## generate temps: regenerate the source file each time the deployment file changes +_gras_prop_client.c _gras_prop_server.c _gras_prop_simulator.c: gras_prop_deployment.xml + gras_stub_generator gras_prop gras_prop_deployment.xml >/dev/null + +## Generate the binaries +gras_prop_simulator: _gras_prop_simulator.o $(OBJ_FILES) + $(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ +gras_prop_client : _gras_prop_client.o $(OBJ_FILES) + $(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ +gras_prop_server : _gras_prop_server.o $(OBJ_FILES) + $(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ + +%: %.o + $(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ + +%.o: %.c + $(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $< + +## Rules for tarballs and cleaning +DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) gras_prop.mk +distdir: $(DIST_FILES) + rm -rf $(DISTDIR) + mkdir -p $(DISTDIR) + cp $^ $(DISTDIR) + +dist: clean distdir + tar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz + +clean: + rm -f $(CLEANFILES) $(BIN_FILES) $(OBJ_FILES) *~ gras_prop.o _gras_prop_simulator.o _gras_prop_client.o _gras_prop_server.o + rm -rf $(DISTDIR) + +.SUFFIXES: +.PHONY : clean + diff --git a/examples/gras/properties/gras_prop_deployment.xml b/examples/gras/properties/gras_prop_deployment.xml new file mode 100644 index 0000000000..85e31a3316 --- /dev/null +++ b/examples/gras/properties/gras_prop_deployment.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/examples/gras/properties/gras_prop_platform.xml b/examples/gras/properties/gras_prop_platform.xml new file mode 100644 index 0000000000..9c758223fd --- /dev/null +++ b/examples/gras/properties/gras_prop_platform.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + -- 2.20.1