Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A string utility class and a new Exception (used to throw out of band exception)
[simgrid.git] / src / cxx / Task.hpp
1 /*\r
2  * Task.hpp\r
3  *\r
4  * This file contains the declaration of the wrapper class of the native MSG task type.\r
5  *\r
6  * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
7  * All right reserved. \r
8  *\r
9  * This program is free software; you can redistribute \r
10  * it and/or modify it under the terms of the license \r
11  *(GNU LGPL) which comes with this package. \r
12  *\r
13  */  \r
14  \r
15 #ifndef MSG_TASK_HPP\r
16 #define MSG_TASK_HPP\r
17 \r
18 // Compilation C++ recquise\r
19 #ifndef __cplusplus\r
20         #error Task.hpp requires C++ compilation (use a .cxx suffix)\r
21 #endif\r
22 \r
23 #include <msg/datatypes.h>\r
24 \r
25 #include <MsgException.hpp>\r
26 #include <InvalidArgumentException.hpp>\r
27 #include <NullPointerException.hpp>\r
28 #include <MsgException.hpp>\r
29 #include <BadAllocException.hpp>\r
30 \r
31 #include <Object.hpp>\r
32 \r
33 namespace SimGrid\r
34 {\r
35         namespace Msg\r
36         {\r
37                 class Process;\r
38                 class Host;\r
39 \r
40                 // SimGrid::Msg::Task wrapper class declaration.\r
41                 class SIMGRIDX_EXPORT Task : public Object\r
42                 {\r
43                         MSG_DECLARE_DYNAMIC(Task);\r
44 \r
45                         friend class Process;\r
46                         friend class Host;\r
47 \r
48                         protected:\r
49                                 // Default constructor.\r
50                                 Task();\r
51                                 \r
52                         public:\r
53                                 /*! \brief Copy constructor.\r
54                                  */\r
55                                 Task(const Task& rTask);\r
56                                 \r
57                                 /*! \brief Destructor.\r
58                                  *\r
59                                  * \exception                           If the destructor failed, it throw the exception described below:\r
60                                  *\r
61                                  *                                                      [MsgException]                          if a native exception occurs.\r
62                                  */\r
63                                 virtual ~Task()\r
64                                 throw(MsgException);\r
65                                 \r
66                                 /*! \brief Constructs an new task with the specified processing amount and amount\r
67                                  * of data needed.\r
68                                  *\r
69                                  * \param name                          Task's name\r
70                                  * \param computeDuration       A value of the processing amount (in flop) needed to process the task. \r
71                                  *                                                      If 0, then it cannot be executed with the execute() method.\r
72                                  *                                                      This value has to be >= 0.\r
73                                  * \param messageSize           A value of amount of data (in bytes) needed to transfert this task.\r
74                                  *                                                      If 0, then it cannot be transfered with the get() and put() methods.\r
75                                  *                                                      This value has to be >= 0.\r
76                                  *\r
77                                  * \exception                           If this method failed, it throws one of the exceptions described below:\r
78                                  *\r
79                                  *                                                      [InvalidArgumentException]      if the parameter computeDuration or messageSize\r
80                                  *                                                                                                              is negative.\r
81                                  *                                                      [NullPointerException]          if the parameter name is NULL.\r
82                                  *\r
83                                  *                                                      [MsgException]                          if a internal exception occurs.\r
84                                  */\r
85                                 Task(const char* name, double computeDuration, double messageSize)\r
86                                 throw (InvalidArgumentException, NullPointerException);\r
87                                 \r
88                                 /*! \Constructs an new parallel task with the specified processing amount and amount for each host\r
89                              * implied.\r
90                              *\r
91                              * \param name                              The name of the parallel task.\r
92                              * \param hosts                             The list of hosts implied by the parallel task.\r
93                              * \param computeDurations  The amount of operations to be performed by each host of \a hosts.\r
94                              * \param messageSizes              A matrix describing the amount of data to exchange between hosts.\r
95                              * \hostCount                               The number of hosts implied in the parallel task.\r
96                              * \r
97                              * \exception                               If this method fails, it throws one of the exceptions described below:\r
98                              *\r
99                              *                                                  [NullPointerException]          if the parameter name is NULL or\r
100                              *                                                                                                          if the parameter computeDurations is NULL or\r
101                              *                                                                                                          if the parameter messageSizes is NULL\r
102                              *\r
103                              *                                                  [InvalidArgumentException]      if the parameter hostCount is negative or zero.                                                 \r
104                              */\r
105                                 Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes, int hostCount)\r
106                                 throw(NullPointerException, InvalidArgumentException);\r
107                         \r
108                         \r
109                                 /*! \brief Task::getName() - Gets the names of the task.\r
110                                  *\r
111                                  * \return                                      The name of the task.\r
112                                  */\r
113                                 const char* getName(void) const;\r
114                         \r
115                                 /*! \brief Task::getSender() - Gets the sender of the task.\r
116                                  *\r
117                                  * \return                                      A reference to the sender of the task.\r
118                                  */\r
119                                 Process& getSender(void) const;\r
120                                 \r
121                                 /*! \brief Task::getSource() - Gets the source of the task.\r
122                                  * \r
123                                  * \return                                      A reference to the source of the task.\r
124                                  */\r
125                                 Host& getSource(void) const;\r
126                                 \r
127                                 /*! \brief Task::getComputeDuration() - Get the computing amount of the task.\r
128                                  *\r
129                                  * \return                                      The computing amount of the task.\r
130                                  */\r
131                         \r
132                                 double getComputeDuration(void) const;\r
133                                 \r
134                                 /*! \brief Task::getRemainingDuration() - Gets the remaining computation.\r
135                                  *\r
136                                  * \return                                      The remining computation of the task.\r
137                                  */\r
138                                 double getRemainingDuration(void) const;\r
139                         \r
140                                 /*! \brief Task::setPrirority() -  Sets the priority of the computation of the task.\r
141                          * The priority doesn't affect the transfert rate. For example a\r
142                          * priority of 2 will make the task receive two times more cpu than\r
143                          * the other ones.\r
144                          *\r
145                          * \param priority                      The new priority of the task.\r
146                          *\r
147                          * execption                            If this method fails, it throws the exception described below:\r
148                          *\r
149                          *                                                      [InvalidArgumentException]      if the parameter priority is negative.\r
150                          */\r
151                                 void setPriority(double priority)\r
152                                 throw(InvalidArgumentException);\r
153                                 \r
154                                 /*! \brief Task::get() - Gets a task from the specified channel of the host of the current process.\r
155                                  *\r
156                                  * \param channel                       The channel number to get the task.\r
157                                  *\r
158                                  * \return                                      If successful the method returns the task. Otherwise the method throws one\r
159                                  *                                                      of the exceptions described below:\r
160                                  *\r
161                                  * \exception                           [InvalidArgumentException]      if the channel parameter is negative.\r
162                                  *                                      \r
163                                  *                                                      [MsgException]                          if an internal excpetion occurs.\r
164                                  */\r
165                                 static Task* get(int channel) \r
166                                 throw(InvalidArgumentException, MsgException);\r
167 \r
168                                 /*! \brief      Task::get() - Gets a task from the given channel number of the given host.      \r
169                                  *\r
170                                  * \param channel                       The channel number.\r
171                                  * \param rHost                         A reference of the host owning the channel.\r
172                                  *\r
173                                  * \return                                      If successful, the method returns the task. Otherwise the method\r
174                                  *                                                      throw one of the exceptions described below:\r
175                                  *\r
176                                  * \exception                           [InvalidArgumentException]      if the channel number is negative.\r
177                                  *\r
178                                  *                                                      [MsgException]                          if an internal exception occurs.\r
179                                  */\r
180                                 static Task* get(int channel, const Host& rHost) \r
181                                 throw(InvalidArgumentException, MsgException);\r
182                                 \r
183                                 /*! \brief Task::get() - Gets a task from the specified channel of the specified host\r
184                                  *  (waiting at most given time).\r
185                                  *\r
186                                  * \param channel                       The channel number.\r
187                                  * \param timeout                       The timeout value.\r
188                                  * \param rHost                         A reference to the host owning the channel.\r
189                                  *\r
190                                  * \return                                      If successful, the method returns the task. Otherwise the method returns\r
191                                  *                                                      one of the exceptions described below:\r
192                                  *\r
193                                  * \exception                           [InvalidArgumentException]      if the channel number is negative or\r
194                                  *                                                                                                              if the timeout value is negative and \r
195                                  *                                                                                                              different than -1.0.\r
196                                  *                                                      [MsgException]                          if an internal exception occurs.\r
197                                  */\r
198                                 static Task* get(int channel, double timeout, const Host& rHost) \r
199                                 throw(InvalidArgumentException, MsgException);  \r
200                                 \r
201                                 /*! \brief Task::probe() - Probes whether there is a waiting task on the given channel of local host.\r
202                                  *\r
203                                  * \param channel                       The channel number.\r
204                                  *\r
205                                  * \return                                      If there is a waiting task on the channel the method returns 1. Otherwise\r
206                                  *                                                      the method returns 0.\r
207                                  *\r
208                                  * \exception                           If this method fails, it throws the exception described below:\r
209                                  *\r
210                                  *                                                      [InvalidArgumentException]      if the parameter channel is negative.\r
211                                  */\r
212                                 static int probe(int channel)\r
213                                 throw(InvalidArgumentException);\r
214                                 \r
215                                 /*! \brief Task::probe() - Counts tasks waiting on the given channel of local host and sent by given host.\r
216                                  *\r
217                                  * \param channel                       The channel id.\r
218                                  * \param rHost                         A reference to the host that has sent the task.\r
219                                  *\r
220                                  * \return                                      The number of tasks.\r
221                                  *\r
222                                  * \exception                           [InvalidArgumentException]      if the parameter channel is negative.\r
223                                  */\r
224                                 static int probe(int channel, const Host& rHost)\r
225                                 throw(InvalidArgumentException);\r
226                                 \r
227                                 /*! \brief Task::execute() - This method executes a task on the location on which the\r
228                                  * process is running.\r
229                                  *\r
230                                  * \exception                           If this method fails, it returns the exception described below:\r
231                                  *\r
232                                  *                                                      [MsgException]                          if an internal exception occurs.\r
233                                  */\r
234                                 void execute(void) \r
235                                 throw(MsgException);\r
236                                 \r
237                                 /*! \brief Task::cancel() - This method cancels a task.\r
238                                  *\r
239                                  * \exception                           If this method fails, it returns the exception described below:\r
240                                  *\r
241                                  *                                                      [MsgException]                          if an internal exception occurs.\r
242                                  */\r
243                                 void cancel(void) \r
244                                 throw(MsgException);\r
245                         \r
246                                 /*! \brief Task::send() - Send the task on the mailbox identified by the default alias.\r
247                                  *\r
248                                  * \exception                           If this method failed, it returns one of the exceptions described\r
249                                  *                                                      below:\r
250                                  *\r
251                                  *                                                      [BadAllocException]                     if there is not enough memory to build the default alias.\r
252                                  *\r
253                                  *                                                      [MsgException]                          if an internal exception occurs.\r
254                                  */\r
255                                 void send(void) \r
256                                 throw(BadAllocException, MsgException);\r
257                                 \r
258                                 /*! \brief Task::send() - Send the task on the mailbox identified by the given alias.\r
259                                  *\r
260                                  * \param alias                         The alias of the mailbox where to send the task.\r
261                                  *\r
262                                  * \exception                           If this method failed, it returns one of the exceptions described\r
263                                  *                                                      below:\r
264                                  *\r
265                                  *                                                      [NullPointerException]          if there parameter alias is NULL.\r
266                                  *\r
267                                  *                                                      [MsgException]                          if an internal exception occurs.\r
268                                  */ \r
269                                 void send(const char* alias) \r
270                                 throw(NullPointerException, MsgException);\r
271                                 \r
272                                 /*! \brief Task::send() - Send the task on the mailbox identified by the default alias\r
273                                  * (waiting at most given time).\r
274                                  *\r
275                                  * \param timeout                       The timeout value.\r
276                                  *\r
277                                  * \exception                           If this method failed, it returns one of the exceptions described\r
278                                  *                                                      below:\r
279                                  *\r
280                                  *                                                      [BadAllocException]                     if there is not enough memory to build the default alias.\r
281                                  *\r
282                                  *                                                      [InvalidArgumentException]      if the timeout value is negative or different -1.0.\r
283                                  *\r
284                                  *                                                      [MsgException]                          if an internal exception occurs.\r
285                                  */\r
286                                 void send(double timeout) \r
287                                 throw(BadAllocException, InvalidArgumentException, MsgException);\r
288                                 \r
289                                 /*! \brief Task::send() - Send the task on the mailbox identified by a given alias\r
290                                  * (waiting at most given time).\r
291                                  *\r
292                                  * \param alias                         The alias of the mailbox where to send the task.\r
293                                  * \param timeout                       The timeout value.\r
294                                  *\r
295                                  * \exception                           If this method failed, it returns one of the exceptions described\r
296                                  *                                                      below:\r
297                                  *\r
298                                  *                                                      [NullPointerException]          if alias parameter is NULL.\r
299                                  *\r
300                                  *                                                      [InvalidArgumentException]      if the timeout value is negative or different -1.0.\r
301                                  *\r
302                                  *                                                      [MsgException]                          if an internal exception occurs.\r
303                                  */\r
304                                 void send(const char* alias, double timeout) \r
305                                 throw(NullPointerException, InvalidArgumentException, MsgException);\r
306                                 \r
307                                 /*! \brief Task::sendBounded() - Sends the task on the mailbox identified by the default alias.\r
308                                  * (capping the emision rate to maxrate).\r
309                                  *\r
310                                  * \param maxRate                       The maximum rate value.\r
311                                  *\r
312                                  * \exception                           If this method failed, it throws one of the exceptions described below:\r
313                                  *\r
314                                  *                                                      [BadAllocException]                     if there is not enough memory to build the default alias.\r
315                                  *\r
316                                  *                                                      [InvalidArgumentException]      if the parameter maxRate is negative and different\r
317                                  *                                                                                                              than -1.0.\r
318                                  *\r
319                                  *                                                      [MsgException]                          if an internal exception occurs.\r
320                                  */\r
321                                 void sendBounded(double maxRate) \r
322                                 throw(BadAllocException, InvalidArgumentException, MsgException);\r
323                                 \r
324                                 /*! \brief Task::sendBounded() - Sends the task on the mailbox identified by the given alias.\r
325                                  * (capping the emision rate to maxrate).\r
326                                  *\r
327                                  *\ param alias                         The alias of the mailbox where to send the task.\r
328                                  * \param maxRate                       The maximum rate value.\r
329                                  *\r
330                                  * \exception                           If this method failed, it throws one of the exceptions described below:\r
331                                  *\r
332                                  *                                                      [NullPointerException]          if the alias parameter is NULL.\r
333                                  *\r
334                                  *                                                      [InvalidArgumentException]      if the parameter maxRate is negative and different\r
335                                  *                                                                                                              than -1.0.\r
336                                  *\r
337                                  *                                                      [MsgException]                          if an internal exception occurs.\r
338                                  */\r
339                                 void sendBounded(const char* alias, double maxRate) \r
340                                 throw(NullPointerException, InvalidArgumentException, MsgException);\r
341                                 \r
342                                 \r
343                                 /*! \brief Task::receive() - Receives a task from the mailbox identified by the default alias (located\r
344                                  * on the local host).\r
345                                  *\r
346                                  * \return                                      A reference to the task.\r
347                                  *\r
348                                  * \exception                           If this method failed, it throws one of the exception described below:\r
349                                  *\r
350                                  *                                                      [BadAllocException]                     if there is not enough memory to build the default alias.\r
351                                  *\r
352                                  *                                                      [MsgException]                          if an internal exception occurs.\r
353                                  */\r
354                                 /*static Task& receive(void) \r
355                                 throw(BadAllocException, MsgException);*/\r
356 \r
357                                 static Task* receive(void) \r
358                                 throw(BadAllocException, MsgException);\r
359                                 \r
360                                 /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias (located\r
361                                  * on the local host).\r
362                                  *\r
363                                  * \alias                                       The alias of the mailbox.\r
364                                  *\r
365                                  * \return                                      A reference to the task.\r
366                                  *\r
367                                  * \exception                           If this method failed, it throws one of the exception described below:\r
368                                  *\r
369                                  *                                                      [NullPointerException]          if the alias parameter is NULL.\r
370                                  *\r
371                                  *                                                      [MsgException]                          if an internal exception occurs.\r
372                                  */\r
373                                 /*static Task& receive(const char* alias) \r
374                                 throw(NullPointerException, MsgException);*/\r
375                                 static Task* receive(const char* alias) \r
376                                 throw(NullPointerException, MsgException);\r
377                                 \r
378                                 /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias (located\r
379                                  * on the local host and waiting at most given time).\r
380                                  *\r
381                                  * \alias                                       The alias of the mailbox.\r
382                                  * \timeout                                     The timeout value.\r
383                                  *\r
384                                  * \return                                      A reference to the task.\r
385                                  *\r
386                                  * \exception                           If this method failed, it throws one of the exception described below:\r
387                                  *\r
388                                  *                                                      [NullPointerException]          if the alias parameter is NULL.\r
389                                  *\r
390                                  *                                                      [InvalidArgumentException]      if the timeout value is negatif and different than\r
391                                  *                                                                                                              -1.0.\r
392                                  *\r
393                                  *                                                      [MsgException]                          if an internal exception occurs.\r
394                                  */\r
395                                 static Task* receive(const char* alias, double timeout) \r
396                                 throw(NullPointerException, InvalidArgumentException, MsgException);\r
397                                 \r
398                                 /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias located\r
399                                  * on the given host.\r
400                                  *\r
401                                  * \alias                                       The alias of the mailbox.\r
402                                  * \rHost                                       The location of the mailbox.\r
403                                  *\r
404                                  * \return                                      A reference to the task.\r
405                                  *\r
406                                  * \exception                           If this method failed, it throws one of the exception described below:\r
407                                  *\r
408                                  *                                                      [NullPointerException]          if the alias parameter is NULL.\r
409                                  *\r
410                                  *                                                      [MsgException]                          if an internal exception occurs.\r
411                                  */\r
412                                 static Task* receive(const char* alias, const Host& rHost) \r
413                                 throw(NullPointerException, MsgException);\r
414                                 \r
415                                 /*! \brief Task::receive() - Receives a task from the mailbox identified by a given alias located\r
416                                  * on the given host (and waiting at most given time).\r
417                                  *\r
418                                  * \alias                                       The alias of the mailbox.\r
419                                  * \timeout                                     The timeout value.\r
420                                  * \rHost                                       The location of the mailbox.\r
421                                  *\r
422                                  * \return                                      A reference to the task.\r
423                                  *\r
424                                  * \exception                           If this method failed, it throws one of the exception described below:\r
425                                  *\r
426                                  *                                                      [NullPointerException]          if the alias parameter is NULL.\r
427                                  *\r
428                                  *                                                      [InvalidArgumentException]      if the timeout value is negatif and different than\r
429                                  *                                                                                                              -1.0.\r
430                                  *\r
431                                  *                                                      [MsgException]                          if an internal exception occurs.\r
432                                  */\r
433                                 static Task* receive(const char* alias, double timeout, const Host& rHost) \r
434                                 throw(NullPointerException, InvalidArgumentException, MsgException);\r
435                                 \r
436                                 /*! \brief Task::listen() - Listen whether there is a waiting task on the mailbox \r
437                                  * identified by the default alias of local host.\r
438                                  *\r
439                                  * \return                                      If there is a waiting task on the mailbox the method returns true.\r
440                                  *                                                      Otherwise the method returns false.\r
441                                  *\r
442                                  * \exception                           If this method fails, it throws one of the exceptions described below:\r
443                                  *\r
444                                  *                                                      [BadAllocException]                     if there is not enough memory to build the default alias.\r
445                                  */\r
446                                 static int listen(void) \r
447                                 throw(BadAllocException);\r
448                                 \r
449                                 /*! \brief Task::listen() - Listen whether there is a waiting task on the mailbox \r
450                                  * identified by the given alias of local host.\r
451                                  *\r
452                                  * \param alias                         The alias of the mailbox.\r
453                                  *\r
454                                  * \return                                      If there is a waiting task on the mailbox the method returns 1.\r
455                                  *                                                      Otherwise the method returns 0.\r
456                                  *\r
457                                  * \exception                           If this method fails, it throws one of the exceptions described below:\r
458                                  *\r
459                                  *                                                      [NullPointerException]          if the parameter alias is NULL.\r
460                                  */\r
461                                 static int listen(const char* alias) \r
462                                 throw(NullPointerException);\r
463                                 \r
464                                 /*! \brief Task::listenFrom() - Tests whether there is a pending communication on the mailbox \r
465                                  * identified by the default alias, and who sent it.\r
466                                  *\r
467                                  * \return                                      If there is a pending communication on the mailbox, the method returns\r
468                                  *                                                      the PID of it sender. Otherwise the method returns -1.\r
469                                  *\r
470                                  * \exception                           If this method fails, it throws the exception described below:\r
471                                  *\r
472                                  *                                                      [BadAllocException]                     if there is not enough memory to build the default\r
473                                  *                                                                                                              alias.\r
474                                  */\r
475                                 static int listenFrom(void) \r
476                                 throw(BadAllocException);\r
477                                 \r
478                                 /*! \brief Task::listenFrom() - Tests whether there is a pending communication on the mailbox \r
479                                  * identified by the specified alias, and who sent it.\r
480                                  *\r
481                                  * \alias                                       The alias of the mailbox.\r
482                                  *\r
483                                  * \return                                      If there is a pending communication on the mailbox, the method returns\r
484                                  *                                                      the PID of it sender. Otherwise the method returns -1.\r
485                                  *\r
486                                  * \exception                           If this method fails, it throws the exception described below:\r
487                                  *\r
488                                  *                                                      [NullPointerException]          if the alias parameter is NULL.\r
489                                  */\r
490                                 static int listenFrom(const char* alias) \r
491                                 throw(NullPointerException);\r
492                                 \r
493                                 /*! \brief Task::listenFromHost() - Tests whether there is a pending communication on the mailbox \r
494                                  * identified by the default alias and located on the host of the current process, and who sent it.\r
495                                  *\r
496                                  * \param rHost                         The location of the mailbox.\r
497                                  *\r
498                                  * \return                                      If there is a pending communication on the mailbox, the method returns\r
499                                  *                                                      the PID of it sender. Otherwise the method returns -1.\r
500                                  *\r
501                                  * \exception                           If this method fails, it throws the exception described below:\r
502                                  *\r
503                                  *                                                      [BadAllocException]                     if there is not enough memory to build the default\r
504                                  *                                                                                                              alias.\r
505                                  */\r
506                                 static int listenFromHost(const Host& rHost) \r
507                                 throw(BadAllocException);\r
508                                 \r
509                                 /*! \brief Task::listenFromHost() - Tests whether there is a pending communication on the mailbox \r
510                                  * identified by the default alias and located on the host of the current process, and who sent it.\r
511                                  *\r
512                                  * \param rHost                         The location of the mailbox.\r
513                                  *\r
514                                  * \return                                      If there is a pending communication on the mailbox, the method returns\r
515                                  *                                                      the PID of it sender. Otherwise the method returns -1.\r
516                                  *\r
517                                  * \exception                           If this method fails, it throws the exception described below:\r
518                                  *\r
519                                  *                                                      [BadAllocException]                     if there is not enough memory to build the default\r
520                                  *                                                                                                              alias.\r
521                                  */\r
522                                 static int listenFromHost(const char* alias, const Host& rHost) \r
523                                 throw(NullPointerException);\r
524 \r
525                                 virtual const Task& operator= (const Task& rTask);\r
526                         \r
527                         protected:\r
528                                 \r
529                                 // Attributes.\r
530                                 \r
531                                 m_task_t nativeTask;    // the native MSG task.\r
532                 };\r
533         \r
534         } // namespace Msg \r
535 } // namespace SimGrid\r
536 \r
537 typedef Task* TaskPtr;\r
538 \r
539 #endif // §MSG_TASK_HPP\r
540 \r