Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allow to define a default value to registered functions. This allows to use generic...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 11 Apr 2009 16:40:44 +0000 (16:40 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 11 Apr 2009 16:40:44 +0000 (16:40 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6231 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/msg/msg.h
src/include/simix/simix.h
src/msg/deployment.c
src/simix/smx_deployment.c

index 28bbc28..05142be 100644 (file)
@@ -23,6 +23,7 @@ XBT_PUBLIC(int) MSG_get_channel_number(void);
 XBT_PUBLIC(MSG_error_t) MSG_main(void);
 XBT_PUBLIC(MSG_error_t) MSG_clean(void);
 XBT_PUBLIC(void) MSG_function_register(const char *name, xbt_main_func_t code);
+XBT_PUBLIC(void) MSG_function_register_default(xbt_main_func_t code);
 XBT_PUBLIC(xbt_main_func_t) MSG_get_registered_function(const char *name);
 XBT_PUBLIC(void) MSG_launch_application(const char *file);
 XBT_PUBLIC(void) MSG_paje_output(const char *filename);
index 6f147c0..9c0a13a 100644 (file)
@@ -24,6 +24,7 @@ XBT_PUBLIC(void) SIMIX_config(const char *name, va_list pa);
 XBT_PUBLIC(void) SIMIX_global_init(int *argc, char **argv);
 XBT_PUBLIC(void) SIMIX_clean(void);
 XBT_PUBLIC(void) SIMIX_function_register(const char *name, xbt_main_func_t code);
+XBT_PUBLIC(void) SIMIX_function_register_default(xbt_main_func_t code);
 XBT_PUBLIC(xbt_main_func_t) SIMIX_get_registered_function(const char *name);
 
 XBT_PUBLIC(void) SIMIX_launch_application(const char *file);
index 35fc38e..7c310f4 100644 (file)
@@ -52,6 +52,17 @@ void MSG_function_register(const char *name, xbt_main_func_t code)
   return;
 }
 
+/** \ingroup msg_easier_life
+ * \brief Registers a function as the default main function of agents.
+ *
+ * Registers a code function as being the default value. This function will get used by MSG_launch_application() when there is no registered function of the requested name in.
+ * \param code the function (must have the same prototype than the main function of any C program: int ..(int argc, char *argv[]))
+ */
+void MSG_function_register_default(xbt_main_func_t code)
+{
+  SIMIX_function_register_default(code);
+}
+
 /** \ingroup msg_easier_life
  * \brief Retrieves a registered main function
  *
index 2ca297f..a19e2b4 100644 (file)
@@ -149,6 +149,21 @@ void SIMIX_function_register(const char *name, xbt_main_func_t code)
   xbt_dict_set(simix_global->registered_functions, name, code, NULL);
 }
 
+static xbt_main_func_t default_function = NULL;
+/**
+ * \brief Registers a #smx_process_code_t code as default value.
+ *
+ * Registers a code function as being the default value. This function will get used by SIMIX_launch_application() when there is no registered function of the requested name in.
+ * \param code the function
+ */
+void SIMIX_function_register_default(xbt_main_func_t code)
+{
+  xbt_assert0(simix_global,
+             "SIMIX_global_init has to be called before SIMIX_function_register.");
+
+  default_function = code;
+}
+
 /**
  * \brief Gets a #smx_process_t code from the global table.
  *
@@ -162,5 +177,6 @@ xbt_main_func_t SIMIX_get_registered_function(const char *name)
   xbt_assert0(simix_global,
              "SIMIX_global_init has to be called before SIMIX_get_registered_function.");
 
-  return xbt_dict_get_or_null(simix_global->registered_functions, name);
+  xbt_main_func_t res = xbt_dict_get_or_null(simix_global->registered_functions, name);
+  return res ? res : default_function;
 }