#include <NetworkViewer.h>
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 |
CTCPSocket * | tcp_socket |
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.
NetworkViewer::NetworkViewer | ( | std::string | filename = "" , |
|
SO_WINDOW | parent = NULL , |
|||
const char * | name = NULL , |
|||
SbBool | embed = TRUE | |||
) |
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 |
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.
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.
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.
data | must be an instance of NetworkViewer |
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.
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().
NetworkViewer::commands [private] |
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().
NetworkViewer::instructionMap [private] |
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().
NetworkViewer::LISTEN_PORT [protected] |
Port which the NetworkViewer is listening on for incomming connections (default = 12345).
Definition at line 52 of file NetworkViewer.h.
Referenced by NetworkViewer().
NetworkViewer::networkReceiveSensor [protected] |
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().
NetworkViewer::networkThread [protected] |
Thread started to wait for an incomming network connection.
Definition at line 50 of file NetworkViewer.h.
Referenced by setupNetworkThread(), and ~NetworkViewer().
NetworkViewer::tcp_socket [private] |
Instance of CTCPSocket. Used for TCP/IP communication.
Definition at line 56 of file NetworkViewer.h.
Referenced by executeCommands(), NetworkSetup(), NetworkViewer(), ReadDatagrams(), and ~NetworkViewer().
Generated on Sat Mar 10 20:00:19 2012 for IPSA by 1.5.8 |