X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e3291ac14eb4c7c8a7fc3db17f6bc0916e160916..2371d0c1060589bd7b8757f47974ceaa906e0dba:/src/cxx/Host.cxx diff --git a/src/cxx/Host.cxx b/src/cxx/Host.cxx index 07ec58c57a..db4722bf45 100644 --- a/src/cxx/Host.cxx +++ b/src/cxx/Host.cxx @@ -14,6 +14,22 @@ */ #include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#include + namespace SimGrid { namespace Msg @@ -37,11 +53,11 @@ namespace SimGrid Host& Host::getByName(const char* hostName) - throw(HostNotFoundException, InvalidParameterException, BadAllocException) + throw(HostNotFoundException, InvalidArgumentException, BadAllocException) { // check the parameters if(!hostName) - throw InvalidParmeterException("hostName"); + throw InvalidArgumentException("hostName"); m_host_t nativeHost = NULL; // native host. Host* host = NULL; // wrapper host. @@ -53,7 +69,7 @@ namespace SimGrid { // native host not associated yet with its wrapper // instanciate a new wrapper - if(!(host = new Host()) + if(!(host = new Host())) throw BadAllocException(hostName); host->nativeHost = nativeHost; @@ -96,19 +112,19 @@ namespace SimGrid } void Host::all(Host*** hosts, int* len) - throw(InvalidParameterException, BadAllocException) + throw(InvalidArgumentException, BadAllocException) { - /* check the parameters */ + // check the parameters if(!hosts) - throw InvalidParameterException("hosts"); + throw InvalidArgumentException("hosts"); if(len < 0) - throw InvalidParameterException("len parameter must be positive"); + throw InvalidArgumentException("len parameter must be positive"); int count = xbt_fifo_size(msg_global->host); if(*len < count) - throw InvalidParameterException("len parameter must be more than the number of installed host\n (use Host::getNumber() to get the number of hosts)"); + throw InvalidArgumentException("len parameter must be more than the number of installed host\n (use Host::getNumber() to get the number of hosts)"); int index; m_host_t nativeHost; @@ -123,7 +139,7 @@ namespace SimGrid if(!host) { - if(!(host = new Host()) + if(!(host = new Host())) { // release all allocated memory. for(int i = 0; i < index; i++) @@ -164,7 +180,7 @@ namespace SimGrid double Host::getSpeed(void) const { - return MSG_get_host_speed(nativeHost->simdata->smx_host); + return MSG_get_host_speed(nativeHost); } bool Host::hasData(void) const @@ -172,31 +188,42 @@ namespace SimGrid return (NULL != this->data); } - bool Host::isAvailable(void) const + int Host::isAvailable(void) const { - return (bool)SIMIX_host_get_state(nativeHost->simdata->smx_host); + return SIMIX_host_get_state(nativeHost->simdata->smx_host); } void Host::put(int channel, const Task& rTask) - throw(MsgException, InvalidParameterException) + throw(MsgException, InvalidArgumentException) { // checks the parameters if(channel < 0) - throw InvalidParameterException("channel (must be more or equal to zero)"); + throw InvalidArgumentException("channel (must be more or equal to zero)"); if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , -1.0)) throw MsgException("MSG_task_put_with_timeout() failed"); } + + void Host::put(int channel, Task* task) + throw(MsgException, InvalidArgumentException) + { + // checks the parameters + if(channel < 0) + throw InvalidArgumentException("channel (must be more or equal to zero)"); + + if(MSG_OK != MSG_task_put_with_timeout(task->nativeTask, nativeHost, channel , -1.0)) + throw MsgException("MSG_task_put_with_timeout() failed"); + } void Host::put(int channel, const Task& rTask, double timeout) - throw(MsgException, InvalidParameterException) + throw(MsgException, InvalidArgumentException) { // checks the parameters if(channel < 0) - throw InvalidParameterException("channel (must be more or equal to zero)"); + throw InvalidArgumentException("channel (must be more or equal to zero)"); if(timeout < 0.0 && timeout != -1.0) - throw InvalidParameterException("timeout (must be more or equal to zero or equal to -1.0)"); + throw InvalidArgumentException("timeout (must be more or equal to zero or equal to -1.0)"); if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , timeout)) @@ -204,25 +231,25 @@ namespace SimGrid } void Host::putBounded(int channel, const Task& rTask, double maxRate) - throw(MsgException, InvalidParameterException) + throw(MsgException, InvalidArgumentException) { // checks the parameters if(channel < 0) - throw InvalidParameterException("channel (must be more or equal to zero)"); + throw InvalidArgumentException("channel (must be more or equal to zero)"); if(maxRate < 0.0 && maxRate != -1.0) - throw InvalidParameterException("maxRate (must be more or equal to zero or equal to -1.0)"); + throw InvalidArgumentException("maxRate (must be more or equal to zero or equal to -1.0)"); if(MSG_OK != MSG_task_put_bounded(rTask.nativeTask, nativeHost, channel, maxRate)) throw MsgException("MSG_task_put_bounded() failed"); } void Host::send(const Task& rTask) - throw(NativeException) + throw(MsgException) { MSG_error_t rv; - char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2); + char* alias = (char*)calloc(strlen(this->getName())+ strlen(Process::currentProcess().getName()) + 2, sizeof(char)); if(!alias) throw BadAllocException("alias"); @@ -238,25 +265,26 @@ namespace SimGrid } void Host::send(const char* alias, const Task& rTask) - throw(InvalidParameterException, MsgException) + throw(InvalidArgumentException, MsgException) { // check the parameters if(!alias) - throw InvalidParmeterException("alias (must not be NULL)"); + throw InvalidArgumentException("alias (must not be NULL)"); if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias, -1.0)) throw MsgException("MSG_task_send_with_timeout() failed"); } void Host::send(const Task& rTask, double timeout) - throw(InvalidParameterException, BadAllocException, MsgException) + throw(InvalidArgumentException, BadAllocException, MsgException) { // check the parameters if(timeout < 0 && timeout != -1.0) - throw InvalidParameterException("timeout (must be positive or equal to zero or equal to -1.0)"); + throw InvalidArgumentException("timeout (must be positive or equal to zero or equal to -1.0)"); + MSG_error_t rv; - char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2); + char* alias = (char*)calloc(strlen(this->getName()) + strlen(Process::currentProcess().getName()) + 2, sizeof(char)); if(!alias) throw BadAllocException("alias"); @@ -273,15 +301,15 @@ namespace SimGrid } void Host::send(const char* alias, const Task& rTask, double timeout) - throw(InvalidParameterException, MsgException) + throw(InvalidArgumentException, MsgException) { // check the parameter if(!alias) - throw InvalidParmeterException("alias (must not be NULL)"); + throw InvalidArgumentException("alias (must not be NULL)"); if(timeout < 0 && timeout != -1.0) - throw InvalidParameterException("timeout (must be positive or equal to zero or equal to -1.0)"); + throw InvalidArgumentException("timeout (must be positive or equal to zero or equal to -1.0)"); if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias, timeout)) throw MsgException("MSG_task_send_with_timeout() failed"); @@ -289,14 +317,14 @@ namespace SimGrid void Host::sendBounded(const Task& rTask, double maxRate) - throw(InvalidParameterException, BadAllocException, MsgException) + throw(InvalidArgumentException, BadAllocException, MsgException) { if(maxRate < 0 && maxRate != -1.0) - throw InvalidParameterException("maxRate (must be positive or equal to zero or equal to -1.0)"); + throw InvalidArgumentException("maxRate (must be positive or equal to zero or equal to -1.0)"); MSG_error_t rv; - char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2); + char* alias = (char*)calloc(strlen(this->getName()) + strlen(Process::currentProcess().getName()) + 2, sizeof(char)); if(!alias) throw BadAllocException("alias"); @@ -312,18 +340,18 @@ namespace SimGrid } void Host::sendBounded(const char* alias, const Task& rTask, double maxRate) - throw(InvalidParameterException, MsgException) + throw(InvalidArgumentException, MsgException) { // check the parameters if(!alias) - throw InvalidParameterException("alias (must not be NULL)"); + throw InvalidArgumentException("alias (must not be NULL)"); if(maxRate < 0 && maxRate != -1) - throw InvalidParameterException("maxRate (must be positive or equal to zero or equal to -1.0)"); + throw InvalidArgumentException("maxRate (must be positive or equal to zero or equal to -1.0)"); if(MSG_OK != MSG_task_send_bounded(rTask.nativeTask, alias, maxRate)) throw MsgException("MSG_task_send_bounded() failed"); - } + } } // namspace Msg } // namespace SimGrid \ No newline at end of file