Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Request.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Request.h (C) 2000-2024 */
9/* */
10/* Requête d'un message. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_MESSAGEPASSING_REQUEST_H
13#define ARCCORE_MESSAGEPASSING_REQUEST_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arccore/message_passing/MessageRank.h"
19#include "arccore/message_passing/MessageTag.h"
20#include "arccore/base/Ref.h"
21
22#include <cstddef>
23#include <iosfwd>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
29{
34class ARCCORE_MESSAGEPASSING_EXPORT ISubRequest
35{
36 public:
37
38 virtual ~ISubRequest() = default;
39
40 public:
41
44};
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
51class ARCCORE_MESSAGEPASSING_EXPORT IRequestCreator
52{
53 public:
54 virtual ~IRequestCreator() = default;
55};
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
76class ARCCORE_MESSAGEPASSING_EXPORT Request
77{
79 {
80 int i;
81 long l;
82 std::size_t st;
83 void* v;
84 const void* cv;
85 };
86
87 enum Type
88 {
89 T_Int,
90 T_Long,
91 T_SizeT,
92 T_Ptr,
93 T_Null
94 };
95
96 public:
97
98 Request()
99 {
100 m_type = T_Null;
101 m_request = null_request;
102 }
103
104 public:
105
106 ARCCORE_DEPRECATED_2020("Use overload with IRequestCreator pointer")
107 Request(int return_value,void* arequest)
108 : m_return_value(return_value)
109 {
110 m_type = T_Ptr;
111 m_request.v = arequest;
112 }
113
114 ARCCORE_DEPRECATED_2020("Use overload with IRequestCreator pointer")
115 Request(int return_value,const void* arequest)
116 : m_return_value(return_value)
117 {
118 m_type = T_Ptr;
119 m_request.cv = arequest;
120 }
121
122 ARCCORE_DEPRECATED_2020("Use overload with IRequestCreator pointer")
123 Request(int return_value,int arequest)
124 : m_return_value(return_value)
125 {
126 m_type = T_Int;
127 m_request.i = arequest;
128 }
129
130 ARCCORE_DEPRECATED_2020("Use overload with IRequestCreator pointer")
131 Request(int return_value,long arequest)
132 : m_return_value(return_value)
133 {
134 m_type = T_Long;
135 m_request.l = arequest;
136 }
137
138 ARCCORE_DEPRECATED_2020("Use overload with IRequestCreator pointer")
139 Request(int return_value,std::size_t arequest)
140 : m_return_value(return_value)
141 {
142 m_type = T_SizeT;
143 m_request.st = arequest;
144 }
145
146 public:
147
148 Request(int return_value,IRequestCreator* creator,void* arequest)
149 : m_return_value(return_value), m_creator(creator)
150 {
151 m_type = T_Ptr;
152 m_request.v = arequest;
153 }
154
155 Request(int return_value,IRequestCreator* creator,const void* arequest)
156 : m_return_value(return_value), m_creator(creator)
157 {
158 m_type = T_Ptr;
159 m_request.cv = arequest;
160 }
161
162 Request(int return_value,IRequestCreator* creator,int arequest)
163 : m_return_value(return_value), m_creator(creator)
164 {
165 m_type = T_Int;
166 m_request.i = arequest;
167 }
168
169 Request(int return_value,IRequestCreator* creator,long arequest)
170 : m_return_value(return_value), m_creator(creator)
171 {
172 m_type = T_Long;
173 m_request.l = arequest;
174 }
175
176 Request(int return_value,IRequestCreator* creator,std::size_t arequest)
177 : m_return_value(return_value), m_creator(creator)
178 {
179 m_type = T_SizeT;
180 m_request.st = arequest;
181 }
182
183 public:
184
185 template<typename T>
186 operator const T*() const { return (const T*)m_request.cv; }
187 template<typename T>
188 operator T*() const { return (T*)m_request.v; }
189 operator int() const { return m_request.i; }
190 operator long() const { return m_request.l; }
191 operator size_t() const { return m_request.st; }
192
193 public:
194
195 int returnValue() const { return m_return_value; }
196 bool isValid() const
197 {
198 if (m_type==T_Null)
199 return false;
200 // Si le type de la requête est différent du type
201 // de la requête nulle, alors la requête est considérée
202 // comme valide.
203 if (m_type!=null_request_type)
204 return true;
205 if (m_type==T_Int)
206 return m_request.i!=null_request.i;
207 if (m_type==T_Long)
208 return m_request.l!=null_request.l;
209 if (m_type==T_SizeT)
210 return m_request.st!=null_request.st;
211 if (m_type==T_Ptr)
212 return m_request.cv!=null_request.cv;
213 return false;
214 }
215 void* requestAsVoidPtr() const { return m_request.v; }
216
217 static void setNullRequest(Request r)
218 {
219 null_request = r.m_request;
220 null_request_type = r.m_type;
221 }
222
223 void reset()
224 {
225 m_request = null_request;
226 m_sub_request.reset();
227 m_type = T_Null;
228 }
229 Ref<ISubRequest> subRequest() const { return m_sub_request; }
230 bool hasSubRequest() const { return !m_sub_request.isNull(); }
231 void setSubRequest(Ref<ISubRequest> s) { m_sub_request = s; }
232
234 IRequestCreator* creator() const { return m_creator; }
235
236 void print(std::ostream& o) const;
237
238 friend inline std::ostream& operator<<(std::ostream& o,const Request& prequest)
239 {
240 prequest.print(o);
241 return o;
242 }
243
245 Int32 _type() const { return m_type; }
246
247 private:
248
249 int m_return_value = 0;
250 int m_type = T_Null;
251 _Request m_request;
252 Ref<ISubRequest> m_sub_request;
253 IRequestCreator* m_creator = nullptr;
254 static _Request null_request;
255 static int null_request_type;
256};
257
258/*---------------------------------------------------------------------------*/
259/*---------------------------------------------------------------------------*/
260
261} // End namespace Arccore::MessagePassing
262
263/*---------------------------------------------------------------------------*/
264/*---------------------------------------------------------------------------*/
265
266#endif
267
Déclarations générales de la composante 'message_passing'.
Gestion des références à une classe C++.
Interface d'un créateur de requête.
Definition Request.h:52
Sous-requête d'une requête.
Definition Request.h:35
virtual Request executeOnCompletion(const SubRequestCompletionInfo &)=0
Callback appelé lorsque la requête associée est terminée.
Requête d'un message.
Definition Request.h:77
IRequestCreator * creator() const
Créateur de la requête.
Definition Request.h:234
Informations de complètion d'une sous-requête.
Référence à une instance.
Espace de nommage contenant les types et déclarations qui gèrent le mécanisme de parallélisme par éch...
std::int32_t Int32
Type entier signé sur 32 bits.