NLNET::CPacsClient Class Reference

#include <pacs_client.h>


Detailed Description

Client side of Pacs Service. Allows to use PACS functionnality by the networtk.

Author:
Cyril 'Hulud' Corvazier

Nevrax France

Date:
2001

Definition at line 52 of file pacs_client.h.

Callbacks

virtual void getPositionSpeedCallback (NLPACS::UMovePrimitive::TUserData id, const NLMISC::CVectorD &position, const NLMISC::CVectorD &speed)
virtual void messageCallback ()
virtual void rayTestCallback (uint32 testId, bool testResult)
virtual void testMoveCallback (NLPACS::UMovePrimitive::TUserData id, bool testResult)
virtual void triggerCallback (uint32 evalId, const std::vector< NLPACS::UTriggerInfo > &triggerInfo)
CMessage _Message
CCallbackClient_Server

Public Member Functions

bool connect ()
 CPacsClient ()
 Constructor.

void disconnect ()
void initMessage ()
void sendMessage ()
void update ()
 ~CPacsClient ()
Move container methods
void addPrimitive (NLPACS::UMovePrimitive::TUserData id)
void evalCollision (uint32 evalId, double deltaTime)
void removePrimitive (NLPACS::UMovePrimitive::TUserData id)
void testMove (NLPACS::UMovePrimitive::TUserData id, const NLMISC::CVectorD &speed, double deltaTime)
Primitives methods
void getPositionSpeed (NLPACS::UMovePrimitive::TUserData id)
void globalMove (const NLMISC::CVectorD &position)
void relativeMove (const NLMISC::CVectorD &speed)
void setAbsorption (float absorption)
void setCollisionMask (NLPACS::UMovePrimitive::TCollisionMask mask)
void setCurrentPrimitive (NLPACS::UMovePrimitive::TUserData id)
void setHeight (float height)
void setObstacle (bool obstacle)
void setOcclusionMask (NLPACS::UMovePrimitive::TCollisionMask mask)
void setOrientation (double orientation)
void setPrimitiveType (NLPACS::UMovePrimitive::TType type)
void setRadius (float radius)
void setReactionType (NLPACS::UMovePrimitive::TReaction type)
void setSize (float width, float depth)
void setTriggerType (NLPACS::UMovePrimitive::TTrigger type)
Global retriever methods
void rayTest (double p0, double p1, uint32 testId)

Friends

void cbPacsAnswer (CMessage &msgin, TSockId from, CCallbackNetBase &netbase)


Constructor & Destructor Documentation

NLNET::CPacsClient::CPacsClient  )  [inline]
 

Constructor.

Definition at line 58 of file pacs_client.h.

00059         {
00060                 // No connexion
00061                 _Server=NULL;
00062         }

NLNET::CPacsClient::~CPacsClient  )  [inline]
 

Definition at line 64 of file pacs_client.h.

References disconnect().

00065         {
00066                 disconnect ();
00067         }


Member Function Documentation

void NLNET::CPacsClient::addPrimitive NLPACS::UMovePrimitive::TUserData  id  )  [inline]
 

Add a primitive in the service. Set the new primitive as current.

No answer will be send by the service.

Parameters:
id is the ID to attach to the new primitive.

Definition at line 149 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), and NLPACS::UMovePrimitive::TUserData.

00150         {
00151                 // Append to the current message
00152                 std::string name="AD";
00153                 bool nlTrue=true;
00154                 _Message.serial (nlTrue, name, id);
00155         }

bool NLNET::CPacsClient::connect  )  [inline]
 

Definition at line 577 of file pacs_client.h.

References NLNET::CCallbackNetBase::addCallbackArray(), NLNET::CCallbackClient::connected(), NLNET::CBufClient::id(), nlassert, NLNET::PacsCallbackArray, NLNET::CBufSock::setAppId(), uint, and uint64.

