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);
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);
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
*
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.
*
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;
}