X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e133a950865071b1c006387e915d39989a53c8cd..d9f6a4409b58ac98618a4b646af874f06ceac856:/src/cxx/Msg.cxx diff --git a/src/cxx/Msg.cxx b/src/cxx/Msg.cxx index 20521cdad7..cb622f8baf 100644 --- a/src/cxx/Msg.cxx +++ b/src/cxx/Msg.cxx @@ -1,56 +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 - -// XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(SimGridX); - -namespace SimGrid -{ - namespace Msg - { - - void init(int argc, char** argv) - { - MSG_global_init(&argc,argv); - MSG_set_channel_number(10); // FIXME: this should not be fixed statically - } - - 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(); - } - - } // namespace Msg - -} // 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 +#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 +