Logo AND Algorithmique Numérique Distribuée

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