-/*\r
- * Process.hpp\r
- *\r
- * Copyright 2006,2007 Martin Quinson, Malek Cherier \r
- * All right reserved. \r
- *\r
- * This program is free software; you can redistribute \r
- * it and/or modify it under the terms of the license \r
- *(GNU LGPL) which comes with this package. \r
- *\r
- */ \r
- \r
-#ifndef MSG_PROCESS_HPP\r
-#define MSG_PROCESS_HPP\r
-\r
-// Compilation C++ recquise\r
-#ifndef __cplusplus\r
- #error Process.hpp requires C++ compilation (use a .cxx suffix)\r
-#endif\r
-\r
-#include <msg/datatypes.h>\r
-\r
-#include <ApplicationHandler.hpp>\r
-#include <Object.hpp>\r
-\r
-#include <MsgException.hpp>\r
-#include <NullPointerException.hpp>\r
-#include <HostNotFoundException.hpp>\r
-#include <ProcessNotFoundException.hpp>\r
-#include <InvalidArgumentException.hpp>\r
-#include <BadAllocException.hpp>\r
-#include <LogicException.hpp>\r
-\r
-namespace SimGrid\r
-{\r
- namespace Msg\r
- {\r
- class ApplicationHandler;\r
- class Host;\r
- class Task;\r
-\r
- // SimGrid::Msg::Process class declaration.\r
- class SIMGRIDX_EXPORT Process : public Object\r
- {\r
- friend class ApplicationHandler::ProcessFactory;\r
- \r
- MSG_DECLARE_DYNAMIC(Process);\r
-\r
- public:\r
-\r
- // Disable the default constructor.\r
- Process();\r
- \r
- \r
- /*! \brief Constructs a process from the name of the host and its name.\r
- *\r
- * \param hostName The host name of the process to create.\r
- * \param name The name of the process to create.\r
- *\r
- * \exception If the constructor failed, it throws one of the exceptions described\r
- * below:\r
- * \r
- * [NullPointerException] if the name of the process is NULL or if the\r
- * name of the host is NULL.\r
- * [HostNotFoundException] if the host is not found.\r
- */ \r
- Process(const char* hostName, const char* name)\r
- throw(NullPointerException, HostNotFoundException, BadAllocException);\r
- \r
- /*! \brief Constructs a process from a reference to an host object and its name.\r
- *\r
- * \param rHost A reference to the host object representing the native\r
- * MSG host where to create the process.\r
- * \param name The name of the process to create.\r
- *\r
- * \exception If the constructor failed, it throws the exception described\r
- * below:\r
- *\r
- * [NullPointerException] if the name of process is NULL.\r
- */ \r
- Process(const Host& rHost, const char* name)\r
- throw(NullPointerException);\r
- \r
- /*! brief Construct a proces from reference to an host object and the name of the process.\r
- * This constuctor takes also the list of the arguments of the process.\r
- *\r
- * \param host A reference to the host where to create the process.\r
- * \param name The name of the process to create.\r
- * \param argc The number of the arguments of the process to create.\r
- * \param argv The list of arguments of the process to create.\r
- *\r
- * \exception If the constructor failed, it throws one of the exceptions described\r
- * below:\r
- *\r
- * [NullPointerException] if the name of the host is NULL or\r
- * if the name of the process is NULL.\r
- * [InvalidArgumentException] if the value of the parameter argv is\r
- * negative.\r
- * [LogicException] if the parameter argv is NULL and the \r
- * parameter argc is different than zero\r
- * if the parameter argv is not NULL and \r
- * the parameter argc is zero.\r
- */\r
- Process(const Host& rHost, const char* name, int argc, char** argv)\r
- throw(NullPointerException, InvalidArgumentException, LogicException);\r
- \r
- /*! brief Constructs a proces from the name of a host and the name of the process.\r
- * This constuctor takes also the list of the arguments of the process.\r
- *\r
- * \param hostName The name of the host where to create the process.\r
- * \param name The name of the process to create.\r
- * \param argc The number of the arguments of the process to create.\r
- * \param argv The list of arguments of the process to create.\r
- *\r
- * \exception If the constructor failed, it throws one of the exceptions described\r
- * below:\r
- * \r
- * [NullPointerException] if the name of the process or if the name\r
- * of the host is NULL.\r
- * [InvalidArgumentException] if the value of the parameter argv is\r
- * negative.\r
- * [LogicException] if the parameter argv is NULL and the \r
- * parameter argc is different than zero\r
- * if the parameter argv is not NULL and \r
- * the parameter argc is zero.\r
- * [HostNotFoundException] if the specified host is no found.\r
- */\r
- Process(const char* hostName, const char* name, int argc, char** argv)\r
- throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException, BadAllocException);\r
- \r
- /*! \brief Process::killAll() - kill all the running processes of the simulation.\r
- *\r
- * \param resetPID Should we reset the PID numbers. A negative number means no reset\r
- * and a positive number will be used to set the PID of the next newly\r
- * created process.\r
- *\r
- * \return The static method returns the PID of the next created process.\r
- */ \r
- static int killAll(int resetPID);\r
- \r
- /*! \brief Process::suspend() - Suspend an MSG process.\r
- * \r
- * \excetpion If this method failed, it throws one the exception described below:\r
- *\r
- * [MsgException] if an internal exception occurs during the operation.\r
- */\r
- void suspend(void)\r
- throw(MsgException);\r
- \r
- \r
- \r
- /*! \brief Process::resume() - Resume the MSG process.\r
- *\r
- * \exception If this method failed, it throws the exception described below:\r
- *\r
- * [MsgException] if an internal exception occurs during the operation.\r
- */\r
- void resume(void) \r
- throw(MsgException);\r
- \r
- /*! \brief Process::isSuspend() - Tests if a process is suspended.\r
- *\r
- * \return This method returns 1 is the process is suspended.\r
- * Otherwise the method returns 0.\r
- */\r
- int isSuspended(void);\r
- \r
- /*! \brief Process::getHost() - Retrieves the host of a process object.\r
- *\r
- * \return The method returns a reference to the\r
- * host of the process.\r
- *\r
- */\r
- Host& getHost(void); \r
- \r
- /*! \brief Process::fromPID() - Retrieves a process from its PID.\r
- *\r
- * \param PID The PID of the process to retrieve.\r
- *\r
- * \return If successful the method returns a reference to\r
- * to process. Otherwise, the method throws one of\r
- * the exceptions described below:\r
- *\r
- * \exception [ProcessNotFoundException] if the process is not found (no process with this PID).\r
- *\r
- * [InvalidArgumentException] if the parameter PID is less than 1.\r
- *\r
- * [MsgException] if a native error occurs during the operation.\r
- */\r
- static Process& fromPID(int PID)\r
- throw(ProcessNotFoundException, InvalidArgumentException, MsgException); \r
- \r
- /*! \brief Process::getPID() - Gets the PID of a process object.\r
- *\r
- * \return This method returns the PID of a process object.\r
- */\r
- int getPID(void);\r
- \r
- /*! \brief Process::getPPID() - Gets the parent PID of a process object.\r
- *\r
- * \return This method returns the parent PID of a process object.\r
- */\r
- int getPPID(void);\r
- \r
- /*! \brief Process::getName() - Gets the name of a process object.\r
- *\r
- * \return This method returns the name of a process object.\r
- */\r
- const char* getName(void) const;\r
- \r
- /*! \brief Process::currentProcess() - Retrieves the current process.\r
- *\r
- * \return This method returns a reference to the current process. Otherwise\r
- * the method throws the excepction described below:\r
- *\r
- * \exception [MsgException] if an internal exception occurs.\r
- */\r
- static Process& currentProcess(void)\r
- throw (MsgException);\r
- \r
- /*! \brief Process::currentProcessPID() - Retrieves the PID of the current process.\r
- *\r
- * \return This method returns the PID of the current process.\r
- */\r
- static int currentProcessPID(void);\r
- \r
- /*! \brief Process::currentProcessPPID() - Retrieves the parent PID of the current process.\r
- *\r
- * \return This method returns the parent PID of the current process.\r
- */\r
- static int currentProcessPPID(void);\r
- \r
- /*! \brief Process::migrate() - Migrate a process object to an another host.\r
- *\r
- * \param rHost A reference to the host to migrate the process to.\r
- *\r
- * \return If successful the method migrate the process to the specified\r
- * host. Otherwise the method throws the exception described\r
- * below:\r
- *\r
- * \exception [MsgException] if an internal exception occurs.\r
- */\r
- void migrate(const Host& rHost)\r
- throw(MsgException);\r
- \r
- /*! \brief Process::sleep() - Makes the current process sleep until time seconds have elapsed. \r
- *\r
- * \param seconds The number of seconds to sleep.\r
- *\r
- * \execption If this method failed, it throws one of the exceptions described\r
- * below: \r
- *\r
- * [InvalidArgumentException] if the parameter seconds is\r
- * less or equals to zero.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- static void sleep(double seconds)\r
- throw(InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::putTask() - This method puts a task on a given channel of a given host.\r
- *\r
- * \exception If this method failed, it throws one of the exceptions described\r
- * below:\r
- *\r
- * [InvalidArgumentException] if the channel number is negative.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- void putTask(const Host& rHost, int channel, Task* task)\r
- throw(InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::putTask() - This method puts a task on a given channel of a given host (waiting at most given time).\r
- *\r
- * \exception If this method failed, it throws one of the exceptions described below:\r
- *\r
- * [MsgException] if an internal error occurs.\r
- *\r
- * [InvalidArgumentException] if the value of the channel specified as\r
- * parameter is negative or if the timeout value\r
- * is less than zero and différent of -1.\r
- *\r
- * \remark Set the timeout with -1.0 to disable it.\r
- */\r
- void putTask(const Host& rHost, int channel, Task* task, double timeout) \r
- throw(InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::getTask() - Retrieves a task from a channel number (waiting at most given time).\r
- *\r
- * \param channel The number of the channel where to get the task.\r
- *\r
- * \return If successful the method returns a reference to \r
- * the getted task. Otherwise the method throws one\r
- * of the exceptions described below:\r
- *\r
- * \exception [InvalidArgumentException] if the channel number is negative.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* getTask(int channel) \r
- throw(InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::taskGet() - Retrieves a task from a channel number (waiting at most given time).\r
- *\r
- * \param channel The number of the channel where to get the task.\r
- * \param timeout The timeout value.\r
- *\r
- * \return If successful the method returns a reference to \r
- * the getted task. Otherwise the method throws one\r
- * of the exceptions described below:\r
- *\r
- * \exception [InvalidArgumentException] if the channel number is negative\r
- * or if the timeout value is less than\r
- * zero and different of -1.0.\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* getTask(int channel, double timeout) \r
- throw(InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host.\r
- *\r
- * \param channel The number of the channel where to get the task.\r
- * \param host The host of the channel to get the task.\r
- *\r
- * \return If successful the method returns a reference to \r
- * the getted task. Otherwise the method throws one\r
- * of the exceptions described below.\r
- *\r
- * \exception [InvalidArgumentException] if the channel number is negative.\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* getTask(int channel, const Host& rHost) \r
- throw(InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host (waiting at most given time).\r
- *\r
- * \param channel The number of the channel where to get the task.\r
- * \param timeout The timeout value.\r
- * \param rHost The host owning the channel.\r
- *\r
- * \return If successful the method returns a reference to \r
- * the getted task. Otherwise the method throws one\r
- * of the exceptions described below:\r
- *\r
- * \exception [InvalidArgumentException] if the channel number is negative or\r
- * if the timeout value is negative and different\r
- * of -1.0.\r
- * [MsgException] if an internal exception occurs.\r
- *\r
- * \remark Set the timeout with -1.0 to disable it.\r
- */\r
- Task* getTask(int channel, double timeout, const Host& rHost)\r
- throw(InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias\r
- * (waiting at most given time).\r
- *\r
- * \param alias The alias of the mailbox where to send the task.\r
- * \param rTask A reference to the task object to send.\r
- * \param timeout The timeout value.\r
- *\r
- * \exception If this method failed, it throws one of the exceptions described below:\r
- *\r
- * [NullPointerException] if the alias specified as parameter is NULL.\r
- * \r
- * [InvalidArgumentException] if the timeout value is negative and different than\r
- * -1.0\r
- * [MsgException] if an internal exception occurs.\r
- *\r
- * \remark Set the timeout with -1.0 to disable it.\r
- */\r
- void sendTask(const char* alias, Task* task, double timeout) \r
- throw(NullPointerException, InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias.\r
- *\r
- * \param alias The alias of the mailbox where to send the task.\r
- * \param rTask A reference to the task object to send.\r
- *\r
- * \exception If this method failed, it throws one of the exceptions described below:\r
- *\r
- * [NullPointerException] if the alias parameter is NULL.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- *\r
- */\r
- void sendTask(const char* alias, Task* task) \r
- throw(NullPointerException, MsgException);\r
- \r
- /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias.\r
- *\r
- * \param rTask A reference to the task object to send.\r
- *\r
- * \exception If this method failed, it throws one of the exceptions described below:\r
- * \r
- * [BadAllocException] if there is not enough memory to build the default alias.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- *\r
- */\r
- void sendTask(Task* task) \r
- throw(BadAllocException, MsgException);\r
- \r
- /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias\r
- * (waiting at most given time).\r
- *\r
- * \param rTask A reference to the task object to send.\r
- * \param timeout The timeout value.\r
- *\r
- * \exception If this method failed, it throws one of the exceptions described below:\r
- *\r
- * [BadAllocException] if there is not enough memory to build the default alias.\r
- *\r
- * [InvalidArgumentException] if the timeout value is negative and different than -1.0.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- *\r
- * \remark set the timeout value with -1.0 to disable it.\r
- */\r
- void sendTask(Task* task, double timeout) \r
- throw(BadAllocException, InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as\r
- * parameter.\r
- *\r
- * \param alias The alias of the mailbox where to retrieve the task.\r
- *\r
- * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
- * throws one of the exceptions described below:\r
- *\r
- * \exception [NullPointerException] if the parameter alias is NULL.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* receiveTask(const char* alias) \r
- throw(NullPointerException, MsgException);\r
- \r
- /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias.\r
- *\r
- * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
- * throws one of the exceptions described below:\r
- *\r
- * \exception [BadAllocException] if there is not enough memory to build the alias. \r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* receiveTask(void) \r
- throw(BadAllocException, MsgException);\r
- \r
- /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as\r
- * parameter(waiting at most given time).\r
- *\r
- * \param alias The alias of the mailbox where to retrieve the task.\r
- * \param timeout The timeout value.\r
- *\r
- * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
- * throws one of the exceptions described below.\r
- *\r
- * \exception [InvalidArgumentException] if the timeout value is negative or different of -1.0.\r
- *\r
- * [NullPointerException] if the parameter alias is NULL.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* receiveTask(const char* alias, double timeout) \r
- throw(NullPointerException, InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias\r
- * (waiting at most given time).\r
- *\r
- * \param timeout The timeout value.\r
- *\r
- * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
- * throws one of the exceptions described below:\r
- *\r
- * \exception [InvalidArgumentException] if the timeout value is negative or different than -1.0.\r
- *\r
- * [BadAllocException] if there is not enough memory to build the alias.\r
- * \r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* receiveTask(double timeout) \r
- throw(InvalidArgumentException, BadAllocException, MsgException);\r
- \r
- /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as\r
- * parameter located on a given host (waiting at most given time).\r
- *\r
- * \param alias The alias of the mailbox where to retrieve the task.\r
- * \param timeout The timeout value.\r
- * \param rHost A reference to the host object owning the mailbox.\r
- *\r
- * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
- * throws one of the exceptions described below:\r
- *\r
- * \exception [InvalidArgumentException] if the timeout value is negative or different of -1.0.\r
- *\r
- * [NullPointerException] if the parameter alias is NULL.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* receiveTask(const char* alias, double timeout, const Host& rHost) \r
- throw(NullPointerException, InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias\r
- * and located on a given host (waiting at most given time).\r
- *\r
- * \param timeout The timeout value.\r
- * \param rHost A reference to the host object owning the mailbox.\r
- *\r
- * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
- * throws one of the exceptions described below:\r
- *\r
- * \exception [InvalidArgumentException] if the timeout value is negative and different than -1.0.\r
- *\r
- * [BadAllocException] if there is not enough memory to build the default alias.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* receiveTask(double timeout, const Host& rHost) \r
- throw(BadAllocException, InvalidArgumentException, MsgException);\r
- \r
- /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias\r
- * specified as parameter and located on a given host.\r
- *\r
- * \param alias The alias using to identify the mailbox from which to get the task.\r
- * \param rHost A reference to the host object owning the mailbox.\r
- *\r
- * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
- * throws one of the exceptions described below:\r
- *\r
- * \exception [NullPointerException] if the parameter alias is NULL.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* receiveTask(const char* alias, const Host& rHost) \r
- throw(NullPointerException, MsgException);\r
- \r
- /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias\r
- * and located on a given host.\r
- *\r
- * \param rHost A reference to the host object owning the mailbox.\r
- *\r
- * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method\r
- * throws one of the exceptions described below:\r
- *\r
- * \exception [BadAllocException] if there is not enough memory to build the alias.\r
- *\r
- * [MsgException] if an internal exception occurs.\r
- */\r
- Task* receiveTask(const Host& rHost) \r
- throw(BadAllocException, MsgException);\r
- \r
- \r
- private:\r
- \r
- /* Process::create() - Creates a process on a given host.\r
- *\r
- * param rHost A reference to a host object where to create the process.\r
- * param name The name of the process to create.\r
- * param argc The number of argument to pass to the main function of the process.\r
- * param argv The list of the arguments of the main function of the process.\r
- *\r
- * exception If this method failed, it throws one of the exceptions described below:\r
- *\r
- * [HostNotFoundException] if the host specified as parameter doesn't exist.\r
- */\r
- void create(const Host& rHost, const char* name, int argc, char** argv) \r
- throw(InvalidArgumentException);\r
- \r
- /* Process::fromNativeProcess() - Retrieves the process wrapper associated with a native process.\r
- *\r
- * \param nativeProcess The native process to get the wrapper.\r
- *\r
- * \return The wrapper associated with the native process specified as parameter.\r
- */\r
- static Process* fromNativeProcess(m_process_t nativeProcess);\r
- \r
- \r
- public:\r
- \r
- /* Process::run() - used to set the field code of the context of the process.\r
- */ \r
- static int run(int argc, char** argv);\r
- \r
- /*! \brief Process::main() - This virtual pure function is the main function of the process.\r
- * You must override this function for each new class of process that you create.\r
- *\r
- * \param argc The number of parameters of the main function.\r
- * \param argv The list of the parameter of the main function.\r
- *\r
- * \return The exit code of the main function.\r
- */\r
- virtual int main(int argc, char** argv);\r
-\r
- // Operators.\r
- \r
- /*\r
- // Override the operator new().\r
- void* operator new(size_t size);\r
- \r
- // Override the operator delete().\r
- void operator delete(void* p);\r
- */\r
- \r
- private:\r
- \r
- // Attributes.\r
- \r
- m_process_t nativeProcess; // pointer to the native msg process.\r
- \r
- };\r
- \r
- } //namepace Msg\r
-\r
-} // namespace SimGrid\r
-\r
-#endif // !MSG_PROCESS_HPP\r
-\r
+/*
+ * Process.hpp
+ *
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier
+ * All right 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.
+ *
+ */
+
+#ifndef MSG_PROCESS_HPP
+#define MSG_PROCESS_HPP
+
+// Compilation C++ recquise
+#ifndef __cplusplus
+ #error Process.hpp requires C++ compilation (use a .cxx suffix)
+#endif
+
+#include <msg/datatypes.h>
+
+#include <ApplicationHandler.hpp>
+#include <Object.hpp>
+
+#include <MsgException.hpp>
+#include <NullPointerException.hpp>
+#include <HostNotFoundException.hpp>
+#include <ProcessNotFoundException.hpp>
+#include <InvalidArgumentException.hpp>
+#include <BadAllocException.hpp>
+#include <LogicException.hpp>
+
+namespace SimGrid
+{
+ namespace Msg
+ {
+ class ApplicationHandler;
+ class Host;
+ class Task;
+
+ // SimGrid::Msg::Process class declaration.
+ class SIMGRIDX_EXPORT Process : public Object
+ {
+ friend class ApplicationHandler::ProcessFactory;
+
+ MSG_DECLARE_DYNAMIC(Process);
+
+ public:
+
+ // Disable the default constructor.
+ Process();
+
+
+ /*! \brief Constructs a process from the name of the host and its name.
+ *
+ * \param hostName The host name of the process to create.
+ * \param name The name of the process to create.
+ *
+ * \exception If the constructor failed, it throws one of the exceptions described
+ * below:
+ *
+ * [NullPointerException] if the name of the process is NULL or if the
+ * name of the host is NULL.
+ * [HostNotFoundException] if the host is not found.
+ */
+ Process(const char* hostName, const char* name)
+ throw(NullPointerException, HostNotFoundException, BadAllocException);
+
+ /*! \brief Constructs a process from a reference to an host object and its name.
+ *
+ * \param rHost A reference to the host object representing the native
+ * MSG host where to create the process.
+ * \param name The name of the process to create.
+ *
+ * \exception If the constructor failed, it throws the exception described
+ * below:
+ *
+ * [NullPointerException] if the name of process is NULL.
+ */
+ Process(const Host& rHost, const char* name)
+ throw(NullPointerException);
+
+ /*! brief Construct a proces from reference to an host object and the name of the process.
+ * This constuctor takes also the list of the arguments of the process.
+ *
+ * \param host A reference to the host where to create the process.
+ * \param name The name of the process to create.
+ * \param argc The number of the arguments of the process to create.
+ * \param argv The list of arguments of the process to create.
+ *
+ * \exception If the constructor failed, it throws one of the exceptions described
+ * below:
+ *
+ * [NullPointerException] if the name of the host is NULL or
+ * if the name of the process is NULL.
+ * [InvalidArgumentException] if the value of the parameter argv is
+ * negative.
+ * [LogicException] if the parameter argv is NULL and the
+ * parameter argc is different than zero
+ * if the parameter argv is not NULL and
+ * the parameter argc is zero.
+ */
+ Process(const Host& rHost, const char* name, int argc, char** argv)
+ throw(NullPointerException, InvalidArgumentException, LogicException);
+
+ /*! brief Constructs a proces from the name of a host and the name of the process.
+ * This constuctor takes also the list of the arguments of the process.
+ *
+ * \param hostName The name of the host where to create the process.
+ * \param name The name of the process to create.
+ * \param argc The number of the arguments of the process to create.
+ * \param argv The list of arguments of the process to create.
+ *
+ * \exception If the constructor failed, it throws one of the exceptions described
+ * below:
+ *
+ * [NullPointerException] if the name of the process or if the name
+ * of the host is NULL.
+ * [InvalidArgumentException] if the value of the parameter argv is
+ * negative.
+ * [LogicException] if the parameter argv is NULL and the
+ * parameter argc is different than zero
+ * if the parameter argv is not NULL and
+ * the parameter argc is zero.
+ * [HostNotFoundException] if the specified host is no found.
+ */
+ Process(const char* hostName, const char* name, int argc, char** argv)
+ throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException, BadAllocException);
+
+ /*! \brief Process::killAll() - kill all the running processes of the simulation.
+ *
+ * \param resetPID Should we reset the PID numbers. A negative number means no reset
+ * and a positive number will be used to set the PID of the next newly
+ * created process.
+ *
+ * \return The static method returns the PID of the next created process.
+ */
+ static int killAll(int resetPID);
+
+ /*! \brief Process::suspend() - Suspend an MSG process.
+ *
+ * \excetpion If this method failed, it throws one the exception described below:
+ *
+ * [MsgException] if an internal exception occurs during the operation.
+ */
+ void suspend(void)
+ throw(MsgException);
+
+
+
+ /*! \brief Process::resume() - Resume the MSG process.
+ *
+ * \exception If this method failed, it throws the exception described below:
+ *
+ * [MsgException] if an internal exception occurs during the operation.
+ */
+ void resume(void)
+ throw(MsgException);
+
+ /*! \brief Process::isSuspend() - Tests if a process is suspended.
+ *
+ * \return This method returns 1 is the process is suspended.
+ * Otherwise the method returns 0.
+ */
+ int isSuspended(void);
+
+ /*! \brief Process::getHost() - Retrieves the host of a process object.
+ *
+ * \return The method returns a reference to the
+ * host of the process.
+ *
+ */
+ Host& getHost(void);
+
+ /*! \brief Process::fromPID() - Retrieves a process from its PID.
+ *
+ * \param PID The PID of the process to retrieve.
+ *
+ * \return If successful the method returns a reference to
+ * to process. Otherwise, the method throws one of
+ * the exceptions described below:
+ *
+ * \exception [ProcessNotFoundException] if the process is not found (no process with this PID).
+ *
+ * [InvalidArgumentException] if the parameter PID is less than 1.
+ *
+ * [MsgException] if a native error occurs during the operation.
+ */
+ static Process& fromPID(int PID)
+ throw(ProcessNotFoundException, InvalidArgumentException, MsgException);
+
+ /*! \brief Process::getPID() - Gets the PID of a process object.
+ *
+ * \return This method returns the PID of a process object.
+ */
+ int getPID(void);
+
+ /*! \brief Process::getPPID() - Gets the parent PID of a process object.
+ *
+ * \return This method returns the parent PID of a process object.
+ */
+ int getPPID(void);
+
+ /*! \brief Process::getName() - Gets the name of a process object.
+ *
+ * \return This method returns the name of a process object.
+ */
+ const char* getName(void) const;
+
+ /*! \brief Process::currentProcess() - Retrieves the current process.
+ *
+ * \return This method returns a reference to the current process. Otherwise
+ * the method throws the excepction described below:
+ *
+ * \exception [MsgException] if an internal exception occurs.
+ */
+ static Process& currentProcess(void)
+ throw (MsgException);
+
+ /*! \brief Process::currentProcessPID() - Retrieves the PID of the current process.
+ *
+ * \return This method returns the PID of the current process.
+ */
+ static int currentProcessPID(void);
+
+ /*! \brief Process::currentProcessPPID() - Retrieves the parent PID of the current process.
+ *
+ * \return This method returns the parent PID of the current process.
+ */
+ static int currentProcessPPID(void);
+
+ /*! \brief Process::migrate() - Migrate a process object to an another host.
+ *
+ * \param rHost A reference to the host to migrate the process to.
+ *
+ * \return If successful the method migrate the process to the specified
+ * host. Otherwise the method throws the exception described
+ * below:
+ *
+ * \exception [MsgException] if an internal exception occurs.
+ */
+ void migrate(const Host& rHost)
+ throw(MsgException);
+
+ /*! \brief Process::sleep() - Makes the current process sleep until time seconds have elapsed.
+ *
+ * \param seconds The number of seconds to sleep.
+ *
+ * \execption If this method failed, it throws one of the exceptions described
+ * below:
+ *
+ * [InvalidArgumentException] if the parameter seconds is
+ * less or equals to zero.
+ *
+ * [MsgException] if an internal exception occurs.
+ */
+ static void sleep(double seconds)
+ throw(InvalidArgumentException, MsgException);
+
+ /*! \brief Process::putTask() - This method puts a task on a given channel of a given host.
+ *
+ * \exception If this method failed, it throws one of the exceptions described
+ * below:
+ *
+ * [InvalidArgumentException] if the channel number is negative.
+ *
+ * [MsgException] if an internal exception occurs.
+ */
+ void putTask(const Host& rHost, int channel, Task* task)
+ throw(InvalidArgumentException, MsgException);
+
+ /*! \brief Process::putTask() - This method puts a task on a given channel of a given host (waiting at most given time).
+ *
+ * \exception If this method failed, it throws one of the exceptions described below:
+ *
+ * [MsgException] if an internal error occurs.
+ *
+ * [InvalidArgumentException] if the value of the channel specified as
+ * parameter is negative or if the timeout value
+ * is less than zero and différent of -1.
+ *
+ * \remark Set the timeout with -1.0 to disable it.
+ */
+ void putTask(const Host& rHost, int channel, Task* task, double timeout)
+ throw(InvalidArgumentException, MsgException);
+
+ /*! \brief Process::getTask() - Retrieves a task from a channel number (waiting at most given time).
+ *
+ * \param channel The number of the channel where to get the task.
+ *
+ * \return If successful the method returns a reference to
+ * the getted task. Otherwise the method throws one
+ * of the exceptions described below:
+ *
+ * \exception [InvalidArgumentException] if the channel number is negative.
+ *
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* getTask(int channel)
+ throw(InvalidArgumentException, MsgException);
+
+ /*! \brief Process::taskGet() - Retrieves a task from a channel number (waiting at most given time).
+ *
+ * \param channel The number of the channel where to get the task.
+ * \param timeout The timeout value.
+ *
+ * \return If successful the method returns a reference to
+ * the getted task. Otherwise the method throws one
+ * of the exceptions described below:
+ *
+ * \exception [InvalidArgumentException] if the channel number is negative
+ * or if the timeout value is less than
+ * zero and different of -1.0.
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* getTask(int channel, double timeout)
+ throw(InvalidArgumentException, MsgException);
+
+ /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host.
+ *
+ * \param channel The number of the channel where to get the task.
+ * \param host The host of the channel to get the task.
+ *
+ * \return If successful the method returns a reference to
+ * the getted task. Otherwise the method throws one
+ * of the exceptions described below.
+ *
+ * \exception [InvalidArgumentException] if the channel number is negative.
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* getTask(int channel, const Host& rHost)
+ throw(InvalidArgumentException, MsgException);
+
+ /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host (waiting at most given time).
+ *
+ * \param channel The number of the channel where to get the task.
+ * \param timeout The timeout value.
+ * \param rHost The host owning the channel.
+ *
+ * \return If successful the method returns a reference to
+ * the getted task. Otherwise the method throws one
+ * of the exceptions described below:
+ *
+ * \exception [InvalidArgumentException] if the channel number is negative or
+ * if the timeout value is negative and different
+ * of -1.0.
+ * [MsgException] if an internal exception occurs.
+ *
+ * \remark Set the timeout with -1.0 to disable it.
+ */
+ Task* getTask(int channel, double timeout, const Host& rHost)
+ throw(InvalidArgumentException, MsgException);
+
+ /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias
+ * (waiting at most given time).
+ *
+ * \param alias The alias of the mailbox where to send the task.
+ * \param rTask A reference to the task object to send.
+ * \param timeout The timeout value.
+ *
+ * \exception If this method failed, it throws one of the exceptions described below:
+ *
+ * [NullPointerException] if the alias specified as parameter is NULL.
+ *
+ * [InvalidArgumentException] if the timeout value is negative and different than
+ * -1.0
+ * [MsgException] if an internal exception occurs.
+ *
+ * \remark Set the timeout with -1.0 to disable it.
+ */
+ void sendTask(const char* alias, Task* task, double timeout)
+ throw(NullPointerException, InvalidArgumentException, MsgException);
+
+ /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias.
+ *
+ * \param alias The alias of the mailbox where to send the task.
+ * \param rTask A reference to the task object to send.
+ *
+ * \exception If this method failed, it throws one of the exceptions described below:
+ *
+ * [NullPointerException] if the alias parameter is NULL.
+ *
+ * [MsgException] if an internal exception occurs.
+ *
+ */
+ void sendTask(const char* alias, Task* task)
+ throw(NullPointerException, MsgException);
+
+ /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias.
+ *
+ * \param rTask A reference to the task object to send.
+ *
+ * \exception If this method failed, it throws one of the exceptions described below:
+ *
+ * [BadAllocException] if there is not enough memory to build the default alias.
+ *
+ * [MsgException] if an internal exception occurs.
+ *
+ */
+ void sendTask(Task* task)
+ throw(BadAllocException, MsgException);
+
+ /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias
+ * (waiting at most given time).
+ *
+ * \param rTask A reference to the task object to send.
+ * \param timeout The timeout value.
+ *
+ * \exception If this method failed, it throws one of the exceptions described below:
+ *
+ * [BadAllocException] if there is not enough memory to build the default alias.
+ *
+ * [InvalidArgumentException] if the timeout value is negative and different than -1.0.
+ *
+ * [MsgException] if an internal exception occurs.
+ *
+ * \remark set the timeout value with -1.0 to disable it.
+ */
+ void sendTask(Task* task, double timeout)
+ throw(BadAllocException, InvalidArgumentException, MsgException);
+
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as
+ * parameter.
+ *
+ * \param alias The alias of the mailbox where to retrieve the task.
+ *
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
+ * throws one of the exceptions described below:
+ *
+ * \exception [NullPointerException] if the parameter alias is NULL.
+ *
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* receiveTask(const char* alias)
+ throw(NullPointerException, MsgException);
+
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias.
+ *
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
+ * throws one of the exceptions described below:
+ *
+ * \exception [BadAllocException] if there is not enough memory to build the alias.
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* receiveTask(void)
+ throw(BadAllocException, MsgException);
+
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as
+ * parameter(waiting at most given time).
+ *
+ * \param alias The alias of the mailbox where to retrieve the task.
+ * \param timeout The timeout value.
+ *
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
+ * throws one of the exceptions described below.
+ *
+ * \exception [InvalidArgumentException] if the timeout value is negative or different of -1.0.
+ *
+ * [NullPointerException] if the parameter alias is NULL.
+ *
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* receiveTask(const char* alias, double timeout)
+ throw(NullPointerException, InvalidArgumentException, MsgException);
+
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias
+ * (waiting at most given time).
+ *
+ * \param timeout The timeout value.
+ *
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
+ * throws one of the exceptions described below:
+ *
+ * \exception [InvalidArgumentException] if the timeout value is negative or different than -1.0.
+ *
+ * [BadAllocException] if there is not enough memory to build the alias.
+ *
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* receiveTask(double timeout)
+ throw(InvalidArgumentException, BadAllocException, MsgException);
+
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as
+ * parameter located on a given host (waiting at most given time).
+ *
+ * \param alias The alias of the mailbox where to retrieve the task.
+ * \param timeout The timeout value.
+ * \param rHost A reference to the host object owning the mailbox.
+ *
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
+ * throws one of the exceptions described below:
+ *
+ * \exception [InvalidArgumentException] if the timeout value is negative or different of -1.0.
+ *
+ * [NullPointerException] if the parameter alias is NULL.
+ *
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* receiveTask(const char* alias, double timeout, const Host& rHost)
+ throw(NullPointerException, InvalidArgumentException, MsgException);
+
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias
+ * and located on a given host (waiting at most given time).
+ *
+ * \param timeout The timeout value.
+ * \param rHost A reference to the host object owning the mailbox.
+ *
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
+ * throws one of the exceptions described below:
+ *
+ * \exception [InvalidArgumentException] if the timeout value is negative and different than -1.0.
+ *
+ * [BadAllocException] if there is not enough memory to build the default alias.
+ *
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* receiveTask(double timeout, const Host& rHost)
+ throw(BadAllocException, InvalidArgumentException, MsgException);
+
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias
+ * specified as parameter and located on a given host.
+ *
+ * \param alias The alias using to identify the mailbox from which to get the task.
+ * \param rHost A reference to the host object owning the mailbox.
+ *
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
+ * throws one of the exceptions described below:
+ *
+ * \exception [NullPointerException] if the parameter alias is NULL.
+ *
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* receiveTask(const char* alias, const Host& rHost)
+ throw(NullPointerException, MsgException);
+
+ /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias
+ * and located on a given host.
+ *
+ * \param rHost A reference to the host object owning the mailbox.
+ *
+ * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
+ * throws one of the exceptions described below:
+ *
+ * \exception [BadAllocException] if there is not enough memory to build the alias.
+ *
+ * [MsgException] if an internal exception occurs.
+ */
+ Task* receiveTask(const Host& rHost)
+ throw(BadAllocException, MsgException);
+
+
+ private:
+
+ /* Process::create() - Creates a process on a given host.
+ *
+ * param rHost A reference to a host object where to create the process.
+ * param name The name of the process to create.
+ * param argc The number of argument to pass to the main function of the process.
+ * param argv The list of the arguments of the main function of the process.
+ *
+ * exception If this method failed, it throws one of the exceptions described below:
+ *
+ * [HostNotFoundException] if the host specified as parameter doesn't exist.
+ */
+ void create(const Host& rHost, const char* name, int argc, char** argv)
+ throw(InvalidArgumentException);
+
+ /* Process::fromNativeProcess() - Retrieves the process wrapper associated with a native process.
+ *
+ * \param nativeProcess The native process to get the wrapper.
+ *
+ * \return The wrapper associated with the native process specified as parameter.
+ */
+ static Process* fromNativeProcess(m_process_t nativeProcess);
+
+
+ public:
+
+ /* Process::run() - used to set the field code of the context of the process.
+ */
+ static int run(int argc, char** argv);
+
+ /*! \brief Process::main() - This virtual pure function is the main function of the process.
+ * You must override this function for each new class of process that you create.
+ *
+ * \param argc The number of parameters of the main function.
+ * \param argv The list of the parameter of the main function.
+ *
+ * \return The exit code of the main function.
+ */
+ virtual int main(int argc, char** argv);
+
+ // Operators.
+
+ /*
+ // Override the operator new().
+ void* operator new(size_t size);
+
+ // Override the operator delete().
+ void operator delete(void* p);
+ */
+
+ private:
+
+ // Attributes.
+
+ m_process_t nativeProcess; // pointer to the native msg process.
+
+ };
+
+ } //namepace Msg
+
+} // namespace SimGrid
+
+#endif // !MSG_PROCESS_HPP
+