Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Last Changes of CPP version of Msg
[simgrid.git] / src / cxx / Task.cxx
index c9ef4f0..b0c2ccb 100644 (file)
@@ -1,9 +1,25 @@
 #include <Task.hpp>\r
 \r
+#include <MsgException.hpp>\r
+#include <InvalidArgumentException.hpp>\r
+#include <NullPointerException.hpp>\r
+#include <MsgException.hpp>\r
+#include <BadAllocException.hpp>\r
+\r
+#include <Process.hpp>\r
+#include <Host.hpp>\r
+\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+#include <msg/msg.h>\r
+\r
 namespace SimGrid\r
 {\r
        namespace Msg\r
        {\r
+\r
+               MSG_IMPLEMENT_DYNAMIC(Task, Object);\r
        \r
                Task::Task()\r
                {\r
@@ -13,11 +29,12 @@ namespace SimGrid
                \r
                Task::Task(const Task& rTask)\r
                {\r
+                       this->nativeTask = rTask.nativeTask;\r
                }\r
                \r
                \r
                Task::~Task()\r
-               throw(NativeException)\r
+               throw(MsgException)\r
                {\r
                        if(NULL != nativeTask)\r
                                if(MSG_OK != MSG_task_destroy(nativeTask))\r
@@ -28,7 +45,7 @@ namespace SimGrid
                Task::Task(const char* name, double computeDuration, double messageSize)\r
                throw(InvalidArgumentException, NullPointerException)\r
                {\r
-                        \r
+\r
                        if(computeDuration < 0) \r
                                throw InvalidArgumentException("computeDuration");\r
                        \r
@@ -47,7 +64,6 @@ namespace SimGrid
                Task::Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes, int hostCount)\r
                throw(NullPointerException, InvalidArgumentException)\r
                {\r
-                       \r
                        // check the parameters\r
                        \r
                        if(!name) \r
@@ -91,7 +107,7 @@ namespace SimGrid
                        \r
                        \r
                        \r
-                       task->data = (void*)this;\r
+                       this->nativeTask->data = (void*)this;\r
                        \r
                }\r
                \r
@@ -102,7 +118,7 @@ namespace SimGrid
                \r
                Process& Task::getSender(void) const\r
                {\r
-                       m_proccess_t nativeProcess = MSG_task_get_sender(nativeTask);\r
+                       m_process_t nativeProcess = MSG_task_get_sender(nativeTask);\r
                        \r
                        return (*((Process*)(nativeProcess->data)));\r
                }\r
@@ -135,7 +151,7 @@ namespace SimGrid
                        MSG_task_set_priority(nativeTask, priority);\r
                }\r
                \r
-               Task& Task::get(int channel) \r
+               /*Task& Task::get(int channel) \r
                throw(InvalidArgumentException, MsgException)\r
                {\r
                        // check the parameters\r
@@ -149,6 +165,22 @@ namespace SimGrid
                                throw MsgException("MSG_task_get_ext() failed");\r
                        \r
                        return (*((Task*)(nativeTask->data)));\r
+               }*/\r
+\r
+               Task* Task::get(int channel) \r
+               throw(InvalidArgumentException, MsgException)\r
+               {\r
+                       // check the parameters\r
+                       \r
+                       if(channel < 0)\r
+                               throw InvalidArgumentException("channel (must not be negative)");\r
+                               \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL)) \r
+                               throw MsgException("MSG_task_get_ext() failed");\r
+                       \r
+                       return ((Task*)(nativeTask->data));\r
                }\r
                \r
                Task& Task::get(int channel, const Host& rHost) \r
@@ -188,7 +220,7 @@ namespace SimGrid
                        return (*((Task*)(nativeTask->data)));\r
                }\r
                \r
-               bool static Task::probe(int channel)\r
+               int Task::probe(int channel)\r
                throw(InvalidArgumentException)\r
                {\r
                        // check the parameters\r
@@ -196,7 +228,7 @@ namespace SimGrid
                        if(channel < 0)\r
                                throw InvalidArgumentException("channel (must not be negative)");\r
                                \r
-                       return (bool)MSG_task_Iprobe(channel);\r
+                       return MSG_task_Iprobe(channel);\r
                }\r
                \r
                int Task::probe(int channel, const Host& rHost)\r
@@ -207,7 +239,7 @@ namespace SimGrid
                        if(channel < 0)\r
                                throw InvalidArgumentException("channel (must not be negative)");\r
                                \r
-                       return MSG_task_probe_from_host(chan_id,rHost.nativeHost);\r
+                       return MSG_task_probe_from_host(channel,rHost.nativeHost);\r
                }\r
                \r
                void Task::execute(void) \r
@@ -227,16 +259,16 @@ namespace SimGrid
                void Task::send(void) \r
                throw(BadAllocException, MsgException)\r
                {       \r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                                \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                                \r
                        MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, -1.0);\r
                \r
-                       free(alias)\r
+                       free(alias);\r
                \r
                        if(MSG_OK != rv)\r
                                throw MsgException("MSG_task_send_with_timeout() failed");\r
@@ -255,23 +287,23 @@ namespace SimGrid
                }\r
                \r
                void Task::send(double timeout) \r
