--- /dev/null
+\r
+\r
+#ifndef MSG_OBJECT_H\r
+#define MSG_OBJECT_H\r
+\r
+// Compilation C++ recquise\r
+#ifndef __cplusplus\r
+ #error object.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+#include <stdlib.h>\r
+\r
+namespace msg\r
+{\r
+ //////////////////////////////////////////////////////////////////////////////\r
+ // Macros\r
+ \r
+ // Returns the runtime class of the class_name object.\r
+ #define MSG_GET_CLASS(class_name) \\r
+ ((Class*)(&class_name::class##class_name))\r
+ \r
+ // Declare the class class_name as dynamic\r
+ #define MSG_DECLARE_DYNAMIC(class_name) \\r
+ public: \\r
+ static const Class class##class_name; \\r
+ virtual Class* getClass() const; \\r
+ static Object* createObject(); \\r
+\r
+ // The runtime class implementation. \r
+ #define MSG_IMPLEMENT_CLASS(class_name, base_class_name, pfn,class_init) \\r
+ const Class class_name::class##class_name = { \\r
+ #class_name, sizeof(class class_name),pfn, \\r
+ MSG_GET_CLASS(base_class_name), NULL,class_init}; \\r
+ Class* class_name::getClass() const \\r
+ { return MSG_GET_CLASS(class_name); } \\r
+ \r
+ // CreateObject implementation. \r
+ #define HX_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
+ MSG_IMPLEMENT_CLASS(class_name, base_class_name, \\r
+ class_name::createObject, &_declaringClass_##class_name) \\r
+\r
+\r
+ //////////////////////////////////////////////////////////////////////////////\r
+ // Classes declared in this file.\r
+\r
+ class Object; // The msg object.\r
+\r
+ //////////////////////////////////////////////////////////////////////////////\r
+ // Structures declared in this files.\r
+\r
+ struct Class; // used during the rtti operations\r
+ struct DeclaringClass; // used during the instances registration.\r
+\r
+\r
+ class DeclaringClasses;\r
+\r
+ //////////////////////////////////////////////////////////////////////////////\r
+ // Global functions\r
+\r
+ // Used during the registration.\r
+ void DeclareClass(Class* c);\r
+\r
+ //////////////////////////////////////////////////////////////////////////////\r
+ // DeclaringClass\r
+\r
+ struct DeclaringClass\r
+ {\r
+ // Constructor : add the runtime classe in the list.\r
+ DeclaringClass(Class* c);\r
+ \r
+ // Destructor\r
+ virtual ~DeclaringClass(void);\r
+\r
+ // Attributes :\r
+ // the list of runtime classes.\r
+ static DeclaringClasses* declaringClasses;\r
+ };\r
+\r
+ #define MSG_DELCARING_CLASSES (*(DeclaringClass::declaringClasses))\r
+ \r
+ \r
+ struct Class\r
+ {\r
+ \r
+ // Attributes\r
+ \r
+ const char* name; // class name.\r
+ int typeSize; // type size. \r
+ Object* (*createObjectFn)(void); // pointer to the create object function. \r
+ Class* baseClass; // the runtime class of the runtime class.\r
+ Class* next; // the next runtime class in the list.\r
+ const DeclaringClass* declaringClass; // used during the registration of the class.\r
+ \r
+ // Operations\r
+ \r
+ // Create the runtime class from its name.\r
+ static Class* fromName(const char* name);\r
+ \r
+ // Create an object from the name of the its class.\r
+ static Object* createObject(const char* name);\r
+ \r
+ // Create an instance of the class.\r
+ Object* createObject(void);\r
+ \r
+ // Return true is the class is dervived from the base class baseClass.\r
+ bool isDerivedFrom(const Class* baseClass) const;\r
+\r
+ };\r
+\r
+ // Create an instance of the class.\r
+ inline Object* Class::createObject(void)\r
+ {\r
+ return (*createObjectFn)();\r
+ }\r
+ \r
+ \r
+ class Object\r
+ {\r
+ public:\r
+ \r
+ // Default constructor.\r
+ Object(){}\r
+ \r
+ // Destructor.\r
+ virtual ~Object(){}\r
+ \r
+ // Operations.\r
+ \r
+ // Get the runtime class.\r
+ virtual Class* getClass(void) const;\r
+ \r
+ // Returns true if the class is derived from the class baseClass. Otherwise\r
+ // the method returns false.\r
+ bool isDerivedFrom(const Class* baseClass) const;\r
+ \r
+ // Returns true if the object is valid. Otherwise the method returns false.\r
+ virtual bool isValid(void) const;\r
+ \r
+ // Operators.\r
+\r
+ // Attributes.\r
+ \r
+ // The runtime class.\r
+ static const Class classObject;\r
+ };\r
+\r
+ // inline member functions of the class Object.\r
+ \r
+ // Returns the runtime class of the object.\r
+ inline Class* Object::getClass(void) const\r
+ {\r
+ return MSG_GET_CLASS(Object);\r
+ }\r
+\r
+ // Returns true if the class is derived from the class pBaseClass. Otherwise\r
+ // the method returns false.\r
+ inline bool Object::isDerivedFrom(const Class* baseClass) const\r
+ {\r
+ return (getClass()->isDerivedFrom(baseClass));\r
+ }\r
+ \r
+ // Returns true if the object is valid. Otherwise the method returns false.\r
+ inline bool Object::isValid(void) const\r
+ {\r
+ // returns always true.\r
+ return true; \r
+ }\r
+ \r
+ class DeclaringClasses \r
+ {\r
+ public:\r
+ \r
+ // Constructor.\r
+ DeclaringClasses();\r
+\r
+ // Destructor.\r
+ virtual ~DeclaringClasses(){}\r
+ \r
+ // Operations.\r
+ \r
+ // Add the class at the head of the list.\r
+ void addHead(Class* c);\r
+ \r
+ // Get the runtime class of the head of the list.\r
+ Class* getHead(void) const ;\r
+ \r
+ // Remove the class from the list (don't destroy it).\r
+ bool remove(Class* c);\r
+ \r
+ // Remove the head of the list.\r
+ Class* removeHead(void);\r
+ \r
+ // Return true if the list is empty.\r
+ \r
+ bool isEmpty(void) const;\r
+ \r
+ // Remove of the elements of the list.\r
+ void removeAll(void);\r
+ \r
+ // Get the number of classes in the list.\r
+ unsigned int getCount(void);\r
+ \r
+ void lock(void){}\r
+ \r
+ void unlock(void){}\r
+ \r
+ //Attributes\r
+ \r
+ // The head of the list.\r
+ Class* head;\r
+\r
+ private:\r
+ \r
+ // Attributes\r
+ \r
+ // The number of elements of the list.\r
+ unsigned int count;\r
+ };\r
+\r
+\r
+ // Constructor (Add the class in the list).\r
+ inline DeclaringClass::DeclaringClass(Class* c)\r
+ {\r
+ if(!declaringClasses)\r
+ declaringClasses = new DeclaringClasses();\r
+\r
+ DeclareClass(c);\r
+ }\r
+\r
+ // Destructor.\r
+ inline DeclaringClass::~DeclaringClass()\r
+ {\r
+ /*if(NULL != declaringClasses)\r
+ delete declaringClasses;\r
+\r
+ declaringClasses=NULL;*/\r
+\r
+ }\r
+\r
+ // Returns the number of elements of the list.\r
+ inline unsigned int DeclaringClasses::getCount()\r
+ {\r
+ return count;\r
+ }\r
+ \r
+ // Returns the head of the list.\r
+ inline Class* DeclaringClasses::getHead() const\r
+ {\r
+ return head;\r
+ }\r
+ \r
+ // Returns true if the list is empty. Otherwise this function\r
+ // returns false.\r
+ inline bool DeclaringClasses::isEmpty() const\r
+ {\r
+ return(!head);\r
+ }\r
+ \r
+ // Removes all the elements of the list.\r
+ inline void DeclaringClasses::removeAll()\r
+ {\r
+ head = 0;\r
+ count=0;\r
+ }\r
+ \r
+ \r
+} \r
+\r
+using namespace msg;\r
+\r
+#endif // !MSG_OBJECT_H\r
+\r
--- /dev/null
+#include <ApplicationHandler.hpp>\r
+\r
+namespace msg\r
+{\r
+ \r
+ApplicationHandler::ProcessFactory::processFactory = NULL;\r
+ \r
+void ApplicationHandler::onStartDocument(void)\r
+{\r
+ processFactory = new ProcessFactory(); \r
+}\r
+\r
+void ApplicationHandler::onEndDocument(void)\r
+{\r
+ if(processFactory)\r
+ delete processFactroy;\r
+}\r
+ \r
+void ApplicationHandler::onBeginProcess(void)\r
+{\r
+ processFactory->setProcessIdentity(A_surfxml_process_host, A_surfxml_process_function);\r
+} \r
+\r
+void ApplicationHandler::onProcessArg(void)\r
+{\r
+ processFactory->registerProcessArg(A_surfxml_argument_value);\r
+}\r
+\r
+void ApplicationHandler::OnProperty(void)\r
+{\r
+ processFactory->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);\r
+}\r
+\r
+void ApplicationHandler::onEndProcess(void)\r
+{\r
+ processFactory->createProcess();\r
+}\r
+\r
+void ApplicationHandler::ProcessFactory::createProcess() \r
+ {\r
+ Process* process = (Process*)Class::fromName(this->function);\r
+ \r
+ Host host = Host::getByName(this->hostName);\r
+\r
+ process->create();\r
+ \r
+ Strings* args = processFactory->args;\r
+ \r
+ int size = args->size();\r
+\r
+ for (int index = 0; index < size; index++)\r
+ process->args->push_back(args->at(index));\r
+ \r
+ process->properties = this->properties;\r
+ this->properties = new Properties();\r
+ }\r
+ \r
+void ApplicationHandler::ProcessFactory::setProcessIdentity(const string& hostName, const string& function) \r
+{\r
+ this->hostName = hostName;\r
+ this->function = function;\r
+\r
+ if (!this->args->empty())\r
+ this->args->clear();\r
+\r
+ if(!this->properties->empty())\r
+ this->properties->clear();\r
+}\r
+\r
+}
\ No newline at end of file
--- /dev/null
+#ifndef MSG_APPLICATION_HANDLER_HPP\r
+#define MSG_APPLICATION_HANDLER_HPP\r
+\r
+// Compilation C++ recquise\r
+#ifndef __cplusplus\r
+ #error ApplicationHandler.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+#include <vector>\r
+#include <map>\r
+\r
+namespace msg\r
+{\r
+ \r
+ struct Compare\r
+ {\r
+ public bool operator(const string& first, const string& second)\r
+ {\r
+ return first.compare(second);\r
+ }\r
+ };\r
+ \r
+ typedef vector<string> Strings;\r
+ \r
+ typedef map<string, string, Compare> Properties;\r
+ \r
+ \r
+class ApplicationHandler\r
+{\r
+private :\r
+ // Default constructor.\r
+ ApplicationHandler();\r
+ \r
+ // Copy constructor.\r
+ ApplicationHandler(const ApplicationHandler& rApplicationHandler);\r
+ \r
+ // Destructor\r
+ virtual ~ApplicationHandler();\r
+ \r
+ class ProcessFactory \r
+ {\r
+ public:\r
+ \r
+ Strings* args;\r
+ Properties* properties;\r
+ \r
+ private:\r
+ string hostName;\r
+ string function;\r
+ \r
+ public :\r
+ \r
+ ProcessFactory() \r
+ {\r
+ this->args = new Strings();\r
+ this->properties = new Properties();\r
+ this->hostName = NULL;\r
+ this->function = NULL;\r
+ } \r
+ \r
+ void setProcessIdentity(const string& hostName, const string& function);\r
+ \r
+ void registerProcessArg(const string& arg) \r
+ {\r
+ this->args->push_back(arg);\r
+ }\r
+\r
+ void setProperty(const string& id, const string& value)\r
+ {\r
+ this->properties->insert(Properties::value_type(id,value)); \r
+ }\r
+\r
+ const String& getHostName(void)\r
+ {\r
+ return this->hostName;\r
+ }\r
+\r
+ void createProcess(void); \r
+ \r
+ };\r
+ \r
+ static ProcessFactory* processFactory;\r
+ \r
+ public:\r
+ \r
+ static void onStartDocument(void);\r
+ \r
+ static void onEndDocument(void);\r
+ \r
+ static void onBeginProcess(void);\r
+ \r
+ static void onProcessArg(void);\r
+ \r
+ static void OnProperty(void);\r
+ \r
+ static void onEndProcess(void);\r
+};\r
+\r
+}\r
+\r
+#endif // !MSG_APPLICATION_HANDLER_HPP\r
+
\ No newline at end of file
--- /dev/null
+#include <Host.hpp>\r
+\r
+namespace msg\r
+{\r
+// Default constructor.\r
+Host::Host()\r
+{\r
+ nativeHost = NULL;\r
+ data = NULL;\r
+}\r
+\r
+// Copy constructor.\r
+Host::Host(const Host& rHost)\r
+{\r
+}\r
+\r
+// Destructor.\r
+Host::~Host()\r
+{\r
+ nativeHost = NULL;\r
+}\r
+\r
+// Operations\r
+\r
+Host& Host::getByName(const char* hostName)\r
+throw(HostNotFoundException)\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
+ \r
+ if(!nativeHost) \r
+ {// invalid host name\r
+ // TODO throw HostNotFoundException\r
+ return NULL;\r
+ }\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
+ 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 the reference to cxx wrapper\r
+ return *((Host*)nativeHost->data); \r
+}\r
+\r
+int Host::getNumber(void)\r
+{\r
+ return MSG_get_host_number();\r
+}\r
+\r
+Host& Host::currentHost(void)\r
+{\r
+ Host* host = NULL;\r
+ m_host_t nativeHost = MSG_host_self();\r
+ \r
+ if(!nativeHost->data) \r
+ {\r
+ // the native host not yet associated with its wrapper\r
+ \r
+ // instanciate a new wrapper\r
+ host = new Host();\r
+ \r
+ host->nativeHost = nativeHost;\r
+ \r
+ nativeHost->data = (void*)host;\r
+ } \r
+ else \r
+ {\r
+ host = (Host*)nativeHost->data;\r
+ }\r
+ \r
+ return *host;\r
+}\r
+\r
+int Host::all(Host** hosts) \r
+{\r
+ int count = xbt_fifo_size(msg_global->host);\r
+ \r
+ *hosts = new Host[count];\r
+ int index;\r
+ m_host_t nativeHost;\r
+ Host* host;\r
+\r
+ m_host_t* table = (m_host_t *)xbt_fifo_to_array(msg_global->host);\r
+ \r
+ for(index = 0; index < count; index++) \r
+ {\r
+ nativeHost = table[index];\r
+ host = (Host*)(nativeHost->data);\r
+ \r
+ if(!host) \r
+ {\r
+ host = new Host();\r
+ \r
+ host->nativeHost = nativeHost;\r
+ nativeHost->data = (void*)host;\r
+ }\r
+ \r
+ hosts[index] = host;\r
+ }\r
+\r
+ return count; \r
+}\r
+\r
+\r
+const char* Host::getName(void) const\r
+{\r
+ return nativeHost->name;\r
+}\r
+\r
+\r
+void Host::setData(void* data)\r
+{\r
+ this->data = data;\r
+}\r
+\r
+// Getters/setters\r
+\r
+void* Host::getData(void) const\r
+{\r
+ return this->data;\r
+}\r
+\r
+int Host::getRunningTaskNumber(void) const\r
+{\r
+ return MSG_get_host_msgload(nativeHost); \r
+}\r
+\r
+double Host::getSpeed(void) const\r
+{\r
+ return MSG_get_host_speed(nativeHost->simdata->smx_host);\r
+}\r
+\r
+bool Host::hasData(void) const\r
+{\r
+ return (NULL != this->data);\r
+}\r
+\r
+bool Host::isAvailable(void) const\r
+{\r
+ return (bool)SIMIX_host_get_state(nativeHost->simdata->smx_host);\r
+}\r
+\r
+void Host::put(int channel, const Task& rTask) \r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , -1.0))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+} \r
+\r
+void Host::put(int channel, const Task& rTask, double timeout) \r
+throw(NativeException) \r
+{\r
+ if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, nativeHost, channel , timeout))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+}\r
+\r
+void Host::putBounded(int channel, const Task& rTask, double maxRate) \r
+throw(NativeException)\r
+{\r
+ MsgNative.hostPutBounded(this, channel, task, maxrate);\r
+ \r
+ if(MSG_OK != MSG_task_put_bounded(rTask.nativeTask, nativeHost, channel, maxRate))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+}\r
+\r
+\r
+\r
+\r
+ \r
+\r
+void Host::send(const Task& rTask) \r
+throw(NativeException) \r
+{ \r
+ MSG_error_t rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);\r
+ sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName());\r
+ \r
+ \r
+ rv = MSG_task_send_with_timeout(rTask.nativeTask, alias, -1.0);\r
+ \r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv)\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+} \r
+\r
+void Host::send(const char* alias, const Task& rTask) \r
+throw(NativeException) \r
+{\r
+ \r
+ if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias, -1.0))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+}\r
+\r
+void Host::send(const Task& rTask, double timeout) \r
+throw(NativeException) \r
+{\r
+ MSG_error_t rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);\r
+ sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName());\r
+ \r
+ \r
+ rv = MSG_task_send_with_timeout(rTask.nativeTask, alias, timeout);\r
+ \r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv)\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+}\r
+\r
+void Host::send(const char* alias, const Task& rTask, double timeout) \r
+throw(NativeException) \r
+{\r
+ if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias, timeout))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+}\r
+\r
+\r
+void Host::sendBounded(const Task& rTask, double maxRate) \r
+throw(NativeException) \r
+{\r
+ \r
+ MSG_error_t rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(this->getName() + strlen(Process::currentProcess().getName()) + 2);\r
+ sprintf(alias,"%s:%s", this->getName(),Process::currentProcess().getName());\r
+ \r
+ rv = MSG_task_send_bounded(rTask.nativeTask, alias, maxRate);\r
+ \r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv)\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+} \r
+\r
+void Host::sendBounded(const char* alias, const Task& rTask, double maxRate) \r
+throw(NativeException) \r
+{\r
+ if(MSG_OK != MSG_task_send_bounded(rTask.nativeTask, alias, maxRate))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+} \r
+\r
+ \r
+}
\ No newline at end of file
--- /dev/null
+#ifndef MSG_HOST_HPP\r
+#define MSG_HOST_HPP\r
+\r
+\r
+// Compilation C++ recquise\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
+\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
+ \r
+ void* data;\r
+ };\r
+}\r
+\r
+#endif // !MSG_HOST_HPP
\ No newline at end of file
--- /dev/null
+#ifndef MSG_EXCEPTION_HPP\r
+#define MSG_EXCEPTION_HPP\r
+\r
+namespace msg\r
+{\r
+ class MsgException\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
+ \r
+ private:\r
+ \r
+ // Attributes.\r
+ \r
+ // The message of the exception.\r
+ const char* msg;\r
+ \r
+ };\r
+}\r
+\r
+#endif // !MSG_EXCEPTION_HPP
\ No newline at end of file
--- /dev/null
+#ifndef MSG_NATIVE_HPP\r
+#define MSG_NATIVE_HPP\r
+\r
+// Compilation C++ recquise\r
+#ifndef __cplusplus\r
+ #error MsgNative.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+namespace msg\r
+{\r
+class MsgNative\r
+{\r
+ private:\r
+ // Default constructor.\r
+ MsgNative(){}\r
+ \r
+ // Copy constructor.\r
+ MsgNative(const MsgNative& rMsgInterface) {}\r
+ \r
+ // Destructor.\r
+ virtual ~MsgNative(){}\r
+ \r
+ public:\r
+ \r
+ \r
+ static void processCreate(const Process& rProcess, const Host& rHost);\r
+ \r
+ static int processKillAll(int resetPID);\r
+ \r
+ static void processSuspend(const Process& process);\r
+ \r
+ static void processKill(const Process& process);\r
+ \r
+ static void processResume(const Process& process);\r
+ \r
+ static bool processIsSuspended(const Process& process);\r
+ \r
+ static Host& processGetHost(const Process& process);\r
+ \r
+ static Process& processFromPID(int PID);\r
+ \r
+ static int processGetPID(const Process& process);\r
+ \r
+ static int processGetPPID(const Process& process);\r
+ \r
+ static Process& processSelf(void);\r
+ \r
+ static int processSelfPID(void);\r
+ \r
+ static int processSelfPPID(void);\r
+ \r
+ static void processChangeHost(const Process& process, const Host& host);\r
+ \r
+ static void processWaitFor(double seconds);\r
+ \r
+ static void processExit(const Process& process);\r
+ \r
+ static Host& hostGetByName(const string& name) throw(HostNotFoundException);\r
+ \r
+ static string& hostGetName(const Host& host);\r
+ \r
+ static int hostGetNumber(void);\r
+ \r
+ static Host& hostSelf(void);\r
+ \r
+ static double hostGetSpeed(const Host& host);\r
+ \r
+ static bool hostIsAvail(const Host& host);\r
+ \r
+ static Host[] allHosts(void);\r
+ \r
+ static int hostGetLoad(const Host& host);\r
+ \r
+ static void taskCreate(const Task& task, const string& name, double computeDuration, double messageSize)\r
+ throw(NullPointerException, IllegalArgumentException);\r
+ \r
+ static Process& taskGetSender(const Task& task);\r
+ \r
+ static Host& taskGetSource(const Task& task);\r
+ \r
+ static string& taskGetName(const Task& task);\r
+ \r
+ static void taskCancel(const Task& task);\r
+ \r
+ static void parallelTaskCreate(const Task& pTask, const string& name, Host[]hosts, double[]computeDurations, double[]messageSizes)\r
+ throw(NullPointerException, IllegalArgumentException);\r
+ \r
+ static double taskGetComputeDuration(const Task& task);\r
+ \r
+ static double taskGetRemainingDuration(const Task& task);\r
+ \r
+ static void taskSetPriority(const Taska task, double priority);\r
+ \r
+ static void taskDestroy(const Task& task);\r
+ \r
+ static void taskExecute(const Task& task);\r
+ \r
+ static Task& taskGet(int channel, double timeout, const Host& host);\r
+ \r
+ static void taskSend(const string& alias, const Task& task, double timeout);\r
+ \r
+ static Task& taskReceive(const string& alias, double timeout, const Host& host);\r
+ \r
+ static int taskListenFrom(const string& alias);\r
+ \r
+ static bool taskListen(const string& alias);\r
+ \r
+ static int taskListenFromHost(const string& alias, const Host& host);\r
+ \r
+ static bool taskProbe(int channel);\r
+ \r
+ static int taskGetCommunicatingProcess(int channel);\r
+ \r
+ static int taskProbeHost(int channel, const Host& host);\r
+ \r
+ static void hostPut(const Host& host, int channel, const Task& task, double timeout);\r
+ \r
+ static void hostPutBounded(const Hos&t host, int channel, const Task& task, double max_rate);\r
+ \r
+ static void taskSendBounded(const string& alias, const Task& task, double maxrate);\r
+};\r
+}\r
+\r
+\r
+\r
+#endif // !MSG_NATIVE_HPP
\ No newline at end of file
--- /dev/null
+#include <object.hpp>\r
+#include <string.h>\r
+\r
+\r
+DeclaringClasses* DeclaringClass::declaringClasses = NULL;\r
+\r
+\r
+namespace msg\r
+{\r
+ // Generate static object constructor for class registration\r
+ void DeclareClass(Class* c)\r
+ {\r
+ MSG_DELCARING_CLASSES.lock();\r
+ MSG_DELCARING_CLASSES.addHead(c);\r
+ MSG_DELCARING_CLASSES.unlock();\r
+ }\r
+} \r
+\r
+//////////////////////////////////////////////////////////////////////////////\r
+// Implémentation des fonctions membre de la classe Class\r
+\r
+// true if the class is derived from base classe referenced \r
+// by pBaseClass\r
+bool Class::isDerivedFrom(const Class* baseClass) const\r
+{\r
+ const Class* cur = this;\r
+\r
+ while(cur)\r
+ {\r
+ if(cur == baseClass)\r
+ return true;\r
+\r
+ cur = cur->baseClass;\r
+ }\r
+\r
+ return false;\r
+}\r
+\r
+// Dynamic name lookup and creation\r
+Class* Class::fromName(const char* name)\r
+{\r
+ Class* cur;\r
+\r
+ MSG_DELCARING_CLASSES.lock();\r
+ \r
+ for(cur = MSG_DELCARING_CLASSES.getHead(); cur; cur = cur->next)\r
+ {\r
+ if(!strcmp(name,cur->name))\r
+ break;\r
+ }\r
+\r
+ MSG_DELCARING_CLASSES.unlock();\r
+ return cur;\r
+}\r
+\r
+Object* Class::createObject(const char* name)\r
+{\r
+ Class* c = fromName(name);\r
+ \r
+ if(NULL == c)\r
+ return NULL;\r
+ \r
+ return c->createObject();\r
+}\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////////////\r
+// Object members implementation\r
+\r
+// Special runtime-class structure for Object (no base class)\r
+const struct Class Object::classObject =\r
+{ \r
+ "Object", // name\r
+ sizeof(Object), // typeSize\r
+ NULL, // baseClass\r
+ NULL, // next\r
+ NULL // declaringClass\r
+};\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////////////\r
+// DeclaringClasses members implementation\r
+//\r
+\r
+DeclaringClasses::DeclaringClasses()\r
+{\r
+ head = NULL;\r
+ count = 0;\r
+}\r
+\r
+\r
+// Ajoute une nouvelle classe en tête de liste\r
+void DeclaringClasses::addHead(Class* c)\r
+{\r
+ if(NULL != head)\r
+ c->next = head;\r
+\r
+ head = c;\r
+ count++;\r
+}\r
+\r
+// Retourne la tête de liste et la retire de la liste\r
+Class* DeclaringClasses::removeHead(void)\r
+{\r
+ Class* c = NULL;\r
+\r
+ if(NULL != head)\r
+ {\r
+ c = head;\r
+ head = head->next;\r
+ count--;\r
+ }\r
+\r
+ return c;\r
+}\r
+\r
+// Retire la classe pClasse de la liste, mais ne la détruit pas \r
+bool DeclaringClasses::remove(Class* c)\r
+{\r
+ if(NULL == head)\r
+ return false;\r
+\r
+ bool success = false;\r
+\r
+ if(head == c)\r
+ {\r
+ head = c->next;\r
+ count--;\r
+ success = true;\r
+ }\r
+ else\r
+ {\r
+ Class* cur = head;\r
+\r
+ while((NULL != cur) && (cur->next!= c))\r
+ cur = cur->next;\r
+\r
+ if(NULL != cur)\r
+ {\r
+ cur->next = c->next;\r
+ count--;\r
+ success = true;\r
+ }\r
+ }\r
+ \r
+ return success;\r
+}\r
+ \r
+\r
--- /dev/null
+#include <Process.hpp>\r
+\r
+namespace msg\r
+{\r
+ \r
+Process* Process::currentProcess = NULL;\r
+\r
+// Default constructor.\r
+Process::Process()\r
+{\r
+ this->nativeProcess = NULL;\r
+}\r
+\r
+Process::Process(const char* hostname, const char* name)\r
+throw(HostNotFoundException)\r
+{\r
+ Host host = Host::getByName(hostname);\r
+ \r
+ create(host, name, 0, NULL); \r
+}\r
+\r
+Process::Process(const char* hostname, const char* name, int argc, char** argv)\r
+throw(HostNotFoundException)\r
+{\r
+ Host host = Host::getByName(hostname);\r
+ \r
+ create(host, name, argc, argv); \r
+}\r
+\r
+Process::Process(const Host& rHost, const char* name)\r
+throw(HostNotFoundException)\r
+{\r
+ \r
+ create(rHost, name, 0, NULL); \r
+}\r
+\r
+Process::Process(const Host& rHost, const char* name, int argc, char** argv)\r
+throw(HostNotFoundException)\r
+{\r
+ \r
+ create(rHost, name, argc, argv); \r
+}\r
+\r
+int Process::run(int argc, char** argv)\r
+{\r
+ Process* process =(Process*)argv[argc];\r
+ \r
+ return process->main(argc, argv);\r
+}\r
+\r
+void Process::create(const Host& rHost, const char* name, int argc, char** argv)\r
+throw(HostNotFoundException)\r
+{\r
+ smx_process_t nativeCurrentProcess = NULL;\r
+ nativeProcess = xbt_new0(s_smx_process_t, 1);\r
+ smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t, 1);\r
+ smx_host_t nativeHost = SIMIX_host_get_by_name(rHost.getName());\r
+ \r
+ argv = (char**)realloc(argc + 1, sizeo(char*));\r
+ \r
+ argv[argc] = (char*)this;\r
+ \r
+ \r
+ // TODO throw HostNotFoundException if host is NULL\r
+ \r
+ // Simulator Data\r
+ simdata->smx_host = nativeHost;\r
+ simdata->mutex = NULL;\r
+ simdata->cond = NULL;\r
+ simdata->argc = argc;\r
+ simdata->argv = argv;\r
+ simdata->context = xbt_context_new(name, Process::run, NULL, NULL, simix_global->cleanup_process_function, nativeProcess, simdata->argc, simdata->argv);\r
+ \r
+ /* Process structure */\r
+ nativeProcess->name = xbt_strdup(name);\r
+ nativeProcess->simdata = simdata;\r
+ \r
+ // Set process data\r
+ nativeProcess->data = NULL;\r
+ \r
+ // Set process properties\r
+ simdata->properties = NULL;\r
+ \r
+ xbt_swag_insert(nativeProcess, nativeHost->simdata->process_list);\r
+ \r
+ /* fix current_process, about which xbt_context_start mocks around */\r
+ nativeCurrentProcess = simix_global->current_process;\r
+ xbt_context_start(nativeProcess->simdata->context);\r
+ simix_global->current_process = nativeCurrentProcess;\r
+ \r
+ xbt_swag_insert(nativeProcess, simix_global->process_list);\r
+ DEBUG2("Inserting %s(%s) in the to_run list", nativeProcess->name, nativeHost->name);\r
+ xbt_swag_insert(nativeProcess, simix_global->process_to_run);\r
+}\r
+\r
+\r
+int Process::killAll(int resetPID) \r
+{\r
+ return MSG_process_killall(resetPID);\r
+}\r
+\r
+void Process::suspend(void)\r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_process_suspend(nativeProcess)) \r
+ {\r
+ // TODO throw NativeException.\r
+ }\r
+}\r
+\r
+void Process::resume(void) \r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_process_resume(nativeProcess))\r
+ {\r
+ // TODO throw NativeException.\r
+ }\r
+}\r
+\r
+\r
+bool Process::isSuspended(void)\r
+{\r
+ return (bool)MSG_process_is_suspended(nativeProcess);\r
+} \r
+\r
+\r
+Host& Process::getHost(void) \r
+throw(NativeException) \r
+{\r
+ m_host_t nativeHost = MSG_process_get_host(nativeProcess);\r
+ \r
+ if(!nativeHost->data) \r
+ {\r
+ // TODO throw NativeException.\r
+ return NULL;\r
+ }\r
+\r
+ // return the reference to the Host object\r
+ return (*((Host*)nativeHost->data));\r
+} \r
+\r
+Process& Process::fromPID(int PID) \r
+throw(ProcessNotFoundException, NativeException)\r
+{\r
+ Process* process = NULL;\r
+ m_process_t nativeProcess = MSG_process_from_PID(PID);\r
+ \r
+ \r
+ if(!process) \r
+ {\r
+ throw ProcessNotFoundException;\r
+ return NULL;\r
+ }\r
+ \r
+ process = Process::fromNativeProcess(nativeProcess);\r
+ \r
+ if(!process) \r
+ {\r
+ // TODO throw NativeException\r
+ return NULL;\r
+ }\r
+ \r
+ return (*process); \r
+}\r
+\r
+// TODO implement this method\r
+Process& Process::fromNativeProcess(m_process_t nativeProcess)\r
+{\r
+ \r
+}\r
+\r
+int Process::getPID(void)\r
+{\r
+ return MSG_process_get_PID(nativeProcess);\r
+}\r
+\r
+int Process::getPPID(void)\r
+{\r
+ return MSG_process_get_PPID(nativeProcess);\r
+}\r
+\r
+\r
+Process& Process::currentProcess(void)\r
+throw(NativeException)\r
+{\r
+ Process* currentProcess = NULL;\r
+ m_process_t currentNativeProcess = MSG_process_self();\r
+\r
+\r
+ if(!currentNativeProcess) \r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+ \r
+ currentProcess = Process::fromNativeProcess(currentNativeProcess);\r
+ \r
+ if(!currentProcess) \r
+ {\r
+ // TODO throw NativeException\r
+ return NULL;\r
+ }\r
+ \r
+ return (*currentProcess); \r
+}\r
+\r
+int Process::currentProcessPID(void)\r
+{\r
+ return MSG_process_self_PID();\r
+}\r
+\r
+\r
+int Process::currentProcessPPID(void)\r
+{\r
+ return MSG_process_self_PPID();\r
+}\r
+\r
+void Process::migrate(const Host& rHost)\r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_process_change_host(nativeProcess, rHost.nativeHost))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+ \r
+}\r
+\r
+void Process::sleep(double seconds)\r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_process_sleep(seconds))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+ \r
+}\r
+\r
+void Process::putTask(const Host& rHost, int channel, const Task& rTask)\r
+throw( NativeException)\r
+{\r
+ if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, rHost.nativeHost, channel, -1.0))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+}\r
+\r
+void Process::putTask(const Host& rHost, int channel, const Task& rTask, double timeout) \r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_task_put_with_timeout(rTask.nativeTask, rHost.nativeHost, channel, timeout))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+}\r
+\r
+Task& Process::getTask(int channel) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, -1.0, NULL)) \r
+ {\r
+ // TODO throw NativeException\r
+ return NULL;\r
+ }\r
+ \r
+ return (*((Task*)(nativeTask->data)));\r
+}\r
+\r
+Task& Process::getTask(int channel, double timeout) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, NULL)) \r
+ {\r
+ // TODO throw NativeException\r
+ return NULL;\r
+ }\r
+ \r
+ return (*((Task*)(nativeTask->data)));\r
+}\r
+\r
+Task& Process::getTask(int channel, const Host& rHost) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, -1.0, rHost.nativeHost)) \r
+ {\r
+ // TODO throw NativeException\r
+ return NULL;\r
+ }\r
+ \r
+ return (*((Task*)(nativeTask->data)));\r
+}\r
+\r
+Task& Process::getTask(int channel, double timeout, const Host& rHost)\r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if (MSG_OK != MSG_task_get_ext(&nativeTask, channel, timeout, rHost.nativeHost)) \r
+ {\r
+ // TODO throw NativeException\r
+ return NULL;\r
+ }\r
+ \r
+ return (*((Task*)(nativeTask->data)));\r
+}\r
+\r
+void Process::sendTask(const char* alias, const Task& rTask, double timeout) \r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,timeout))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+ \r
+}\r
+\r
+void Process::sendTask(const char* alias, const Task& rTask) \r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0))\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+}\r
+\r
+void Process::sendTask(const Task& rTask) \r
+throw(NativeException)\r
+{\r
+ MSG_error_t rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+ sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+ \r
+ rv = MSG_task_send_with_timeout(rTask.nativeTask, alias ,-1.0);\r
+ \r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv)\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+}\r
+\r
+void Process::sendTask(const Task& rTask, double timeout) \r
+throw(NativeException)\r
+{\r
+ MSG_error_t rv;\r
+ \r
+ char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+ sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+ \r
+ rv = MSG_task_send_with_timeout(rTask.nativeTask, alias ,timeout);\r
+ \r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv)\r
+ {\r
+ // TODO throw NativeException\r
+ }\r
+}\r
+\r
+Task& Process::receiveTask(const char* alias) \r
+throw(NativeException)\r
+{\r
+ \r
+ m_task_t nativeTask = NULL;\r
+ \r
+ if (MSG_OK != MSG_task_receive_ext(&nativeTask,alias, -1.0, NULL)) \r
+ {\r
+ // TODO throw NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+\r
+Task& Process::receiveTask(void) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+ sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+ \r
+ MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, NULL);\r
+ \r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv) \r
+ {\r
+ //TODO throw NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+\r
+Task& Process::receiveTask(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 throw NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+\r
+Task& Process::receiveTask(double timeout) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+ sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+ \r
+ MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, NULL);\r
+ \r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv) \r
+ {\r
+ //TODO throw NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+\r
+Task& Process::receiveTask(const char* alias, double timeout, const Host& rHost) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ if(MSG_OK != MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost)) \r
+ {\r
+ //TODO throw NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+\r
+Task& Process::receiveTask(double timeout, const Host& rHost) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+ sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+ \r
+ MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, timeout, rHost.nativeHost);\r
+ \r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv) \r
+ {\r
+ //TODO throw NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+\r
+Task& Process::receiveTask(const char* alias, const Host& rHost) \r
+throw(NativeException)\r
+{\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 throw NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+Task& Process::receiveTask(const Host& rHost) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ char* alias = (char*)calloc(strlen(Host::currentHost().getName() + strlen(nativeProcess->name) + 2);\r
+ sprintf(alias,"%s:%s", Host::currentHost().getName() ,nativeProcess->name);\r
+ \r
+ MSG_error_t rv = MSG_task_receive_ext(&nativeTask, alias, -1.0, rHost.nativeHost);\r
+ \r
+ free(alias);\r
+ \r
+ if(MSG_OK != rv) \r
+ {\r
+ //TODO throw NativeException\r
+ return NULL;\r
+ }\r
+\r
+ return (*((Task*)nativeTask->data));\r
+}\r
+\r
+const char* Process::getName(void) const\r
+{\r
+ return nativeProcess->name;\r
+}\r
+\r
+\r
+}
\ No newline at end of file
--- /dev/null
+#ifndef MSG_PROCESS_HPP\r
+#define MSG_PROCESS_HPP\r
+\r
+// Compilation C++ recquise\r
+#ifndef __cplusplus\r
+ #error Process.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+namespace msg\r
+{\r
+ \r
+class Process\r
+{\r
+ \r
+ friend ApplicationHandler;\r
+ \r
+ private;\r
+ \r
+ // Default constructor.\r
+ Process();\r
+ \r
+ public:\r
+ \r
+ // Construct a process from the name of the host and its name. \r
+ Process(const char* hostName, const char* name)\r
+ throw(HostNotFoundException);\r
+ \r
+ Process(const Host& rHost, const char* name)\r
+ throw(HostNotFoundException);\r
+ \r
+ Process(const char* hostName, const char* name, int argc, char** argv)\r
+ throw(HostNotFoundException);\r
+ \r
+ Process(const Host& rHost, const char* name, int argc, char** argv)\r
+ throw(HostNotFoundException);\r
+ \r
+ static int killAll(int resetPID);\r
+ \r
+ void Process::suspend(void)\r
+ throw(NativeException);\r
+ \r
+ void Process::resume(void) \r
+ throw(NativeException);\r
+ \r
+ bool isSuspended(void);\r
+ \r
+ Host& getHost(void) \r
+ throw(NativeException);\r
+ \r
+ static Process& fromPID(int PID); \r
+ \r
+ \r
+ int getPID(void);\r
+ \r
+ int getPPID(void);\r
+ \r
+ const char* getName(void) const;\r
+ \r
+ static Process& currentProcess(void);\r
+ \r
+ static int currentProcessPID(void);\r
+ \r
+ static int currentProcessPPID(void);\r
+ \r
+ void migrate(const Host& rHost)\r
+ throw(NativeException);\r
+ \r
+ static void sleep(double seconds)\r
+ throw(NativeException);\r
+ \r
+ void putTask(const Host& rHost, int channel, const Task& rTask)\r
+ throw( NativeException);\r
+ \r
+ void putTask(const Host& rHost, int channel, const Task& rTask, double timeout) \r
+ throw(NativeException);\r
+ \r
+ Task& getTask(int channel) \r
+ throw(NativeException);\r
+ \r
+ Task& getTask(int channel, double timeout) \r
+ throw(NativeException);\r
+ \r
+ Task& getTask(int channel, const Host& rHost) \r
+ throw(NativeException);\r
+ \r
+ Task& getTask(int channel, double timeout, const Host& rHost)\r
+ throw(NativeException);\r
+ \r
+ void sendTask(const char* alias, const Task& rTask, double timeout) \r
+ throw(NativeException);\r
+ \r
+ void sendTask(const char* alias, const Task& rTask) \r
+ throw(NativeException);\r
+ \r
+ void sendTask(const Task& rTask) \r
+ throw(NativeException);\r
+ \r
+ void sendTask(const Task& rTask, double timeout) \r
+ throw(NativeException);\r
+ \r
+ Task& receiveTask(const char* alias) \r
+ throw(NativeException);\r
+ \r
+ Task& receiveTask(void) \r
+ throw(NativeException);\r
+ \r
+ Task& receiveTask(const char* alias, double timeout) \r
+ throw(NativeException);\r
+ \r
+ Task& receiveTask(double timeout) \r
+ throw(NativeException);\r
+ \r
+ Task& receiveTask(const char* alias, double timeout, const Host& rHost) \r
+ throw(NativeException);\r
+ \r
+ Task& Process::receiveTask(double timeout, const Host& rHost) \r
+ throw(NativeException);\r
+ \r
+ Task& receiveTask(const char* alias, const Host& rHost) \r
+ throw(NativeException);\r
+ \r
+ Task& receiveTask(const Host& rHost) \r
+ throw(NativeException);\r
+ \r
+ \r
+ private:\r
+ void create(const Host& rHost, const char* name, int argc, char** argv) \r
+ throw(HostNotFoundException);\r
+ \r
+ \r
+ static Process& fromNativeProcess(m_process_t nativeProcess);\r
+ \r
+ \r
+ public:\r
+ \r
+ static int run(int argc, char** argv);\r
+ \r
+ virtual int main(int argc, char** argv) = 0;\r
+ \r
+ private:\r
+ \r
+ // Attributes.\r
+ \r
+ m_process_t nativeProcess; // pointer to the native msg process.\r
+ \r
+};\r
+\r
+}
\ No newline at end of file
--- /dev/null
+#include <Task.hpp>\r
+\r
+namespace msg\r
+{\r
+ \r
+Task::Task()\r
+{\r
+ nativeTask = NULL;\r
+}\r
+\r
+\r
+Task::Task(const Task& rTask)\r
+{\r
+}\r
+\r
+\r
+Task::~Task()\r
+throw(NativeException)\r
+{\r
+ if(NULL != nativeTask)\r
+ {\r
+ if(MSG_OK != MSG_task_destroy(nativeTask))\r
+ {\r
+ // TODO throw NativeException\r
+ } \r
+ }\r
+}\r
+\r
+\r
+Task::Task(const char* name, double computeDuration, double messageSize)\r
+{\r
+ \r
+ if(computeDuration < 0) \r
+ {\r
+ // TODO throw exception\r
+ return;\r
+ }\r
+ \r
+ if(messageSize < 0) \r
+ {\r
+ // TODO throw exception\r
+ return;\r
+ }\r
+ \r
+ if(!name) \r
+ {\r
+ // TODO throw exception\r
+ return;\r
+ }\r
+ \r
+ // create the task\r
+ nativeTask = MSG_task_create(name, computeDuration, messageSize, NULL);\r
+ \r
+ nativeTask->data = (void*)this;\r
+}\r
+\r
+Task::Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes)\r
+{\r
+ // TODO parallel task create \r
+}\r
+\r
+\r
+const char* Task::getName(void) const\r
+{\r
+ return nativeTask->name;\r
+}\r
+\r
+Process& Task::getSender(void) const\r
+{\r
+ m_proccess_t nativeProcess = MSG_task_get_sender(nativeTask);\r
+ \r
+ return (*((Process*)(nativeProcess->data)));\r
+}\r
+\r
+Host& Task::getSource(void) const \r
+throw(NativeException)\r
+{\r
+ m_host_t nativeHost = MSG_task_get_source(nativeTask);\r
+ \r
+ if(!nativeHost->data) \r
+ {\r
+ // TODO throw the exception\r
+ return NULL;\r
+ }\r
+ \r
+ return (*((Host*)(nativeHost->data))); \r
+}\r
+\r
+double Task::getComputeDuration(void) const\r
+{\r
+ return MSG_task_get_compute_duration(nativeTask);\r
+}\r
+\r
+double Task::getRemainingDuration(void) const\r
+{\r
+ return MSG_task_get_remaining_computation(nativeTask);\r
+}\r
+\r
+void Task::setPriority(double priority)\r
+{\r
+ MSG_task_set_priority(nativeTask, priority);\r
+}\r
+\r
+Task& Task::get(int channel) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, NULL)) \r
+ {\r
+ // TODO throw the NativeException\r
+ return NULL;\r
+ }\r
+ \r
+ return (*((Task*)(nativeTask->data)));\r
+}\r
+\r
+Task& Task::get(int channel, const Host& rHost) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , -1.0, rHost.nativeHost)) \r
+ {\r
+ // TODO throw the NativeException\r
+ return NULL;\r
+ }\r
+ \r
+ return (*((Task*)(nativeTask->data)));\r
+}\r
+\r
+Task& Task::get(int channel, double timeout, const Host& rHost) \r
+throw(NativeException)\r
+{\r
+ m_task_t nativeTask = NULL;\r
+ \r
+ \r
+ if(MSG_OK != MSG_task_get_ext(&nativeTask, channel , timeout, rHost.nativeHost)) \r
+ {\r
+ // TODO throw the NativeException\r
+ return NULL;\r
+ }\r
+ \r
+ return (*((Task*)(nativeTask->data)));\r
+}\r
+\r
+bool static Task::probe(int channel)\r
+{\r
+ return (bool)MSG_task_Iprobe(channel);\r
+}\r
+\r
+int Task::probe(int channel, const Host& rHost)\r
+{\r
+ return MSG_task_probe_from_host(chan_id,rHost.nativeHost);\r
+}\r
+\r
+void Task::execute(void) \r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_task_execute(nativeTask))\r
+ {\r
+ // TODO throw NativeException\r
+ } \r
+}\r
+\r
+void Task::cancel(void) \r
+throw(NativeException)\r
+{\r
+ if(MSG_OK != MSG_task_cancel(nativeTask))\r
+ {\r
+ // TODO throw NativeException\r
+ } \r
+}\r
+\r
+void send(void) \r
+throw(NativeException)\r
+{\r
+} \r
+\r
+}\r
+\r
--- /dev/null
+#ifndef MSG_TASK_HPP\r
+#define MSG_TASK_HPP\r
+\r
+// Compilation C++ recquise\r
+#ifndef __cplusplus\r
+ #error Process.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+namespace msg\r
+{\r
+class Task\r
+{\r
+ protected:\r
+ // Default constructor.\r
+ Task();\r
+ \r
+ public:\r
+ // Copy constructor.\r
+ Task(const Task& rTask);\r
+ \r
+ // Destructor.\r
+ virtual ~Task()\r
+ throw(NativeException);\r
+ \r
+ // Other constructors.\r
+ Task(const char* name, double computeDuration, double messageSize);\r
+ \r
+ Task(const char* name, Host* hosts, double* computeDurations, double* messageSizes);\r
+ \r
+ \r
+ // Getters/setters.\r
+ const char* getName(void) const;\r
+ \r
+ \r
+ Process& getSender(void) const;\r
+ \r
+ Host& getSource(void) const \r
+ throw(NativeException);\r
+ \r
+ double getComputeDuration(void) const;\r
+ \r
+ double getRemainingDuration(void) const;\r
+ \r
+ void setPriority(double priority);\r
+ \r
+ static Task& get(int channel) \r
+ throw(NativeException); \r
+ \r
+ static Task& get(int channel, const Host& rHost) \r
+ throw(NativeException);\r
+ \r
+ static Task& get(int channel, double timeout, const Host& rHost) \r
+ throw(NativeException); \r
+ \r
+ static bool probe(int channel);\r
+ \r
+ static int probe(int channel, const Host& rHost);\r
+ \r
+ void execute(void) \r
+ throw(NativeException);\r
+ \r
+ void cancel(void) \r
+ throw(NativeException);\r
+ \r
+ \r
+ void send(void) \r
+ throw(NativeException);\r
+ \r
+ private:\r
+ \r
+ m_task_t nativeTask;\r
+ \r
+ \r
+};\r
+\r
+}\r
+\r
+#endif // §MSG_TASK_HPP
\ No newline at end of file