00578 {
00579         // Create a connexion
00580         _Server = new CCallbackClient;
00581 
00582         // Look up for PACS service
00583         CNamingClient::lookupAndConnect ("PS", *_Server);
00584         if (_Server->connected())
00585         {
00586                 // Add callback array
00587                 _Server->addCallbackArray (PacsCallbackArray, sizeof (PacsCallbackArray) / sizeof (PacsCallbackArray[0]));
00588 
00589                 // This code can work only if sizeof (uint) == sizeof (void*)
00590                 nlassert (sizeof (uint)==sizeof (void*));
00591                 _Server->id ()->setAppId ((uint64)(uint)this);
00592 
00593                 // Return ok
00594                 return true;
00595         }
00596         else
00597         {
00598                 return false;
00599         }
00600 }

void NLNET::CPacsClient::disconnect  )  [inline]
 

Definition at line 71 of file pacs_client.h.

References NLNET::CCallbackClient::disconnect().

Referenced by ~CPacsClient().

00072         {
00073                 if (_Server)
00074                 {
00075                         _Server->disconnect ();
00076                         delete _Server;
00077                 }
00078         }

void NLNET::CPacsClient::evalCollision uint32  evalId,
double  deltaTime
[inline]
 

Evaluate the collision on the servive.

The service will answer this message with a triggerCallback message.

Parameters:
evalId is the id of the evaluation.
deltaTime is the delta time used to evaluate the system.

Definition at line 180 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), and uint32.

00181         {
00182                 // Append to the current message
00183                 std::string name="EV";
00184                 bool nlTrue=true;
00185                 _Message.serial (nlTrue, name, evalId, deltaTime);
00186         }

void NLNET::CPacsClient::getPositionSpeed NLPACS::UMovePrimitive::TUserData  id  )  [inline]
 

Query the position and the speed of the primitive after an evalCollision message.

The service will answer with a getPositionSpeedCallback message.

Parameters:
id is the id of the primitive to get the position and the speed.

Definition at line 433 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), and NLPACS::UMovePrimitive::TUserData.

00434         {
00435                 // Append to the current message
00436                 std::string name="PS";
00437                 bool nlTrue=true;
00438                 _Message.serial (nlTrue, name, id);
00439         }

virtual void NLNET::CPacsClient::getPositionSpeedCallback NLPACS::UMovePrimitive::TUserData  id,
const NLMISC::CVectorD position,
const NLMISC::CVectorD speed
[inline, protected, virtual]
 

This message is send by the service to answer the getPositionSpeed request.

Parameters:
id is the id of the primitive.
position is the new position of the primitive.
speed is the new speed of the primitive.

Definition at line 486 of file pacs_client.h.

References NLPACS::UMovePrimitive::TUserData.

Referenced by NLNET::cbPacsAnswer().

00487         {}

void NLNET::CPacsClient::globalMove const NLMISC::CVectorD position  )  [inline]
 

Make the current primitive a global move. This move is slow. Use it only for the first placement and for teleporting.

No answer will be send by the service.

Parameters:
position is the new position for the primitive on the service.

Definition at line 400 of file pacs_client.h.

References _Message, and NLMISC::CMemStream::serial().

00401         {
00402                 // Append to the current message
00403                 std::string name="GM";
00404                 bool nlTrue=true;
00405                 _Message.serial (nlTrue, name, const_cast<NLMISC::CVectorD&> (position));
00406         }

void NLNET::CPacsClient::initMessage  )  [inline]
 

Prepare a new message

You must call this method before do anything before sending the message.

Definition at line 85 of file pacs_client.h.

References _Message, NLNET::CMessage::clear(), NLNET_PACS_PROTOCOL_VERSION, NLMISC::IStream::serialCheck(), NLNET::CMessage::setType(), and uint32.

00086         {
00087                 _Message.clear ();
00088                 _Message.setType ("PACS");
00089                 _Message.serialCheck ((uint32)NLNET_PACS_PROTOCOL_VERSION);
00090         }

