Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some code refactoring
[simgrid.git] / src / cxx / Process.cxx
1 /*\r
2  * Process.cxx\r
3  *\r
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
5  * All right reserved. \r
6  *\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
10  *\r
11  */\r
12  \r
13  /* Process member functions implementation.\r
14   */  \r
15 \r
16 #include <Process.hpp>\r
17 \r
18 \r
19 #include <ApplicationHandler.hpp>\r
20 #include <Host.hpp>\r
21 #include <Task.hpp>\r
22 \r
23 #include <stdlib.h>\r
24 #include <stdio.h>\r
25 \r
26 #include <msg/msg.h>\r
27 #include <msg/private.h>\r
28 #include <msg/mailbox.h>\r
29 \r
30 \r
31 \r
32 namespace SimGrid\r
33 {\r
34         namespace Msg\r
35         {\r
36 \r
37                 MSG_IMPLEMENT_DYNAMIC(Process, Object);\r
38 \r
39                 // Default constructor.\r
40                 Process::Process()\r
41                 {\r
42                         this->nativeProcess = NULL;\r
43                 }\r
44                 \r
45                 Process::Process(const char* hostName, const char* name)\r
46                 throw(NullPointerException, HostNotFoundException, BadAllocException)\r
47                 {\r
48                         // check the parameters\r
49                         \r
50                         if(!name)\r
51                                 throw NullPointerException("name");\r
52                                 \r
53                         if(!hostName)\r
54                                 throw NullPointerException("hostName");\r
55                         \r
56                         Host host = Host::getByName(hostName);\r
57                                 \r
58                         create(host, name, 0, NULL);    \r
59                 }\r
60                 \r
61                 Process::Process(const Host& rHost, const char* name)\r
62                 throw(NullPointerException)\r
63                 {\r
64                         if(!name)\r
65                                 throw NullPointerException("name");\r
66                                 \r
67                         create(rHost, name, 0, NULL);   \r
68                 }\r
69                 \r
70                 Process::Process(const Host& rHost, const char* name, int argc, char** argv)\r
71                 throw(NullPointerException, InvalidArgumentException, LogicException)\r
72                 {\r
73                         \r
74                         // check the parameters\r
75                         \r
76                         if(!name)\r
77                                 throw NullPointerException("name");\r
78                                 \r
79                         if(argc < 0)\r
80                                 throw InvalidArgumentException("argc (must be positive)");\r
81                                 \r
82                         if(!argc && argv)\r
83                                 throw LogicException("argv is not NULL but argc is zero");\r
84                         \r
85                         if(argc && !argv)\r
86                                 throw LogicException("argv is NULL but argc is not zero");\r
87                         \r
88                         create(rHost, name, argc, argv);        \r
89                 }\r
90                 \r
91                 Process::Process(const char* hostName, const char* name, int argc, char** argv)\r
92                 throw(NullPointerException, InvalidArgumentException, LogicException, HostNotFoundException, BadAllocException)\r
93                 {\r
94                         // check the parameters\r
95                         \r
96                         if(!name)\r
97                                 throw NullPointerException("name");\r
98                                 \r
99                         if(!hostName)\r
100                                 throw NullPointerException("hostName");\r
101                                 \r
102                         if(argc < 0)\r
103                                 throw InvalidArgumentException("argc (must be positive)");\r
104                                 \r
105                         if(!argc && argv)\r
106                                 throw LogicException("argv is not NULL but argc is zero");\r
107                         \r
108                         if(argc && !argv)\r
109                                 throw LogicException("argv is NULL but argc is not zero");\r
110                                 \r
111                         Host host = Host::getByName(hostName);\r
112                                 \r
113                         create(host, name, argc, argv); \r
114                 }\r
115                 \r
116                 int Process::killAll(int resetPID) \r
117                 {\r
118                     return MSG_process_killall(resetPID);\r
119                 }\r
120                 \r
121                 void Process::suspend(void)\r
122                 throw(MsgException)\r
123                 {\r
124                     if(MSG_OK != MSG_process_suspend(nativeProcess)) \r
125                         throw MsgException("MSG_process_suspend() failed");\r
126                 }\r
127                 \r
128                 void Process::resume(void) \r
129                 throw(MsgException)\r
130                 {\r
131                         if(MSG_OK != MSG_process_resume(nativeProcess))\r
132                                 throw MsgException("MSG_process_resume() failed");\r
133                 }\r
134                 \r
135                 int Process::isSuspended(void)\r
136                 {\r
137                    return MSG_process_is_suspended(nativeProcess);\r
138                 }  \r
139                 \r
140                 Host& Process::getHost(void) \r
141                 {\r
142                   m_host_t nativeHost = MSG_process_get_host(nativeProcess);\r
143                         \r
144                   // return the reference to the Host object\r
145                   return (*((Host*)nativeHost->data));\r
146                 }\r
147                 \r
148                 Process& Process::fromPID(int PID) \r
149                 throw(ProcessNotFoundException, InvalidArgumentException, MsgException)\r
150                 {\r
151                         // check the parameters\r
152                         \r
153                         if(PID < 1)\r
154                                 throw InvalidArgumentException("PID (the PID of the process to retrieve is not less than 1)");\r
155                                 \r
156                         Process* process = NULL;\r
157                         m_process_t nativeProcess = MSG_process_from_PID(PID);\r
158                         \r
159                         if(!nativeProcess) \r
160                                 throw ProcessNotFoundException(PID);\r
161                         \r
162                         process = Process::fromNativeProcess(nativeProcess);\r
163                                 \r
164                         if(!process) \r
165                                 throw MsgException("Process::fromNativeProcess() failed");\r
166                         \r
167                         return (*process);   \r
168                 } \r
169                 \r
170                 int Process::getPID(void)\r
171                 {\r
172                     return MSG_process_get_PID(nativeProcess);\r
173                 }\r
174                 \r
175                 int Process::getPPID(void)\r
176                 {\r
177                         return MSG_process_get_PPID(nativeProcess);\r
178                 }\r
179                 \r
180                 const char* Process::getName(void) const\r
181                 {\r
182                         return nativeProcess->name;\r
183                 }\r
184                 \r
185                 Process& Process::currentProcess(void)\r
186                 throw(MsgException)\r
187                 {\r
188                         Process* currentProcess = NULL;\r
189                     m_process_t currentNativeProcess = MSG_process_self();\r
190                 \r
191                 \r
192                         if(!currentNativeProcess) \r
193                                 throw MsgException("MSG_process_self() failed");\r
194                         \r
195                         currentProcess = Process::fromNativeProcess(currentNativeProcess);\r
196                                 \r
197                         if(!currentProcess) \r
198                                 throw MsgException("Process::fromNativeProcess() failed");\r
199                         \r
200                         return (*currentProcess);  \r
201                 }\r
202                 \r
203                 int Process::currentProcessPID(void)\r
204                 {\r
205                          return MSG_process_self_PID();\r
206                 }\r
207                 \r
208                 \r
209                 int Process::currentProcessPPID(void)\r
210                 {\r
211                         return MSG_process_self_PPID();\r
212                 }\r
213                 \r
214                 void Process::migrate(const Host& rHost)\r
215                 throw(MsgException)\r
216                 {\r
217                         if(MSG_OK != MSG_process_change_host(rHost.nativeHost))\r
218                                 throw MsgException("MSG_process_change_host()");\r
219                         \r
220                 }\r
221                 \r
222                 void Process::sleep(double seconds)\r
223                 throw(InvalidArgumentException, MsgException)\r
224                 {\r
225                         // check the parameters.\r
226                         if(seconds <= 0)\r
227                                 throw InvalidArgumentException("seconds (must not be less or equals to zero");\r
228                                 \r
229                         if(MSG_OK != MSG_process_sleep(seconds))\r
230                                 throw MsgException("MSG_process_sleep()");\r
231                         \r
232                 }\r
233                 \r
234                 void Process::putTask(const Host& rHost, int channel, Task* task)\r
235                 throw(InvalidArgumentException, MsgException)\r
236                 {\r
237                         // check the parameters\r
238                         \r
239                         if(channel < 0)\r
240                                 throw InvalidArgumentException("channel (must not be negative)");\r
241                                 \r
242                         if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, rHost.nativeHost, channel, -1.0))\r
243                                 throw MsgException("MSG_task_put_with_timeout()");\r
244                 }\r
245                 \r
246                 void Process::putTask(const Host& rHost, int channel, Task* task, double timeout) \r
247                 throw(InvalidArgumentException, MsgException)\r
248                 {\r
249                         // check the parameters\r
250                         if(channel < 0)\r
251                                 throw InvalidArgumentException("channel (must not be negative)");\r
252                                 \r
253                         if(timeout < 0 && timeout != -1.0)\r
254                                 throw InvalidArgumentException("timeout (must not be less than zero an different of -1.0)");\r
255                                 \r
256                         if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, rHost.nativeHost, channel, timeout))\r
257                                 throw MsgException("MSG_task_put_with_timeout() failed");\r
258                 }\r
259                 \r
260                 Task* Process::getTask(int channel) \r
261                 throw(InvalidArgumentException, MsgException)\r
262                 {\r
263                         // check the parameters\r
264                         \r
265                         if(channel < 0)\r
266                                 throw InvalidArgumentException("channel (must not be negative)");\r
267                         \r
268                         m_task_t nativeTask = NULL;\r
269                         \r
270                         if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, -1.0, NULL)) \r
271                                 throw MsgException("MSG_task_get_ext() failed");\r
272                         \r
273                         return (Task*)(nativeTask->data);\r
274                 }\r
275                 \r
276                 Task* Process::getTask(int channel, double timeout) \r
277                 throw(InvalidArgumentException, MsgException)\r
278                 {\r
279                         // check the parameters\r
280                         if(channel < 0)\r
281                                 throw InvalidArgumentException("channel (must not be negative)");\r
282                                 \r
283                         if(timeout < 0 && timeout != -1.0)\r
284                                 throw InvalidArgumentException("timeout (must not be less than zero an different of -1.0)");\r
285                         \r
286                         m_task_t nativeTask = NULL;\r
287                         \r
288                         if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, NULL)) \r
289                                 throw MsgException("MSG_task_get_ext() failed");\r
290                         \r
291                         return (Task*)(nativeTask->data);\r
292                 }\r
293                 \r
294                 Task* Process::getTask(int channel, const Host& rHost) \r
295                 throw(InvalidArgumentException, MsgException)\r
296                 {\r
297                         // check the parameters\r
298                         if(channel < 0)\r
299                                 throw InvalidArgumentException("channel (must not be negative)");\r
300                                 \r
301                         m_task_t nativeTask = NULL;\r
302                         \r
303                         if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, -1.0, rHost.nativeHost)) \r
304                                 throw MsgException("MSG_task_get_ext() failed");\r
305                         \r
306                         return (Task*)(nativeTask->data);\r
307                 }\r
308                 \r
309                 Task* Process::getTask(int channel, double timeout, const Host& rHost)\r
310                 throw(InvalidArgumentException, MsgException)\r
311                 {\r
312                         // check the parameters\r
313                         if(channel < 0)\r
314                                 throw InvalidArgumentException("channel (must not be negative)");\r
315                                 \r
316                         if(timeout < 0 && timeout != -1.0)\r
317                                 throw InvalidArgumentException("timeout (must not be less than zero an different of -1.0)");\r
318                         \r
319                         m_task_t nativeTask = NULL;     \r
320                         \r
321                         if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, rHost.nativeHost)) \r
322                                 throw MsgException("MSG_task_get_ext() failed");\r
323                         \r
324                         return (Task*)(nativeTask->data);\r
325                 }\r
326                 \r
327                 void Process::sendTask(const char* alias, Task* task, double timeout) \r
328                 throw(NullPointerException, InvalidArgumentException, MsgException)\r
329                 {\r
330                         // check the parameters\r
331                         \r
332                         if(!alias)\r
333                                 throw NullPointerException("alias");\r
334                         \r
335                         if(timeout < 0 && timeout !=-1.0)\r
336                                 throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
337                         \r
338                         if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias ,timeout))\r
339                                 throw MsgException("MSG_task_send_with_timeout()");\r
340                                 \r
341                 }\r
342                 \r
343                 void Process::sendTask(const char* alias, Task* task) \r
344                 throw(NullPointerException, MsgException)\r
345                 {\r
346                         // check the parameters\r
347                         \r
348                         if(!alias)\r
349                                 throw NullPointerException("alias");\r
350                                 \r
351                         if(MSG_OK != MSG_task_send_with_timeout(task->nativeTask, alias ,-1.0))\r
352                                 throw MsgException("MSG_task_send_with_timeout()");\r
353                 }\r
354                 \r
355                 void Process::sendTask(Task* task) \r
356                 throw(BadAllocException, MsgException)\r
357                 {\r
358                         char* alias = (char*)calloc( strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
359                                 \r
360                         if(!alias)\r
361                                 throw BadAllocException("alias");\r
362                                 \r
363                         sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
364                         \r
365                         MSG_error_t rv = MSG_task_send_with_timeout(task->nativeTask, alias ,-1.0);\r
366                         \r
367                         free(alias);\r
368                         \r
369                         if(MSG_OK != rv)\r
370                                 throw MsgException("MSG_task_send_with_timeout()");\r
371                 }\r
372                 \r
373                 void Process::sendTask(Task* task, double timeout) \r
374                 throw(BadAllocException, InvalidArgumentException, MsgException)\r
375                 {\r
376                         // check the parameters\r
377                         \r
378                         if(timeout < 0 && timeout !=-1.0)\r
379                                 throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
380                         \r
381                         char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2 , sizeof(char));\r
382                                 \r
383                         if(!alias)\r
384                                 throw BadAllocException("alias");\r
385                                 \r
386                         sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
387                         \r
388                         MSG_error_t rv = MSG_task_send_with_timeout(task->nativeTask, alias ,timeout);\r
389                         \r
390                         free(alias);\r
391                         \r
392                         if(MSG_OK != rv)\r
393                                 throw MsgException("MSG_task_send_with_timeout()");     \r
394                 }\r
395                 \r
396                 Task* Process::receiveTask(const char* alias) \r
397                 throw(NullPointerException, MsgException)\r
398                 {\r
399                         // check the parameters\r
400                         \r
401                         if(!alias)\r
402                                 throw NullPointerException(alias);\r
403                                 \r
404                         m_task_t nativeTask = NULL;\r
405                         \r
406                         if (MSG_OK !=  MSG_task_receive_ext(&nativeTask,alias, -1.0, NULL)) \r
407                                 throw MsgException("MSG_task_receive_ext() failed");\r
408                 \r
409                         return (Task*)(nativeTask->data);\r
410                 }\r
411                 \r
412                 \r
413                 Task* Process::receiveTask(void) \r
414                 throw(BadAllocException, MsgException)\r
415                 {\r
416                         \r
417                         char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
418                         \r
419                         if(!alias)\r
420                                 throw BadAllocException("alias");       \r
421                         \r
422                         sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
423                         \r
424                         m_task_t nativeTask = NULL;\r
425                         \r
426                         MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL);\r
427                         \r
428                         free(alias);\r
429                         \r
430                         if(MSG_OK !=  rv) \r
431                                 throw MsgException("MSG_task_receive_ext() failed");    \r
432                 \r
433                         return (Task*)(nativeTask->data);\r
434                 }\r
435                 \r
436                 \r
437                 Task* Process::receiveTask(const char* alias, double timeout) \r
438                 throw(NullPointerException, InvalidArgumentException, MsgException)\r
439                 {\r
440                         // check the parameters\r
441                         \r
442                         if(!alias)\r
443                                 throw NullPointerException("alias");\r
444                                 \r
445                         if(timeout < 0 && timeout !=-1.0)\r
446                                 throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
447                                 \r
448                         m_task_t nativeTask = NULL;\r
449                         \r
450                         if(MSG_OK !=  MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) \r
451                                 throw MsgException("MSG_task_receive_ext() failed");            \r
452                 \r
453                         return (Task*)(nativeTask->data);\r
454                 }\r
455                 \r
456                 \r
457                 Task* Process::receiveTask(double timeout) \r
458                 throw(InvalidArgumentException, BadAllocException, MsgException)\r
459                 {\r
460                         // check the parameters\r
461                         \r
462                         if(timeout < 0 && timeout !=-1.0)\r
463                                 throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
464                                 \r
465                         \r
466                         char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2,  sizeof(char));\r
467                         \r
468                         if(!alias)\r
469                                 throw BadAllocException("alias");\r
470                         \r
471                         sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
472                         \r
473                         m_task_t nativeTask = NULL;\r
474                         \r
475                         MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, NULL);\r
476                         \r
477                         free(alias);\r
478                         \r
479                         if(MSG_OK !=  rv) \r
480                                 throw MsgException("MSG_task_receive_ext() failed");    \r
481                 \r
482                         return (Task*)(nativeTask->data);\r
483                 }\r
484                 \r
485                 \r
486                 Task* Process::receiveTask(const char* alias, double timeout, const Host& rHost) \r
487                 throw(NullPointerException, InvalidArgumentException, MsgException)\r
488                 {\r
489                         // check the parameters\r
490                         \r
491                         if(!alias)\r
492                                 throw NullPointerException("alias");\r
493                         \r
494                         if(timeout < 0 && timeout !=-1.0)\r
495                                 throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
496                                 \r
497                         m_task_t nativeTask = NULL;\r
498                         \r
499                         if(MSG_OK !=  MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) \r
500                                 throw MsgException("MSG_task_receive_ext() failed");\r
501                 \r
502                         return (Task*)(nativeTask->data);\r
503                 }\r
504                 \r
505                 \r
506                 Task* Process::receiveTask(double timeout, const Host& rHost) \r
507                 throw(BadAllocException, InvalidArgumentException, MsgException)\r
508                 {\r
509                         // check the parameters\r
510                         \r
511                         if(timeout < 0 && timeout !=-1.0)\r
512                                 throw InvalidArgumentException("timeout (the timeout value must not be negative and different than -1.0)");\r
513                         \r
514                         char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
515                         \r
516                         if(!alias)\r
517                                 throw BadAllocException("alias");\r
518                                 \r
519                         sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
520                         \r
521                         m_task_t nativeTask = NULL;\r
522                         \r
523                         MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost);\r
524                         \r
525                         free(alias);\r
526                         \r
527                         if(MSG_OK !=  rv) \r
528                                 throw MsgException("MSG_task_receive_ext() failed");\r
529                 \r
530                         return (Task*)(nativeTask->data);\r
531                 }\r
532                 \r
533                 \r
534                 Task* Process::receiveTask(const char* alias, const Host& rHost) \r
535                 throw(NullPointerException, MsgException)\r
536                 {\r
537                         \r
538                         // check the parameters\r
539                         \r
540                         if(!alias)\r
541                                 throw NullPointerException("alias");\r
542                         \r
543                         m_task_t nativeTask = NULL;\r
544                         \r
545                         if(MSG_OK !=   MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) \r
546                                 throw MsgException("MSG_task_receive_ext() failed");\r
547                 \r
548                         return (Task*)(nativeTask->data);\r
549                 }\r
550                 \r
551                 Task* Process::receiveTask(const Host& rHost) \r
552                 throw(BadAllocException, MsgException)\r
553                 {\r
554                         char* alias = (char*)calloc(strlen(Host::currentHost().getName()) + strlen(nativeProcess->name) + 2, sizeof(char));\r
555                         \r
556                         if(!alias)\r
557                                 throw BadAllocException("alias");\r
558                         \r
559                         sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
560                         \r
561                         m_task_t nativeTask = NULL;\r
562                         \r
563                         MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost);\r
564                         \r
565                         free(alias);\r
566                         \r
567                         if(MSG_OK !=  rv) \r
568                                 throw MsgException("MSG_task_receive_ext() failed");\r
569                 \r
570                         return (Task*)(nativeTask->data);\r
571                 }\r
572 \r
573                 void Process::create(const Host& rHost, const char* name, int argc, char** argv)\r
574                 throw(InvalidArgumentException)\r
575                 {\r
576                         char alias[MAX_ALIAS_NAME + 1] = {0};\r
577                         msg_mailbox_t mailbox;\r
578                         \r
579                         \r
580                         // try to retrieve the host where to createt the process from its name\r
581                         m_host_t nativeHost = rHost.nativeHost;\r
582                         \r
583                         if(!nativeHost)\r
584                                 throw InvalidArgumentException("rHost"); \r
585                         \r
586                         /* allocate the data of the simulation */\r
587                         this->nativeProcess = xbt_new0(s_m_process_t,1);\r
588                         this->nativeProcess->simdata = xbt_new0(s_simdata_process_t,1);\r
589                         this->nativeProcess->name = _strdup(name);\r
590                         this->nativeProcess->simdata->m_host = nativeHost;\r
591                         this->nativeProcess->simdata->PID = msg_global->PID++;\r
592                         \r
593                         // realloc the list of the argument to add the pointer to this process instance at the end\r
594                         if(argc)\r
595                                 argv = (char**)realloc(argv , (argc + 1) * sizeof(char*));\r
596                         else\r
597                                 argv = (char**)calloc(1 ,sizeof(char*));\r
598                         \r
599                         // add the pointer to this instance at the end of the list of the arguments of the process\r
600                         // so the static method Process::run() (passed as argument of the MSG function xbt_context_new())\r
601                         // can retrieve the concerned process object by the run\r
602                         // so Process::run() can call the method main() of the good process\r
603                         // for more detail see Process::run() method\r
604                         argv[argc] = (char*)this;\r
605 \r
606                         this->nativeProcess->simdata->argc = argc;\r
607                         this->nativeProcess->simdata->argv = argv;\r
608                         \r
609                         this->nativeProcess->simdata->s_process = SIMIX_process_create(\r
610                                                                         this->nativeProcess->name,\r
611                                                                         Process::run, \r
612                                                                         (void*)this->nativeProcess,\r
613                                                                         nativeHost->name, \r
614                                                                         argc,\r
615                                                                         argv, \r
616                                                                         NULL);\r
617                         \r
618                         if (SIMIX_process_self()) \r
619                         {/* someone created me */\r
620                                 this->nativeProcess->simdata->PPID = MSG_process_get_PID((m_process_t)SIMIX_process_self()->data);\r
621                         } \r
622                         else \r
623                         {\r
624                                 this->nativeProcess->simdata->PPID = -1;\r
625                         }\r
626                         \r
627                         this->nativeProcess->simdata->last_errno = MSG_OK;\r
628                         \r
629                         /* add the process to the list of the processes of the simulation */\r
630                         xbt_fifo_unshift(msg_global->process_list, this->nativeProcess);\r
631                         \r
632                         sprintf(alias,"%s:%s",(this->nativeProcess->simdata->m_host->simdata->smx_host)->name,this->nativeProcess->name);\r
633                         \r
634                         mailbox = MSG_mailbox_new(alias);\r
635                         \r
636                         MSG_mailbox_set_hostname(mailbox, this->nativeProcess->simdata->m_host->simdata->smx_host->name);       \r
637                 }\r
638                 \r
639                 Process* Process::fromNativeProcess(m_process_t nativeProcess)\r
640                 {\r
641                         return ((Process*)(nativeProcess->simdata->argv[nativeProcess->simdata->argc]));\r
642                 }\r
643                 \r
644                 int Process::run(int argc, char** argv)\r
645                 {\r
646                         \r
647                         // the last argument of the process is the pointer to the process to run\r
648                         // for more detail see Process::create() method\r
649                         return ((Process*)argv[argc])->main(argc, argv);\r
650                 }\r
651 \r
652                 int Process::main(int argc, char** argv)\r
653                 {\r
654                         throw LogicException("Process::main() not implemented");\r
655                 }\r
656 \r
657                 /*void* Process::operator new(size_t size)\r
658                 {\r
659                         // TODO\r
660                 }\r
661 \r
662                 void Process::operator delete(void* p)\r
663                 {\r
664                         // TODO\r
665                 }*/\r
666                 \r
667         } // namespace Msg\r
668 \r
669 } // namespace SimGrid\r
670 \r