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
00034
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
00046
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
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
00074 if (actorMethods != 0)
00075 delete actorMethods;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084 int
00085 Actor::addMethod(int tag, int (*fp)())
00086 {
00087
00088 if (numMethods >= maxNumMethods)
00089 return -2;
00090
00091
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
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
00117
00118
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
00133
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