00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <Actor.h>
00034 #include <Channel.h>
00035 #include <ChannelAddress.h>
00036 #include <Message.h>
00037 #include <MovableObject.h>
00038 #include <Matrix.h>
00039 #include <Vector.h>
00040 #include <ID.h>
00041
00042
00043
00044
00045
00046 Actor::Actor(Channel &theChan,
00047 FEM_ObjectBroker &myBroker,
00048 int numActorMethods)
00049 :theBroker(&myBroker), theChannel(&theChan),
00050 numMethods(0), maxNumMethods(numActorMethods), actorMethods(0),
00051 theRemoteShadowsAddress(0), commitTag(0)
00052 {
00053
00054 theChannel->setUpConnection();
00055 theRemoteShadowsAddress = theChan.getLastSendersAddress();
00056
00057 if (numActorMethods != 0)
00058 actorMethods = new ActorMethod *[numActorMethods];
00059
00060 if (actorMethods == 0)
00061 maxNumMethods = 0;
00062
00063 for (int i=0; i<numMethods; i++)
00064 actorMethods[i] = 0;
00065 }
00066
00067
00068 Actor::~Actor()
00069 {
00070
00071 if (actorMethods != 0)
00072 delete actorMethods;
00073 }
00074
00075
00076
00077
00078
00079
00080
00081 int
00082 Actor::addMethod(int tag, int (*fp)())
00083 {
00084
00085 if (numMethods >= maxNumMethods)
00086 return -2;
00087
00088
00089 ActorMethod *methodPtr;
00090 for (int i=0; i<numMethods; i++) {
00091 methodPtr = actorMethods[i];
00092 if (methodPtr->tag == tag)
00093 return -1;
00094 }
00095
00096
00097 ActorMethod *newMethod = new ActorMethod;
00098 if (newMethod == 0)
00099 return -3;
00100
00101 newMethod->tag = tag;
00102 newMethod->theMethod = fp;
00103
00104 actorMethods[numMethods] = newMethod;
00105 numMethods++;
00106 return 0;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 int
00118 Actor::getMethod()
00119 {
00120 int method = -1;
00121 Message msg(&method,1);
00122 this->recvMessage(msg);
00123 return method;
00124 }
00125
00126
00127
00128
00129
00130
00131
00132 int
00133 Actor::processMethod(int tag)
00134 {
00135 ActorMethod *current =0;
00136
00137 for (int i=0; i<numMethods; i++)
00138 if (actorMethods[i]->tag == tag) {
00139 current = actorMethods[tag];
00140 }
00141
00142 if (current == 0)
00143 return -1;
00144
00145 return (*current).theMethod();
00146 }
00147
00148
00149
00150 int
00151 Actor::sendObject(MovableObject &theObject,
00152 ChannelAddress *theAddress )
00153 {
00154 if (theAddress == 0)
00155 return theChannel->sendObj(commitTag, theObject,theRemoteShadowsAddress);
00156 else
00157 return theChannel->sendObj(commitTag, theObject,theAddress);
00158 }
00159
00160 int
00161 Actor::recvObject(MovableObject &theObject,
00162 ChannelAddress *theAddress )
00163 {
00164 if (theAddress == 0)
00165 return theChannel->recvObj(commitTag, theObject,*theBroker,
00166 theRemoteShadowsAddress);
00167 else
00168 return theChannel->recvObj(commitTag, theObject,*theBroker,theAddress);
00169 }
00170
00171
00172 int
00173 Actor::recvMessage(Message &theMessage, ChannelAddress *theAddress )
00174 {
00175 if (theAddress == 0)
00176 return theChannel->recvMsg(0, commitTag, theMessage,theRemoteShadowsAddress);
00177 else
00178 return theChannel->recvMsg(0, commitTag, theMessage,theAddress);
00179 }
00180
00181 int
00182 Actor::sendMessage(const Message &theMessage, ChannelAddress *theAddress )
00183 {
00184 if (theAddress == 0)
00185 return theChannel->sendMsg(0, commitTag, theMessage,theRemoteShadowsAddress);
00186 else
00187 return theChannel->sendMsg(0, commitTag, theMessage,theAddress);
00188 }
00189
00190
00191
00192 int
00193 Actor::sendMatrix(const Matrix &theMatrix, ChannelAddress *theAddress )
00194 {
00195 if (theAddress == 0)
00196 return theChannel->sendMatrix(0, commitTag, theMatrix,theRemoteShadowsAddress);
00197 else
00198 return theChannel->sendMatrix(0, commitTag, theMatrix,theAddress);
00199 }
00200
00201 int
00202 Actor::recvMatrix(Matrix &theMatrix, ChannelAddress *theAddress )
00203 {
00204 if (theAddress == 0)
00205 return theChannel->recvMatrix(0, commitTag, theMatrix,theRemoteShadowsAddress);
00206 else
00207 return theChannel->recvMatrix(0, commitTag, theMatrix,theAddress);
00208 }
00209
00210 int
00211 Actor::sendVector(const Vector &theVector, ChannelAddress *theAddress )
00212 {
00213 if (theAddress == 0)
00214 return theChannel->sendVector(0, commitTag, theVector,theRemoteShadowsAddress);
00215 else
00216 return theChannel->sendVector(0, commitTag, theVector,theAddress);
00217 }
00218
00219 int
00220 Actor::recvVector(Vector &theVector, ChannelAddress *theAddress )
00221 {
00222 if (theAddress == 0)
00223 return theChannel->recvVector(0, commitTag, theVector,theRemoteShadowsAddress);
00224 else
00225 return theChannel->recvVector(0, commitTag, theVector,theAddress);
00226 }
00227
00228 int
00229 Actor::sendID(const ID &theID, ChannelAddress *theAddress )
00230 {
00231 if (theAddress == 0)
00232 return theChannel->sendID(0, commitTag, theID,theRemoteShadowsAddress);
00233 else
00234 return theChannel->sendID(0, commitTag, theID,theAddress);
00235 }
00236
00237 int
00238 Actor::recvID(ID &theID, ChannelAddress *theAddress )
00239 {
00240 if (theAddress == 0)
00241 return theChannel->recvID(0, commitTag, theID,theRemoteShadowsAddress);
00242 else
00243 return theChannel->recvID(0, commitTag, theID,theAddress);
00244 }
00245
00246
00247 void
00248 Actor::setCommitTag(int tag)
00249 {
00250 commitTag = tag;
00251 }
00252
00253
00254 Channel *
00255 Actor::getChannelPtr(void) const
00256 {
00257 return theChannel;
00258 }
00259
00260 FEM_ObjectBroker *
00261 Actor::getObjectBrokerPtr(void) const
00262 {
00263 return theBroker;
00264 }
00265
00266
00267
00268 ChannelAddress *
00269 Actor::getShadowsAddressPtr(void) const
00270 {
00271 return theRemoteShadowsAddress;
00272 }
00273
00274
00275
00276
00277 int
00278 Actor::barrierCheck(int myResult = 0)
00279 {
00280 int result;
00281 static ID data(1);
00282 data(0) = myResult;
00283 theChannel->sendID(0, commitTag, data);
00284 theChannel->recvID(0, commitTag, data);
00285 result = data(0);
00286 return result;
00287 }
00288