[152] | 1 | #ifndef __XMLIO_CBufferPair__ |
---|
| 2 | #define __XMLIO_CBufferPair__ |
---|
| 3 | |
---|
| 4 | /// xmlioserver headers /// |
---|
| 5 | #include "xmlioserver_spl.hpp" |
---|
| 6 | #include "buffer.hpp" |
---|
| 7 | #include "circular_buffer.hpp" |
---|
| 8 | #include "linear_buffer.hpp" |
---|
[157] | 9 | #include "mpi_manager.hpp" |
---|
[152] | 10 | |
---|
| 11 | namespace xmlioserver |
---|
| 12 | { |
---|
| 13 | namespace comm |
---|
| 14 | { |
---|
| 15 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
| 16 | class CBufferPair |
---|
| 17 | { |
---|
| 18 | |
---|
| 19 | /// Définition de type /// |
---|
| 20 | typedef CLinearBuffer BufferType; |
---|
| 21 | |
---|
| 22 | public : |
---|
| 23 | |
---|
| 24 | /// Construteurs /// |
---|
| 25 | CBufferPair(MPIComm com_client_server = CMPIManager::GetCommWorld()); |
---|
| 26 | CBufferPair(const CBufferPair & buffer_pair); // Not implemented yet. |
---|
| 27 | CBufferPair(const CBufferPair * const buffer_pair); // Not implemented yet. |
---|
| 28 | |
---|
[178] | 29 | template <typename A1, typename A2, typename A3, typename A4> |
---|
| 30 | void prepareRequest(const long int & managerId, |
---|
| 31 | const long int & methodId, |
---|
| 32 | A1 * arg1 = CLinearBuffer::NULL_ARG, |
---|
| 33 | A2 * arg2 = CLinearBuffer::NULL_ARG, |
---|
| 34 | A3 * arg3 = CLinearBuffer::NULL_ARG, |
---|
| 35 | A4 * arg4 = CLinearBuffer::NULL_ARG); |
---|
[190] | 36 | /// Accesseur /// |
---|
| 37 | CLinearBuffer & getCurrentBuffer(void); |
---|
[191] | 38 | |
---|
| 39 | /// Traitements divers /// |
---|
[198] | 40 | int wait(void); |
---|
[191] | 41 | void sendCurrentBuffer(void); |
---|
| 42 | |
---|
[152] | 43 | /// Destructeur /// |
---|
| 44 | virtual ~CBufferPair(void); |
---|
[178] | 45 | |
---|
| 46 | protected : |
---|
| 47 | |
---|
| 48 | /// Test /// |
---|
[191] | 49 | bool mustBeSent(void); |
---|
[152] | 50 | |
---|
| 51 | private : |
---|
| 52 | |
---|
[190] | 53 | /// Propriétés privées /// |
---|
[152] | 54 | MPIComm com_client_server; |
---|
[178] | 55 | CLinearBuffer first, second; |
---|
| 56 | MPIRequest first_request, second_request; |
---|
| 57 | int currentBuffer; |
---|
[152] | 58 | |
---|
| 59 | }; // class CBufferPair |
---|
[178] | 60 | |
---|
| 61 | ///-------------------------------------------------------------- |
---|
| 62 | |
---|
| 63 | template <typename A1, typename A2, typename A3, typename A4> |
---|
| 64 | void CBufferPair::prepareRequest(const long int & managerId, |
---|
| 65 | const long int & methodId, |
---|
| 66 | A1 * arg1, A2 * arg2, A3 * arg3, A4 * arg4) |
---|
[199] | 67 | { |
---|
[196] | 68 | if (this->mustBeSent()) |
---|
| 69 | this->sendCurrentBuffer(); |
---|
[178] | 70 | |
---|
| 71 | CLinearBuffer & cbuffer = this->getCurrentBuffer(); |
---|
| 72 | StdSize usize = cbuffer.getUnusedSize(); |
---|
| 73 | StdSize rsize = cbuffer.getRequestedSize(arg1, arg2, arg3, arg4) ; |
---|
| 74 | StdSize msize = cbuffer.getSize(); |
---|
| 75 | |
---|
| 76 | long int nbargs = 0; |
---|
| 77 | |
---|
[190] | 78 | if (arg1 != NULL) nbargs++; |
---|
| 79 | if (arg2 != NULL) nbargs++; |
---|
| 80 | if (arg3 != NULL) nbargs++; |
---|
| 81 | if (arg4 != NULL) nbargs++; |
---|
[178] | 82 | |
---|
| 83 | if (rsize > msize) |
---|
| 84 | ERROR("CBufferPair::sendRequest(...)", << "Le tampon client est trop petit !"); |
---|
| 85 | |
---|
| 86 | if (rsize <= usize) |
---|
| 87 | { |
---|
[198] | 88 | cbuffer.appendRequestInfos(managerId, methodId, nbargs); |
---|
[178] | 89 | } |
---|
| 90 | else |
---|
| 91 | { |
---|
[199] | 92 | this->wait(); |
---|
[178] | 93 | this->prepareRequest(managerId, methodId, arg1, arg2, arg3, arg4); |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | ///-------------------------------------------------------------- |
---|
| 98 | |
---|
| 99 | |
---|
[152] | 100 | } // namespace comm |
---|
| 101 | } // namespace xmlioserver |
---|
| 102 | |
---|
| 103 | #endif // __XMLIO_CBufferPair__ |
---|