vrpn 07.35
Virtual Reality Peripheral Network
 
Loading...
Searching...
No Matches
vrpn_Connection_IP Class Reference

#include <vrpn_Connection.h>

Inheritance diagram for vrpn_Connection_IP:
Collaboration diagram for vrpn_Connection_IP:

Public Member Functions

 vrpn_Connection_IP (unsigned short listen_port_no=vrpn_DEFAULT_LISTEN_PORT_NO, const char *local_in_logfile_name=NULL, const char *local_out_logfile_name=NULL, const char *NIC_IPaddress=NULL, vrpn_Endpoint_IP *(*epa)(vrpn_Connection *, vrpn_int32 *)=allocateEndpoint)
 Make a server that listens for client connections. DEPRECATED: Call vrpn_create_server_connection() with the NIC name and port number you want.
 
virtual ~vrpn_Connection_IP (void)
 
virtual int connect_to_client (const char *machine, int port)
 This is similar to check connection except that it can be used to receive requests from before a server starts up.
 
virtual int mainloop (const struct timeval *timeout=NULL)
 Call each time through program main loop to handle receiving any incoming messages and sending any packed messages. Returns -1 when connection dropped due to error, 0 otherwise. (only returns -1 once per connection drop). Optional argument is TOTAL time to block on select() calls; there may be multiple calls to select() per call to mainloop(), and this timeout will be divided evenly between them.
 
- Public Member Functions inherited from vrpn_Connection
virtual ~vrpn_Connection (void)
 
virtual vrpn_bool doing_okay (void) const
 Returns vrpn_true if the connection is okay, vrpn_false if not.
 
virtual vrpn_bool connected (void) const
 Returns vrpn_true if the connection has been established, vrpn_false if not (For a networkless connection, this is equivalent to doing_okay()).
 
void get_log_names (char **local_in_logname, char **local_out_logname, char **remote_in_logname, char **remote_out_logname)
 This function returns the logfile names of this connection in the parameters. It will allocate memory for the name of each log file in use. If no logging of a particular type is happening, then *(X_Y_logname) will be set to NULL. IMPORTANT: code calling this function is responsible for freeing the memory allocated for these strings.
 
virtual vrpn_int32 register_sender (const char *name)
 Get a token to use for the string name of the sender or type. Remember to check for -1 meaning failure.
 
virtual vrpn_int32 register_message_type (const char *name)
 
