\r
// Compilation C++ recquise\r
#ifndef __cplusplus\r
- #error object.hpp requires C++ compilation (use a .cxx suffix)\r
+ #error Object.hpp requires C++ compilation (use a .cxx suffix)\r
#endif\r
\r
#include <stdlib.h>\r
{ return MSG_GET_CLASS(class_name); } \\r
\r
// CreateObject implementation. \r
- #define HX_IMPLEMENT_DYNAMIC(class_name, base_class_name) \\r
+ #define MSG_IMPLEMENT_DYNAMIC(class_name, base_class_name) \\r
Object* class_name::createObject() \\r
{ return (Object*)(new class_name); } \\r
DeclaringClass _declaringClass_##class_name(MSG_GET_CLASS(class_name)); \\r
--- /dev/null
+#include "BadAllocException.hpp"\r
+\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+using namespace std;\r
+\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ \r
+ BadAllocException::BadAllocException()\r
+ {\r
+ this->reason = (char*) calloc(strlen("Not enough memory") + 1, sizeof(char));\r
+ strcpy(this->reason, "Not enough memory");\r
+ }\r
+ \r
+ \r
+ BadAllocException::BadAllocException(const BadAllocException& rBadAllocException)\r
+ {\r
+ const char* reason = rBadAllocException.toString();\r
+ this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+ strcpy(this->reason, reason);\r
+ \r
+ }\r
+ \r
+ BadAllocException::BadAllocException(const char* objectName)\r
+ {\r
+ this->reason = (char*) calloc(strlen("Not enough memory to allocate ") + strlen(objectName) + 1, sizeof(char));\r
+ sprintf(this->reason, "Not enough memory to allocate %s", objectName);\r
+ }\r
+ \r
+ \r
+ BadAllocException::~BadAllocException()\r
+ {\r
+ if(this->reason)\r
+ free(this->reason);\r
+ }\r
+ \r
+ const char* BadAllocException::toString(void) const\r
+ {\r
+ return (const char*)(this->reason); \r
+ }\r
+ \r
+ \r
+ const BadAllocException& BadAllocException::operator = (const BadAllocException& rBadAllocException)\r
+ {\r
+ const char* reason = rBadAllocException.toString();\r
+ this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+ \r
+ return *this;\r
+ }\r
+ \r
+ } // namespace Msg \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+\r
--- /dev/null
+/*\r
+ * BadAllocException.hpp\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */ \r
+ \r
+#ifndef MSG_MSGEXCEPTION_HPP\r
+#define MSG_MSGEXCEPTION_HPP\r
+\r
+#include "Exception.hpp"\r
+\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ \r
+ class BadAllocException : public Exception\r
+ {\r
+ public:\r
+ \r
+ // Default constructor.\r
+ BadAllocException();\r
+ \r
+ // Copy constructor.\r
+ BadAllocException(const BadAllocException& rBadAllocException);\r
+ \r
+ // This constructor takes the name of the object of the allocation failure.\r
+ BadAllocException(const char* objectName);\r
+ \r
+ // Destructor.\r
+ virtual ~BadAllocException();\r
+ \r
+ // Operations.\r
+ \r
+ // Returns the reason of the exception :\r
+ // the message "Not enough memory to allocate : `object name'"\r
+ const char* toString(void) const;\r
+ \r
+ // Operators.\r
+ \r
+ // Assignement.\r
+ const BadAllocException& operator = (const BadAllocException& rBadAllocException);\r
+ \r
+ private :\r
+ \r
+ // Attributes.\r
+ \r
+ // A buffer used to build the message returned by the methode toString().\r
+ char* reason;\r
+ };\r
+ \r
+ \r
+ } // namespace Msg \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+#endif // !MSG_MSGEXCEPTION_HPP\r
--- /dev/null
+#include "Exception.hpp"\r
+\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ \r
+ Exception::Exception()\r
+ {\r
+ reason = "Unknown reason";\r
+ }\r
+ \r
+ \r
+ Exception::Exception(const Exception& rException)\r
+ {\r
+ this->reason = rException.toString();\r
+ }\r
+ \r
+ \r
+ Exception::Exception(const char* reason)\r
+ {\r
+ this->reason = reason;\r
+ }\r
+ \r
+ \r
+ Exception::~Exception()\r
+ {\r
+ // NOTHING TODO\r
+ }\r
+ \r
+ const char* Exception::toString(void) const\r
+ {\r
+ return this->reason; \r
+ }\r
+ \r
+ \r
+ const Exception& Exception::operator = (const Exception& rException)\r
+ {\r
+ this->reason = rException.toString();\r
+ return *this;\r
+ }\r
+ \r
+ } // namespace Msg \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+\r
--- /dev/null
+/*\r
+ * Exception.hpp\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */ \r
+ \r
+#ifndef MSG_EXCEPTION_HPP\r
+#define MSG_EXCEPTION_HPP\r
+\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ \r
+ class Exception\r
+ {\r
+ public:\r
+ \r
+ // Default constructor.\r
+ Exception();\r
+ \r
+ // Copy constructor.\r
+ Exception(const Exception& rException);\r
+ \r
+ // This constructor takes the reason of the exception.\r
+ Exception(const char* reason);\r
+ \r
+ // Destructor.\r
+ virtual ~Exception();\r
+ \r
+ // Operations.\r
+ \r
+ // Returns the reason of the exception.\r
+ const char* toString(void) const;\r
+ \r
+ // Operators.\r
+ \r
+ // Assignement.\r
+ const Exception& operator = (const Exception& rException);\r
+ \r
+ private :\r
+ \r
+ // Attributes.\r
+ \r
+ // The reason of the exceptions.\r
+ const char* reason;\r
+ };\r
+ \r
+ \r
+ } // namespace Msg \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+#endif // !MSG_EXCEPTION_HPP\r
#include <Host.hpp>\r
\r
-namespace msg\r
+namespace SimGrid\r
{\r
-// Default constructor.\r
+namespace Msg\r
+{\r
+\r
+\r
Host::Host()\r
{\r
nativeHost = NULL;\r
data = NULL;\r
}\r
\r
-// Copy constructor.\r
Host::Host(const Host& rHost)\r
{\r
+ this->nativeHost = rHost.nativeHost;\r
+ this->data = rHost.getData(); \r
}\r
\r
-// Destructor.\r
Host::~Host()\r
{\r
- nativeHost = NULL;\r
+ // NOTHING TODO\r
}\r
\r
-// Operations\r
\r
Host& Host::getByName(const char* hostName)\r
-throw(HostNotFoundException)\r
+throw(HostNotFoundException, InvalidParameterException, BadAllocException)\r
{\r
- m_host_t nativeHost; // native host.\r
- Host* host = NULL; // wrapper host.\r
- \r
- /* get the host by name (the hosts are created during the grid resolution) */\r
- nativeHost = MSG_get_host_by_name(name);\r
- DEBUG2("MSG gave %p as native host (simdata=%p)",nativeHost,nativeHost->simdata);\r
+ // check the parameters\r
+ if(!hostName)\r
+ throw InvalidParmeterException("hostName");\r
+ \r
+ m_host_t nativeHost = NULL; // native host.\r
+ Host* host = NULL; // wrapper host.\r
\r
- if(!nativeHost) \r
- {// invalid host name\r
- // TODO throw HostNotFoundException\r
- return NULL;\r
- }\r
+ if(!(nativeHost = MSG_get_host_by_name(hostName))) \r
+ throw HostNotFoundException(hostName);\r
\r
if(!nativeHost->data) \r
{ // native host not associated yet with its wrapper\r
\r
// instanciate a new wrapper \r
- host = new Host();\r
- \r
+ if(!(host = new Host())\r
+ throw BadAllocException(hostName);\r
+ \r
host->nativeHost = nativeHost; \r
\r
// the native host data field is set with its wrapper returned \r
- \r
nativeHost->data = (void*)host;\r
}\r
\r
return *host;\r
}\r
\r
-int Host::all(Host** hosts) \r
+void Host::all(Host*** hosts, int* len) \r
+throw(InvalidParameterException, BadAllocException) \r
{\r
+ /* check the parameters */\r
+ if(!hosts)\r
+ throw InvalidParameterException("hosts");\r
+ \r
+ if(len < 0)\r
+ throw InvalidParameterException("len parameter must be positive");\r
+ \r
int count = xbt_fifo_size(msg_global->host);\r
\r
- *hosts = new Host[count];\r
+ if(*len < count)\r
+ throw InvalidParameterException("len parameter must be more than the number of installed host\n (use Host::getNumber() to get the number of hosts)");\r
+ \r
int index;\r
m_host_t nativeHost;\r
Host* host;\r
\r
if(!host) \r
{\r
- host = new Host();\r
+ if(!(host = new Host())\r
+ {\r
+ // release all allocated memory.\r
+ for(int i = 0; i < index; i++)\r
+ delete (*(hosts)[i]);\r
+ \r
+ throw BadAllocException("to fill the table of the hosts installed on your platform");\r
+ }\r
\r
host->nativeHost = nativeHost;\r
nativeHost->data = (void*)host;\r
}\r
\r
- hosts[index] = host;\r
+ (*hosts)[index] = host;\r
}\r
\r
- return count; \r
+ *len = count; \r
}\r
\r
\r
}\r
}\r
\r
-\r
-\r
-\r
- \r
-\r
void Host::send(const Task& rTask) \r
throw(NativeException) \r
{ \r
} \r
\r
\r
-}
\ No newline at end of file
+} // namspace Msg\r
+} // namespace SimGrid
\ No newline at end of file
+/*\r
+ * Host.hpp\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */ \r
#ifndef MSG_HOST_HPP\r
#define MSG_HOST_HPP\r
\r
\r
-// Compilation C++ recquise\r
+/*! \brief Host class declaration.\r
+ *\r
+ * An host instance represents a location (any possible place) where a process may run. \r
+ * Thus it is represented as a physical resource with computing capabilities, some \r
+ * mailboxes to enable running process to communicate with remote ones, and some private \r
+ * data that can be only accessed by local process. An instance of this class is always \r
+ * binded with the corresponding native host. All the native hosts are automaticaly created \r
+ * during the call of the static method Msg::createEnvironment(). This method takes as parameter\r
+ * the platform file which describes all elements of the platform (host, link, root..).\r
+ * You never need to create an host your self.\r
+ *\r
+ * The best way to get an host is to call the static method \r
+ * Host.getByName() which returns a reference.\r
+ *\r
+ * For example to get the instance of the host. If your platform\r
+ * file description contains an host named "Jacquelin" :\r
+ *\r
+ * \verbatim\r
+using namespace SimGrid.Msg;\r
+\r
+Host jacquelin;\r
+\r
+try \r
+{ \r
+ jacquelin = Host::getByName("Jacquelin");\r
+}\r
+catch(HostNotFoundException e) \r
+{\r
+ cerr << e.toString();\r
+}\r
+...\r
+\endverbatim\r
+ *\r
+ */\r
+\r
#ifndef __cplusplus\r
#error Host.hpp requires C++ compilation (use a .cxx suffix)\r
#endif\r
\r
-namespace msg\r
-{\r
-class Host\r
-{\r
- private :\r
- // Default constructor.\r
- Host();\r
- \r
- // Copy constructor.\r
- Host(const Host& rHost);\r
- \r
- // Destructor.\r
- virtual ~Host();\r
- \r
- public: \r
- \r
- // Operations\r
- \r
- static Host& getByName(const char* hostName)\r
- throw(HostNotFoundException);\r
- \r
- static int getNumber(void);\r
- \r
- static Host& currentHost(void);\r
- \r
- static int all(Host** hosts);\r
- \r
- \r
- const char* getName(void) const;\r
- \r
- void setData(void* data);\r
- \r
- // Getters/setters\r
- \r
- void* getData(void) const;\r
- \r
- int Host::getRunningTaskNumber(void) const;\r
- \r
- double getSpeed(void) const;\r
- \r
- bool hasData(void) const;\r
- \r
- bool isAvailble(void) const;\r
- \r
- void put(int channel, const Task& rTask)\r
- throw(NativeException);\r
- \r
- void put(int channel, Task task, double timeout) \r
- throw(NativeException);\r
- \r
- void Host::putBounded(int channel, const Task& rTask, double maxRate) \r
- throw(NativeException);\r
+#include <InvalidArgumentException.hpp>\r
+#include <BadAllocException.hpp>\r
+#include <HostNotFoundException.hpp>\r
\r
- \r
- void send(const Task& rTask) \r
- throw(NativeException);\r
- \r
- void send(const char* alias, const Task& rTask) \r
- throw(NativeException);\r
- \r
- void send(const Task& rTask, double timeout) \r
- throw(NativeException);\r
- \r
- void send(const char* alias, const Task& rTask, double timeout) \r
- throw(NativeException);\r
- \r
- void sendBounded(const Task& rTask, double maxRate) \r
- throw(NativeException);\r
- \r
- void sendBounded(const char* alias, const Task& rTask, double maxRate) \r
- throw(NativeException); \r
- \r
- \r
- private:\r
- // Attributes.\r
- \r
- m_host_t nativeHost;\r
+// namespace SimGrid::Msg\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ // Declaration of the class SimGrid::Msg::Host.\r
+ class Host\r
+ {\r
+ // Desable the default constructor.\r
+ // The best way to get an host instance is to use the static method Host::getByName().\r
+ \r
+ private :\r
+ \r
+ // Default constructor (desabled).\r
+ Host();\r
+ \r
+ public: \r
+ \r
+ // Copy constructor (desabled).\r
+ Host(const Host& rHost);\r
+ \r
+ // Destructor (desable).\r
+ virtual ~Host();\r
+ \r
+ // Operations\r
+ \r
+ /*! \brief Host::getByName() - returns an host by its name\r
+ *\r
+ * This static method returns a reference to the host instance associated \r
+ * with a native host of your platform. This is the best way to get a host.\r
+ *\r
+ * \param hostName The name of the host.\r
+ *\r
+ * \return If successful the method returns a reference to the instance\r
+ * associated with the native host having the name specified\r
+ * as parameter of your platform. Otherwise the method throws\r
+ * one of the exceptions detailed below.\r
+ *\r
+ * \exception [HostNotFoundException] if no host with the specified name\r
+ * was found.\r
+ * [InvalidParameterException] if the hostName parameter is invalid (NULL).\r
+ * [BadAllocException] if there is not enough memory to allocate the host.\r
+ */ \r
+ static Host& getByName(const char* hostName)\r
+ throw(HostNotFoundException, InvalidParameterException, BadAllocException);\r
+ \r
+ /*! \brief Host::getNumber() - returns the number of the installed hosts.\r
+ *\r
+ * \return The number of hosts installed.\r
+ */\r
+ static int getNumber(void);\r
+ \r
+ \r
+ /*! \brief Host::currentHost() - This static method returns the location on which the current \r
+ * process is executed.\r
+ *\r
+ * \return The host of the current process.\r
+ *\r
+ * \see Process::currentProcess().\r
+ */\r
+ static Host& currentHost(void)\r
+ throw(InvalidParameterException, BadAllocException);\r
+ \r
+ /*! \brief Host::all() - This static method retrieves all of the hosts of the installed platform.\r
+ *\r
+ * \param hosts A pointer to array of Host pointers that receives all the hosts of the platform.\r
+ *\r
+ * \param len A pointer to the length of the table of pointers.\r
+ *\r
+ * \return If successful the hosts table is filled and\r
+ * the parameter len is set with the number of hosts of the platform.\r
+ * Otherwise the method throw one of the exception described below.\r
+ *\r
+ * \exception [InvalidParameterException] if the parameter hosts is invalid or\r
+ * if the parameter len is negative or\r
+ * less than the number of hosts installed\r
+ * on the current platform.\r
+ * [BadAllocException] If the method can't allocate memory to fill\r
+ * the table of hosts.\r
+ *\r
+ *\r
+ * \remark To get the number of hosts installed on your platform use the static method\r
+ * Host::getNumber().\r
+ *\r
+ * \see Host::getNumber().\r
+ *\r
+ *\verbatim\r
+ * // This example show how to use this method to get the list of hosts installed on your platform.\r
+ *\r
+ * using namespace SimGrid::Msg;\r
+ * using <iostream>\r
+ *\r
+ * // (1) get the number of hosts.\r
+ * int number = Host::getNumber();\r
+ * \r
+ * // (2) allocate the array that receives the list of hosts.\r
+ * HostPtr* ar = new HostPtr[number]; // HostPtr is defined as (typedef Host* HostPtr at the end of the\r
+ * // declaration of this class.\r
+ *\r
+ * // (3) call the method\r
+ * try\r
+ * {\r
+ * Host::all(&ar, &number);\r
+ * }\r
+ * catch(BadAllocException e)\r
+ * {\r
+ * cerr << e.toString() << endl;\r
+ * ...\r
+ * }\r
+ * catch(InvalidArgumentException e)\r
+ * {\r
+ * cerr << e.toString() << endl;\r
+ * ..\r
+ * } \r
+ *\r
+ * // (4) use the table of host (for example print all the name of all the hosts);\r
+ * \r
+ * for(int i = 0; i < number ; i++)\r
+ * cout << ar[i]->getName() << endl;\r
+ *\r
+ * ...\r
+ * \r
+ * // (5) release the allocate table\r
+ * \r
+ * delete[] ar;\r
+ *\r
+ */ \r
+ static void all(Host*** hosts /*in|out*/, int* len /*in|out*/);\r
+ \r
+ \r
+ const char* getName(void) const;\r
+ \r
+ void setData(void* data);\r
+ \r
+ // Getters/setters\r
+ \r
+ void* getData(void) const;\r
+ \r
+ int Host::getRunningTaskNumber(void) const;\r
+ \r
+ double getSpeed(void) const;\r
+ \r
+ bool hasData(void) const;\r
+ \r
+ bool isAvailble(void) const;\r
+ \r
+ void put(int channel, const Task& rTask)\r
+ throw(NativeException);\r
+ \r
+ void put(int channel, Task task, double timeout) \r
+ throw(NativeException);\r
+ \r
+ void Host::putBounded(int channel, const Task& rTask, double maxRate) \r
+ throw(NativeException);\r
+ \r
+ \r
+ void send(const Task& rTask) \r
+ throw(NativeException);\r
+ \r
+ void send(const char* alias, const Task& rTask) \r
+ throw(NativeException);\r
+ \r
+ void send(const Task& rTask, double timeout) \r
+ throw(NativeException);\r
+ \r
+ void send(const char* alias, const Task& rTask, double timeout) \r
+ throw(NativeException);\r
+ \r
+ void sendBounded(const Task& rTask, double maxRate) \r
+ throw(NativeException);\r
+ \r
+ void sendBounded(const char* alias, const Task& rTask, double maxRate) \r
+ throw(NativeException);\r
+ \r
+ \r
+ \r
+ \r
+ protected:\r
+ // Attributes.\r
+ \r
+ /**\r
+ * This attribute represents the msg native host object. \r
+ * It is set automaticatly during the call of the static \r
+ * method Host::getByName().\r
+ *\r
+ * @see Host::getByName().\r
+ */ \r
+ m_host_t nativeHost;\r
+ \r
+ private:\r
+ /**\r
+ * User host data. \r
+ */ \r
+ void* data;\r
+ };\r
\r
- void* data;\r
- };\r
-}\r
+ typedef Host* HostPtr;\r
+ } // namespace Msg\r
+} // namespace SimGrid\r
\r
#endif // !MSG_HOST_HPP
\ No newline at end of file
+#include "HostNotFoundException.hpp"\r
+\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+using namespace std;\r
+\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ \r
+ HostNotFoundException::HostNotFoundException()\r
+ {\r
+ this->reason = (char*) calloc(strlen("Host not found : unknown") + 1, sizeof(char));\r
+ strcpy(this->reason, "Host not found : unknown");\r
+ }\r
+ \r
+ \r
+ HostNotFoundException::HostNotFoundException(const HostNotFoundException& rHostNotFoundException)\r
+ {\r
+ const char* reason = rHostNotFoundException.toString();\r
+ this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+ strcpy(this->reason, reason);\r
+ \r
+ }\r
+ \r
+ \r
+ HostNotFoundException::HostNotFoundException(const char* name)\r
+ {\r
+ this->reason = (char*) calloc(strlen("Host not found : ") + strlen(name) + 1, sizeof(char));\r
+ sprintf(this->reason, "Host not found : %s", name);\r
+ }\r
+ \r
+ \r
+ HostNotFoundException::~HostNotFoundException()\r
+ {\r
+ if(this->reason)\r
+ free(this->reason);\r
+ }\r
+ \r
+ const char* HostNotFoundException::toString(void) const\r
+ {\r
+ return (const char*)(this->reason); \r
+ }\r
+ \r
+ \r
+ const HostNotFoundException& HostNotFoundException::operator = (const HostNotFoundException& rHostNotFoundException)\r
+ {\r
+ const char* reason = rHostNotFoundException.toString();\r
+ this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+ \r
+ return *this;\r
+ }\r
+ \r
+ } // namespace Msg \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+\r
--- /dev/null
+/*\r
+ * HostNotFoundException.hpp\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */ \r
+ \r
+#ifndef MSG_HOSTNOTFOUNDEXCEPTION_HPP\r
+#define MSG_HOSTNOTFOUNDEXCEPTION_HPP\r
+\r
+#include "Exception.hpp"\r
+\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ \r
+ class HostNotFoundException : public Exception\r
+ {\r
+ public:\r
+ \r
+ // Default constructor.\r
+ HostNotFoundException();\r
+ \r
+ // Copy constructor.\r
+ HostNotFoundException(const HostNotFoundException& rHostNotFoundException);\r
+ \r
+ // This constructor takes the name of the host not found.\r
+ HostNotFoundException(const char* name);\r
+ \r
+ // Destructor.\r
+ virtual ~HostNotFoundException();\r
+ \r
+ // Operations.\r
+ \r
+ // Returns the reason of the exception :\r
+ // the message "Host not found `host name'"\r
+ const char* toString(void) const;\r
+ \r
+ // Operators.\r
+ \r
+ // Assignement.\r
+ const HostNotFoundException& operator = (const HostNotFoundException& rHostNotFoundException);\r
+ \r
+ private :\r
+ \r
+ // Attributes.\r
+ \r
+ // A buffer used to build the message returned by the methode toString().\r
+ char* reason;\r
+ };\r
+ \r
+ \r
+ } // namespace Msg \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+#endif // !MSG_HOSTNOTFOUNDEXCEPTION_HPP\r
--- /dev/null
+#include "InvalidArgumentException.hpp"\r
+\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+using namespace std;\r
+\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ \r
+ InvalidArgumentException::InvalidArgumentException()\r
+ {\r
+ this->reason = (char*) calloc(strlen("Invalid argument : unknown") + 1, sizeof(char));\r
+ strcpy(this->reason, "Invalid argument : unknown");\r
+ }\r
+ \r
+ \r
+ InvalidArgumentException::InvalidArgumentException(const InvalidArgumentException& rInvalidArgumentException)\r
+ {\r
+ const char* reason = rInvalidArgumentException.toString();\r
+ this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+ strcpy(this->reason, reason);\r
+ \r
+ }\r
+ \r
+ \r
+ InvalidArgumentException::InvalidArgumentException(const char* name)\r
+ {\r
+ this->reason = (char*) calloc(strlen("Invalid argument : ") + strlen(name) + 1, sizeof(char));\r
+ sprintf(this->reason, "Invalid argument : %s", name);\r
+ }\r
+ \r
+ \r
+ InvalidArgumentException::~InvalidArgumentException()\r
+ {\r
+ if(this->reason)\r
+ free(this->reason);\r
+ }\r
+ \r
+ const char* InvalidArgumentException::toString(void) const\r
+ {\r
+ return (const char*)(this->reason); \r
+ }\r
+ \r
+ \r
+ const InvalidArgumentException& InvalidArgumentException::operator = (const InvalidArgumentException& rInvalidArgumentException)\r
+ {\r
+ const char* reason = rInvalidArgumentException.toString();\r
+ this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+ \r
+ return *this;\r
+ }\r
+ \r
+ } // namespace Msg \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+\r
--- /dev/null
+/*\r
+ * InvalidArgumentException.hpp\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */ \r
+ \r
+#ifndef MSG_INVALIDARGUMENTEXCEPTION_HPP\r
+#define MSG_INVALIDARGUMENTEXCEPTION_HPP\r
+\r
+#include "Exception.hpp"\r
+\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ \r
+ class InvalidArgumentException : public Exception\r
+ {\r
+ public:\r
+ \r
+ // Default constructor.\r
+ InvalidArgumentException();\r
+ \r
+ // Copy constructor.\r
+ InvalidArgumentException(const InvalidArgumentException& rInvalidArgumentException);\r
+ \r
+ // This constructor takes the name of the invalid argument.\r
+ InvalidArgumentException(const char* name);\r
+ \r
+ // Destructor.\r
+ virtual ~InvalidArgumentException();\r
+ \r
+ // Operations.\r
+ \r
+ // Returns the reason of the exception :\r
+ // the message "Invalid argument `argument name'"\r
+ const char* toString(void) const;\r
+ \r
+ // Operators.\r
+ \r
+ // Assignement.\r
+ const InvalidArgumentException& operator = (const InvalidArgumentException& rInvalidArgumentException);\r
+ \r
+ private :\r
+ \r
+ // Attributes.\r
+ \r
+ // A buffer used to build the message returned by the methode toString().\r
+ char* reason;\r
+ };\r
+ \r
+ \r
+ } // namespace Msg \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+#endif // !MSG_INVALIDARGUMENTEXCEPTION_HPP\r
+#include "MsgException.hpp"\r
+\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+using namespace std;\r
+\r
+namespace SimGrid\r
+{\r
+ namespace Msg\r
+ {\r
+ \r
+ MsgException::MsgException()\r
+ {\r
+ this->reason = (char*) calloc(strlen("Internal exception : unknown reason") + 1, sizeof(char));\r
+ strcpy(this->reason, "Internal exception : unknown reason");\r
+ }\r
+ \r
+ \r
+ MsgException::MsgException(const MsgException& rMsgException)\r
+ {\r
+ const char* reason = rMsgException.toString();\r
+ this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+ strcpy(this->reason, reason);\r
+ \r
+ }\r
+ \r
+ MsgException::MsgException(const char* reason)\r
+ {\r
+ this->reason = (char*) calloc(strlen("Internal exception : ") + strlen(reason) + 1, sizeof(char));\r
+ sprintf(this->reason, "Invalid exception : %s", reason);\r
+ }\r
+ \r
+ \r
+ MsgException::~MsgException()\r
+ {\r
+ if(this->reason)\r
+ free(this->reason);\r
+ }\r
+ \r
+ const char* MsgException::toString(void) const\r
+ {\r
+ return (const char*)(this->reason); \r
+ }\r
+ \r
+ \r
+ const MsgException& MsgException::operator = (const MsgException& rMsgException)\r
+ {\r
+ const char* reason = rMsgException.toString();\r
+ this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+ \r
+ return *this;\r
+ }\r
+ \r
+ } // namespace Msg \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+\r
-#ifndef MSG_EXCEPTION_HPP\r
-#define MSG_EXCEPTION_HPP\r
+/*\r
+ * MsgException.hpp\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */ \r
+ \r
+#ifndef MSG_MSGEXCEPTION_HPP\r
+#define MSG_MSGEXCEPTION_HPP\r
\r
-namespace msg\r
+#include "Exception.hpp"\r
+\r
+namespace SimGrid\r
{\r
- class MsgException\r
+ namespace Msg\r
{\r
- public:\r
- // Default constructor.\r
- MsgException();\r
- \r
- // This constructor takes as parameter the message of the \r
- // MsgException object.\r
- MsgException(const char* msg);\r
- \r
- // Copy constructor.\r
- MsgException(const MsgException& rMsgException);\r
- \r
- // Destructor.\r
- virtual ~MsgException();\r
- \r
\r
- // Operations.\r
- \r
- // Returns the message of the exception.\r
- const char* what(void) const;\r
- \r
- \r
- // Getters/setters.\r
- \r
- // Operators.\r
+ class MsgException : public Exception\r
+ {\r
+ public:\r
+ \r
+ // Default constructor.\r
+ MsgException();\r
+ \r
+ // Copy constructor.\r
+ MsgException(const MsgException& rMsgException);\r
+ \r
+ // This constructor takes the reason of the exception.\r
+ MsgException(const char* reason);\r
+ \r
+ // Destructor.\r
+ virtual ~MsgException();\r
+ \r
+ // Operations.\r
+ \r
+ // Returns the reason of the exception :\r
+ // the message "Internal exception `reason'"\r
+ const char* toString(void) const;\r
+ \r
+ // Operators.\r
+ \r
+ // Assignement.\r
+ const MsgException& operator = (const MsgException& rMsgException);\r
+ \r
+ private :\r
+ \r
+ // Attributes.\r
+ \r
+ // A buffer used to build the message returned by the methode toString().\r
+ char* reason;\r
+ };\r
\r
- private:\r
\r
- // Attributes.\r
- \r
- // The message of the exception.\r
- const char* msg;\r
- \r
- };\r
-}\r
+ } // namespace Msg \r
+\r
+}// namespace SimGrid\r
+\r
\r
-#endif // !MSG_EXCEPTION_HPP
\ No newline at end of file
+#endif // !MSG_MSGEXCEPTION_HPP\r
} \r
}\r
\r
-void send(void) \r
+void Task::send(void) \r
throw(NativeException)\r
{\r
-} \r
+ MSG_error_t rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ \r
+\r
+ rv = MSG_task_send_with_timeout(nativeTask, alias, -1.0);\r
+\r
+ free(alias)\r
+\r
+ if(MSG_OK != rv)\r
+ {\r
+ // TODO throw the NativeException\r
+ }\r
+}\r
+\r
+\r
+void Task::send(const char* alias) \r
+throw(NativeException)\r
+{\r
+\r
+ if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, -1.0))\r
+ {\r
+ // TODO throw the NativeException\r
+ }\r
+}\r
+\r
+void Task::send(double timeout) \r
+throw(NativeException)\r
+{\r
+ MSG_error_t rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ \r
+\r
+ rv = MSG_task_send_with_timeout(nativeTask, alias, timeout);\r
+\r
+ free(alias)\r
+\r
+ if(MSG_OK != rv)\r
+ {\r
+ // TODO throw the NativeException\r
+ }\r
+} \r
+\r
+void Task::send(const char* alias, double timeout) \r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_task_send_with_timeout(nativeTask, alias, timeout))\r
+ {\r
+ // TODO throw the NativeException\r
+ }\r
+}\r
+\r
+void Task::sendBounded(double maxRate) \r
+throw(NativeException)\r
+{\r
+ MSG_error_t rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ rv = MSG_task_send_bounded(nativeTask, alias, maxRate);\r
+ \r
+ free(alias);\r
+ \r
+ \r
+ \r
+ if(MSG_OK != rv)\r
+ {\r
+ // TODO throw the NativeException\r
+ }\r
+}\r
+\r
+void Task::sendBounded(const char* alias, double maxRate) \r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_task_send_bounded(nativeTask, alias, maxRate))\r
+ {\r
+ // TODO throw the NativeException\r
+ }\r
+}\r
+\r
+Task& Task::receive(void) \r
+throw(NativeException)\r
+{\r
+ MSG_error_t rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ m_task_t nativeTask = NULL;\r
+ \r
+ rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL); \r
+\r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv) \r
+ {\r
+ // TODO thow NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+Task& Task::receive(const char* alias) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL)) \r
+ {\r
+ // TODO thow NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+Task& Task::receive(const char* alias, double timeout) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, NULL)) \r
+ {\r
+ // TODO thow NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+Task& Task::receive(const char* alias, const Host& rHost) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost)) \r
+ {\r
+ // TODO thow NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+} \r
+\r
+Task& Task::receive(const char* alias, double timeout, const Host& rHost) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) \r
+ {\r
+ // TODO thow NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+bool Task::listen(void) \r
+throw(NativeException)\r
+{\r
+ int rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ rv = MSG_task_listen(alias);\r
+ \r
+ free(alias);\r
+ \r
+ return (bool)rv;\r
+} \r
+\r
+bool Task::listen(const char* alias) \r
+throw(NativeException)\r
+{\r
+ return (bool)MSG_task_listen(alias);\r
+}\r
+\r
+bool Task::listenFrom(void) \r
+throw(NativeException)\r
+{\r
+ int rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ rv = MSG_task_listen_from(alias);\r
+ \r
+ free(alias);\r
+ \r
+ return (int)rv;\r
+} \r
+\r
+bool Task::listenFrom(const char* alias) \r
+throw(NativeException)\r
+{\r
+ return (bool)MSG_task_listen_from(alias);\r
+ \r
+}\r
+\r
+bool Task::listenFromHost(const Host& rHost) \r
+throw(NativeException)\r
+{\r
+ int rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(Process::currentProcess().getName() + strlen(Host::currentHost().getName()) + 2);\r
+ sprintf(alias,"%s:%s", Process::currentProcess().getName(),Host::currentHost().getName());\r
+ \r
+ rv = MSG_task_listen_from_host(alias, rHost.nativeHost);\r
+ \r
+ free(alias);\r
+ \r
+ return (bool)rv;\r
+}\r
+ \r
+bool Task::listenFromHost(const char* alias, const Host& rHost) \r
+throw(NativeException)\r
+{\r
+ return (bool)MSG_task_listen_from_host(alias, rHost.nativeHost);\r
+} \r
\r
}\r
\r
void send(void) \r
throw(NativeException);\r
\r
+ void send(const char* alias) \r
+ throw(NativeException);\r
+ \r
+ void send(double timeout) \r
+ throw(NativeException);\r
+ \r
+ void send(const char* alias, double timeout) \r
+ throw(NativeException);\r
+ \r
+ void sendBounded(double maxRate) \r
+ throw(NativeException);\r
+ \r
+ void sendBounded(const char* alias, double maxRate) \r
+ throw(NativeException);\r
+ \r
+ static Task& receive(void) \r
+ throw(NativeException);\r
+ \r
+ static Task& receive(const char* alias) \r
+ throw(NativeException);\r
+ \r
+ static Task& receive(const char* alias, double timeout) \r
+ throw(NativeException);\r
+ \r
+ static Task& receive(const char* alias, const Host& rHost) \r
+ throw(NativeException);\r
+ \r
+ static Task& receive(const char* alias, double timeout, const Host& rHost) \r
+ throw(NativeException);\r
+ \r
+ static bool listen(void) \r
+ throw(NativeException);\r
+ \r
+ static bool listen(const char* alias) \r
+ throw(NativeException);\r
+ \r
+ static bool listenFrom(void) \r
+ throw(NativeException);\r
+ \r
+ static bool listenFrom(const char* alias) \r
+ throw(NativeException);\r
+ \r
+ \r
+ static bool listenFromHost(const Host& rHost) \r
+ throw(NativeException);\r
+ \r
+ static bool listenFromHost(const char* alias, const Host& rHost) \r
+ throw(NativeException);\r
+ \r
+ \r
+ \r
private:\r
\r
m_task_t nativeTask;\r