xc
Channel.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // XC program; finite element analysis code
4 // for structural analysis and design.
5 //
6 // Copyright (C) Luis C. Pérez Tato
7 //
8 // This program derives from OpenSees <http://opensees.berkeley.edu>
9 // developed by the «Pacific earthquake engineering research center».
10 //
11 // Except for the restrictions that may arise from the copyright
12 // of the original program (see copyright_opensees.txt)
13 // XC is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // This software is distributed in the hope that it will be useful, but
19 // WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program.
26 // If not, see <http://www.gnu.org/licenses/>.
27 //----------------------------------------------------------------------------
28 /* ****************************************************************** **
29 ** OpenSees - Open System for Earthquake Engineering Simulation **
30 ** Pacific Earthquake Engineering Research Center **
31 ** **
32 ** **
33 ** (C) Copyright 1999, The Regents of the University of California **
34 ** All Rights Reserved. **
35 ** **
36 ** Commercial use of this program without express permission of the **
37 ** University of California, Berkeley, is strictly prohibited. See **
38 ** file 'COPYRIGHT' in main directory for information on usage and **
39 ** redistribution, and for a DISCLAIMER OF ALL WARRANTIES. **
40 ** **
41 ** Developed by: **
42 ** Frank McKenna (fmckenna@ce.berkeley.edu) **
43 ** Gregory L. Fenves (fenves@ce.berkeley.edu) **
44 ** Filip C. Filippou (filippou@ce.berkeley.edu) **
45 ** **
46 ** ****************************************************************** */
47 
48 // $Revision: 1.5 $
49 // $Date: 2005/11/23 18:27:24 $
50 // $Source: /usr/local/cvs/OpenSees/SRC/actor/channel/Channel.h,v $
51 
52 
53 #ifndef Channel_h
54 #define Channel_h
55 
56 // Written: fmk
57 // Created: 11/96
58 // Revision: A
59 //
60 // Purpose: This file contains the class definition for Channel.
61 // Channel is an abstract base class which defines the channel interface.
62 // A channel is a point of communication in a program, a mailbox to/from
63 // which data enters/leaves a program.
64 //
65 // What: "@(#) Channel.h, revA"
66 
67 
68 #include "utility/kernel/CommandEntity.h"
69 #include <set>
70 
71 namespace XC {
72 class ChannelAddress;
73 class Message;
74 class MovableObject;
75 class Matrix;
76 class Vector;
77 class ID;
78 class FEM_ObjectBroker;
79 
81 //
92 class Channel: public CommandEntity
93  {
94  private:
95  static int numChannel;
96  int tag;
97  std::set<int> usedDbTags;
98  protected:
99  int sendMovable(int commitTag, MovableObject &);
100  int receiveMovable(int commitTag, MovableObject &, FEM_ObjectBroker &);
101  public:
102  Channel(CommandEntity *owr= nullptr);
103  inline virtual ~Channel(void) {}
104 
105  // methods to set up the channel in an actor space
111  virtual std::string addToProgram(void) =0;
112  virtual int setUpConnection(void) =0;
116  virtual int setNextAddress(const ChannelAddress &theAddress) =0;
117  virtual ChannelAddress *getLastSendersAddress(void) =0;
118 
119  virtual bool isDatastore(void) const;
120  virtual int getDbTag(void) const;
121  bool checkDbTag(const int &dbTag);
122  const ID &getUsedTags(void) const;
123  void clearDbTags(void);
124  int getTag(void) const;
125 
126  // methods to send/receive messages and objects on channels.
133  virtual int sendObj(int commitTag, MovableObject &theObj, ChannelAddress *theAddress= nullptr) =0;
139  virtual int recvObj(int commitTag, MovableObject &theObj, FEM_ObjectBroker &theBroker, ChannelAddress *theAddress= nullptr) =0;
140  template <class inputIterator>
141  int sendObjs(int commitTag,const inputIterator &first,const inputIterator &last,ChannelAddress *theAddress= nullptr);
142  template <class inputIterator>
143  int recvObjs(int commitTag,const inputIterator &first,const inputIterator &last, FEM_ObjectBroker &, ChannelAddress *theAddress= nullptr);
144 
154  virtual int sendMsg(int dbTag, int commitTag, const Message &theMsg, ChannelAddress *theAddress= nullptr) =0;
155 
165  virtual int recvMsg(int dbTag, int commitTag, Message &theMsg, ChannelAddress *theAddress= nullptr) =0;
166 
176  virtual int sendMatrix(int dbTag, int commitTag, const Matrix &theMatrix,ChannelAddress *theAddress= nullptr) =0;
177 
187  virtual int recvMatrix(int dbTag, int commitTag, Matrix &theMatrix, ChannelAddress *theAddress= nullptr) =0;
188 
198  virtual int sendVector(int dbTag, int commitTag, const Vector &theVector, ChannelAddress *theAddress= nullptr) =0;
199 
209  virtual int recvVector(int dbTag, int commitTag, Vector &theVector, ChannelAddress *theAddress= nullptr) =0;
210 
220  virtual int sendID(int dbTag, int commitTag,const ID &theID, ChannelAddress *theAddress= nullptr) =0;
221 
231  virtual int recvID(int dbTag, int commitTag,ID &theID, ChannelAddress *theAddress= nullptr) =0;
232  };
233 
235 template <class inputIterator>
236 int Channel::sendObjs(int commitTag,const inputIterator &first,const inputIterator &last,ChannelAddress *theAddress)
237  {
238  int retval= 0;
239  for(inputIterator i= first;i!=last;i++)
240  {
241  retval= sendObj(commitTag,*i,theAddress);
242  if(retval!=0)
243  break;
244  }
245  return retval;
246  }
247 
249 template <class inputIterator>
250 int Channel::recvObjs(int commitTag,const inputIterator &first,const inputIterator &last, FEM_ObjectBroker &ob, ChannelAddress *theAddress)
251  {
252  int retval= 0;
253  for(inputIterator i= first;i!=last;i++)
254  {
255  retval= recvObj(commitTag,*i,ob,theAddress);
256  if(retval!=0)
257  break;
258  }
259  return retval;
260  }
261 
262 } // end of XC namespace
263 
264 #endif
virtual int sendID(int dbTag, int commitTag, const ID &theID, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the ID object theID to another Channel object.
Float vector abstraction.
Definition: Vector.h:94
virtual int recvMsg(int dbTag, int commitTag, Message &theMsg, ChannelAddress *theAddress=nullptr)=0
Invoked to send the data in the Message object theMsg to another Channel object.
virtual int recvMatrix(int dbTag, int commitTag, Matrix &theMatrix, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the Matrix object theMatrix to another Channel object.
virtual int recvVector(int dbTag, int commitTag, Vector &theVector, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the Vector object theVector to another Channel object.
int recvObjs(int commitTag, const inputIterator &first, const inputIterator &last, FEM_ObjectBroker &, ChannelAddress *theAddress=nullptr)
Receive an object sequence.
Definition: Channel.h:250
virtual int sendMsg(int dbTag, int commitTag, const Message &theMsg, ChannelAddress *theAddress=nullptr)=0
A method invoked to send the data in the Message object theMsg to another Channel object...
int getTag(void) const
Return the object tag.
Definition: Channel.cpp:126
Object that can move between processes.
Definition: MovableObject.h:100
void clearDbTags(void)
Reset used database tags set.
Definition: Channel.cpp:122
virtual int recvObj(int commitTag, MovableObject &theObj, FEM_ObjectBroker &theBroker, ChannelAddress *theAddress=nullptr)=0
To receive the object theObj with the commit tag commitTag from a remote Channel whose address is giv...
virtual int sendObj(int commitTag, MovableObject &theObj, ChannelAddress *theAddress=nullptr)=0
To send the object theObj and the commit tag commitTag to a remote Channel whose address is given by ...
FEM_ObjectBroker is is an object broker class for the finite element method.
Definition: FEM_ObjectBroker.h:151
Vector of integers.
Definition: ID.h:95
int sendMovable(int commitTag, MovableObject &)
Send theObject.
Definition: Channel.cpp:130
virtual int recvID(int dbTag, int commitTag, ID &theID, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the ID object theID to another Channel object.
const ID & getUsedTags(void) const
Return the list of dbTags already used.
Definition: Channel.cpp:95
bool checkDbTag(const int &dbTag)
Check if a dbTag is already used.
Definition: Channel.cpp:107
virtual int sendMatrix(int dbTag, int commitTag, const Matrix &theMatrix, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the Matrix object theMatrix to another Channel object.
virtual int setNextAddress(const ChannelAddress &theAddress)=0
A method invoked to set specify the next address that the next messages to be sent if {sendMessage()}...
int receiveMovable(int commitTag, MovableObject &, FEM_ObjectBroker &)
Receive theObject.
Definition: Channel.cpp:137
Objet that can execute python scripts.
Definition: CommandEntity.h:40
Channel is an abstract base class which defines the channel interface.
Definition: Channel.h:92
int sendObjs(int commitTag, const inputIterator &first, const inputIterator &last, ChannelAddress *theAddress=nullptr)
Send the objects on interval [first,last).
Definition: Channel.h:236
Message between processes.
Definition: Message.h:77
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
virtual int sendVector(int dbTag, int commitTag, const Vector &theVector, ChannelAddress *theAddress=nullptr)=0
Invoked to receive the data in the Vector object theVector to another Channel object.
Base class for classes that encapsulate channel addresses.
Definition: ChannelAddress.h:78
Matrix of floats.
Definition: Matrix.h:111
virtual int getDbTag(void) const
Return next available database tag.
Definition: Channel.cpp:91
virtual bool isDatastore(void) const
Return true if channel is a data store.
Definition: Channel.cpp:81
Channel(CommandEntity *owr=nullptr)
Constructor.
Definition: Channel.cpp:73
virtual std::string addToProgram(void)=0
When creating remote actors the channels created in the actor space need to know how to contact the s...