1 | #include "xmlioserver_spl.hpp" |
---|
2 | #include "server.hpp" |
---|
3 | |
---|
4 | #include "tree_manager.hpp" |
---|
5 | #include "duration.hpp" |
---|
6 | #include "data_treatment.hpp" |
---|
7 | #include "group_template_impl.hpp" |
---|
8 | |
---|
9 | namespace xmlioserver { |
---|
10 | namespace comm { |
---|
11 | |
---|
12 | /// ////////////////////// Définitions ////////////////////// /// |
---|
13 | |
---|
14 | CServer::CServer(MPI_Comm comm_client_server) |
---|
15 | : blist(comm_client_server) |
---|
16 | { /* Ne rien faire de plus */ } |
---|
17 | |
---|
18 | CServer::~CServer(void) |
---|
19 | { /* Ne rien faire de plus */ } |
---|
20 | |
---|
21 | ///-------------------------------------------------------------- |
---|
22 | |
---|
23 | boost::shared_ptr<CServer> CServer::Server; |
---|
24 | |
---|
25 | ///-------------------------------------------------------------- |
---|
26 | |
---|
27 | const CBufferList & CServer::getBufferList(void) const |
---|
28 | { |
---|
29 | return (this->blist); |
---|
30 | } |
---|
31 | |
---|
32 | ///-------------------------------------------------------------- |
---|
33 | |
---|
34 | boost::shared_ptr<CServer> CServer::CreateServer(MPI_Comm comm_client_server) |
---|
35 | { |
---|
36 | if (CServer::Server.get() == NULL) |
---|
37 | CServer::Server = boost::shared_ptr<CServer>(new CServer(comm_client_server)); |
---|
38 | return (CServer::GetServer()); |
---|
39 | } |
---|
40 | |
---|
41 | ///-------------------------------------------------------------- |
---|
42 | |
---|
43 | boost::shared_ptr<CServer> CServer::GetServer(void) |
---|
44 | { |
---|
45 | return (CServer::Server); |
---|
46 | } |
---|
47 | |
---|
48 | //--------------------------------------------------------------- |
---|
49 | |
---|
50 | void CServer::run(void) |
---|
51 | { |
---|
52 | while (this->blist.recvRequests()) |
---|
53 | { |
---|
54 | long int managerId = -1, methodId = -1, nbargs = -1; |
---|
55 | long int managerId_= -1, methodId_ = -1, nbargs_ = -1; |
---|
56 | std::vector<CLinearBuffer> lbuffer; |
---|
57 | this->blist.getRequests(lbuffer); |
---|
58 | |
---|
59 | for (StdSize i = 0; i < lbuffer.size(); i++) |
---|
60 | { |
---|
61 | lbuffer[i].getRequestInfos(0, managerId, methodId, nbargs); |
---|
62 | if (((managerId_ != managerId) || (methodId_ != methodId) || (nbargs_ != nbargs)) && (i != 0 )) |
---|
63 | { |
---|
64 | //std::cout << managerId_ << "<->" << managerId << std::endl |
---|
65 | // << methodId_ << "<->" << methodId << std::endl |
---|
66 | // << nbargs_ << "<->" << nbargs << std::endl; |
---|
67 | ERROR("CServer::run(void)", << "[" << i << "] Les requêtes ne sont pas synchronisées !"); |
---|
68 | } |
---|
69 | managerId_ = managerId; |
---|
70 | methodId_ = methodId; |
---|
71 | nbargs_ = nbargs; |
---|
72 | } |
---|
73 | |
---|
74 | if (managerId == 0) |
---|
75 | { |
---|
76 | switch(methodId) |
---|
77 | { |
---|
78 | case (0) : |
---|
79 | // std::cout<<"--> Request initialize()"<<std::endl ; |
---|
80 | this->initialize(); |
---|
81 | continue; |
---|
82 | case (1) : |
---|
83 | // std::cout<<"--> Request finalize()"<<std::endl ; |
---|
84 | this->finalize(); |
---|
85 | return; |
---|
86 | default : |
---|
87 | ERROR("CServer::run(void)", |
---|
88 | << "[ managerId = " << managerId << ", " |
---|
89 | << "[ methodId = " << methodId << ", " |
---|
90 | << "[ nbargs = " << nbargs << "] " |
---|
91 | << " Methode inconnue !"); |
---|
92 | } |
---|
93 | } |
---|
94 | if (managerId == 1) |
---|
95 | { |
---|
96 | switch(methodId) |
---|
97 | { |
---|
98 | case (0) : |
---|
99 | // std::cout<<"--> Request setContext()"<<std::endl ; |
---|
100 | this->setContext(lbuffer); |
---|
101 | continue; |
---|
102 | case (1) : |
---|
103 | // std::cout<<"--> Request updateCalendar()"<<std::endl ; |
---|
104 | this->updateCalendar(lbuffer); |
---|
105 | continue; |
---|
106 | case (2) : |
---|
107 | // std::cout<<"--> Request setTimestep()"<<std::endl ; |
---|
108 | this->setTimestep(lbuffer); |
---|
109 | continue; |
---|
110 | default : |
---|
111 | ERROR("CServer::run(void)", |
---|
112 | << "[ managerId = " << managerId << ", " |
---|
113 | << "[ methodId = " << methodId << ", " |
---|
114 | << "[ nbargs = " << nbargs << "] " |
---|
115 | << " Methode inconnue !"); |
---|
116 | } |
---|
117 | } |
---|
118 | if (managerId == 2) |
---|
119 | { |
---|
120 | switch(methodId) |
---|
121 | { |
---|
122 | case (0) : |
---|
123 | // std::cout<<"--> Request writeData()"<<std::endl ; |
---|
124 | this->writeData(lbuffer, 4); |
---|
125 | continue; |
---|
126 | case (1) : |
---|
127 | // std::cout<<"--> Request writeData()"<<std::endl ; |
---|
128 | this->writeData(lbuffer, 8); |
---|
129 | continue; |
---|
130 | default : |
---|
131 | ERROR("CServer::run(void)", |
---|
132 | << "[ managerId = " << managerId << ", " |
---|
133 | << "[ methodId = " << methodId << ", " |
---|
134 | << "[ nbargs = " << nbargs << "] " |
---|
135 | << " Methode inconnue !"); |
---|
136 | } |
---|
137 | } |
---|
138 | ERROR("CServer::run(void)", |
---|
139 | << "[ managerId = " << managerId << ", " |
---|
140 | << "[ methodId = " << methodId << ", " |
---|
141 | << "[ nbargs = " << nbargs << "] " |
---|
142 | << " Methode inconnue !"); |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | //-------------------------------------------------------------- |
---|
147 | |
---|
148 | void CServer::initialize(void) // manager 0, method 0 |
---|
149 | { |
---|
150 | } |
---|
151 | |
---|
152 | //-------------------------------------------------------------- |
---|
153 | |
---|
154 | void CServer::finalize(void) // manager 0, method 1 |
---|
155 | { |
---|
156 | boost::shared_ptr<CContext> context = |
---|
157 | CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()); |
---|
158 | boost::shared_ptr<data::CDataTreatment> dtreat = context->getDataTreatment(); |
---|
159 | dtreat->finalize() ; |
---|
160 | |
---|
161 | comm::CMPIManager::Barrier(CMPIManager::GetCommClientServer()); |
---|
162 | } |
---|
163 | |
---|
164 | //-------------------------------------------------------------- |
---|
165 | |
---|
166 | void CServer::setTimestep(const std::vector<CLinearBuffer> & buffer)// manager 1, method 2 |
---|
167 | { |
---|
168 | boost::shared_ptr<CContext> context = |
---|
169 | CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()); |
---|
170 | boost::shared_ptr<data::CDataTreatment> dtreat = context->getDataTreatment(); |
---|
171 | |
---|
172 | StdString durationstr; |
---|
173 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
174 | { |
---|
175 | StdString durationstr_ = buffer[i].getString(3); |
---|
176 | if (durationstr.compare(durationstr_) != 0 && (i != 0)) |
---|
177 | { |
---|
178 | ERROR("CServer::setTimestep(const std::vector<CLinearBuffer> & buffer)", |
---|
179 | << "[ durationstr 1 = " << durationstr << ", " |
---|
180 | << "[ durationstr 2 = " << durationstr_ << "] " |
---|
181 | << " Modification de timestep désynchronisé !"); |
---|
182 | } |
---|
183 | else durationstr = durationstr_; |
---|
184 | |
---|
185 | } |
---|
186 | dtreat->set_timestep(date::CDuration::FromString(durationstr)); |
---|
187 | } |
---|
188 | |
---|
189 | //-------------------------------------------------------------- |
---|
190 | |
---|
191 | void CServer::setContext(const std::vector<CLinearBuffer> & buffer) // manager 1, method 0 |
---|
192 | { |
---|
193 | StdString contextId; |
---|
194 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
195 | { |
---|
196 | StdString contextId_ = buffer[i].getString(3); |
---|
197 | if (contextId.compare(contextId_) != 0 && (i != 0)) |
---|
198 | { |
---|
199 | ERROR("CServer::setContext(const std::vector<CLinearBuffer> & buffer)", |
---|
200 | << "[ contextId 1 = " << contextId << ", " |
---|
201 | << "[ contextId 2 = " << contextId_ << "] " |
---|
202 | << " Changement de contexte désynchronisé !"); |
---|
203 | } |
---|
204 | else contextId = contextId_; |
---|
205 | |
---|
206 | } |
---|
207 | CTreeManager::SetCurrentContextId(contextId); |
---|
208 | } |
---|
209 | |
---|
210 | //-------------------------------------------------------------- |
---|
211 | |
---|
212 | void CServer::updateCalendar(const std::vector<CLinearBuffer> & buffer) // manager 1, method 1 |
---|
213 | { |
---|
214 | boost::shared_ptr<CContext> context = |
---|
215 | CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()); |
---|
216 | boost::shared_ptr<data::CDataTreatment> dtreat = context->getDataTreatment(); |
---|
217 | |
---|
218 | int timestep = -1; |
---|
219 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
220 | { |
---|
221 | int timestep_ = buffer[i].getInt(3); |
---|
222 | if ((timestep_ != timestep) && (i != 0)) |
---|
223 | { |
---|
224 | ERROR("CServer::updateCalendar(const std::vector<CLinearBuffer> & buffer)", |
---|
225 | << "[ timestep 1 = " << timestep << ", " |
---|
226 | << "[ timestep 2 = " << timestep_ << "] " |
---|
227 | << " Mise à jour du calendrier désynchronisée !"); |
---|
228 | } |
---|
229 | else timestep = timestep_; |
---|
230 | } |
---|
231 | dtreat->update_calendar(timestep); |
---|
232 | } |
---|
233 | |
---|
234 | //-------------------------------------------------------------- |
---|
235 | |
---|
236 | void CServer::writeData(const std::vector<CLinearBuffer> & buffer, int prec) // manager 2, method 0 - 1 |
---|
237 | { |
---|
238 | boost::shared_ptr<CContext> context = |
---|
239 | CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()); |
---|
240 | boost::shared_ptr<data::CDataTreatment> dtreat = context->getDataTreatment(); |
---|
241 | |
---|
242 | StdString fieldId, fileId; |
---|
243 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
244 | { |
---|
245 | StdString fieldId_ = buffer[i].getString(3); |
---|
246 | StdString fileId_ = buffer[i].getString(4); |
---|
247 | |
---|
248 | if (fieldId.compare(fieldId_) != 0 && (i != 0)) |
---|
249 | { |
---|
250 | ERROR("CServer::writeData(const std::vector<CLinearBuffer> & buffer, int prec)", |
---|
251 | << "[fieldId 1 = " << fieldId << ", " |
---|
252 | << " fieldId 2 = " << fieldId_ << "] " |
---|
253 | << " Ecriture des données désynchronisée !"); |
---|
254 | } |
---|
255 | else fieldId = fieldId_; |
---|
256 | |
---|
257 | if (fileId.compare(fileId_) != 0 && (i != 0)) |
---|
258 | { |
---|
259 | ERROR("CServer::writeData(const std::vector<CLinearBuffer> & buffer, int prec)", |
---|
260 | << "[fileId 1 = " << fileId << ", " |
---|
261 | << " fileId 2 = " << fileId_ << "] " |
---|
262 | << " Ecriture des données désynchronisée !"); |
---|
263 | } |
---|
264 | else fileId = fileId_; |
---|
265 | } |
---|
266 | |
---|
267 | if (prec == 4) |
---|
268 | { |
---|
269 | std::deque<ARRAY(float, 1)> dataArray(buffer.size()); |
---|
270 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
271 | dataArray[i] = buffer[i].getFloatArray(5); |
---|
272 | std::cout << "writeData called (float) " << fieldId << ", " << dataArray[0] << std::endl; |
---|
273 | // Jamais atteint car les données sont transférées en tant que double |
---|
274 | return; |
---|
275 | } |
---|
276 | else if (prec == 8) |
---|
277 | { |
---|
278 | std::deque<ARRAY(double, 1)> dataArray(buffer.size()); |
---|
279 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
280 | dataArray[i] = buffer[i].getDoubleArray(5); |
---|
281 | std::cout << "writeData called (double) " << fieldId << ", " << dataArray[0] << std::endl; |
---|
282 | dtreat->write_data(fieldId, fileId, dataArray); |
---|
283 | return; |
---|
284 | } |
---|
285 | else |
---|
286 | { |
---|
287 | ERROR("CServer::writeData(const std::vector<CLinearBuffer> & buffer, int prec)", |
---|
288 | << " Précision des données invalide !"); |
---|
289 | } |
---|
290 | } |
---|
291 | |
---|
292 | ///-------------------------------------------------------------- |
---|
293 | |
---|
294 | |
---|
295 | } // namespace comm |
---|
296 | } // namespace xmlioserver |
---|