virtual void NLNET::CPacsClient::messageCallback  )  [inline, protected, virtual]
 

This call back is called when a message is coming. Used for synchronisation.

Definition at line 448 of file pacs_client.h.

Referenced by NLNET::cbPacsAnswer().

00449         {}

void NLNET::CPacsClient::rayTest double  p0,
double  p1,
uint32  testId
[inline]
 

Make a raytrace test on the service.

The service will answer this message with a rayTestCallback message.

Parameters:
p0 is the first point of the ray.
p1 is the second point of the ray.
testId is the id of the test.

Definition at line 132 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), and uint32.

00133         {
00134                 // Append to the current message
00135                 std::string name="RY";
00136                 bool nlTrue=true;
00137                 _Message.serial (nlTrue, name, p0, p1, testId);
00138         }

virtual void NLNET::CPacsClient::rayTestCallback uint32  testId,
bool  testResult
[inline, protected, virtual]
 

This message is send by the service to answer the rayTest request.

Parameters:
testId is the test ID passed to rayTest().
testResult is false if the ray is not clipped, else true.

Definition at line 457 of file pacs_client.h.

References uint32.

Referenced by NLNET::cbPacsAnswer().

00458         {}

void NLNET::CPacsClient::relativeMove const NLMISC::CVectorD speed  )  [inline]
 

Make the current primitive a relative move. This move is fast. Use it for current move. Make first a relative move of all your primitives, then put a evalCollision message. Then you can query position and speed by posting getPositionSpeed message.

No answer will be send by the service.

Parameters:
position is the new position for the primitive on the service.

Definition at line 418 of file pacs_client.h.

References _Message, and NLMISC::CMemStream::serial().

00419         {
00420                 // Append to the current message
00421                 std::string name="RM";
00422                 bool nlTrue=true;
00423                 _Message.serial (nlTrue, name, const_cast<NLMISC::CVectorD&> (speed));
00424         }

void NLNET::CPacsClient::removePrimitive NLPACS::UMovePrimitive::TUserData  id  )  [inline]
 

Remove a primitive from the service.

No answer will be send by the service.

Parameters:
id is the ID attach to the primitive to remove.

Definition at line 164 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), and NLPACS::UMovePrimitive::TUserData.

00165         {
00166                 // Append to the current message
00167                 std::string name="RV";
00168                 bool nlTrue=true;
00169                 _Message.serial (nlTrue, name, id);
00170         }

void NLNET::CPacsClient::sendMessage  )  [inline]
 

Send the message

You must call this method after initMessage and others calls to setup methods.

Definition at line 97 of file pacs_client.h.

References _Message, nlassert, NLNET::CCallbackClient::send(), and NLMISC::CMemStream::serial().

00098         {
00099                 // Checks
00100                 nlassert (_Server);
00101 
00102                 // Close the message
00103                 bool nlFalse=false;
00104                 _Message.serial (nlFalse);
00105 
00106                 // Send the message
00107                 _Server->send (_Message);
00108         }

void NLNET::CPacsClient::setAbsorption float  absorption  )  [inline]
 

Set the attenuation factor of the current primitive on the service.

No answer will be send by the service.

Parameters:
absorption is the new attenuation factor for the primitive on the service.

Definition at line 338 of file pacs_client.h.

References _Message, and NLMISC::CMemStream::serial().

00339         {
00340                 // Append to the current message
00341                 std::string name="AB";
00342                 bool nlTrue=true;
00343                 _Message.serial (nlTrue, name, absorption);
00344         }

void NLNET::CPacsClient::setCollisionMask NLPACS::UMovePrimitive::TCollisionMask  mask  )  [inline]
 

Set the collision mask of the current primitive on the service.

No answer will be send by the service.

Parameters:
mask is the new collision mask for the primitive on the service.

