Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix constness of arguments
[simgrid.git] / src / msg / m_process.c
index 34afa54..d36c64a 100644 (file)
@@ -29,21 +29,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_process, msg,
  */
 
 /******************************** Process ************************************/
-/** \ingroup m_process_management
- * \brief Creates and runs a new #m_process_t.
- *
- * Does exactly the same as #MSG_process_create_with_arguments but without 
-   providing standard arguments (\a argc, \a argv, \a start_time, \a kill_time).
- * \sa MSG_process_create_with_arguments
- */
-m_process_t MSG_process_create(const char *name,
-                              xbt_main_func_t code, void *data,
-                              m_host_t host)
-{
-  return MSG_process_create_with_arguments(name, code, data, host, -1,
-                                          NULL);
-}
-
 void __MSG_process_cleanup(void *arg)
 {
   /* arg is a pointer to a simix process, we can get the msg process with the field data */
@@ -59,16 +44,30 @@ void __MSG_process_cleanup(void *arg)
   return;
 }
 
-/* This function creates a MSG process. It has the prototype by SIMIX_function_register_process_create */
+/* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
 void *_MSG_process_create_from_SIMIX(const char *name,
                                     xbt_main_func_t code, void *data,
-                                    char *hostname, int argc, char **argv)
+                                    char *hostname, int argc, char **argv, xbt_dict_t properties)
 {
   m_host_t host = MSG_get_host_by_name(hostname);
-  return (void *) MSG_process_create_with_arguments(name, code, data, host,
-                                                   argc, argv);
+  return (void *) MSG_process_create_with_environment(name, code, data, host,
+                                                     argc, argv,properties);
 }
 
+/** \ingroup m_process_management
+ * \brief Creates and runs a new #m_process_t.
+ *
+ * Does exactly the same as #MSG_process_create_with_arguments but without 
+   providing standard arguments (\a argc, \a argv, \a start_time, \a kill_time).
+ * \sa MSG_process_create_with_arguments
+ */
+m_process_t MSG_process_create(const char *name,
+                              xbt_main_func_t code, void *data,
+                              m_host_t host)
+{
+  return MSG_process_create_with_environment(name, code, data, host, -1,
+                                            NULL,NULL);
+}
 
 /** \ingroup m_process_management
  * \brief Creates and runs a new #m_process_t.
@@ -99,6 +98,40 @@ m_process_t MSG_process_create_with_arguments(const char *name,
                                              xbt_main_func_t code,
                                              void *data, m_host_t host,
                                              int argc, char **argv)
+{
+  return MSG_process_create_with_environment(name, code, data, host, 
+                                            argc,argv,NULL);
+}
+
+/** \ingroup m_process_management
+ * \brief Creates and runs a new #m_process_t.
+
+ * A constructor for #m_process_t taking four arguments and returning the 
+ * corresponding object. The structure (and the corresponding thread) is
+ * created, and put in the list of ready process.
+ * \param name a name for the object. It is for user-level information
+   and can be NULL.
+ * \param code is a function describing the behavior of the agent. It
+   should then only use functions described in \ref
+   m_process_management (to create a new #m_process_t for example),
+   in \ref m_host_management (only the read-only functions i.e. whose
+   name contains the word get), in \ref m_task_management (to create
+   or destroy some #m_task_t for example) and in \ref
+   msg_gos_functions (to handle file transfers and task processing).
+ * \param data a pointer to any data one may want to attach to the new
+   object.  It is for user-level information and can be NULL. It can
+   be retrieved with the function \ref MSG_process_get_data.
+ * \param host the location where the new agent is executed.
+ * \param argc first argument passed to \a code
+ * \param argv second argument passed to \a code
+ * \param properties list a properties defined for this process
+ * \see m_process_t
+ * \return The new corresponding object.
+ */
+m_process_t MSG_process_create_with_environment(const char *name,
+                                             xbt_main_func_t code,
+                                             void *data, m_host_t host,
+                                             int argc, char **argv, xbt_dict_t properties)
 {
   simdata_process_t simdata = xbt_new0(s_simdata_process_t, 1);
   m_process_t process = xbt_new0(s_m_process_t, 1);
@@ -112,7 +145,7 @@ m_process_t MSG_process_create_with_arguments(const char *name,
   simdata->argv = argv;
   simdata->s_process = SIMIX_process_create(name, code,
                                            (void *) process, host->name,
-                                           argc, argv);
+                                           argc, argv, properties);
 
   if (SIMIX_process_self()) {
     simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data);
@@ -130,8 +163,8 @@ m_process_t MSG_process_create_with_arguments(const char *name,
   xbt_fifo_unshift(msg_global->process_list, process);
 
   return process;
-}
 
+}
 
 void _MSG_process_kill_from_SIMIX(void *p)
 {
@@ -287,6 +320,31 @@ const char *MSG_process_get_name(m_process_t process)
   return (process->name);
 }
 
+/** \ingroup m_process_management
+ * \brief Returns the value of a given process property
+ *
+ * \param process a process
+ * \param name a property name
+ * \return value of a property (or NULL if the property is not set)
+ */
+const char* MSG_process_get_property_value(m_process_t process, const char* name)
+{
+  return xbt_dict_get_or_null(MSG_process_get_properties(process), name);
+}
+
+/** \ingroup m_process_management
+ * \brief Return the list of properties
+ *
+ * This functions returns all the parameters associated with a process
+ */
+xbt_dict_t MSG_process_get_properties(m_process_t process)
+{
+   xbt_assert0((process != NULL), "Invalid parameters");
+
+  return (SIMIX_process_get_properties(((simdata_process_t)process->simdata)->s_process));
+
+}
+
 /** \ingroup m_process_management
  * \brief Return the PID of the current agent.
  *