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