X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/846b7de4a868bf8dc1270f76a01c33738576694d..1544c44ae892f12125f1355d83e275d8299418ed:/src/cxx/Msg.cxx diff --git a/src/cxx/Msg.cxx b/src/cxx/Msg.cxx index 443ac6b2f9..cb622f8baf 100644 --- a/src/cxx/Msg.cxx +++ b/src/cxx/Msg.cxx @@ -1,80 +1,152 @@ - -/* - * 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 - -#include -#include -#include - - - - -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 char* s) - { - //INFO1("%s",s); - printf("[SimGridX/info] %s\n", s); - } - - 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 - + +/* + * 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 +#include +#include + + +#include +#include + +#include +using std::cout; +using std::endl; +using std::streamsize; + +#include +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 +