virtual int register_handler (vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
 Set up (or remove) a handler for a message of a given type. Optionally, specify which sender to handle messages from. Handlers will be called during mainloop(). Your handler should return 0 or a communication error is assumed and the connection will be shut down.
 
virtual int unregister_handler (vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
 
virtual int pack_message (vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)
 Pack a message that will be sent the next time mainloop() is called. Turn off the RELIABLE flag if you want low-latency (UDP) send.
 
virtual int time_since_connection_open (struct timeval *elapsed_time)
 Returns the time since the connection opened. Some subclasses may redefine time.
 
virtual timeval get_time ()
 returns the current time in the connection (since the epoch – UTC time).
 
virtual const char * sender_name (vrpn_int32 sender)
 Returns the name of the specified sender/type, or NULL if the parameter is invalid. Only works for user messages (type >= 0).
 
virtual const char * message_type_name (vrpn_int32 type)
 
virtual int register_log_filter (vrpn_LOGFILTER filter, void *userdata)
 Sets up a filter function for logging. Any user message to be logged is first passed to this function, and will only be logged if the function returns zero (XXX). NOTE: this only affects local logging - remote logging is unfiltered! Only user messages are filtered; all system messages are logged. Returns nonzero on failure.
 
virtual int save_log_so_far ()
 Save any messages on any endpoints which have been logged so far.
 
virtual vrpn_File_Connectionget_File_Connection (void)
 vrpn_File_Connection implements this as "return this" so it can be used to detect a File_Connection and get the pointer for it
 
void Jane_stop_this_crazy_thing (vrpn_uint32 stop_looking_after)
 This function should be seldom used. It is here for the case of the vrpn_Imager, whose servers do not follow "The VRPN Way" because they try to jam more data into the network than there is bandwidth to support it. As a result, a client may call mainloop() on the connection and have it never return – there is always more data in the network to read, so we never hand control back to the main program. The reason for the name comes from an old U.S. cartoon called "The Jetsons". In it, George Jetson is running on a treadmill when it goes out of control and starts spinning so fast that he can't even run fast enough to reach the controls and turn it off. He cries out to his wife, "Jane! Stop this crazy thing!" The parameter specifies a trigger: if more than the specified number of messages come in on a given input channel during one mainloop() call, the connection should stop looking for more messages. NOTE: this does not guarantee that only this many messages will be received, only that the connection will stop looking for new ones on a given channel once that many have been received (for example, UDP channels will parse all the rest of the messages in a packet before stopping). A value of 0 turns off the limit, and will cause all incoming messages to be handled before returning.
 
vrpn_uint32 get_Jane_value (void)
 
void addReference ()
 Counting references to this connection.
 
void removeReference ()
 
void setAutoDeleteStatus (bool setvalue)
 Specify whether this connection should be deleted automatically when it is no longer need (reference count reaches zero). For connections created by the VRPN code (as is done in get_connection_by_name) these should be auto-deleted. Connections created by user code should not be auto-deleted; that is up to the user to decide when finished. By default, the constructor sets this to FALSE. VRPN code (or user code) can set this to TRUE if it wants the connection to be deleted automatically when the last service on it is deleted.
 

Protected Member Functions

 vrpn_Connection_IP (const char *server_name, int port=vrpn_DEFAULT_LISTEN_PORT_NO, const char *local_in_logfile_name=NULL, const char *local_out_logfile_name=NULL, const char *remote_in_logfile_name=NULL, const char *remote_out_logfile_name=NULL, const char *NIC_IPaddress=NULL, vrpn_EndpointAllocator epa=allocateEndpoint)
 Make a client connection. To access this from user code, call vrpn_get_connection_by_name(). Create a connection - if server_name is not a file: name, makes an SDI-like connection to the named remote server (otherwise functions as a non-networked messaging hub). Port less than zero forces default. Currently, server_name is an extended URL that defaults to VRPN connections at the port, but can be file:: to read from a file. Other extensions should maintain this, so that VRPN uses URLs to name things that are to be connected to.
 
void init (void)
 Called by all constructors.
 
virtual int send_pending_reports (void)
 send pending report, clear the buffer.
 
virtual void server_check_for_incoming_connections (const struct timeval *timeout=NULL)
 
virtual void handle_connection (vrpn_Endpoint *endpoint)
 This routine is called by a server-side connection when a new connection has just been established, and the tcp port has been connected to it.
 
virtual void drop_connection (vrpn_Endpoint *endpoint)
 Drops the connection with the given, non-NULL endpoint. Depending on if we're a server or a client, this may result in the endpoints needing compacting once you're no longer iterating on the endpoint container.
 
void drop_connection_and_compact (vrpn_Endpoint *endpoint)
 Like drop_connection, except it includes the call to compact the endpoints. Only safe to call if you can guarantee no iterators are open to the container, since compact invalidates them.
 
- Protected Member Functions inherited from vrpn_Connection
 vrpn_Connection (const char *local_in_logfile_name, const char *local_out_logfile_name, vrpn_EndpointAllocator epa=allocateEndpoint)
 Constructor for server connection. This cannot be called directly any more because vrpn_Connection is an abstract base class. Call vrpn_create_server_connection() to make a server of arbitrary type based on a name.
 
 vrpn_Connection (const char *local_in_logfile_name, const char *local_out_logfile_name, const char *remote_in_logfile_name, const char *remote_out_logfile_name, vrpn_EndpointAllocator epa=allocateEndpoint)
 Constructor for client connection. This cannot be called directly because vrpn_Connection is an abstract base class. Call vrpn_get_connection_by_name() to create a client connection.
 
int delete_endpoint (vrpn_Endpoint *endpoint)
 Deletes the endpoint and NULLs the entry in the list of open endpoints.
 
int compact_endpoints (void)
 Makes sure the endpoint array is set up cleanly for the next pass through.
 
virtual int pack_sender_description (vrpn_int32 which)
 Send the sender description to ALL endpoints.
 
virtual int pack_type_description (vrpn_int32 which)
 Send the type description to ALL endpoints.
 
virtual int do_callbacks_for (vrpn_int32 type, vrpn_int32 sender, struct timeval time, vrpn_uint32 len, const char *buffer)
 
int message_type_is_registered (const char *) const
 Returns message type ID, or -1 if unregistered.
 
int doSystemCallbacksFor (vrpn_HANDLERPARAM, void *)
 
virtual void updateEndpoints (void)
 This function will be called on the mainloop() iteration after *d_endpointAllocator is called, which lets subclasses do initialization. (They can't do so during allocateEndpoint because it's called during the Connection constructor when their constructors haven't executed yet.)
 

Static Protected Member Functions

static int VRPN_CALLBACK handle_UDP_message (void *userdata, vrpn_HANDLERPARAM p)
 Routines that handle system messages.
 
- Static Protected Member Functions inherited from vrpn_Connection
static vrpn_Endpoint_IPallocateEndpoint (vrpn_Connection *, vrpn_int32 *connectedEC)
 Redefining this and passing it to constructors allows a subclass to use a different subclass of Endpoint. It should do NOTHING but return an endpoint of the appropriate class; it may not access subclass data, since it'll be called from a constructor.
 
static int VRPN_CALLBACK handle_log_message (void *userdata, vrpn_HANDLERPARAM p)
 Routines that handle system messages.
 
static int VRPN_CALLBACK handle_disconnect_message (void *userdata, vrpn_HANDLERPARAM p)
 

Protected Attributes

vrpn_uint32 d_stop_processing_messages_after
 If this value is greater than zero, the connection should stop looking for new messages on a given endpoint after this many are found.
 
char * d_NIC_IP
 
Only used for a vrpn_Connection that awaits incoming connections
SOCKET listen_udp_sock
 UDP Connect requests come here.
 
SOCKET listen_tcp_sock
 TCP Connection requests come here.
 
- Protected Attributes inherited from vrpn_Connection
vrpn_uint32 d_stop_processing_messages_after
 If this value is greater than zero, the connection should stop looking for new messages on a given endpoint after this many are found.
 
int connectionStatus
 Status of the connection.
 
vrpn::BoundEndpointAllocator d_boundEndpointAllocator
 Function object wrapping an endpoint allocator and binding its arguments.
 
vrpn::EndpointContainer d_endpoints
 Sockets used to talk to remote Connection(s) and other information needed on a per-connection basis.
 
vrpn_int32 d_numConnectedEndpoints
 We need to track the number of connected endpoints separately to properly send out got-first-connection/dropped-last-connection messages. This value is managed by the Endpoints, but we need exactly one copy per Connection, so it's on the Connection.
 
timeval start_time
 Timekeeping - TCH 30 June 98.
 
int d_serverLogCount
 Server logging w. multiconnection - TCH July 00 Use one "hidden" endpoint for outgoing logs (?), standard per-endpoint logs with augmented names for incoming. To make a hidden endpoint we create d_endpoints[0] and increment the d_numEndpoints, but DON'T pass it d_numConnectedEndpoints (although it should be safe to do so, since it should never truly become connected, but we might have to "fake" it to get it to log correctly).
 
vrpn_int32 d_serverLogMode
 
char * d_serverLogName
 
vrpn_bool d_updateEndpoint
 

Friends

VRPN_API vrpn_Connectionvrpn_get_connection_by_name (const char *cname, const char *local_in_logfile_name=NULL, const char *local_out_logfile_name=NULL, const char *remote_in_logfile_name=NULL, const char *remote_out_logfile_name=NULL, const char *NIC_IPaddress=NULL, bool force_connection=false)
 Create a client connection of arbitrary type (VRPN UDP/TCP, TCP, File, Loopback, MPI).
 
VRPN_API vrpn_Connectionvrpn_create_server_connection (const char *cname, const char *local_in_logfile_name=NULL, const char *local_out_logfile_name=NULL)
 Create a server connection of arbitrary type (VRPN UDP/TCP, TCP, File, Loopback, MPI).
 

Additional Inherited Members

- Public Attributes inherited from vrpn_Connection
vrpn_TypeDispatcherd_dispatcher
 Derived classes need access to d_dispatcher in their allocateEndpoint() routine. Several compilers won't give it to them, even if they do inherit publicly. Until we figure that out, d_dispatcher needs to be public.
 

Detailed Description

Definition at line 827 of file vrpn_Connection.h.

Constructor & Destructor Documentation

◆ vrpn_Connection_IP() [1/2]

vrpn_Connection_IP::vrpn_Connection_IP ( const char * server_name,
int port = vrpn_DEFAULT_LISTEN_PORT_NO,
const char * local_in_logfile_name = NULL,
const char * local_out_logfile_name = NULL,
const char * remote_in_logfile_name = NULL,
const char * remote_out_logfile_name = NULL,
const char * NIC_IPaddress = NULL,
vrpn_EndpointAllocator epa = allocateEndpoint )
protected

Make a client connection. To access this from user code, call vrpn_get_connection_by_name(). Create a connection - if server_name is not a file: name, makes an SDI-like connection to the named remote server (otherwise functions as a non-networked messaging hub). Port less than zero forces default. Currently, server_name is an extended URL that defaults to VRPN connections at the port, but can be file:: to read from a file. Other extensions should maintain this, so that VRPN uses URLs to name things that are to be connected to.

Todo
do we drop the endpoint here?
Todo
do we drop the endpoint here?
Todo
do we drop the endpoint here?
Todo
do we drop the endpoint here?
Todo
do we drop the endpoint here (and places like it)?

Definition at line 6189 of file vrpn_Connection.C.

References vrpn_ConnectionManager::addConnection(), BROKEN, vrpn_Endpoint_IP::connect_tcp_to(), vrpn_Connection::connectionStatus, COOKIE_PENDING, vrpn_Connection::d_endpoints, vrpn_Endpoint_IP::d_last_connect_attempt, d_NIC_IP, vrpn_Endpoint_IP::d_remote_machine_name, vrpn_Endpoint_IP::d_remote_port_number, vrpn_Endpoint_IP::d_tcp_only, vrpn_Endpoint_IP::d_tcpListenPort, vrpn_Endpoint_IP::d_tcpListenSocket, vrpn_Endpoint_IP::d_tcpSocket, vrpn_Endpoint_IP::d_udpLobSocket, drop_connection_and_compact(), init(), vrpn_ConnectionManager::instance(), INVALID_SOCKET, listen_tcp_sock, listen_udp_sock, vrpn_Endpoint_IP::setNICaddress(), vrpn_Endpoint_IP::setup_new_connection(), vrpn_Endpoint::status, TRYING_TO_CONNECT, vrpn_Connection::vrpn_Connection(), vrpn_copy_machine_name(), vrpn_copy_rsh_arguments(), vrpn_copy_rsh_program(), vrpn_DEFAULT_LISTEN_PORT_NO, vrpn_gettimeofday, and vrpn_udp_request_lob_packet().

Referenced by vrpn_create_server_connection, and vrpn_get_connection_by_name.

Here is the call graph for this function:

◆ vrpn_Connection_IP() [2/2]

vrpn_Connection_IP::vrpn_Connection_IP ( unsigned short listen_port_no = vrpn_DEFAULT_LISTEN_PORT_NO,
const char * local_in_logfile_name = NULL,
const char * local_out_logfile_name = NULL,
const char * NIC_IPaddress = NULL,
vrpn_Endpoint_IP *(* epa )(vrpn_Connection *, vrpn_int32 *) = allocateEndpoint )

Make a server that listens for client connections. DEPRECATED: Call vrpn_create_server_connection() with the NIC name and port number you want.

Definition at line 6135 of file vrpn_Connection.C.

References vrpn_ConnectionManager::addConnection(), BROKEN, vrpn_Connection::connectionStatus, d_NIC_IP, init(), vrpn_ConnectionManager::instance(), INVALID_SOCKET, LISTEN, listen_tcp_sock, listen_udp_sock, and vrpn_Connection::vrpn_Connection().

Here is the call graph for this function:

◆ ~vrpn_Connection_IP()

vrpn_Connection_IP::~vrpn_Connection_IP ( void )
virtual

Definition at line 6476 of file vrpn_Connection.C.

References vrpn_Connection::d_endpoints, d_NIC_IP, INVALID_SOCKET, listen_tcp_sock, listen_udp_sock, send_pending_reports(), and vrpn_closeSocket.

Here is the call graph for this function:

Member Function Documentation

◆ connect_to_client()

int vrpn_Connection_IP::connect_to_client ( const char * machine,
int port )
virtual

This is similar to check connection except that it can be used to receive requests from before a server starts up.

Create a new endpoint for this connection and connect to using a TCP connection directly to the specified machine and port.

This bypasses the UDP send, and is used as part of the vrpn "RSH" startup, where the server is started by the client program and calls it back at a specified port.

Returns 0 on success and -1 on failure.

Todo
Only the other branch incremented numEndpoints - why?

Definition at line 5628 of file vrpn_Connection.C.

References BROKEN, vrpn_Endpoint_IP::connect_tcp_to(), vrpn_Connection::connectionStatus, COOKIE_PENDING, vrpn_Connection::d_boundEndpointAllocator, vrpn_Connection::d_endpoints, vrpn_Connection::d_updateEndpoint, handle_connection(), LISTEN, vrpn_Endpoint::setConnection(), and vrpn_Endpoint::status.

Here is the call graph for this function:

◆ drop_connection()

void vrpn_Connection_IP::drop_connection ( vrpn_Endpoint * endpoint)
protectedvirtual

Drops the connection with the given, non-NULL endpoint. Depending on if we're a server or a client, this may result in the endpoints needing compacting once you're no longer iterating on the endpoint container.

Definition at line 6058 of file vrpn_Connection.C.

References vrpn_Connection::delete_endpoint(), vrpn_Endpoint::drop_connection(), INVALID_SOCKET, listen_udp_sock, vrpn_Endpoint::status, and TRYING_TO_CONNECT.

Referenced by drop_connection_and_compact(), mainloop(), and send_pending_reports().

Here is the call graph for this function:

◆ drop_connection_and_compact()

void vrpn_Connection_IP::drop_connection_and_compact ( vrpn_Endpoint * endpoint)
protected

Like drop_connection, except it includes the call to compact the endpoints. Only safe to call if you can guarantee no iterators are open to the container, since compact invalidates them.

Definition at line 6073 of file vrpn_Connection.C.

References vrpn_Connection::compact_endpoints(), and drop_connection().

Referenced by handle_connection(), and vrpn_Connection_IP().

Here is the call graph for this function:

◆ handle_connection()

void vrpn_Connection_IP::handle_connection ( vrpn_Endpoint * endpoint)
protectedvirtual

This routine is called by a server-side connection when a new connection has just been established, and the tcp port has been connected to it.

Definition at line 5667 of file vrpn_Connection.C.

References drop_connection_and_compact(), and vrpn_Endpoint::setup_new_connection().

Referenced by connect_to_client(), and server_check_for_incoming_connections().

Here is the call graph for this function:

◆ handle_UDP_message()

int vrpn_Connection_IP::handle_UDP_message ( void * userdata,
vrpn_HANDLERPARAM p )
staticprotected

Routines that handle system messages.

Definition at line 5684 of file vrpn_Connection.C.

References BROKEN, vrpn_HANDLERPARAM::buffer, vrpn_Endpoint_IP::connect_udp_to(), vrpn_Endpoint::rhostname, vrpn_HANDLERPARAM::sender, vrpn_Endpoint::status, and vrpn_strcpy().

Referenced by init().

Here is the call graph for this function:

◆ init()

void vrpn_Connection_IP::init ( void )
protected

Called by all constructors.

Definition at line 5735 of file vrpn_Connection.C.

References vrpn_Connection::d_dispatcher, handle_UDP_message(), and vrpn_CONNECTION_UDP_DESCRIPTION.

Referenced by vrpn_Connection_IP(), and vrpn_Connection_IP().

Here is the call graph for this function:

◆ mainloop()

int vrpn_Connection_IP::mainloop ( const struct timeval * timeout = NULL)
virtual

Call each time through program main loop to handle receiving any incoming messages and sending any packed messages. Returns -1 when connection dropped due to error, 0 otherwise. (only returns -1 once per connection drop). Optional argument is TOTAL time to block on select() calls; there may be multiple calls to select() per call to mainloop(), and this timeout will be divided evenly between them.

Implements vrpn_Connection.

Definition at line 6079 of file vrpn_Connection.C.

References BROKEN, vrpn_Connection::compact_endpoints(), vrpn_Connection::connectionStatus, vrpn_Connection::d_endpoints, vrpn_Connection::d_updateEndpoint, drop_connection(), LISTEN, server_check_for_incoming_connections(), and vrpn_Connection::updateEndpoints().

Here is the call graph for this function:

◆ send_pending_reports()

int vrpn_Connection_IP::send_pending_reports ( void )
protectedvirtual

send pending report, clear the buffer.

This function was protected, now is public, so we can use it to send out intermediate results without calling mainloop

Implements vrpn_Connection.

Definition at line 5716 of file vrpn_Connection.C.

References vrpn_Connection::compact_endpoints(), vrpn_Connection::d_endpoints, and drop_connection().

Referenced by ~vrpn_Connection_IP().

Here is the call graph for this function:

◆ server_check_for_incoming_connections()

Friends And Related Symbol Documentation

◆ vrpn_create_server_connection

VRPN_API vrpn_Connection * vrpn_create_server_connection ( const char * cname,
const char * local_in_logfile_name = NULL,
const char * local_out_logfile_name = NULL )
friend

Create a server connection of arbitrary type (VRPN UDP/TCP, TCP, File, Loopback, MPI).

Returns NULL if the name is not understood or the connection cannot be created. WARNING: May not be thread safe. To create a VRPN TCP/UDP server, use a name like: vrpn:machine_name_or_ip:port machine_name_or_ip:port machine_name_or_ip :port (This port on any network card.) To create an MPI server, use a name like: mpi:MPI_COMM_WORLD mpi:comm_number When done with the object, call removeReference() on it (which will delete it if there are no other references).

Definition at line 5507 of file vrpn_Connection.C.

References vrpn_Connection::addReference(), vrpn_Connection::setAutoDeleteStatus(), vrpn_Connection::vrpn_Connection(), vrpn_Connection_IP(), vrpn_copy_machine_name(), vrpn_copy_service_location(), vrpn_DEFAULT_LISTEN_PORT_NO, and vrpn_get_port_number().

◆ vrpn_get_connection_by_name

VRPN_API vrpn_Connection * vrpn_get_connection_by_name ( const char * cname,
const char * local_in_logfile_name = NULL,
const char * local_out_logfile_name = NULL,
const char * remote_in_logfile_name = NULL,
const char * remote_out_logfile_name = NULL,
const char * NIC_IPaddress = NULL,
bool force_connection = false )
friend

Create a client connection of arbitrary type (VRPN UDP/TCP, TCP, File, Loopback, MPI).

WARNING: May not be thread safe. If no IP address for the NIC to use is specified, uses the default NIC. If the force_reopen flag is set, a new connection will be made even if there was already one to that server. When done with the object, call removeReference() on it (which will delete it if there are no other references).

Definition at line 5417 of file vrpn_Connection.C.

References vrpn_Connection::addReference(), vrpn_ConnectionManager::getByName(), vrpn_ConnectionManager::instance(), vrpn_Connection::setAutoDeleteStatus(), vrpn_Connection::vrpn_Connection(), vrpn_Connection_IP(), vrpn_File_Connection, and vrpn_get_port_number().

Member Data Documentation

◆ d_NIC_IP

char* vrpn_Connection_IP::d_NIC_IP
protected

◆ d_stop_processing_messages_after

vrpn_uint32 vrpn_Connection_IP::d_stop_processing_messages_after
protected

If this value is greater than zero, the connection should stop looking for new messages on a given endpoint after this many are found.

Definition at line 881 of file vrpn_Connection.h.

◆ listen_tcp_sock

SOCKET vrpn_Connection_IP::listen_tcp_sock
protected

TCP Connection requests come here.

Definition at line 896 of file vrpn_Connection.h.

Referenced by server_check_for_incoming_connections(), vrpn_Connection_IP(), vrpn_Connection_IP(), and ~vrpn_Connection_IP().

◆ listen_udp_sock

SOCKET vrpn_Connection_IP::listen_udp_sock
protected

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