Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Include surf_resource.h, for surf_resource_name().
[simgrid.git] / src / cxx / Msg.cxx
index 94c7e81..cb622f8 100644 (file)
-\r
-/*\r
- * Msg.cxx\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
- /* Msg functions implementation.\r
-  */  \r
-#include <Msg.hpp>\r
-\r
-namespace SimGrid\r
-{\r
-       namespace Msg\r
-       {\r
-               \r
-               void init(int argc, char** argv)\r
-               {\r
-                       MSG_global_init(&argc,argv);\r
-                       MSG_set_channel_number(10); // FIXME: this should not be fixed statically \r
-               }       \r
-               \r
-               void finalize(void)\r
-               throw (MsgException)\r
-               {\r
-                       if(MSG_OK != MSG_clean())\r
-                               throw MsgException("MSG_clean() failed");\r
-               }\r
-               \r
-               void info(const char* s)\r
-               {\r
-                        INFO1("%s",s);\r
-               }\r
-\r
-       } // namespace Msg\r
-\r
-} // namespace SimGrid
\ No newline at end of file
+
+/*
+ * Msg.cxx
+ *
+ * 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. 
+ *
+ */
+ /* Msg functions implementation.
+  */  
+
+
+#include <Msg.hpp>
+#include <MsgHost.hpp>
+#include <MsgProcess.hpp>
+
+
+#include <msg/msg.h>
+#include <msg/private.h>
+
+#include <iostream>
+using std::cout;
+using std::endl;
+using std::streamsize;
+
+#include <iomanip>
+using std::setprecision;
+using std::setw;
+
+
+
+namespace SimGrid
+{
+       namespace Msg
+       {
+               #define SIMGRIDX_DEFAULT_CHANNEL_NUMBER ((int)10)
+               
+               void init(int argc, char** argv)
+               {
+                       MSG_global_init(&argc,argv);
+
+                       if(getMaxChannelNumber() == 0)
+                               setMaxChannelNumber(SIMGRIDX_DEFAULT_CHANNEL_NUMBER);
+               }       
+               
+               void finalize(void)
+               throw (MsgException)
+               {
+                       if(MSG_OK != MSG_clean())
+                               throw MsgException("MSG_clean() failed");
+                       
+               }
+               
+               void info(const StringHelper& s)
+               {
+                       StringHelper clock;
+
+                       cout << "[";
+                       cout << Host::currentHost().getName();
+                       cout << ":";
+                       cout << Process::currentProcess().getName();
+                       cout << ":(";
+                       cout << Process::currentProcess().getPID();
+                       cout << ") " ;
+                       cout << clock.append(getClock(), "%07lf");
+                       cout << "] [cxx4msg/INFO] ";
+                       cout << s;
+                       cout << endl;
+               }
+
+               void info(const char* s)
+               {
+                       StringHelper clock;
+                       
+                       cout << "[";
+                       cout << Host::currentHost().getName();
+                       cout << ":";
+                       cout << Process::currentProcess().getName();
+                       cout << ":(";
+                       cout << Process::currentProcess().getPID();
+                       cout << ") " ;
+                       cout << clock.append(getClock(), "%07lf");
+                       cout << "] [cxx4msg/INFO] ";
+                       cout << s;
+                       cout << endl;
+               }
+
+               void error(const StringHelper& s)
+               {
+                       StringHelper clock;
+
+                       cout << "[";
+                       cout << Host::currentHost().getName();
+                       cout << ":";
+                       cout << Process::currentProcess().getName();
+                       cout << ":(";
+                       cout << Process::currentProcess().getPID();
+                       cout << ") " ;
+                       cout << clock.append(getClock(), "%07lf");
+                       cout << "] [cxx4msg/ERROR] ";
+                       cout << s;
+                       cout << endl;
+               }
+
+               void error(const char* s)
+               {
+                       StringHelper clock;
+                       
+                       cout << "[";
+                       cout << Host::currentHost().getName();
+                       cout << ":";
+                       cout << Process::currentProcess().getName();
+                       cout << ":(";
+                       cout << Process::currentProcess().getPID();
+                       cout << ") " ;
+                       cout << clock.append(getClock(), "%07lf");
+                       cout << "] [cxx4msg/ERROR] ";
+                       cout << s;
+                       cout << endl;
+               }
+
+               double getClock(void)
+               {
+                       return MSG_get_clock();
+               }
+
+               void setMaxChannelNumber(int number)
+               throw(InvalidArgumentException, LogicException)
+               {
+                       if(msg_global->max_channel > 0)
+                               throw LogicException("Max channel number already setted");
+
+                       if(number < 0)
+                               throw InvalidArgumentException("number");
+
+                       msg_global->max_channel = number;
+               }
+
+               int getMaxChannelNumber(void)
+               {
+                       return msg_global->max_channel;
+               }
+
+       } // namespace Msg
+
+} // namespace SimGrid
+