1 | #include "xios_spl.hpp" |
---|
2 | #include "buffer_in.hpp" |
---|
3 | #include "type.hpp" |
---|
4 | #include "event_server.hpp" |
---|
5 | #include "buffer_server.hpp" |
---|
6 | |
---|
7 | namespace xios |
---|
8 | { |
---|
9 | void CEventServer::push(int rank, CServerBuffer* serverBuffer, char* startBuffer, int size) |
---|
10 | { |
---|
11 | CBufferIn buffer(startBuffer, size); |
---|
12 | size_t timeLine; |
---|
13 | int myClassId, myType, myNbSender; |
---|
14 | |
---|
15 | buffer >> size >> timeLine >> myNbSender >> myClassId >> myType; |
---|
16 | |
---|
17 | if (subEvents.empty()) |
---|
18 | { |
---|
19 | nbSender = myNbSender; |
---|
20 | classId = myClassId; |
---|
21 | type = myType; |
---|
22 | } |
---|
23 | else |
---|
24 | { |
---|
25 | if (classId != myClassId || type != myType || nbSender != myNbSender) |
---|
26 | ERROR("void CEventServer::push(int rank, CServerBuffer* serverBuffer, char* startBuffer, int size)", |
---|
27 | << "The callers of event " << timeLine << " are not coherent." << std::endl |
---|
28 | << "Received subevent: classId = " << myClassId << ", type = " << myType << ", nbSender = " << myNbSender << std::endl |
---|
29 | << "Expected subevent: classId = " << classId << ", type = " << type << ", nbSender = " << nbSender); |
---|
30 | } |
---|
31 | |
---|
32 | SSubEvent ev; |
---|
33 | ev.rank = rank; |
---|
34 | ev.serverBuffer = serverBuffer; |
---|
35 | ev.buffer = new CBufferIn(buffer.ptr(), buffer.remain()); |
---|
36 | ev.size = size; |
---|
37 | ev.startBuffer = startBuffer ; // for one sided, take ownership of buffer for now |
---|
38 | subEvents.push_back(ev); |
---|
39 | |
---|
40 | if (subEvents.size() > nbSender) |
---|
41 | { |
---|
42 | ERROR("void CEventServer::push(int rank, CServerBuffer* serverBuffer, char* startBuffer, int size)", |
---|
43 | << "The callers of event " << timeLine << " are not coherent." << std::endl |
---|
44 | << "Too many subevents have been received (" << subEvents.size() << " instead of " << nbSender << ")."); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | bool CEventServer::isFull(void) |
---|
50 | { |
---|
51 | return (nbSender == subEvents.size()); |
---|
52 | } |
---|
53 | |
---|
54 | CEventServer::~CEventServer() |
---|
55 | { |
---|
56 | list<SSubEvent>::iterator it; |
---|
57 | for (it = subEvents.begin(); it != subEvents.end(); it++) |
---|
58 | { |
---|
59 | if (it->serverBuffer==nullptr) // one_sided case |
---|
60 | { |
---|
61 | delete [] it->startBuffer ; |
---|
62 | delete it->buffer; |
---|
63 | } |
---|
64 | else // legacy case |
---|
65 | { |
---|
66 | it->serverBuffer->freeBuffer(it->size); |
---|
67 | delete it->buffer; |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|