-               throw(BadAllocationException, InvalidArgumentException, MsgException)\r
+               throw(BadAllocException, InvalidArgumentException, MsgException)\r
                {\r
                        // check the parameters\r
                        \r
                        if(timeout < 0  && timeout != -1.0)\r
                                throw InvalidArgumentException("timeout (must not be negative and different than -1.0");\r
                                                \r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                                \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                \r
                        MSG_error_t rv = MSG_task_send_with_timeout(nativeTask, alias, timeout);\r
                \r
-                       free(alias)\r
+                       free(alias);\r
                \r
                        if(MSG_OK != rv)\r
                                throw MsgException("MSG_task_send_with_timeout() failed");\r
@@ -301,12 +333,12 @@ namespace SimGrid
                        if(maxRate < 0 && maxRate != -1.0)\r
                                throw InvalidArgumentException("maxRate (must not be negative and different than -1.0");\r
                                        \r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                        \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                        \r
                        MSG_error_t rv = MSG_task_send_bounded(nativeTask, alias, maxRate);\r
                        \r
@@ -332,15 +364,15 @@ namespace SimGrid
                                throw MsgException("MSG_task_send_bounded() failed");\r
                }\r
                \r
-               Task& Task::receive(void) \r
-               throw(throw(BadAllocException, MsgException))\r
+               /*Task& Task::receive(void) \r
+               throw(BadAllocException, MsgException)\r
                {\r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                                \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                                \r
                        m_task_t nativeTask = NULL;\r
                        \r
@@ -352,9 +384,31 @@ namespace SimGrid
                                throw MsgException("MSG_task_receive_ext() failed");\r
                \r
                        return (*((Task*)nativeTask->data));\r
+               }*/\r
+\r
+               Task* Task::receive(void) \r
+               throw(BadAllocException, MsgException)\r
+               {\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
+                       \r
+                       if(!alias)\r
+                               throw BadAllocException("alias");\r
+                               \r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
+                               \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL);  \r
+               \r
+                       free(alias);\r
+                       \r
+                       if(MSG_OK != rv) \r
+                               throw MsgException("MSG_task_receive_ext() failed");\r
+               \r
+                       return ((Task*)nativeTask->data);\r
                }\r
                \r
-               Task& Task::receive(const char* alias) \r
+               /*Task& Task::receive(const char* alias) \r
                throw(NullPointerException, MsgException)\r
                {\r
                        // check the parameters\r
@@ -368,6 +422,22 @@ namespace SimGrid
                                throw MsgException("MSG_task_receive_ext() failed");\r
                \r
                        return (*((Task*)nativeTask->data));\r
+               }*/\r
+\r
+               Task* Task::receive(const char* alias) \r
+               throw(NullPointerException, MsgException)\r
+               {\r
+                       // check the parameters\r
+                       \r
+                       if(!alias)\r
+                               throw NullPointerException("alias");\r
+                               \r
+                       m_task_t nativeTask = NULL;\r
+                       \r
+                       if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL)) \r
+                               throw MsgException("MSG_task_receive_ext() failed");\r
+               \r
+                       return ((Task*)nativeTask->data);\r
                }\r
                \r
                Task& Task::receive(const char* alias, double timeout) \r
@@ -378,7 +448,7 @@ namespace SimGrid
                        if(!alias)\r
                                throw NullPointerException("alias");\r
                        \r
-                       if(timeout < 0 && alias != -1.0)\r
+                       if(timeout < 0 && timeout != -1.0)\r
                                throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)");\r
                                \r
                        m_task_t nativeTask = NULL;\r
@@ -413,7 +483,7 @@ namespace SimGrid
                        if(!alias)\r
                                throw NullPointerException("alias");\r
                        \r
-                       if(timeout < 0 && alias != -1.0)\r
+                       if(timeout < 0 && timeout != -1.0)\r
                                throw InvalidArgumentException("timeout (must not be negative and differnt than -1.0)");\r
                                \r
                        m_task_t nativeTask = NULL;\r
@@ -425,24 +495,24 @@ namespace SimGrid
                        return (*((Task*)nativeTask->data));\r
                }\r
                \r
-               bool Task::listen(void) \r
+               int Task::listen(void) \r
                throw(BadAllocException)\r
                {\r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                                \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                                \r
                        int rv = MSG_task_listen(alias);\r
                        \r
                        free(alias);\r
                        \r
-                       return (bool)rv;\r
+                       return rv;\r
                }       \r
                \r
-               bool Task::listen(const char* alias) \r
+               int Task::listen(const char* alias) \r
                throw(NullPointerException)\r
                {\r
                        // check the parameters\r
@@ -450,18 +520,18 @@ namespace SimGrid
                        if(!alias)\r
                                throw NullPointerException("alias");\r
                                \r
-                       return (bool)MSG_task_listen(alias);\r
+                       return MSG_task_listen(alias);\r
                }\r
                \r
                int Task::listenFrom(void) \r
                throw(BadAllocException)\r
                {\r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                                \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                        \r
                        int rv = MSG_task_listen_from(alias);\r
                        \r
@@ -483,12 +553,12 @@ namespace SimGrid
                int Task::listenFromHost(const Host& rHost) \r
                throw(BadAllocException)\r
                {\r
-                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+                       char* alias = (char*)calloc(strlen(Process::currentProcess().getName()) + strlen(Host::currentHost().getName()) + 2, sizeof(char));\r
                        \r
                        if(!alias)\r
                                throw BadAllocException("alias");\r
                        \r
-                       sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+                       sprintf(alias,"%s:%s", Host::currentHost().getName(), Process::currentProcess().getName());\r
                        \r
                        int rv = MSG_task_listen_from_host(alias, rHost.nativeHost);\r
                        \r
@@ -506,6 +576,12 @@ namespace SimGrid
                                \r
                        return MSG_task_listen_from_host(alias, rHost.nativeHost);\r
                }       \r
+\r
+               const Task& Task::operator = (const Task& rTask)\r
+               {\r
+                       this->nativeTask = rTask.nativeTask;\r
+                       return *this;\r
+               }\r
        } // namespace Msg                                                                                                                                                                                              \r
 } // namespace SimGrid\r
 \r