Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
BasicSerializeMessage.cc
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/* BasicSerializeMessage.cc (C) 2000-2020 */
9/* */
10/* Message utilisant un BasicSerializeMessage. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/message_passing/BasicSerializeMessage.h"
15#include "arccore/base/FatalErrorException.h"
16#include "arccore/base/Ref.h"
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21namespace Arccore::MessagePassing::internal
22{
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27ePointToPointMessageType BasicSerializeMessage::
28_toP2PType(eMessageType mtype)
29{
30 switch(mtype){
31 case MT_Send: return MsgSend;
32 case MT_Recv: return MsgReceive;
33 case MT_Broadcast: return MsgSend;
34 }
35 ARCCORE_FATAL("Unsupported value '{0}'",mtype);
36}
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41ISerializeMessage::eMessageType BasicSerializeMessage::
42_toMessageType(ePointToPointMessageType type)
43{
44 switch(type){
45 case MsgSend: return MT_Send;
46 case MsgReceive: return MT_Recv;
47 }
48 ARCCORE_FATAL("Unsupported value '{0}'",type);
49}
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
53
54BasicSerializeMessage::
55BasicSerializeMessage(MessageRank orig_rank,MessageRank dest_rank,
56 MessageTag tag,ePointToPointMessageType type,
57 BasicSerializer* s)
58: m_orig_rank(orig_rank)
59, m_dest_rank(dest_rank)
60, m_tag(tag)
61, m_old_message_type(_toMessageType(type))
62, m_message_type(type)
63, m_is_send(false)
64, m_buffer(s)
65{
66 _init();
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72BasicSerializeMessage::
73BasicSerializeMessage(MessageRank orig_rank,MessageRank dest_rank,
74 ePointToPointMessageType type,
75 BasicSerializer* s)
76: BasicSerializeMessage(orig_rank,dest_rank,defaultTag(),type,s)
77{
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83BasicSerializeMessage::
84BasicSerializeMessage(MessageRank orig_rank,MessageId message_id,
85 BasicSerializer* s)
86: m_orig_rank(orig_rank)
87, m_dest_rank(message_id.sourceInfo().rank())
88, m_tag(message_id.sourceInfo().tag())
89, m_old_message_type(MT_Recv)
90, m_message_type(MsgReceive)
91, m_is_send(false)
92, m_buffer(s)
93, m_message_id(message_id)
94{
95 _init();
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101BasicSerializeMessage::
102BasicSerializeMessage(MessageRank orig_rank,MessageRank dest_rank,
103 MessageTag tag,ePointToPointMessageType type)
104: BasicSerializeMessage(orig_rank,dest_rank,tag,type,new BasicSerializer())
105{
106}
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
111BasicSerializeMessage::
112BasicSerializeMessage(MessageRank orig_rank,MessageRank dest_rank,
113 ePointToPointMessageType type)
114: BasicSerializeMessage(orig_rank,dest_rank,defaultTag(),type)
115{
116}
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120
121BasicSerializeMessage::
122~BasicSerializeMessage()
123{
124 delete m_buffer;
125}
126
127/*---------------------------------------------------------------------------*/
128/*---------------------------------------------------------------------------*/
129
130void BasicSerializeMessage::
131_init()
132{
133 switch(m_old_message_type){
134 case MT_Send:
135 case MT_Broadcast:
136 m_is_send = true;
137 break;
138 case MT_Recv:
139 m_is_send = false;
140 break;
141 }
142}
143
144/*---------------------------------------------------------------------------*/
145/*---------------------------------------------------------------------------*/
146
147void BasicSerializeMessage::
148setStrategy(eStrategy strategy)
149{
150 if (m_is_processed)
151 ARCCORE_FATAL("Can not change strategy if isProcessed() is true");
152 m_strategy = strategy;
153}
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
158Ref<ISerializeMessage> BasicSerializeMessage::
159create(MessageRank source,MessageRank destination,MessageTag tag,
161{
162 ISerializeMessage* m = new BasicSerializeMessage(source,destination,tag,type);
163 return makeRef(m);
164}
165
166/*---------------------------------------------------------------------------*/
167/*---------------------------------------------------------------------------*/
168
169Ref<ISerializeMessage> BasicSerializeMessage::
170create(MessageRank source,MessageRank destination,ePointToPointMessageType type)
171{
172 ISerializeMessage* m = new BasicSerializeMessage(source,destination,type);
173 return makeRef(m);
174}
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179Ref<ISerializeMessage> BasicSerializeMessage::
180create(MessageRank source,MessageId message_id)
181{
182 ISerializeMessage* m = new BasicSerializeMessage(source,message_id,new BasicSerializer());
183 return makeRef(m);
184}
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
189} // End namespace Arccore::MessagePassing
190
191/*---------------------------------------------------------------------------*/
192/*---------------------------------------------------------------------------*/
Gestion des références à une classe C++.
Implémentation basique de 'ISerializer'.
Message de sérialisation utilisant un BasicSerializer.
Référence à une instance.
ePointToPointMessageType
Type de message point à point.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.