Definition at line 278 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), and NLPACS::UMovePrimitive::TCollisionMask.

00279         {
00280                 // Append to the current message
00281                 std::string name="CT";
00282                 bool nlTrue=true;
00283                 _Message.serial (nlTrue, name, mask);
00284         }

void NLNET::CPacsClient::setCurrentPrimitive NLPACS::UMovePrimitive::TUserData  id  )  [inline]
 

Set the current primitive on the service. The primitive stay current for the current message.

No answer will be send by the service.

Parameters:
id is the id of the current primitive to use.

Definition at line 215 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), and NLPACS::UMovePrimitive::TUserData.

00216         {
00217                 // Append to the current message
00218                 std::string name="CU";
00219                 bool nlTrue=true;
00220                 _Message.serial (nlTrue, name, id);
00221         }

void NLNET::CPacsClient::setHeight float  height  )  [inline]
 

Set the height of the current primitive on the service. For boxes and cylinders primitives.

No answer will be send by the service.

Parameters:
height is the new size on Z axis factor for the primitive on the service.

Definition at line 369 of file pacs_client.h.

References _Message, height, and NLMISC::CMemStream::serial().

00370         {
00371                 // Append to the current message
00372                 std::string name="HE";
00373                 bool nlTrue=true;
00374                 _Message.serial (nlTrue, name, height);
00375         }

void NLNET::CPacsClient::setObstacle bool  obstacle  )  [inline]
 

Set the obstacle flag of the current primitive on the service.

No answer will be send by the service.

Parameters:
obstacle is the new obstacle flag for the primitive on the service.

Definition at line 308 of file pacs_client.h.

References _Message, and NLMISC::CMemStream::serial().

00309         {
00310                 // Append to the current message
00311                 std::string name="OB";
00312                 bool nlTrue=true;
00313                 _Message.serial (nlTrue, name, obstacle);
00314         }

void NLNET::CPacsClient::setOcclusionMask NLPACS::UMovePrimitive::TCollisionMask  mask  )  [inline]
 

Set the occlusion mask of the current primitive on the service.

No answer will be send by the service.

Parameters:
mask is the new occlusion mask for the primitive on the service.

Definition at line 293 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), and NLPACS::UMovePrimitive::TCollisionMask.

00294         {
00295                 // Append to the current message
00296                 std::string name="OT";
00297                 bool nlTrue=true;
00298                 _Message.serial (nlTrue, name, mask);
00299         }

void NLNET::CPacsClient::setOrientation double  orientation  )  [inline]
 

Set the orientation the current primitive on the service.

No answer will be send by the service.

Parameters:
orientation is the new orientation for the primitive on the service.

Definition at line 323 of file pacs_client.h.

References _Message, and NLMISC::CMemStream::serial().

00324         {
00325                 // Append to the current message
00326                 std::string name="OR";
00327                 bool nlTrue=true;
00328                 _Message.serial (nlTrue, name, orientation);
00329         }

void NLNET::CPacsClient::setPrimitiveType NLPACS::UMovePrimitive::TType  type  )  [inline]
 

Set the type of the current primitive on the service.

No answer will be send by the service.

Parameters:
type is the new type for the primitive on the service.

Definition at line 230 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), t, type, and uint32.

00231         {
00232                 // Append to the current message
00233                 std::string name="TY";
00234                 uint32 t=(uint32)type;
00235                 bool nlTrue=true;
00236                 _Message.serial (nlTrue, name, t);
00237         }

void NLNET::CPacsClient::setRadius float  radius  )  [inline]
 

Set the radius of the current primitive on the service. For cylinders primitives.

No answer will be send by the service.

Parameters:
height is the new size on Z axis factor for the primitive on the service.

Definition at line 384 of file pacs_client.h.

References _Message, and NLMISC::CMemStream::serial().

00385         {
00386                 // Append to the current message
00387                 std::string name="RD";
00388                 bool nlTrue=true;
00389                 _Message.serial (nlTrue, name, radius);
00390         }

