TAGS
*.mk
*.l[oa]
+*.loT
*.[oa]
*.class
.libs
examples/gras/spawn/spawn_father
examples/gras/synchro/synchro_philosopher
examples/gras/timer/timer_client
+examples/msg/actions/actions
examples/msg/gtnets/gtnets
examples/msg/masterslave/masterslave_bypass
examples/msg/masterslave/masterslave_failure
parallel_task/parallel_task \
parallel_task/test_ptask \
priority/priority \
- properties/msg_prop
+ properties/msg_prop \
+ actions/actions
if HAVE_GTNETS
noinst_PROGRAMS += gtnets/gtnets gtnets/gtnets_kayo
properties_msg_prop_SOURCES = properties/msg_prop.c
properties_msg_prop_LDADD = $(top_builddir)/src/libsimgrid.la
+# actions example
+actions_actions_SOURCES = actions/actions.c
+actions_actions_LDADD = $(top_builddir)/src/libsimgrid.la
+
# sendrecv simple example
sendrecv_sendrecv_SOURCES = sendrecv/sendrecv.c
--- /dev/null
+/* $Id$ */
+
+/* Copyright (c) 2009. The SimGrid team. 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 <stdio.h>
+#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
+#include "xbt.h" /* calloc, printf */
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
+
+/* My actions */
+static void send(xbt_dynar_t action) {
+ INFO1("Send: %s",xbt_str_join(action," "));
+}
+static void recv(xbt_dynar_t action) {
+ INFO1("Recv: %s",xbt_str_join(action," "));
+}
+static void sleep(xbt_dynar_t action) {
+ INFO1("Recv: %s",xbt_str_join(action," "));
+}
+static void compute(xbt_dynar_t action) {
+ INFO1("compute: %s",xbt_str_join(action," "));
+}
+
+/** Main function */
+int main(int argc, char *argv[]){
+ MSG_error_t res = MSG_OK;
+
+ /* Check the given arguments */
+ MSG_global_init(&argc,argv);
+ if (argc < 4) {
+ printf ("Usage: %s platform_file deployment_file action_files\n",argv[0]);
+ printf ("example: %s msg_platform.xml msg_deployment.xml actions\n",argv[0]);
+ exit(1);
+ }
+
+ /* Simulation setting */
+ MSG_create_environment(argv[1]);
+
+ /* No need to register functions as in classical MSG programs: the actions get started anyway */
+ MSG_launch_application(argv[2]);
+
+ /* Action registration */
+ MSG_action_register("send", send);
+ MSG_action_register("recv", recv);
+ MSG_action_register("sleep", sleep);
+ MSG_action_register("compute", sleep);
+
+ /* Actually do the simulation using MSG_action_trace_run */
+ res = MSG_action_trace_run(argv[3]);
+
+ INFO1("Simulation time %g",MSG_get_clock());
+ MSG_clean();
+
+ if(res==MSG_OK)
+ return 0;
+ else
+ return 1;
+} /* end_of_main */
--- /dev/null
+# sample action file
+tutu send toto 12
+toto recv any
+tutu sleep 12
+toto compute 12
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "simgrid.dtd">
+<platform version="2">
+ <process host="Tremblay" function="toto"/>
+ <process host="Jupiter" function="tutu"/>
+</platform>
--- /dev/null
+#! /bin/sh
+
+set -e
+make -C ../../../src
+make -C ..
+./actions ../small_platform.xml actions_deployment.xml actions.txt
XBT_PUBLIC(MSG_error_t)
MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task, double timeout);
+/************************** Action handling **********************************/
+typedef void (*msg_action_fun)(xbt_dynar_t args);
+XBT_PUBLIC(void) MSG_action_register(const char*action_name, msg_action_fun function);
+XBT_PUBLIC(void) MSG_action_unregister(const char*action_name);
+MSG_error_t MSG_action_trace_run(char*path);
+
+
SG_END_DECL()
#endif
MSG_SRC= msg/msg_config.c \
msg/task.c msg/host.c msg/m_process.c msg/gos.c \
- msg/global.c msg/environment.c msg/deployment.c msg/msg_mailbox.c
+ msg/global.c msg/environment.c msg/deployment.c msg/msg_mailbox.c \
+ msg/msg_actions.c
JMSG_C_SRC = \
xbt/xbt_context_java.c \
/* initialization of the mailbox module */
MSG_mailbox_mod_init();
+ /* initialization of the action module */
+ _MSG_action_init();
+
SIMIX_function_register_process_create(_MSG_process_create_from_SIMIX);
SIMIX_function_register_process_cleanup(__MSG_process_cleanup);
SIMIX_function_register_process_kill(_MSG_process_kill_from_SIMIX);
--- /dev/null
+/* Copyright (c) 2009 The SimGrid team. 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 "msg/private.h"
+#include "xbt/str.h"
+#include "xbt/dynar.h"
+
+static xbt_dict_t action_funs;
+static xbt_dynar_t action_list;
+
+
+/** \ingroup msg_actions
+ * \brief Registers a function to handle a kind of action
+ *
+ * Registers a function to handle a kind of action
+ * This table is then used by #MSG_action_trace_run
+ *
+ * The argument of the function is the line describing the action, splitted on spaces with xbt_str_split_quoted()
+ *
+ * \param name the reference name of the action.
+ * \param code the function; prototype given by the type: void...(xbt_dynar_t action)
+ */
+void MSG_action_register(const char*action_name, msg_action_fun function) {
+ xbt_dict_set(action_funs,action_name,function,NULL);
+}
+/** \ingroup msg_actions
+ * \brief Unregisters a function, which handled a kind of action
+ *
+ * \param name the reference name of the action.
+ */
+void MSG_action_unregister(const char*action_name) {
+ xbt_dict_remove(action_funs,action_name);
+}
+
+static int MSG_action_runner(int argc, char* argv[]) {
+ xbt_dynar_t evt;
+ unsigned int cursor;
+
+ xbt_dynar_foreach(action_list,cursor,evt) {
+ if (!strcmp(xbt_dynar_get_as(evt,0,char*),argv[0])) {
+ msg_action_fun function = xbt_dict_get(action_funs,xbt_dynar_get_as(evt,1,char*));
+ (*function)(evt);
+ }
+ }
+
+ return 0;
+}
+
+void _MSG_action_init() {
+ action_funs = xbt_dict_new();
+ action_list = xbt_dynar_new(sizeof(xbt_dynar_t),xbt_dynar_free_voidp);
+ MSG_function_register_default(MSG_action_runner);
+}
+
+/** \ingroup msg_actions
+ * \brief A trace loader
+ *
+ * Load a trace file containing actions, and execute them.
+ */
+MSG_error_t MSG_action_trace_run(char*path) {
+ MSG_error_t res;
+
+ FILE * fp;
+ char * line = NULL;
+ size_t len = 0;
+ ssize_t read;
+
+ xbt_dynar_t evt;
+
+ fp = fopen(path, "r");
+ xbt_assert2(fp != NULL,"Cannot open %s: %s",path,strerror(errno));
+
+ while ((read = getline(&line, &len, fp)) != -1) {
+ char *comment = strchr(line,'#');
+ if (comment!=NULL)
+ *comment='\0';
+ xbt_str_trim(line,NULL);
+ if (line[0]=='\0')
+ continue;
+ evt = xbt_str_split_quoted(line);
+ xbt_dynar_push(action_list,&evt);
+ }
+
+ if (line)
+ free(line);
+ fclose(fp);
+
+ res = MSG_main();
+ xbt_dynar_free(&action_list);
+ action_list = xbt_dynar_new(sizeof(xbt_dynar_t),xbt_dynar_free_voidp);
+
+ return res;
+}
char * hostname, int argc, char **argv, xbt_dict_t properties);
void _MSG_process_kill_from_SIMIX(void *p);
+void _MSG_action_init(void);
+
SG_END_DECL()
#endif