Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Actor.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.1.1.1 $
00022 // $Date: 2000/09/15 08:23:15 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/actor/actor/Actor.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/actor/Actor.C
00027 //
00028 // Written: fmk
00029 // Created: 11/96
00030 // Revision: A
00031 //
00032 // Purpose: This file contains the implementation of Actor.
00033 //
00034 // What: "@(#) Actor.C, revA"
00035 
00036 #include <Actor.h>
00037 #include <Channel.h>
00038 #include <ChannelAddress.h>
00039 #include <Message.h>
00040 #include <MovableObject.h>
00041 #include <Matrix.h>
00042 #include <Vector.h>
00043 #include <ID.h>
00044 
00045 // Actor
00046 // constructor to init the list.
00047 
00048 
00049 Actor::Actor(Channel &theChan,
00050       FEM_ObjectBroker &myBroker,
00051       int numActorMethods)
00052 :numMethods(0), maxNumMethods(numActorMethods), actorMethods(0),
00053  theChannel(&theChan), theBroker(&myBroker), theRemoteShadowsAddress(0)
00054 {
00055     // call setUpActor on the channel and get shadows address
00056     
00057     theChan.setUpActor();
00058     theRemoteShadowsAddress = theChan.getLastSendersAddress();
00059 
00060     if (numActorMethods != 0)
00061  actorMethods = new ActorMethod *[numActorMethods];
00062 
00063     if (actorMethods == 0)
00064  maxNumMethods = 0;
00065 
00066     for (int i=0; i<numMethods; i++)
00067  actorMethods[i] = 0;
00068 }
00069 
00070 
00071 Actor::~Actor()
00072 {
00073     // delete the array of actorMethods if constructed one
00074     if (actorMethods != 0)
00075  delete actorMethods;
00076 }
00077 
00078 
00079 // void AddMethod(int tag, int (*fp)()):
00080 // Method to add a function to the list of avaiable actor methods.
00081 // The function will be identified as tag, it is a function with
00082 // no args that returns an int.
00083 
00084 int 
00085 Actor::addMethod(int tag, int (*fp)())
00086 {
00087     // check we are not over our limit
00088     if (numMethods >= maxNumMethods)
00089  return -2;
00090 
00091     // check no other with the same tag exists
00092     ActorMethod *methodPtr;
00093     for (int i=0; i<numMethods; i++) {
00094  methodPtr = actorMethods[i];
00095  if (methodPtr->tag == tag)
00096      return -1;
00097     }
00098 
00099     // add the new method
00100     ActorMethod *newMethod = new ActorMethod;
00101     if (newMethod == 0)
00102  return -3;
00103     
00104     newMethod->tag = tag;
00105     newMethod->theMethod = fp;
00106 
00107     actorMethods[numMethods] = newMethod;
00108     numMethods++;
00109     return 0;
00110 }
00111 
00112 
00113 
00114 
00115 
00116 // int GetMethod():
00117 // Method to return the integer tag of the next method the actor
00118 // has been asked to invoke.
00119 
00120 int 
00121 Actor::getMethod()
00122 {
00123     int method = -1;
00124     Message msg(&method,1);
00125     this->recvMessage(msg);
00126     return method;
00127 }
00128 
00129 
00130 
00131 
00132 // int ProcMethod(int tag):
00133 // Method to process the function whose id is tag.
00134 
00135 int 
00136 Actor::processMethod(int tag)
00137 {
00138     ActorMethod *current =0;
00139 
00140     for (int i=0; i<numMethods; i++)
00141  if (actorMethods[i]->tag == tag) {
00142      current = actorMethods[tag];
00143  }
00144 
00145     if (current == 0)
00146  return -1;
00147     
00148     return (*current).theMethod();
00149 }
00150 
00151 
00152 
00153 int
00154 Actor::sendObject(MovableObject &theObject, 
00155     ChannelAddress *theAddress )
00156 {
00157     if (theAddress == 0)
00158  return theChannel->sendObj(0, theObject,theRemoteShadowsAddress);
00159     else
00160  return theChannel->sendObj(0, theObject,theAddress); 
00161 }
00162 
00163 int
00164 Actor::recvObject(MovableObject &theObject, 
00165     ChannelAddress *theAddress )
00166 {
00167     if (theAddress == 0)
00168  return theChannel->recvObj(0, theObject,*theBroker,
00169        theRemoteShadowsAddress); 
00170     else
00171  return theChannel->recvObj(0, theObject,*theBroker,theAddress); 
00172 }
00173 
00174 
00175 int
00176 Actor::recvMessage(Message &theMessage, ChannelAddress *theAddress )
00177 {
00178     if (theAddress == 0)
00179  return theChannel->recvMsg(0,0, theMessage,theRemoteShadowsAddress);
00180     else
00181  return theChannel->recvMsg(0,0, theMessage,theAddress); 
00182 }
00183 
00184 int
00185 Actor::sendMessage(const Message &theMessage, ChannelAddress *theAddress )
00186 {
00187     if (theAddress == 0)
00188  return theChannel->sendMsg(0,0, theMessage,theRemoteShadowsAddress);
00189     else
00190  return theChannel->sendMsg(0,0, theMessage,theAddress); 
00191 }
00192 
00193 
00194 
00195 int
00196 Actor::sendMatrix(const Matrix &theMatrix, ChannelAddress *theAddress )
00197 {
00198     if (theAddress == 0)    
00199  return theChannel->sendMatrix(0,0, theMatrix,theRemoteShadowsAddress);
00200     else
00201  return theChannel->sendMatrix(0,0, theMatrix,theAddress); 
00202 }
00203 
00204 int
00205 Actor::recvMatrix(Matrix &theMatrix, ChannelAddress *theAddress )
00206 {
00207     if (theAddress == 0)
00208  return theChannel->recvMatrix(0,0, theMatrix,theRemoteShadowsAddress);
00209     else
00210  return theChannel->recvMatrix(0,0, theMatrix,theAddress); 
00211 }
00212 
00213 int
00214 Actor::sendVector(const Vector &theVector, ChannelAddress *theAddress )
00215 {
00216     if (theAddress == 0)
00217  return theChannel->sendVector(0,0, theVector,theRemoteShadowsAddress);
00218     else
00219  return theChannel->sendVector(0,0, theVector,theAddress); 
00220 }
00221 
00222 int
00223 Actor::recvVector(Vector &theVector, ChannelAddress *theAddress )
00224 {
00225     if (theAddress == 0)
00226  return theChannel->recvVector(0,0, theVector,theRemoteShadowsAddress);
00227     else
00228  return theChannel->recvVector(0,0, theVector,theAddress); 
00229 }
00230 
00231 int
00232 Actor::sendID(const ID &theID, ChannelAddress *theAddress )
00233 {
00234     if (theAddress == 0)
00235  return theChannel->sendID(0,0, theID,theRemoteShadowsAddress);
00236     else
00237  return theChannel->sendID(0,0, theID,theAddress); 
00238 }
00239 
00240 int
00241 Actor::recvID(ID &theID, ChannelAddress *theAddress )
00242 {
00243     if (theAddress == 0)
00244  return theChannel->recvID(0,0, theID,theRemoteShadowsAddress);
00245     else
00246  return theChannel->recvID(0,0, theID,theAddress); 
00247 }
00248 
00249 
00250 Channel *
00251 Actor::getChannelPtr(void) const
00252 {
00253     return theChannel;
00254 }
00255 
00256 FEM_ObjectBroker *
00257 Actor::getObjectBrokerPtr(void) const
00258 {
00259     return theBroker;
00260 }
00261 
00262 
00263 
00264 ChannelAddress *
00265 Actor::getShadowsAddressPtr(void) const
00266 {
00267     return theRemoteShadowsAddress;
00268 }
00269 
00270 
00271 
00272 
Copyright Contact Us