void NLNET::CPacsClient::setReactionType NLPACS::UMovePrimitive::TReaction  type  )  [inline]
 

Set the reaction type of the current primitive on the service.

No answer will be send by the service.

Parameters:
type is the newreaction type for the primitive on the service.

Definition at line 246 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), t, type, and uint32.

00247         {
00248                 // Append to the current message
00249                 std::string name="RT";
00250                 uint32 t=(uint32)type;
00251                 bool nlTrue=true;
00252                 _Message.serial (nlTrue, name, t);
00253         }

void NLNET::CPacsClient::setSize float  width,
float  depth
[inline]
 

Set the size of the current primitive on the service. Only for boxes primitives.

No answer will be send by the service.

Parameters:
width is the new size on X axis factor for the primitive on the service.
depth is the new size on Y axis factor for the primitive on the service.

Definition at line 354 of file pacs_client.h.

References _Message, depth, NLMISC::CMemStream::serial(), and width.

00355         {
00356                 // Append to the current message
00357                 std::string name="SZ";
00358                 bool nlTrue=true;
00359                 _Message.serial (nlTrue, name, width, depth);
00360         }

void NLNET::CPacsClient::setTriggerType NLPACS::UMovePrimitive::TTrigger  type  )  [inline]
 

Set the trigger type of the current primitive on the service.

No answer will be send by the service.

Parameters:
type is the new trigger type for the primitive on the service.

Definition at line 262 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), t, type, and uint32.

00263         {
00264                 // Append to the current message
00265                 std::string name="TT";
00266                 uint32 t=(uint32)type;
00267                 bool nlTrue=true;
00268                 _Message.serial (nlTrue, name, t);
00269         }

void NLNET::CPacsClient::testMove NLPACS::UMovePrimitive::TUserData  id,
const NLMISC::CVectorD speed,
double  deltaTime
[inline]
 

Test a move of a primitive on the service.

The service will answer this message with a testMoveCallback message.

Parameters:
id is the id of the primitive to test a move.
speed is the speed of the primitive during its move.
deltaTime is the time interval of the move to test.

Definition at line 197 of file pacs_client.h.

References _Message, NLMISC::CMemStream::serial(), and NLPACS::UMovePrimitive::TUserData.

00198         {
00199                 // Append to the current message
00200                 std::string name="TS";
00201                 bool nlTrue=true;
00202                 _Message.serial (nlTrue, name, id, const_cast<NLMISC::CVectorD&> (speed), deltaTime);
00203         }

virtual void NLNET::CPacsClient::testMoveCallback NLPACS::UMovePrimitive::TUserData  id,
bool  testResult
[inline, protected, virtual]
 

This message is send by the service to answer the testMove request.

Parameters:
id is the id of the primitive tested.
testResult is true if the primitive can do that move, else false.

Definition at line 476 of file pacs_client.h.

References NLPACS::UMovePrimitive::TUserData.

Referenced by NLNET::cbPacsAnswer().

00477         {}

virtual void NLNET::CPacsClient::triggerCallback uint32  evalId,
const std::vector< NLPACS::UTriggerInfo > &  triggerInfo
[inline, protected, virtual]
 

This message is send by the service to answer the evalCollision request.

Parameters:
evalId is the id of the evaluation passed to evalCollision.
triggerInfo is an array of trigger descriptor. Each entry of the array is a new trigger raised by evalCollision.

Definition at line 467 of file pacs_client.h.

References uint32.

Referenced by NLNET::cbPacsAnswer().

00468         {}

void NLNET::CPacsClient::update  )  [inline]
 

Update method. Should be called evenly.

Definition at line 113 of file pacs_client.h.

References nlassert, and NLNET::CCallbackClient::update().

00114         {
00115                 // Checks
00116                 nlassert (_Server);
00117 
00118                 _Server->update ();
00119         }


