NetworkViewer Class Reference
[libipsaViewer classes]

Extends IpsaViewer by adding the capability to receive commands over a TCP/IP connection. More...

#include <NetworkViewer.h>

Inheritance diagram for NetworkViewer:

Inheritance graph
[legend]
Collaboration diagram for NetworkViewer:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 NetworkViewer (std::string filename="", SO_WINDOW parent=NULL, const char *name=NULL, SbBool embed=TRUE)
virtual ~NetworkViewer ()

Static Public Member Functions

static void ReadDatagrams (void *data, SoSensor *)

Protected Member Functions

void setupNetworkThread ()

Static Protected Member Functions

static void * NetworkSetup (void *data)

Protected Attributes

const int LISTEN_PORT
SoTimerSensor networkReceiveSensor
SbThread * networkThread

Private Member Functions

void executeCommands (std::vector< std::vector< std::string > > &Instr)

Private Attributes

std::string commands
std::map< std::string,
Instruction * > 
instructionMap
CTCPSockettcp_socket


Detailed Description

Extends IpsaViewer by adding the capability to receive commands over a TCP/IP connection.

After a successful startup it is possible to connect to the NetworkViewer over a Telnet or TCP/IP Connection.

Connecting to IPSRV with an external program:

On Windows use any telnet or terminal client and on Linux/OS X use netcat (executable name is usually nc) for example to connect to the viewer. The standard port is NetworkViewer::LISTEN_PORT

If a connection could be established it is possible to send commands to the NetworkViewer. A list of all commands available can be obtained by sending the help command (just type help and hit enter/return).

Connecting to IPSRV from within a C++ program:

To connect to IPSRV from within a C++ program the class NVRemoteConnection can be used. The files NVRemoteConnection.[h|cpp] are stored in $(IPSA_HOME)/examples/ and method calls to an instance of this class will directly send the commands to the NetworkViewer and the return values will also get parsed immediately.

Creating new IPSRV instructions:

Have a look at the documentation of Instruction to see how to create new IPSRV instructions.

Definition at line 39 of file NetworkViewer.h.


Constructor & Destructor Documentation

NetworkViewer::NetworkViewer ( std::string  filename = "",
SO_WINDOW  parent = NULL,
const char *  name = NULL,
SbBool  embed = TRUE 
)

Parameters:
filename name of the file to load
parent pointer to the parent widget (usually created by SO_PLATFORM::init() if executed standalone)
name name the widget should get
embed should widget get embedded or not
See also:
IpsaViewer

Definition at line 107 of file NetworkViewer.cpp.

References commands, instructionMap, LISTEN_PORT, networkReceiveSensor, ReadDatagrams(), setupNetworkThread(), and tcp_socket.

NetworkViewer::~NetworkViewer (  )  [virtual]

Destructor.
Delete the NetworkViewer::tcp_socket.

Definition at line 134 of file NetworkViewer.cpp.

References networkThread, and tcp_socket.


Member Function Documentation

void NetworkViewer::executeCommands ( std::vector< std::vector< std::string > > &  Instr  )  [private]

This method iterates over the Instr vector and calls Instruction::findAndExecute() for each entry. If the current instruction is unknown it is skipped and the next instruction is executed.

Parameters:
Instr each entry is a vector of a command name and the corresponding parameters

Definition at line 241 of file NetworkViewer.cpp.

References instructionMap, CTCPSocket::send(), and tcp_socket.

Referenced by ReadDatagrams().

void * NetworkViewer::NetworkSetup ( void *  data  )  [static, protected]

If data is not a NetworkViewer instance or NetworkViewer::tcp_socket is connected return immediately.
Then unschedule NetworkViewer::networkReceiveSensor and open socket NetworkViewer::tcp_socket and wait for a connection on TCPSocket::PORT (default = NetworkViewer::LISTEN_PORT). Afterwards schedule NetworkViewer::networkReceiveSensor.

This is used in NetworkViewer::setupNetworkThread() for creating NetworkViewer::networkThread.

See also:
NetworkViewer::setupNetworkThread().
Parameters:
data must be an instance of NetworkViewer
Returns:
NULL always as there is currently no use for a return value

Definition at line 282 of file NetworkViewer.cpp.

References CTCPSocket::isConnected(), networkReceiveSensor, CTCPSocket::openSocket(), CTCPSocket::PORT, and tcp_socket.

Referenced by setupNetworkThread().

void NetworkViewer::ReadDatagrams ( void *  data,
SoSensor *   
) [static]

This method is the callback executed by NetworkViewer::networkReceiveSensor.
If a read error occurs or NetworkViewer::tcp_socket is not connected it just returns.
If the remote connection was closed it reopens a new listening connection by closing NetworkViewer::tcp_socket first and then calling NetworkViewer::setupNetworkThread().
If data was successfully read the received string gets parsed into the structure NetworkViewer::executeCommands() understands and this method is called after the parsing was done successfully.

Parameters:
data pointer to the networkViewer instance which calls this callback.

Definition at line 153 of file NetworkViewer.cpp.

References CTCPSocket::closeSocket(), commands, executeCommands(), CTCPSocket::isConnected(), CTCPSocket::receive(), setupNetworkThread(), SOCKET_ERROR, and tcp_socket.

Referenced by NetworkViewer().

void NetworkViewer::setupNetworkThread (  )  [protected]

Destroys the current NetworkViewer::networkThread and calls SbThread::create() with NetworkViewer::NetworkSetup() as function pointer and this as data pointer.

Definition at line 225 of file NetworkViewer.cpp.

References NetworkSetup(), and networkThread.

Referenced by NetworkViewer(), and ReadDatagrams().


Member Data Documentation

The data received in NetworkViewer::ReadDatagrams() is appended to this string until the transmission finished. Afterwards the resulting string gets processed and split up into the single commands.

Definition at line 57 of file NetworkViewer.h.

Referenced by NetworkViewer(), and ReadDatagrams().

Gets filled in the constructor by calling NVInstructions::CreateInstructionMap() with this as argument.

Definition at line 58 of file NetworkViewer.h.

Referenced by executeCommands(), and NetworkViewer().

Port which the NetworkViewer is listening on for incomming connections (default = 12345).

Definition at line 52 of file NetworkViewer.h.

Referenced by NetworkViewer().

Calls NetworkViewer::ReadDatagrams() with this as data pointer everytime the sensor is scheduled.

Definition at line 51 of file NetworkViewer.h.

Referenced by NetworkSetup(), and NetworkViewer().

Thread started to wait for an incomming network connection.

See also:
NetworkViewer::setupNetworkThread().

Definition at line 50 of file NetworkViewer.h.

Referenced by setupNetworkThread(), and ~NetworkViewer().

Instance of CTCPSocket. Used for TCP/IP communication.

Definition at line 56 of file NetworkViewer.h.

Referenced by executeCommands(), NetworkSetup(), NetworkViewer(), ReadDatagrams(), and ~NetworkViewer().


The documentation for this class was generated from the following files:

Get IPSA - Inventor Physics Simulation API at SourceForge.net. Fast, secure and Free Open Source software downloads
Generated on Sat Mar 10 20:00:19 2012 for IPSA by  doxygen 1.5.8