ClientSocket Class Reference

Subclass of QSocket that parses input, implements commands, and writes output. More...

#include <graspitServer.h>

List of all members.

Public Member Functions

 ClientSocket (int sock, QObject *parent=0, const char *name=0)
 ~ClientSocket ()

Private Slots

void connectionClosed ()
void readClient ()

Private Member Functions

void computeNewVelocities (double ts)
void moveDynamicBodies (double ts)
int readBodyIndList (std::vector< Body * > &bodyVec)
int readDOFForces (Robot *rob)
int readDOFVals ()
int readRobotIndList (std::vector< Robot * > &robVec)
void sendAverageContacts (Body *bod)
void sendBodyName (Body *bod)
void sendContacts (Body *bod, int numData)
void sendDOFVals (Robot *rob)
void sendRobotName (Robot *rob)

Private Attributes

QString line
 The current line of text read from the socket.
QStringList lineStrList
 The list of strings after splitting the line at each space character.
QStringList::const_iterator strPtr
 An iterator into the string list.

Detailed Description

Subclass of QSocket that parses input, implements commands, and writes output.

A ClientSocket is created whenever the GraspitServer accepts a new connection. Whenever there is data ready to be read, it calls the readClient method, which parses the text command and calls the appropriate method. Some of these methods write results back to the socket. When it receives a connection closed signal the ClientSocekt deletes itself.

The following commands are currently recognized and processed:

Each command requiring an index list, accept the word "ALL" meaning every body or robot in the world, or a number of bodies or robots followed by a space sparated list of the body or robot indicies.

getContacts also requires numData, which specifies the number of vectors of data that should be returned (1, 2 or 3) about each contact.

The routines will send back an error message if there is a problem with the input.

Definition at line 71 of file graspitServer.h.


Constructor & Destructor Documentation

ClientSocket::ClientSocket ( int  sock,
QObject *  parent = 0,
const char *  name = 0 
) [inline]

Connects the readyRead signal to the readClient slot, and the connectionClosed signal to the connectionClosed slot. Sets the socket to use sock .

Definition at line 82 of file graspitServer.h.

ClientSocket::~ClientSocket (  ) 

Stub destructor.

Definition at line 43 of file graspitServer.cpp.


Member Function Documentation

void ClientSocket::computeNewVelocities ( double  timeStep  )  [private]

This calls the computeNewVelocities routine in the dynamics with the given value of the timestep. Afterwards, it sends out a line containing the result code from that operation.

Definition at line 609 of file graspitServer.cpp.

void ClientSocket::connectionClosed (  )  [inline, private, slot]

Deletes this instance of ClientSocket

Definition at line 125 of file graspitServer.h.

void ClientSocket::moveDynamicBodies ( double  timeStep  )  [private]

If given a positive time step value, this will move the dynamic world bodies with that value. Otherwise it uses the world default time step. A line with the actual length of that timestep is then sent back.

Definition at line 589 of file graspitServer.cpp.

int ClientSocket::readBodyIndList ( std::vector< Body * > &  bodyVec  )  [private]

This reads the next portion of a command line after the command to collect the body indices, and returns a vector of pointers to those bodies. If this portion starts with the word "ALL", then all the bodies in the world are added to the body vector. Otherwise it reads the number of body indices, and reads each index in turn, adding the corresponding body pointer to the vector. If an index is read that does not exist, an error message is sent back and this method returns FAILURE.

Definition at line 60 of file graspitServer.cpp.

void ClientSocket::readClient (  )  [private, slot]

This is the main routine for parsing input on the clientSocket. There should be one command for each line of input. This reads one line, and looks at the first word (up to the first space character) to determine the command. Then if there are body or robot indices to read, it calls a support routine to read those and return a vector of bodies or robots. These are then passed to the appropriate routine to carry out the action and write out any necessary results.

Definition at line 176 of file graspitServer.cpp.

int ClientSocket::readDOFForces ( Robot rob  )  [private]

After the readDOFForces command was read by readClient, this expects to the correct number of DOF's for this robot, and then a desired force for each DOF. It sets each DOF force and sends a line for each containing the current force.

Definition at line 514 of file graspitServer.cpp.

int ClientSocket::readDOFVals (  )  [private]

After the readDOFVals command was read by readClient, this expects to read a valid robot index, then the correct number of DOF's for this robot, then a desired value for each DOF, and finally a value for each DOF to step by during the move. It performs the DOF moves, finds the new contacts, updates the grasp, and then it sends one line for each DOF containing the actual value for the DOF after the move.

Definition at line 416 of file graspitServer.cpp.

int ClientSocket::readRobotIndList ( std::vector< Robot * > &  robVec  )  [private]

This reads the next portion of a command line after the command to collect the robot indices, and returns a vector of pointers to those robots. If this portion starts with the word "ALL", then all the robots in the world are added to the robot vector. Otherwise it reads the number of robot indices, and reads each index in turn, adding the corresponding robot pointer to the vector. If an index is read that does not exist, an error message is sent back and this method returns FAILURE.

Definition at line 119 of file graspitServer.cpp.

void ClientSocket::sendAverageContacts ( Body bod  )  [private]

Given a pointer to a body, this examines all the contacts on that body and finds the average wrench acting on the body through those contacts and the average contact location in body coordinates. This is written to the socket on 2 separate lines.

Definition at line 299 of file graspitServer.cpp.

void ClientSocket::sendBodyName ( Body bod  )  [private]

Given a pointer to a body, this writes the name of the body and a newline to the socket.

Definition at line 333 of file graspitServer.cpp.

void ClientSocket::sendContacts ( Body bod,
int  numData 
) [private]

Given a pointer to a body, this first writes a line containing the number of contacts on the body. Then it writes numData lines for each contact. The first line contains the 6 numbers of the contact wrench. The next line (if required) contains the 3 numbers specifying the contact location in body coordinates, and the last line (if required) contains the scalar constraint error for that contact.

Definition at line 361 of file graspitServer.cpp.

void ClientSocket::sendDOFVals ( Robot rob  )  [private]

Given a pointer to robot, this first writes a line to the socket containing the number of DOF's in the robot, then for each DOF, it writes a line containting the current value of that DOF.

Definition at line 397 of file graspitServer.cpp.

void ClientSocket::sendRobotName ( Robot rob  )  [private]

Given a pointer to a robot, this writes the name of the robot and a newline to the socket.

Definition at line 345 of file graspitServer.cpp.


Member Data Documentation

QString ClientSocket::line [private]

The current line of text read from the socket.

Definition at line 95 of file graspitServer.h.

QStringList ClientSocket::lineStrList [private]

The list of strings after splitting the line at each space character.

Definition at line 98 of file graspitServer.h.

QStringList::const_iterator ClientSocket::strPtr [private]

An iterator into the string list.

Definition at line 101 of file graspitServer.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


graspit
Author(s):
autogenerated on Wed Jan 25 11:00:20 2012