Friends And Related Function Documentation

void cbPacsAnswer CMessage msgin,
TSockId  from,
CCallbackNetBase netbase
[friend]
 

Definition at line 495 of file pacs_client.h.

00496 {
00497         // Get the client pointer
00498         CPacsClient *client=(CPacsClient*)(uint)from->appId ();
00499 
00500         // Check stream
00501         msgin.serialCheck ((uint32)NLNET_PACS_PROTOCOL_VERSION);
00502 
00503         // Message callback
00504         client->messageCallback ();
00505 
00506         bool again;
00507         msgin.serial (again);
00508         
00509         while (again)
00510         {
00511                 // Read the message sub string
00512                 std::string subMessage;
00513                 msgin.serial (subMessage);
00514 
00515                 // This code can work only if sizeof (uint) == sizeof (void*)
00516                 nlassert (sizeof (uint)==sizeof (void*));
00517 
00518                 // Raytrace callback ?
00519                 if (subMessage=="RY")
00520                 {
00521                         // Read test id and test result
00522                         uint32 testId;
00523                         bool testResult;
00524                         msgin.serial (testId, testResult);
00525 
00526                         // Call the callback
00527                         client->rayTestCallback (testId, testResult);
00528                 }
00529                 // Trigger callback ?
00530                 else if (subMessage=="TR")
00531                 {
00532                         // Read eval id and trigger info
00533                         uint32 evalId;
00534                         std::vector<NLPACS::UTriggerInfo> triggerInfo;
00535                         msgin.serial (evalId);
00536                         msgin.serialCont (triggerInfo);
00537 
00538                         // Call the callback
00539                         client->triggerCallback (evalId, triggerInfo);
00540                 }
00541                 // Test move callback ?
00542                 else if (subMessage=="TM")
00543                 {
00544                         // Read the primitive id and test result
00545                         NLPACS::UMovePrimitive::TUserData id;
00546                         bool testResult;
00547                         msgin.serial (id, testResult);
00548                         
00549                         // Call the callback    
00550                         client->testMoveCallback (id, testResult);
00551                 }
00552                 // Test move callback ?
00553                 else if (subMessage=="PS")
00554                 {
00555                         // Read the primitive id and test result
00556                         NLPACS::UMovePrimitive::TUserData id;
00557                         NLMISC::CVectorD position;
00558                         NLMISC::CVectorD speed;
00559                         msgin.serial (id, position, speed);
00560                         
00561                         // Call the callback    
00562                         client->getPositionSpeedCallback (id, position, speed);
00563                 }
00564                 else
00565                         NLMISC::nlError ("Pacs client: unkown sub message string");
00566 
00567                 // Next message ?
00568                 msgin.serial (again);
00569         }
00570 }


Field Documentation

CMessage NLNET::CPacsClient::_Message [private]
 

This message is send by the service to answer the getPositionSpeed request.

Parameters:
id is the id of the primitive.
position is the new position of the primitive.
speed is the new speed of the primitive.

Definition at line 491 of file pacs_client.h.

Referenced by addPrimitive(), evalCollision(), getPositionSpeed(), globalMove(), initMessage(), rayTest(), relativeMove(), removePrimitive(), sendMessage(), setAbsorption(), setCollisionMask(), setCurrentPrimitive(), setHeight(), setObstacle(), setOcclusionMask(), setOrientation(), setPrimitiveType(), setRadius(), setReactionType(), setSize(), setTriggerType(), and testMove().

CCallbackClient* NLNET::CPacsClient::_Server [private]
 

This message is send by the service to answer the getPositionSpeed request.

Parameters:
id is the id of the primitive.
position is the new position of the primitive.
speed is the new speed of the primitive.

Definition at line 490 of file pacs_client.h.


The documentation for this class was generated from the following file:
Generated on Tue Mar 16 14:02:48 2004 for NeL by doxygen 1.3.6