Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
started of C++ wrappers for Msg
[simgrid.git] / src / cxx / Task.cxx
1 #include <Task.hpp>\r
2 \r
3 namespace msg\r
4 {\r
5         \r
6 Task::Task()\r
7 {\r
8         nativeTask = NULL;\r
9 }\r
10 \r
11 \r
12 Task::Task(const Task& rTask)\r
13 {\r
14 }\r
15 \r
16 \r
17 Task::~Task()\r
18 throw(NativeException)\r
19 {\r
20         if(NULL != nativeTask)\r
21         {\r
22                 if(MSG_OK != MSG_task_destroy(nativeTask))\r
23                 {\r
24                         // TODO throw NativeException\r
25                 }       \r
26         }\r
27 }\r
28 \r
29 \r
30 Task::Task(const char* name, double computeDuration, double messageSize)\r
31 {\r
32          \r
33         if(computeDuration < 0) \r
34         {\r
35                 // TODO throw exception\r
36                 return;\r
37         }\r
38         \r
39         if(messageSize < 0) \r
40         {\r
41                 // TODO throw exception\r
42                 return;\r
43         }\r
44         \r
45         if(!name) \r
46         {\r
47                 // TODO throw exception\r
48                 return;\r
49         }\r
50         \r
51         // create the task\r
52         nativeTask = MSG_task_create(name, computeDuration, messageSize, NULL);\r
53         \r
54         nativeTask->data = (void*)this;\r
55 }\r
56 \r
57 Task::Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes)\r
58 {\r
59         // TODO parallel task create    \r
60 }\r
61 \r
62 \r
63 const char* Task::getName(void) const\r
64 {\r
65         return nativeTask->name;\r
66 }\r
67 \r
68 Process& Task::getSender(void) const\r
69 {\r
70         m_proccess_t nativeProcess = MSG_task_get_sender(nativeTask);\r
71         \r
72         return (*((Process*)(nativeProcess->data)));\r
73 }\r
74 \r
75 Host& Task::getSource(void) const \r
76 throw(NativeException)\r
77 {\r
78         m_host_t nativeHost = MSG_task_get_source(nativeTask);\r
79         \r
80         if(!nativeHost->data) \r
81         {\r
82         // TODO throw the exception\r
83         return NULL;\r
84         }\r
85         \r
86         return (*((Host*)(nativeHost->data)));  \r
87 }\r
88 \r
89 double Task::getComputeDuration(void) const\r
90 {\r
91         return MSG_task_get_compute_duration(nativeTask);\r
92 }\r
93 \r
94 double Task::getRemainingDuration(void) const\r
95 {\r
96         return MSG_task_get_remaining_computation(nativeTask);\r
97 }\r
98 \r
99 void Task::setPriority(double priority)\r
100 {\r
101         MSG_task_set_priority(nativeTask, priority);\r
102 }\r
103 \r
104 Task& Task::get(int channel) \r
105 throw(NativeException)\r
106 {\r
107         m_task_t nativeTask = NULL;\r
108         \r
109         \r
110         if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL)) \r
111         {\r
112                 // TODO throw the NativeException\r
113                 return NULL;\r
114         }\r
115         \r
116         return (*((Task*)(nativeTask->data)));\r
117 }\r
118 \r
119 Task& Task::get(int channel, const Host& rHost) \r
120 throw(NativeException)\r
121 {\r
122         m_task_t nativeTask = NULL;\r
123         \r
124         \r
125         if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, rHost.nativeHost)) \r
126         {\r
127                 // TODO throw the NativeException\r
128                 return NULL;\r
129         }\r
130         \r
131         return (*((Task*)(nativeTask->data)));\r
132 }\r
133 \r
134 Task& Task::get(int channel, double timeout, const Host& rHost) \r
135 throw(NativeException)\r
136 {\r
137         m_task_t nativeTask = NULL;\r
138         \r
139         \r
140         if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , timeout, rHost.nativeHost)) \r
141         {\r
142                 // TODO throw the NativeException\r
143                 return NULL;\r
144         }\r
145         \r
146         return (*((Task*)(nativeTask->data)));\r
147 }\r
148 \r
149 bool static Task::probe(int channel)\r
150 {\r
151         return (bool)MSG_task_Iprobe(channel);\r
152 }\r
153 \r
154 int Task::probe(int channel, const Host& rHost)\r
155 {\r
156         return MSG_task_probe_from_host(chan_id,rHost.nativeHost);\r
157 }\r
158 \r
159 void Task::execute(void) \r
160 throw(NativeException)\r
161 {\r
162         if(MSG_OK != MSG_task_execute(nativeTask))\r
163         {\r
164                 // TODO throw NativeException\r
165         }       \r
166 }\r
167 \r
168 void Task::cancel(void) \r
169 throw(NativeException)\r
170 {\r
171         if(MSG_OK != MSG_task_cancel(nativeTask))\r
172         {\r
173                 // TODO throw NativeException\r
174         }       \r
175 }\r
176 \r
177 void send(void) \r
178 throw(NativeException)\r
179 {\r
180 }                       \r
181 \r
182 }\r
183 \r