4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
\r
5 * All right reserved.
\r
7 * This program is free software; you can redistribute
\r
8 * it and/or modify it under the terms of the license
\r
9 *(GNU LGPL) which comes with this package.
\r
13 #ifndef MSG_PROCESS_HPP
\r
14 #define MSG_PROCESS_HPP
\r
16 // Compilation C++ recquise
\r
18 #error Process.hpp requires C++ compilation (use a .cxx suffix)
\r
26 // SimGrid::Msg::Process class declaration.
\r
29 friend ApplicationHandler;
\r
33 // Disable the default constructor.
\r
38 /*! \brief Constructs a process from the name of the host and its name.
\r
40 * \param hostName The host name of the process to create.
\r
41 * \param name The name of the process to create.
\r
43 * \exception If the constructor failed, it throws one of the exceptions described
\r
46 * [NullPointerException] if the name of the process is NULL or if the
\r
47 * name of the host is NULL.
\r
48 * [HostNotFoundException] if the host is not found.
\r
50 Process(const char* hostName, const char* name)
\r
51 throw(NullPointerException, HostNotFoundException);
\r
53 /*! \brief Constructs a process from a reference to an host object and its name.
\r
55 * \param rHost A reference to the host object representing the native
\r
56 * MSG host where to create the process.
\r
57 * \param name The name of the process to create.
\r
59 * \exception If the constructor failed, it throws the exception described
\r
62 * [NullPointerException] if the name of process is NULL.
\r
64 Process(const Host& rHost, const char* name)
\r
65 throw(NullPointerException);
\r
67 /*! brief Construct a proces from reference to an host object and the name of the process.
\r
68 * This constuctor takes also the list of the arguments of the process.
\r
70 * \param host A reference to the host where to create the process.
\r
71 * \param name The name of the process to create.
\r
72 * \param argc The number of the arguments of the process to create.
\r
73 * \param argv The list of arguments of the process to create.
\r
75 * \exception If the constructor failed, it throws one of the exceptions described
\r
78 * [NullPointerException] if the name of the host is NULL or
\r
79 * if the name of the process is NULL.
\r
80 * [InvalidArgumentException] if the value of the parameter argv is
\r
82 * [LogicException] if the parameter argv is NULL and the
\r
83 * parameter argc is different than zero
\r
84 * if the parameter argv is not NULL and
\r
85 * the parameter argc is zero.
\r
87 Process(const Host& rHost, const char* name, int argc, char** argv)
\r
88 throw(NullPointerException, InvalidArgumentException, LogicException);
\r
90 /*! brief Constructs a proces from the name of a host and the name of the process.
\r
91 * This constuctor takes also the list of the arguments of the process.
\r
93 * \param hostName The name of the host where to create the process.
\r
94 * \param name The name of the process to create.
\r
95 * \param argc The number of the arguments of the process to create.
\r
96 * \param argv The list of arguments of the process to create.
\r
98 * \exception If the constructor failed, it throws one of the exceptions described
\r
101 * [NullPointerException] if the name of the process or if the name
\r
102 * of the host is NULL.
\r
103 * [InvalidArgumentException] if the value of the parameter argv is
\r
105 * [LogicException] if the parameter argv is NULL and the
\r
106 * parameter argc is different than zero
\r
107 * if the parameter argv is not NULL and
\r
108 * the parameter argc is zero.
\r
109 * [HostNotFoundException] if the specified host is no found.
\r
111 Process(const char* hostName, const char* name, int argc, char** argv)
\r
112 throw(NullPointerException, HostNotFoundException);
\r
114 /*! \brief Process::killAll() - kill all the running processes of the simulation.
\r
116 * \param resetPID Should we reset the PID numbers. A negative number means no reset
\r
117 * and a positive number will be used to set the PID of the next newly
\r
120 * \return The static method returns the PID of the next created process.
\r
122 static int killAll(int resetPID);
\r
124 /*! \brief Process::suspend() - Suspend an MSG process.
\r
126 * \excetpion If this method failed, it throws one the exception described below:
\r
128 * [MsgException] if an internal exception occurs during the operation.
\r
131 throw(MsgException);
\r
135 /*! \brief Process::resume() - Resume the MSG process.
\r
137 * \exception If this method failed, it throws the exception described below:
\r
139 * [MsgException] if an internal exception occurs during the operation.
\r
142 throw(MsgException);
\r
144 /*! \brief Process::isSuspend() - Tests if a process is suspended.
\r
146 * \return This method returns true is the process is suspended.
\r
147 * Otherwise the method returns false.
\r
149 bool isSuspended(void);
\r
151 /*! \brief Process::getHost() - Retrieves the host of a process object.
\r
153 * \return The method returns a reference to the
\r
154 * host of the process.
\r
157 Host& getHost(void);
\r
159 /*! \brief Process::fromPID() - Retrieves a process from its PID.
\r
161 * \param PID The PID of the process to retrieve.
\r
163 * \return If successful the method returns a reference to
\r
164 * to process. Otherwise, the method throws one of
\r
165 * the exceptions described below:
\r
167 * \exception [ProcessNotFoundException] if the process is not found (no process with this PID).
\r
169 * [InvalidArgumentException] if the parameter PID is less than 1.
\r
171 * [MsgException] if a native error occurs during the operation.
\r
173 static Process& fromPID(int PID)
\r
174 throw(ProcessNotFoundException, InvalidArgumentException, MsgException);
\r
176 /*! \brief Process::getPID() - Gets the PID of a process object.
\r
178 * \return This method returns the PID of a process object.
\r
182 /*! \brief Process::getPPID() - Gets the parent PID of a process object.
\r
184 * \return This method returns the parent PID of a process object.
\r
188 /*! \brief Process::getName() - Gets the name of a process object.
\r
190 * \return This method returns the name of a process object.
\r
192 const char* getName(void) const;
\r
194 /*! \brief Process::currentProcess() - Retrieves the current process.
\r
196 * \return This method returns a reference to the current process. Otherwise
\r
197 * the method throws the excepction described below:
\r
199 * \exception [MsgException] if an internal exception occurs.
\r
201 static Process& currentProcess(void)
\r
202 throw (MsgException);
\r
204 /*! \brief Process::currentProcessPID() - Retrieves the PID of the current process.
\r
206 * \return This method returns the PID of the current process.
\r
208 static int currentProcessPID(void);
\r
210 /*! \brief Process::currentProcessPPID() - Retrieves the parent PID of the current process.
\r
212 * \return This method returns the parent PID of the current process.
\r
214 static int currentProcessPPID(void);
\r
216 /*! \brief Process::migrate() - Migrate a process object to an another host.
\r
218 * \param rHost A reference to the host to migrate the process to.
\r
220 * \return If successful the method migrate the process to the specified
\r
221 * host. Otherwise the method throws the exception described
\r
224 * \exception [MsgException] if an internal exception occurs.
\r
226 void migrate(const Host& rHost)
\r
227 throw(MsgException);
\r
229 /*! \brief Process::sleep() - Makes the current process sleep until time seconds have elapsed.
\r
231 * \param seconds The number of seconds to sleep.
\r
233 * \execption If this method failed, it throws one of the exceptions described
\r
236 * [InvalidArgumentException] if the parameter seconds is
\r
237 * less or equals to zero.
\r
239 * [MsgException] if an internal exception occurs.
\r
241 static void sleep(double seconds)
\r
242 throw(InvalidArgumentException, MsgException);
\r
244 /*! \brief Process::putTask() - This method puts a task on a given channel of a given host.
\r
246 * \exception If this method failed, it throws one of the exceptions described
\r
249 * [InvalidArgumentException] if the channel number is negative.
\r
251 * [MsgException] if an internal exception occurs.
\r
253 void putTask(const Host& rHost, int channel, const Task& rTask)
\r
254 throw(InvalidArgumentException, MsgException);
\r
256 /*! \brief Process::putTask() - This method puts a task on a given channel of a given host (waiting at most given time).
\r
258 * \exception If this method failed, it throws one of the exceptions described below:
\r
260 * [MsgException] if an internal error occurs.
\r
262 * [InvalidArgumentException] if the value of the channel specified as
\r
263 * parameter is negative or if the timeout value
\r
264 * is less than zero and différent of -1.
\r
266 * \remark Set the timeout with -1.0 to disable it.
\r
268 void putTask(const Host& rHost, int channel, const Task& rTask, double timeout)
\r
269 throw(InvalidArgumentException, MsgException);
\r
271 /*! \brief Process::getTask() - Retrieves a task from a channel number (waiting at most given time).
\r
273 * \param channel The number of the channel where to get the task.
\r
275 * \return If successful the method returns a reference to
\r
276 * the getted task. Otherwise the method throws one
\r
277 * of the exceptions described below:
\r
279 * \exception [InvalidArgumentException] if the channel number is negative.
\r
281 * [MsgException] if an internal exception occurs.
\r
283 Task& getTask(int channel)
\r
284 throw(InvalidArgumentException, MsgException);
\r
286 /*! \brief Process::taskGet() - Retrieves a task from a channel number (waiting at most given time).
\r
288 * \param channel The number of the channel where to get the task.
\r
289 * \param timeout The timeout value.
\r
291 * \return If successful the method returns a reference to
\r
292 * the getted task. Otherwise the method throws one
\r
293 * of the exceptions described below:
\r
295 * \exception [InvalidArgumentException] if the channel number is negative
\r
296 * or if the timeout value is less than
\r
297 * zero and different of -1.0.
\r
298 * [MsgException] if an internal exception occurs.
\r
300 Task& getTask(int channel, double timeout)
\r
301 throw(InvalidArgumentException, MsgException);
\r
303 /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host.
\r
305 * \param channel The number of the channel where to get the task.
\r
306 * \param host The host of the channel to get the task.
\r
308 * \return If successful the method returns a reference to
\r
309 * the getted task. Otherwise the method throws one
\r
310 * of the exceptions described below.
\r
312 * \exception [InvalidArgumentException] if the channel number is negative.
\r
313 * [MsgException] if an internal exception occurs.
\r
315 Task& getTask(int channel, const Host& rHost)
\r
316 throw(InvalidArgumentException, MsgException);
\r
318 /*! \brief Process::taskGet() - Retrieves a task from a channel number and a host (waiting at most given time).
\r
320 * \param channel The number of the channel where to get the task.
\r
321 * \param timeout The timeout value.
\r
322 * \param rHost The host owning the channel.
\r
324 * \return If successful the method returns a reference to
\r
325 * the getted task. Otherwise the method throws one
\r
326 * of the exceptions described below:
\r
328 * \exception [InvalidArgumentException] if the channel number is negative or
\r
329 * if the timeout value is negative and different
\r
331 * [MsgException] if an internal exception occurs.
\r
333 * \remark Set the timeout with -1.0 to disable it.
\r
335 Task& getTask(int channel, double timeout, const Host& rHost)
\r
336 throw(InvalidArgumentException MsgException);
\r
338 /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias
\r
339 * (waiting at most given time).
\r
341 * \param alias The alias of the mailbox where to send the task.
\r
342 * \param rTask A reference to the task object to send.
\r
343 * \param timeout The timeout value.
\r
345 * \exception If this method failed, it throws one of the exceptions described below:
\r
347 * [NullPointerException] if the alias specified as parameter is NULL.
\r
349 * [InvalidArgumentException] if the timeout value is negative and different than
\r
351 * [MsgException] if an internal exception occurs.
\r
353 * \remark Set the timeout with -1.0 to disable it.
\r
355 void sendTask(const char* alias, const Task& rTask, double timeout)
\r
356 throw(NullPointerException, InvalidArgumentException, MsgException);
\r
358 /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the specified alias.
\r
360 * \param alias The alias of the mailbox where to send the task.
\r
361 * \param rTask A reference to the task object to send.
\r
363 * \exception If this method failed, it throws one of the exceptions described below:
\r
365 * [NullPointerException] if the alias parameter is NULL.
\r
367 * [MsgException] if an internal exception occurs.
\r
370 void sendTask(const char* alias, const Task& rTask)
\r
371 throw(NullPointerException, MsgException);
\r
373 /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias.
\r
375 * \param rTask A reference to the task object to send.
\r
377 * \exception If this method failed, it throws one of the exceptions described below:
\r
379 * [BadAllocException] if there is not enough memory to build the default alias.
\r
381 * [MsgException] if an internal exception occurs.
\r
384 void sendTask(const Task& rTask)
\r
385 throw(BadAllocException, MsgException);
\r
387 /*! \brief Process::sendTask() - Sends the given task in the mailbox identified by the default alias
\r
388 * (waiting at most given time).
\r
390 * \param rTask A reference to the task object to send.
\r
391 * \param timeout The timeout value.
\r
393 * \exception If this method failed, it throws one of the exceptions described below:
\r
395 * [BadAllocException] if there is not enough memory to build the default alias.
\r
397 * [InvalidArgumentException] if the timeout value is negative and different than -1.0.
\r
399 * [MsgException] if an internal exception occurs.
\r
401 * \remark set the timeout value with -1.0 to disable it.
\r
403 void sendTask(const Task& rTask, double timeout)
\r
404 throw(BadAllocException, InvalidArgumentException, MsgException);
\r
406 /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as
\r
409 * \param alias The alias of the mailbox where to retrieve the task.
\r
411 * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
\r
412 * throws one of the exceptions described below:
\r
414 * \exception [NullPointerException] if the parameter alias is NULL.
\r
416 * [MsgException] if an internal exception occurs.
\r
418 Task& receiveTask(const char* alias)
\r
419 throw(NullPointerException, MsgException);
\r
421 /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias.
\r
423 * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
\r
424 * throws one of the exceptions described below:
\r
426 * \exception [BadAllocException] if there is not enough memory to build the alias.
\r
427 * [MsgException] if an internal exception occurs.
\r
429 Task& receiveTask(void)
\r
430 throw(BadAllocException, MsgException);
\r
432 /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as
\r
433 * parameter(waiting at most given time).
\r
435 * \param alias The alias of the mailbox where to retrieve the task.
\r
436 * \param timeout The timeout value.
\r
438 * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
\r
439 * throws one of the exceptions described below.
\r
441 * \exception [InvalidArgumentException] if the timeout value is negative or different of -1.0.
\r
443 * [NullPointerException] if the parameter alias is NULL.
\r
445 * [MsgException] if an internal exception occurs.
\r
447 Task& receiveTask(const char* alias, double timeout)
\r
448 throw(NullPointerException, InvalidArgumentException, MsgException);
\r
450 /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the default alias
\r
451 * (waiting at most given time).
\r
453 * \param timeout The timeout value.
\r
455 * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
\r
456 * throws one of the exceptions described below:
\r
458 * \exception [InvalidArgumentException] if the timeout value is negative or different than -1.0.
\r
460 * [BadAllocException] if there is not enough memory to build the alias.
\r
462 * [MsgException] if an internal exception occurs.
\r
464 Task& receiveTask(double timeout)
\r
465 throw(InvalidArgumentException, BadAllocException, MsgException);
\r
467 /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias specified as
\r
468 * parameter located on a given host (waiting at most given time).
\r
470 * \param alias The alias of the mailbox where to retrieve the task.
\r
471 * \param timeout The timeout value.
\r
472 * \param rHost A reference to the host object owning the mailbox.
\r
474 * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
\r
475 * throws one of the exceptions described below:
\r
477 * \exception [InvalidArgumentException] if the timeout value is negative or different of -1.0.
\r
479 * [NullPointerException] if the parameter alias is NULL.
\r
481 * [MsgException] if an internal exception occurs.
\r
483 Task& receiveTask(const char* alias, double timeout, const Host& rHost)
\r
484 throw(NullPointerException, InvalidArgumentException, MsgException);
\r
486 /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias
\r
487 * and located on a given host (waiting at most given time).
\r
489 * \param timeout The timeout value.
\r
490 * \param rHost A reference to the host object owning the mailbox.
\r
492 * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
\r
493 * throws one of the exceptions described below:
\r
495 * \exception [InvalidArgumentException] if the timeout value is negative and different than -1.0.
\r
497 * [BadAllocException] if there is not enough memory to build the default alias.
\r
499 * [MsgException] if an internal exception occurs.
\r
501 Task& Process::receiveTask(double timeout, const Host& rHost)
\r
502 throw(BadAllocException, InvalidArgumentException, MsgException);
\r
504 /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by the alias
\r
505 * specified as parameter and located on a given host.
\r
507 * \param alias The alias using to identify the mailbox from which to get the task.
\r
508 * \param rHost A reference to the host object owning the mailbox.
\r
510 * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
\r
511 * throws one of the exceptions described below:
\r
513 * \exception [NullPointerException] if the parameter alias is NULL.
\r
515 * [MsgException] if an internal exception occurs.
\r
517 Task& receiveTask(const char* alias, const Host& rHost)
\r
518 throw(NullPointerException, MsgException);
\r
520 /*! \brief Process::receiveTask() - Retrieves a task from the mailbox identified by default alias
\r
521 * and located on a given host.
\r
523 * \param rHost A reference to the host object owning the mailbox.
\r
525 * \return If succcessful, the method returns a task of the mailbox. Otherwise, the method
\r
526 * throws one of the exceptions described below:
\r
528 * \exception [BadAllocException] if there is not enough memory to build the alias.
\r
530 * [MsgException] if an internal exception occurs.
\r
532 Task& receiveTask(const Host& rHost)
\r
533 throw(BadAllocException, MsgException);
\r
538 /* Process::create() - Creates a process on a given host.
\r
540 * param rHost A reference to a host object where to create the process.
\r
541 * param name The name of the process to create.
\r
542 * param argc The number of argument to pass to the main function of the process.
\r
543 * param argv The list of the arguments of the main function of the process.
\r
545 * exception If this method failed, it throws one of the exceptions described below:
\r
547 * [HostNotFoundException] if the host specified as parameter doesn't exist.
\r
549 void create(const Host& rHost, const char* name, int argc, char** argv)
\r
550 throw(HostNotFoundException);
\r
552 /* Process::fromNativeProcess() - Retrieves the process wrapper associated with a native process.
\r
554 * \param nativeProcess The native process to get the wrapper.
\r
556 * \return The wrapper associated with the native process specified as parameter.
\r
558 static Process& fromNativeProcess(m_process_t nativeProcess);
\r
563 /* Process::run() - used to set the field code of the context of the process.
\r
565 static int run(int argc, char** argv);
\r
567 /*! \brief Process::main() - This virtual pure function is the main function of the process.
\r
568 * You must override this function for each new class of process that you create.
\r
570 * \param argc The number of parameters of the main function.
\r
571 * \param argv The list of the parameter of the main function.
\r
573 * \return The exit code of the main function.
\r
575 virtual int main(int argc, char** argv) = 0;
\r
581 m_process_t nativeProcess; // pointer to the native msg process.
\r