Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
daac88e4b1544d48962a5d80eb8992d4f2533085
[simgrid.git] / src / cxx / Msg.cxx
1 \r
2 /*\r
3  * Msg.cxx\r
4  *\r
5  * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
6  * All right reserved. \r
7  *\r
8  * This program is free software; you can redistribute \r
9  * it and/or modify it under the terms of the license \r
10  *(GNU LGPL) which comes with this package. \r
11  *\r
12  */\r
13  \r
14  /* Msg functions implementation.\r
15   */  \r
16 \r
17 \r
18 #include <Msg.hpp>\r
19 #include <Host.hpp>\r
20 #include <Process.hpp>\r
21 \r
22 \r
23 #include <msg/msg.h>\r
24 #include <msg/private.h>\r
25 \r
26 #include <iostream>\r
27 using std::cout;\r
28 using std::endl;\r
29 using std::streamsize;\r
30 \r
31 #include <iomanip>\r
32 using std::setprecision;\r
33 using std::setw;\r
34 \r
35 \r
36 \r
37 namespace SimGrid\r
38 {\r
39         namespace Msg\r
40         {\r
41                 #define SIMGRIDX_DEFAULT_CHANNEL_NUMBER ((int)10)\r
42                 \r
43                 void init(int argc, char** argv)\r
44                 {\r
45                         MSG_global_init(&argc,argv);\r
46 \r
47                         if(getMaxChannelNumber() == 0)\r
48                                 setMaxChannelNumber(SIMGRIDX_DEFAULT_CHANNEL_NUMBER);\r
49                 }       \r
50                 \r
51                 void finalize(void)\r
52                 throw (MsgException)\r
53                 {\r
54                         if(MSG_OK != MSG_clean())\r
55                                 throw MsgException("MSG_clean() failed");\r
56                         \r
57                 }\r
58                 \r
59                 void info(const StringHelper& s)\r
60                 {\r
61                         StringHelper clock;\r
62                         \r
63                         cout << "[";\r
64                         cout << Host::currentHost().getName();\r
65                         cout << ":";\r
66                         cout << Process::currentProcess().getName();\r
67                         cout << ":(";\r
68                         cout << Process::currentProcess().getPID();\r
69                         cout << ") " ;\r
70                         cout << clock.append(getClock(), "%07lf");\r
71                         cout << "] [cxx4msg/INFO] ";\r
72                         cout << s;\r
73                         cout << endl;\r
74                 }\r
75 \r
76                 void info(const char* s)\r
77                 {\r
78                         StringHelper clock;\r
79                         \r
80                         cout << "[";\r
81                         cout << Host::currentHost().getName();\r
82                         cout << ":";\r
83                         cout << Process::currentProcess().getName();\r
84                         cout << ":(";\r
85                         cout << Process::currentProcess().getPID();\r
86                         cout << ") " ;\r
87                         cout << clock.append(getClock(), "%07lf");\r
88                         cout << "] [cxx4msg/INFO] ";\r
89                         cout << s;\r
90                         cout << endl;\r
91                 }\r
92 \r
93                 void error(const StringHelper& s)\r
94                 {\r
95                         StringHelper clock;\r
96                         \r
97                         cout << "[";\r
98                         cout << Host::currentHost().getName();\r
99                         cout << ":";\r
100                         cout << Process::currentProcess().getName();\r
101                         cout << ":(";\r
102                         cout << Process::currentProcess().getPID();\r
103                         cout << ") " ;\r
104                         cout << clock.append(getClock(), "%07lf");\r
105                         cout << "] [cxx4msg/ERROR] ";\r
106                         cout << s;\r
107                         cout << endl;\r
108                 }\r
109 \r
110                 void error(const char* s)\r
111                 {\r
112                         StringHelper clock;\r
113                         \r
114                         cout << "[";\r
115                         cout << Host::currentHost().getName();\r
116                         cout << ":";\r
117                         cout << Process::currentProcess().getName();\r
118                         cout << ":(";\r
119                         cout << Process::currentProcess().getPID();\r
120                         cout << ") " ;\r
121                         cout << clock.append(getClock(), "%07lf");\r
122                         cout << "] [cxx4msg/ERROR] ";\r
123                         cout << s;\r
124                         cout << endl;\r
125                 }\r
126 \r
127                 double getClock(void)\r
128                 {\r
129                         return MSG_get_clock();\r
130                 }\r
131 \r
132                 void setMaxChannelNumber(int number)\r
133                 throw(InvalidArgumentException, LogicException)\r
134                 {\r
135                         if(msg_global->max_channel > 0)\r
136                                 throw LogicException("Max channel number already setted");\r
137 \r
138                         if(number < 0)\r
139                                 throw InvalidArgumentException("number");\r
140 \r
141                         msg_global->max_channel = number;\r
142                 }\r
143 \r
144                 int getMaxChannelNumber(void)\r
145                 {\r
146                         return msg_global->max_channel;\r
147                 }\r
148 \r
149         } // namespace Msg\r
150 \r
151 } // namespace SimGrid\r
152 \r