From: cherierm Date: Thu, 15 May 2008 16:13:59 +0000 (+0000) Subject: Some modifications and some files added. X-Git-Tag: v3.3~506 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9b1ec3c5445076d8f5827f850a9a5e9ea4853696?hp=624064042aa82cbdb6d83b0f73bba7ba61048bbc Some modifications and some files added. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5430 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/cxx/0bject.hpp b/src/cxx/0bject.hpp index cf0b8d1596..6841835cdf 100644 --- a/src/cxx/0bject.hpp +++ b/src/cxx/0bject.hpp @@ -5,7 +5,7 @@ // Compilation C++ recquise #ifndef __cplusplus - #error object.hpp requires C++ compilation (use a .cxx suffix) + #error Object.hpp requires C++ compilation (use a .cxx suffix) #endif #include @@ -35,7 +35,7 @@ namespace msg { return MSG_GET_CLASS(class_name); } \ // CreateObject implementation. - #define HX_IMPLEMENT_DYNAMIC(class_name, base_class_name) \ + #define MSG_IMPLEMENT_DYNAMIC(class_name, base_class_name) \ Object* class_name::createObject() \ { return (Object*)(new class_name); } \ DeclaringClass _declaringClass_##class_name(MSG_GET_CLASS(class_name)); \ diff --git a/src/cxx/BadAllocException.cxx b/src/cxx/BadAllocException.cxx new file mode 100644 index 0000000000..07df2b614c --- /dev/null +++ b/src/cxx/BadAllocException.cxx @@ -0,0 +1,61 @@ +#include "BadAllocException.hpp" + +#include +#include +#include + +using namespace std; + +namespace SimGrid +{ + namespace Msg + { + + BadAllocException::BadAllocException() + { + this->reason = (char*) calloc(strlen("Not enough memory") + 1, sizeof(char)); + strcpy(this->reason, "Not enough memory"); + } + + + BadAllocException::BadAllocException(const BadAllocException& rBadAllocException) + { + const char* reason = rBadAllocException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + BadAllocException::BadAllocException(const char* objectName) + { + this->reason = (char*) calloc(strlen("Not enough memory to allocate ") + strlen(objectName) + 1, sizeof(char)); + sprintf(this->reason, "Not enough memory to allocate %s", objectName); + } + + + BadAllocException::~BadAllocException() + { + if(this->reason) + free(this->reason); + } + + const char* BadAllocException::toString(void) const + { + return (const char*)(this->reason); + } + + + const BadAllocException& BadAllocException::operator = (const BadAllocException& rBadAllocException) + { + const char* reason = rBadAllocException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/BadAllocException.hpp b/src/cxx/BadAllocException.hpp new file mode 100644 index 0000000000..df050b8dea --- /dev/null +++ b/src/cxx/BadAllocException.hpp @@ -0,0 +1,64 @@ +/* + * BadAllocException.hpp + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + +#ifndef MSG_MSGEXCEPTION_HPP +#define MSG_MSGEXCEPTION_HPP + +#include "Exception.hpp" + +namespace SimGrid +{ + namespace Msg + { + + class BadAllocException : public Exception + { + public: + + // Default constructor. + BadAllocException(); + + // Copy constructor. + BadAllocException(const BadAllocException& rBadAllocException); + + // This constructor takes the name of the object of the allocation failure. + BadAllocException(const char* objectName); + + // Destructor. + virtual ~BadAllocException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Not enough memory to allocate : `object name'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const BadAllocException& operator = (const BadAllocException& rBadAllocException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_MSGEXCEPTION_HPP diff --git a/src/cxx/Exception.cxx b/src/cxx/Exception.cxx new file mode 100644 index 0000000000..924eab874c --- /dev/null +++ b/src/cxx/Exception.cxx @@ -0,0 +1,48 @@ +#include "Exception.hpp" + +namespace SimGrid +{ + namespace Msg + { + + Exception::Exception() + { + reason = "Unknown reason"; + } + + + Exception::Exception(const Exception& rException) + { + this->reason = rException.toString(); + } + + + Exception::Exception(const char* reason) + { + this->reason = reason; + } + + + Exception::~Exception() + { + // NOTHING TODO + } + + const char* Exception::toString(void) const + { + return this->reason; + } + + + const Exception& Exception::operator = (const Exception& rException) + { + this->reason = rException.toString(); + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/Exception.hpp b/src/cxx/Exception.hpp new file mode 100644 index 0000000000..ad22e99387 --- /dev/null +++ b/src/cxx/Exception.hpp @@ -0,0 +1,61 @@ +/* + * Exception.hpp + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + +#ifndef MSG_EXCEPTION_HPP +#define MSG_EXCEPTION_HPP + +namespace SimGrid +{ + namespace Msg + { + + class Exception + { + public: + + // Default constructor. + Exception(); + + // Copy constructor. + Exception(const Exception& rException); + + // This constructor takes the reason of the exception. + Exception(const char* reason); + + // Destructor. + virtual ~Exception(); + + // Operations. + + // Returns the reason of the exception. + const char* toString(void) const; + + // Operators. + + // Assignement. + const Exception& operator = (const Exception& rException); + + private : + + // Attributes. + + // The reason of the exceptions. + const char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_EXCEPTION_HPP diff --git a/src/cxx/Host.cxx b/src/cxx/Host.cxx index e1adb5f959..8cb4a08e35 100644 --- a/src/cxx/Host.cxx +++ b/src/cxx/Host.cxx @@ -1,53 +1,52 @@ #include -namespace msg +namespace SimGrid { -// Default constructor. +namespace Msg +{ + + Host::Host() { nativeHost = NULL; data = NULL; } -// Copy constructor. Host::Host(const Host& rHost) { + this->nativeHost = rHost.nativeHost; + this->data = rHost.getData(); } -// Destructor. Host::~Host() { - nativeHost = NULL; + // NOTHING TODO } -// Operations Host& Host::getByName(const char* hostName) -throw(HostNotFoundException) +throw(HostNotFoundException, InvalidParameterException, BadAllocException) { - m_host_t nativeHost; // native host. - Host* host = NULL; // wrapper host. - - /* get the host by name (the hosts are created during the grid resolution) */ - nativeHost = MSG_get_host_by_name(name); - DEBUG2("MSG gave %p as native host (simdata=%p)",nativeHost,nativeHost->simdata); + // check the parameters + if(!hostName) + throw InvalidParmeterException("hostName"); + + m_host_t nativeHost = NULL; // native host. + Host* host = NULL; // wrapper host. - if(!nativeHost) - {// invalid host name - // TODO throw HostNotFoundException - return NULL; - } + if(!(nativeHost = MSG_get_host_by_name(hostName))) + throw HostNotFoundException(hostName); if(!nativeHost->data) { // native host not associated yet with its wrapper // instanciate a new wrapper - host = new Host(); - + if(!(host = new Host()) + throw BadAllocException(hostName); + host->nativeHost = nativeHost; // the native host data field is set with its wrapper returned - nativeHost->data = (void*)host; } @@ -84,11 +83,21 @@ Host& Host::currentHost(void) return *host; } -int Host::all(Host** hosts) +void Host::all(Host*** hosts, int* len) +throw(InvalidParameterException, BadAllocException) { + /* check the parameters */ + if(!hosts) + throw InvalidParameterException("hosts"); + + if(len < 0) + throw InvalidParameterException("len parameter must be positive"); + int count = xbt_fifo_size(msg_global->host); - *hosts = new Host[count]; + 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)"); + int index; m_host_t nativeHost; Host* host; @@ -102,16 +111,23 @@ int Host::all(Host** hosts) if(!host) { - host = new Host(); + if(!(host = new Host()) + { + // release all allocated memory. + for(int i = 0; i < index; i++) + delete (*(hosts)[i]); + + throw BadAllocException("to fill the table of the hosts installed on your platform"); + } host->nativeHost = nativeHost; nativeHost->data = (void*)host; } - hosts[index] = host; + (*hosts)[index] = host; } - return count; + *len = count; } @@ -182,11 +198,6 @@ throw(NativeException) } } - - - - - void Host::send(const Task& rTask) throw(NativeException) { @@ -274,4 +285,5 @@ throw(NativeException) } -} \ No newline at end of file +} // namspace Msg +} // namespace SimGrid \ No newline at end of file diff --git a/src/cxx/Host.hpp b/src/cxx/Host.hpp index 03b9232724..e8b2854e54 100644 --- a/src/cxx/Host.hpp +++ b/src/cxx/Host.hpp @@ -1,92 +1,259 @@ +/* + * Host.hpp + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ #ifndef MSG_HOST_HPP #define MSG_HOST_HPP -// Compilation C++ recquise +/*! \brief Host class declaration. + * + * An host instance represents a location (any possible place) where a process may run. + * Thus it is represented as a physical resource with computing capabilities, some + * mailboxes to enable running process to communicate with remote ones, and some private + * data that can be only accessed by local process. An instance of this class is always + * binded with the corresponding native host. All the native hosts are automaticaly created + * during the call of the static method Msg::createEnvironment(). This method takes as parameter + * the platform file which describes all elements of the platform (host, link, root..). + * You never need to create an host your self. + * + * The best way to get an host is to call the static method + * Host.getByName() which returns a reference. + * + * For example to get the instance of the host. If your platform + * file description contains an host named "Jacquelin" : + * + * \verbatim +using namespace SimGrid.Msg; + +Host jacquelin; + +try +{ + jacquelin = Host::getByName("Jacquelin"); +} +catch(HostNotFoundException e) +{ + cerr << e.toString(); +} +... +\endverbatim + * + */ + #ifndef __cplusplus #error Host.hpp requires C++ compilation (use a .cxx suffix) #endif -namespace msg -{ -class Host -{ - private : - // Default constructor. - Host(); - - // Copy constructor. - Host(const Host& rHost); - - // Destructor. - virtual ~Host(); - - public: - - // Operations - - static Host& getByName(const char* hostName) - throw(HostNotFoundException); - - static int getNumber(void); - - static Host& currentHost(void); - - static int all(Host** hosts); - - - const char* getName(void) const; - - void setData(void* data); - - // Getters/setters - - void* getData(void) const; - - int Host::getRunningTaskNumber(void) const; - - double getSpeed(void) const; - - bool hasData(void) const; - - bool isAvailble(void) const; - - void put(int channel, const Task& rTask) - throw(NativeException); - - void put(int channel, Task task, double timeout) - throw(NativeException); - - void Host::putBounded(int channel, const Task& rTask, double maxRate) - throw(NativeException); +#include +#include +#include - - void send(const Task& rTask) - throw(NativeException); - - void send(const char* alias, const Task& rTask) - throw(NativeException); - - void send(const Task& rTask, double timeout) - throw(NativeException); - - void send(const char* alias, const Task& rTask, double timeout) - throw(NativeException); - - void sendBounded(const Task& rTask, double maxRate) - throw(NativeException); - - void sendBounded(const char* alias, const Task& rTask, double maxRate) - throw(NativeException); - - - private: - // Attributes. - - m_host_t nativeHost; +// namespace SimGrid::Msg +namespace SimGrid +{ + namespace Msg + { + // Declaration of the class SimGrid::Msg::Host. + class Host + { + // Desable the default constructor. + // The best way to get an host instance is to use the static method Host::getByName(). + + private : + + // Default constructor (desabled). + Host(); + + public: + + // Copy constructor (desabled). + Host(const Host& rHost); + + // Destructor (desable). + virtual ~Host(); + + // Operations + + /*! \brief Host::getByName() - returns an host by its name + * + * This static method returns a reference to the host instance associated + * with a native host of your platform. This is the best way to get a host. + * + * \param hostName The name of the host. + * + * \return If successful the method returns a reference to the instance + * associated with the native host having the name specified + * as parameter of your platform. Otherwise the method throws + * one of the exceptions detailed below. + * + * \exception [HostNotFoundException] if no host with the specified name + * was found. + * [InvalidParameterException] if the hostName parameter is invalid (NULL). + * [BadAllocException] if there is not enough memory to allocate the host. + */ + static Host& getByName(const char* hostName) + throw(HostNotFoundException, InvalidParameterException, BadAllocException); + + /*! \brief Host::getNumber() - returns the number of the installed hosts. + * + * \return The number of hosts installed. + */ + static int getNumber(void); + + + /*! \brief Host::currentHost() - This static method returns the location on which the current + * process is executed. + * + * \return The host of the current process. + * + * \see Process::currentProcess(). + */ + static Host& currentHost(void) + throw(InvalidParameterException, BadAllocException); + + /*! \brief Host::all() - This static method retrieves all of the hosts of the installed platform. + * + * \param hosts A pointer to array of Host pointers that receives all the hosts of the platform. + * + * \param len A pointer to the length of the table of pointers. + * + * \return If successful the hosts table is filled and + * the parameter len is set with the number of hosts of the platform. + * Otherwise the method throw one of the exception described below. + * + * \exception [InvalidParameterException] if the parameter hosts is invalid or + * if the parameter len is negative or + * less than the number of hosts installed + * on the current platform. + * [BadAllocException] If the method can't allocate memory to fill + * the table of hosts. + * + * + * \remark To get the number of hosts installed on your platform use the static method + * Host::getNumber(). + * + * \see Host::getNumber(). + * + *\verbatim + * // This example show how to use this method to get the list of hosts installed on your platform. + * + * using namespace SimGrid::Msg; + * using + * + * // (1) get the number of hosts. + * int number = Host::getNumber(); + * + * // (2) allocate the array that receives the list of hosts. + * HostPtr* ar = new HostPtr[number]; // HostPtr is defined as (typedef Host* HostPtr at the end of the + * // declaration of this class. + * + * // (3) call the method + * try + * { + * Host::all(&ar, &number); + * } + * catch(BadAllocException e) + * { + * cerr << e.toString() << endl; + * ... + * } + * catch(InvalidArgumentException e) + * { + * cerr << e.toString() << endl; + * .. + * } + * + * // (4) use the table of host (for example print all the name of all the hosts); + * + * for(int i = 0; i < number ; i++) + * cout << ar[i]->getName() << endl; + * + * ... + * + * // (5) release the allocate table + * + * delete[] ar; + * + */ + static void all(Host*** hosts /*in|out*/, int* len /*in|out*/); + + + const char* getName(void) const; + + void setData(void* data); + + // Getters/setters + + void* getData(void) const; + + int Host::getRunningTaskNumber(void) const; + + double getSpeed(void) const; + + bool hasData(void) const; + + bool isAvailble(void) const; + + void put(int channel, const Task& rTask) + throw(NativeException); + + void put(int channel, Task task, double timeout) + throw(NativeException); + + void Host::putBounded(int channel, const Task& rTask, double maxRate) + throw(NativeException); + + + void send(const Task& rTask) + throw(NativeException); + + void send(const char* alias, const Task& rTask) + throw(NativeException); + + void send(const Task& rTask, double timeout) + throw(NativeException); + + void send(const char* alias, const Task& rTask, double timeout) + throw(NativeException); + + void sendBounded(const Task& rTask, double maxRate) + throw(NativeException); + + void sendBounded(const char* alias, const Task& rTask, double maxRate) + throw(NativeException); + + + + + protected: + // Attributes. + + /** + * This attribute represents the msg native host object. + * It is set automaticatly during the call of the static + * method Host::getByName(). + * + * @see Host::getByName(). + */ + m_host_t nativeHost; + + private: + /** + * User host data. + */ + void* data; + }; - void* data; - }; -} + typedef Host* HostPtr; + } // namespace Msg +} // namespace SimGrid #endif // !MSG_HOST_HPP \ No newline at end of file diff --git a/src/cxx/HostNotFoundException.cxx b/src/cxx/HostNotFoundException.cxx index e69de29bb2..c0dac52229 100644 --- a/src/cxx/HostNotFoundException.cxx +++ b/src/cxx/HostNotFoundException.cxx @@ -0,0 +1,62 @@ +#include "HostNotFoundException.hpp" + +#include +#include +#include + +using namespace std; + +namespace SimGrid +{ + namespace Msg + { + + HostNotFoundException::HostNotFoundException() + { + this->reason = (char*) calloc(strlen("Host not found : unknown") + 1, sizeof(char)); + strcpy(this->reason, "Host not found : unknown"); + } + + + HostNotFoundException::HostNotFoundException(const HostNotFoundException& rHostNotFoundException) + { + const char* reason = rHostNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + + HostNotFoundException::HostNotFoundException(const char* name) + { + this->reason = (char*) calloc(strlen("Host not found : ") + strlen(name) + 1, sizeof(char)); + sprintf(this->reason, "Host not found : %s", name); + } + + + HostNotFoundException::~HostNotFoundException() + { + if(this->reason) + free(this->reason); + } + + const char* HostNotFoundException::toString(void) const + { + return (const char*)(this->reason); + } + + + const HostNotFoundException& HostNotFoundException::operator = (const HostNotFoundException& rHostNotFoundException) + { + const char* reason = rHostNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/HostNotFoundException.hpp b/src/cxx/HostNotFoundException.hpp new file mode 100644 index 0000000000..25d3330521 --- /dev/null +++ b/src/cxx/HostNotFoundException.hpp @@ -0,0 +1,64 @@ +/* + * HostNotFoundException.hpp + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + +#ifndef MSG_HOSTNOTFOUNDEXCEPTION_HPP +#define MSG_HOSTNOTFOUNDEXCEPTION_HPP + +#include "Exception.hpp" + +namespace SimGrid +{ + namespace Msg + { + + class HostNotFoundException : public Exception + { + public: + + // Default constructor. + HostNotFoundException(); + + // Copy constructor. + HostNotFoundException(const HostNotFoundException& rHostNotFoundException); + + // This constructor takes the name of the host not found. + HostNotFoundException(const char* name); + + // Destructor. + virtual ~HostNotFoundException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Host not found `host name'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const HostNotFoundException& operator = (const HostNotFoundException& rHostNotFoundException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_HOSTNOTFOUNDEXCEPTION_HPP diff --git a/src/cxx/InvalidArgumentException.cxx b/src/cxx/InvalidArgumentException.cxx new file mode 100644 index 0000000000..ffc120830a --- /dev/null +++ b/src/cxx/InvalidArgumentException.cxx @@ -0,0 +1,62 @@ +#include "InvalidArgumentException.hpp" + +#include +#include +#include + +using namespace std; + +namespace SimGrid +{ + namespace Msg + { + + InvalidArgumentException::InvalidArgumentException() + { + this->reason = (char*) calloc(strlen("Invalid argument : unknown") + 1, sizeof(char)); + strcpy(this->reason, "Invalid argument : unknown"); + } + + + InvalidArgumentException::InvalidArgumentException(const InvalidArgumentException& rInvalidArgumentException) + { + const char* reason = rInvalidArgumentException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + + InvalidArgumentException::InvalidArgumentException(const char* name) + { + this->reason = (char*) calloc(strlen("Invalid argument : ") + strlen(name) + 1, sizeof(char)); + sprintf(this->reason, "Invalid argument : %s", name); + } + + + InvalidArgumentException::~InvalidArgumentException() + { + if(this->reason) + free(this->reason); + } + + const char* InvalidArgumentException::toString(void) const + { + return (const char*)(this->reason); + } + + + const InvalidArgumentException& InvalidArgumentException::operator = (const InvalidArgumentException& rInvalidArgumentException) + { + const char* reason = rInvalidArgumentException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/InvalidArgumentException.hpp b/src/cxx/InvalidArgumentException.hpp new file mode 100644 index 0000000000..e81fdd406a --- /dev/null +++ b/src/cxx/InvalidArgumentException.hpp @@ -0,0 +1,64 @@ +/* + * InvalidArgumentException.hpp + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + +#ifndef MSG_INVALIDARGUMENTEXCEPTION_HPP +#define MSG_INVALIDARGUMENTEXCEPTION_HPP + +#include "Exception.hpp" + +namespace SimGrid +{ + namespace Msg + { + + class InvalidArgumentException : public Exception + { + public: + + // Default constructor. + InvalidArgumentException(); + + // Copy constructor. + InvalidArgumentException(const InvalidArgumentException& rInvalidArgumentException); + + // This constructor takes the name of the invalid argument. + InvalidArgumentException(const char* name); + + // Destructor. + virtual ~InvalidArgumentException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Invalid argument `argument name'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const InvalidArgumentException& operator = (const InvalidArgumentException& rInvalidArgumentException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_INVALIDARGUMENTEXCEPTION_HPP diff --git a/src/cxx/MsgException.cxx b/src/cxx/MsgException.cxx index e69de29bb2..5b9bd4645e 100644 --- a/src/cxx/MsgException.cxx +++ b/src/cxx/MsgException.cxx @@ -0,0 +1,61 @@ +#include "MsgException.hpp" + +#include +#include +#include + +using namespace std; + +namespace SimGrid +{ + namespace Msg + { + + MsgException::MsgException() + { + this->reason = (char*) calloc(strlen("Internal exception : unknown reason") + 1, sizeof(char)); + strcpy(this->reason, "Internal exception : unknown reason"); + } + + + MsgException::MsgException(const MsgException& rMsgException) + { + const char* reason = rMsgException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + MsgException::MsgException(const char* reason) + { + this->reason = (char*) calloc(strlen("Internal exception : ") + strlen(reason) + 1, sizeof(char)); + sprintf(this->reason, "Invalid exception : %s", reason); + } + + + MsgException::~MsgException() + { + if(this->reason) + free(this->reason); + } + + const char* MsgException::toString(void) const + { + return (const char*)(this->reason); + } + + + const MsgException& MsgException::operator = (const MsgException& rMsgException) + { + const char* reason = rMsgException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/MsgException.hpp b/src/cxx/MsgException.hpp index bcc3c4491f..55d151a1b0 100644 --- a/src/cxx/MsgException.hpp +++ b/src/cxx/MsgException.hpp @@ -1,43 +1,64 @@ -#ifndef MSG_EXCEPTION_HPP -#define MSG_EXCEPTION_HPP +/* + * MsgException.hpp + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + +#ifndef MSG_MSGEXCEPTION_HPP +#define MSG_MSGEXCEPTION_HPP -namespace msg +#include "Exception.hpp" + +namespace SimGrid { - class MsgException + namespace Msg { - public: - // Default constructor. - MsgException(); - - // This constructor takes as parameter the message of the - // MsgException object. - MsgException(const char* msg); - - // Copy constructor. - MsgException(const MsgException& rMsgException); - - // Destructor. - virtual ~MsgException(); - - // Operations. - - // Returns the message of the exception. - const char* what(void) const; - - - // Getters/setters. - - // Operators. + class MsgException : public Exception + { + public: + + // Default constructor. + MsgException(); + + // Copy constructor. + MsgException(const MsgException& rMsgException); + + // This constructor takes the reason of the exception. + MsgException(const char* reason); + + // Destructor. + virtual ~MsgException(); + + // Operations. + + // Returns the reason of the exception : + // the message "Internal exception `reason'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const MsgException& operator = (const MsgException& rMsgException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; - private: - // Attributes. - - // The message of the exception. - const char* msg; - - }; -} + } // namespace Msg + +}// namespace SimGrid + -#endif // !MSG_EXCEPTION_HPP \ No newline at end of file +#endif // !MSG_MSGEXCEPTION_HPP diff --git a/src/cxx/Task.cxx b/src/cxx/Task.cxx index 30f2dd0532..2ab132fe98 100644 --- a/src/cxx/Task.cxx +++ b/src/cxx/Task.cxx @@ -174,10 +174,239 @@ throw(NativeException) } } -void send(void) +void Task::send(void) throw(NativeException) { -} + MSG_error_t rv; + + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + + + rv = MSG_task_send_with_timeout(nativeTask, alias, -1.0); + + free(alias) + + if(MSG_OK != rv) + { + // TODO throw the NativeException + } +} + + +void Task::send(const char* alias) +throw(NativeException) +{ + + if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, -1.0)) + { + // TODO throw the NativeException + } +} + +void Task::send(double timeout) +throw(NativeException) +{ + MSG_error_t rv; + + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + + + rv = MSG_task_send_with_timeout(nativeTask, alias, timeout); + + free(alias) + + if(MSG_OK != rv) + { + // TODO throw the NativeException + } +} + +void Task::send(const char* alias, double timeout) +throw(NativeException) +{ + if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, timeout)) + { + // TODO throw the NativeException + } +} + +void Task::sendBounded(double maxRate) +throw(NativeException) +{ + MSG_error_t rv; + + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + rv = MSG_task_send_bounded(nativeTask, alias, maxRate); + + free(alias); + + + + if(MSG_OK != rv) + { + // TODO throw the NativeException + } +} + +void Task::sendBounded(const char* alias, double maxRate) +throw(NativeException) +{ + if(MSG_OK != MSG_task_send_bounded(nativeTask, alias, maxRate)) + { + // TODO throw the NativeException + } +} + +Task& Task::receive(void) +throw(NativeException) +{ + MSG_error_t rv; + + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + m_task_t nativeTask = NULL; + + rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL); + + free(alias); + + if(MSG_OK != rv) + { + // TODO thow NativeException + return NULL; + } + + return (*((Task*)nativeTask->data)); +} + +Task& Task::receive(const char* alias) +throw(NativeException) +{ + m_task_t nativeTask = NULL; + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL)) + { + // TODO thow NativeException + return NULL; + } + + return (*((Task*)nativeTask->data)); +} + +Task& Task::receive(const char* alias, double timeout) +throw(NativeException) +{ + m_task_t nativeTask = NULL; + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) + { + // TODO thow NativeException + return NULL; + } + + return (*((Task*)nativeTask->data)); +} + +Task& Task::receive(const char* alias, const Host& rHost) +throw(NativeException) +{ + m_task_t nativeTask = NULL; + + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) + { + // TODO thow NativeException + return NULL; + } + + return (*((Task*)nativeTask->data)); +} + +Task& Task::receive(const char* alias, double timeout, const Host& rHost) +throw(NativeException) +{ + m_task_t nativeTask = NULL; + + + if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) + { + // TODO thow NativeException + return NULL; + } + + return (*((Task*)nativeTask->data)); +} + +bool Task::listen(void) +throw(NativeException) +{ + int rv; + + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + rv = MSG_task_listen(alias); + + free(alias); + + return (bool)rv; +} + +bool Task::listen(const char* alias) +throw(NativeException) +{ + return (bool)MSG_task_listen(alias); +} + +bool Task::listenFrom(void) +throw(NativeException) +{ + int rv; + + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + rv = MSG_task_listen_from(alias); + + free(alias); + + return (int)rv; +} + +bool Task::listenFrom(const char* alias) +throw(NativeException) +{ + return (bool)MSG_task_listen_from(alias); + +} + +bool Task::listenFromHost(const Host& rHost) +throw(NativeException) +{ + int rv; + + char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2); + sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName()); + + rv = MSG_task_listen_from_host(alias, rHost.nativeHost); + + free(alias); + + return (bool)rv; +} + +bool Task::listenFromHost(const char* alias, const Host& rHost) +throw(NativeException) +{ + return (bool)MSG_task_listen_from_host(alias, rHost.nativeHost); +} } diff --git a/src/cxx/Task.hpp b/src/cxx/Task.hpp index 4b55a64b39..173f4a73c0 100644 --- a/src/cxx/Task.hpp +++ b/src/cxx/Task.hpp @@ -66,6 +66,57 @@ class Task void send(void) throw(NativeException); + void send(const char* alias) + throw(NativeException); + + void send(double timeout) + throw(NativeException); + + void send(const char* alias, double timeout) + throw(NativeException); + + void sendBounded(double maxRate) + throw(NativeException); + + void sendBounded(const char* alias, double maxRate) + throw(NativeException); + + static Task& receive(void) + throw(NativeException); + + static Task& receive(const char* alias) + throw(NativeException); + + static Task& receive(const char* alias, double timeout) + throw(NativeException); + + static Task& receive(const char* alias, const Host& rHost) + throw(NativeException); + + static Task& receive(const char* alias, double timeout, const Host& rHost) + throw(NativeException); + + static bool listen(void) + throw(NativeException); + + static bool listen(const char* alias) + throw(NativeException); + + static bool listenFrom(void) + throw(NativeException); + + static bool listenFrom(const char* alias) + throw(NativeException); + + + static bool listenFromHost(const Host& rHost) + throw(NativeException); + + static bool listenFromHost(const char* alias, const Host& rHost) + throw(NativeException); + + + private: m_task_t nativeTask;