5 // Default constructor.
\r
12 // Copy constructor.
\r
13 Host::Host(const Host& rHost)
\r
25 Host& Host::getByName(const char* hostName)
\r
26 throw(HostNotFoundException)
\r
28 m_host_t nativeHost; // native host.
\r
29 Host* host = NULL; // wrapper host.
\r
31 /* get the host by name (the hosts are created during the grid resolution) */
\r
32 nativeHost = MSG_get_host_by_name(name);
\r
33 DEBUG2("MSG gave %p as native host (simdata=%p)",nativeHost,nativeHost->simdata);
\r
36 {// invalid host name
\r
37 // TODO throw HostNotFoundException
\r
41 if(!nativeHost->data)
\r
42 { // native host not associated yet with its wrapper
\r
44 // instanciate a new wrapper
\r
47 host->nativeHost = nativeHost;
\r
49 // the native host data field is set with its wrapper returned
\r
51 nativeHost->data = (void*)host;
\r
54 // return the reference to cxx wrapper
\r
55 return *((Host*)nativeHost->data);
\r
58 int Host::getNumber(void)
\r
60 return MSG_get_host_number();
\r
63 Host& Host::currentHost(void)
\r
66 m_host_t nativeHost = MSG_host_self();
\r
68 if(!nativeHost->data)
\r
70 // the native host not yet associated with its wrapper
\r
72 // instanciate a new wrapper
\r
75 host->nativeHost = nativeHost;
\r
77 nativeHost->data = (void*)host;
\r
81 host = (Host*)nativeHost->data;
\r
87 int Host::all(Host** hosts)
\r
89 int count = xbt_fifo_size(msg_global->host);
\r
91 *hosts = new Host[count];
\r
93 m_host_t nativeHost;
\r
96 m_host_t* table = (m_host_t *)xbt_fifo_to_array(msg_global->host);
\r
98 for(index = 0; index < count; index++)
\r
100 nativeHost = table[index];
\r
101 host = (Host*)(nativeHost->data);
\r
107 host->nativeHost = nativeHost;
\r
108 nativeHost->data = (void*)host;
\r
111 hosts[index] = host;
\r
118 const char* Host::getName(void) const
\r
120 return nativeHost->name;
\r
124 void Host::setData(void* data)
\r
131 void* Host::getData(void) const
\r
136 int Host::getRunningTaskNumber(void) const
\r
138 return MSG_get_host_msgload(nativeHost);
\r
141 double Host::getSpeed(void) const
\r
143 return MSG_get_host_speed(nativeHost->simdata->smx_host);
\r
146 bool Host::hasData(void) const
\r
148 return (NULL != this->data);
\r
151 bool Host::isAvailable(void) const
\r
153 return (bool)SIMIX_host_get_state(nativeHost->simdata->smx_host);
\r
156 void Host::put(int channel, const Task& rTask)
\r
157 throw(NativeException)
\r
159 if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , -1.0))
\r
161 // TODO throw NativeException
\r
165 void Host::put(int channel, const Task& rTask, double timeout)
\r
166 throw(NativeException)
\r
168 if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , timeout))
\r
170 // TODO throw NativeException
\r
174 void Host::putBounded(int channel, const Task& rTask, double maxRate)
\r
175 throw(NativeException)
\r
177 MsgNative.hostPutBounded(this, channel, task, maxrate);
\r
179 if(MSG_OK != MSG_task_put_bounded(rTask.nativeTask, nativeHost, channel, maxRate))
\r
181 // TODO throw NativeException
\r
190 void Host::send(const Task& rTask)
\r
191 throw(NativeException)
\r
195 char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);
\r
196 sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName());
\r
199 rv = MSG_task_send_with_timeout(rTask.nativeTask, alias, -1.0);
\r
205 // TODO throw NativeException
\r
209 void Host::send(const char* alias, const Task& rTask)
\r
210 throw(NativeException)
\r
213 if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias, -1.0))
\r
215 // TODO throw NativeException
\r
219 void Host::send(const Task& rTask, double timeout)
\r
220 throw(NativeException)
\r
224 char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);
\r
225 sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName());
\r
228 rv = MSG_task_send_with_timeout(rTask.nativeTask, alias, timeout);
\r
234 // TODO throw NativeException
\r
238 void Host::send(const char* alias, const Task& rTask, double timeout)
\r
239 throw(NativeException)
\r
241 if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias, timeout))
\r
243 // TODO throw NativeException
\r
248 void Host::sendBounded(const Task& rTask, double maxRate)
\r
249 throw(NativeException)
\r
254 char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);
\r
255 sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName());
\r
257 rv = MSG_task_send_bounded(rTask.nativeTask, alias, maxRate);
\r
263 // TODO throw NativeException
\r
267 void Host::sendBounded(const char* alias, const Task& rTask, double maxRate)
\r
268 throw(NativeException)
\r
270 if(MSG_OK != MSG_task_send_bounded(rTask.nativeTask, alias, maxRate))
\r
272 // TODO throw NativeException
\r