1#ifndef VRPN_CONNECTION_H
2#define VRPN_CONNECTION_H
11#if !(defined(_WIN32) && defined(VRPN_USE_WINSOCK_SOCKETS))
12#include <sys/select.h>
19#pragma warning(disable : 4995 4996)
182 , numActiveEndpoints_(NULL)
187 vrpn_int32 *numActiveEndpoints = NULL)
190 , numActiveEndpoints_(numActiveEndpoints)
202 return (*epa_)(conn_, numActiveEndpoints_);
211 return (*epa_)(conn_, alternateNumActiveEndpoints);
217 vrpn_int32 *numActiveEndpoints_;
257 vrpn_int32 *connectedEndpointCounter);
264 int local_type_id(vrpn_int32 remote_type)
const;
267 int local_sender_id(vrpn_int32 remote_sender)
const;
282 void clear_other_senders_and_types(
void);
287 int newLocalSender(
const char *name, vrpn_int32 which);
288 int newLocalType(
const char *name, vrpn_int32 which);
293 int newRemoteType(
cName type_name, vrpn_int32 remote_id,
294 vrpn_int32 local_id);
295 int newRemoteSender(
cName sender_name, vrpn_int32 remote_id,
296 vrpn_int32 local_id);
302 vrpn_int32 type, vrpn_int32 sender,
304 vrpn_uint32 class_of_service) = 0;
311 int pack_log_description(
void);
330 int pack_sender_description(vrpn_int32 which);
333 int pack_type_description(vrpn_int32 which);
360 void setLogNames(
const char *inName,
const char *outName);
382 virtual int dispatch(vrpn_int32 type, vrpn_int32 sender, timeval time,
383 vrpn_uint32 payload_len,
char *bufptr);
385 int tryToMarshall(
char *outbuf, vrpn_int32 &buflen, vrpn_int32 &numOut,
386 vrpn_uint32 len, timeval time, vrpn_int32 type,
387 vrpn_int32 sender,
const char *buffer,
388 vrpn_uint32 classOfService);
393 int marshall_message(
char *outbuf, vrpn_uint32 outbuf_size,
394 vrpn_uint32 initial_out, vrpn_uint32 len,
395 struct timeval time, vrpn_int32 type,
396 vrpn_int32 sender,
const char *buffer,
397 vrpn_uint32 sequenceNumber);
426 vrpn_int32 *connectedEndpointCounter);
431 virtual vrpn_bool doing_okay(
void)
const;
434 vrpn_bool outbound_udp_open(
void)
const;
436 vrpn_int32 tcp_outbuf_size(
void)
const;
437 vrpn_int32 udp_outbuf_size(
void)
const;
445 int mainloop(timeval *timeout);
451 int pack_message(vrpn_uint32 len,
struct timeval time, vrpn_int32 type,
452 vrpn_int32 sender,
const char *buffer,
453 vrpn_uint32 class_of_service);
459 virtual int send_pending_reports(
void);
461 int pack_udp_description(
int portno);
463 int handle_tcp_messages(
const timeval *timeout);
464 int handle_udp_messages(
const timeval *timeout);
466 int connect_tcp_to(
const char *msg);
467 int connect_tcp_to(
const char *addr,
int port);
470 int connect_udp_to(
const char *addr,
int port);
475 int setup_new_connection(
void);
479 void poll_for_cookie(
const timeval *timeout = NULL);
480 int finish_new_connection_setup(
void);
482 void drop_connection(
void);
487 void clearBuffers(
void);
491 void setNICaddress(
const char *);
524 int getOneTCPMessage(
int fd,
char *buf,
size_t buflen);
525 int getOneUDPMessage(
char *buf,
size_t buflen);
569 const char *local_out_logfile_name,
576 const char *local_out_logfile_name,
577 const char *remote_in_logfile_name,
578 const char *remote_out_logfile_name,
585 virtual vrpn_bool doing_okay(
void)
const;
590 virtual vrpn_bool connected(
void)
const;
598 void get_log_names(
char **local_in_logname,
char **local_out_logname,
599 char **remote_in_logname,
char **remote_out_logname);
608 virtual int mainloop(
const struct timeval *timeout = NULL) = 0;
612 virtual vrpn_int32 register_sender(
const char *name);
613 virtual vrpn_int32 register_message_type(
const char *name);
629 virtual int pack_message(vrpn_uint32 len,
struct timeval time,
630 vrpn_int32 type, vrpn_int32 sender,
631 const char *buffer, vrpn_uint32 class_of_service);
640 virtual int time_since_connection_open(
struct timeval *elapsed_time);
644 virtual timeval get_time();
649 virtual const char *sender_name(vrpn_int32 sender);
650 virtual const char *message_type_name(vrpn_int32 type);
659 virtual int register_log_filter(
vrpn_LOGFILTER filter,
void *userdata);
662 virtual int save_log_so_far();
690 d_stop_processing_messages_after = stop_looking_after;
694 return d_stop_processing_messages_after;
711 vrpn_int32 *connectedEC);
716#pragma warning(disable : 4251)
748 int compact_endpoints(
void);
750 virtual int pack_sender_description(vrpn_int32 which);
753 virtual int pack_type_description(vrpn_int32 which);
756 virtual int do_callbacks_for(vrpn_int32 type, vrpn_int32 sender,
757 struct timeval time, vrpn_uint32 len,
761 int message_type_is_registered(
const char *)
const;
770 void removeReference();
790 bool d_autoDeleteStatus;
819 virtual void updateEndpoints(
void);
843 const char *local_in_logfile_name = NULL,
844 const char *local_out_logfile_name = NULL,
845 const char *remote_in_logfile_name = NULL,
846 const char *remote_out_logfile_name = NULL,
847 const char *NIC_IPaddress = NULL,
856 const char *local_in_logfile_name = NULL,
857 const char *local_out_logfile_name = NULL,
858 const char *NIC_IPaddress = NULL,
860 vrpn_int32 *) = allocateEndpoint);
866 virtual int connect_to_client(
const char *machine,
int port);
875 virtual int mainloop(
const struct timeval *timeout = NULL);
884 const char *cname,
const char *local_in_logfile_name,
885 const char *local_out_logfile_name,
const char *remote_in_logfile_name,
886 const char *remote_out_logfile_name,
const char *NIC_IPaddress,
887 bool force_connection);
890 const char *local_in_logfile_name,
891 const char *local_out_logfile_name);
910 virtual int send_pending_reports(
void);
916 server_check_for_incoming_connections(
const struct timeval *timeout = NULL);
960 virtual int mainloop(
const struct timeval *timeout = NULL);
963 virtual vrpn_bool
doing_okay(
void)
const {
return vrpn_true; }
968 virtual vrpn_bool
connected(
void)
const {
return vrpn_true; }
973 const char *local_in_logfile_name,
974 const char *local_out_logfile_name);
993 const char *cname,
const char *local_in_logfile_name = NULL,
994 const char *local_out_logfile_name = NULL,
995 const char *remote_in_logfile_name = NULL,
996 const char *remote_out_logfile_name = NULL,
997 const char *NIC_IPaddress = NULL,
bool force_reopen =
false);
1017 const char *local_in_logfile_name = NULL,
1018 const char *local_out_logfile_name = NULL);
1026 const char *local_in_logfile_name = NULL,
1027 const char *local_out_logfile_name = NULL,
1028 const char *NIC_NAME = NULL)
1031 if (NIC_NAME == NULL) {
1032 sprintf(name,
":%d", port);
1035 sprintf(name,
"%s:%d", NIC_NAME, port);
1038 local_out_logfile_name);
1096 long remote_log_mode);
1101#ifndef VRPN_USE_WINSOCK_SOCKETS
1106 fd_set *exceptfds,
struct timeval *timeout);
1163 struct knownConnection {
1166 knownConnection *next;
1170 knownConnection *d_kcList;
1173 knownConnection *d_anonList;
Combines the function pointer for an Endpoint Allocator with its two arguments into a single callable...
return_type operator()() const
Default, fully pre-bound.
vrpn_Endpoint_IP * return_type
return_type operator()(vrpn_int32 *alternateNumActiveEndpoints) const
Overload, with alternate num active connnection pointer.
BoundEndpointAllocator(vrpn_EndpointAllocator epa, vrpn_Connection *conn, vrpn_int32 *numActiveEndpoints=NULL)
Container for endpoints, held by pointer.
Singleton class that keeps track of all known VRPN connections and makes sure they're deleted on shut...
SOCKET listen_udp_sock
UDP Connect requests come here.
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 en...
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()....
SOCKET listen_tcp_sock
TCP Connection requests come here.
Constructor for a Loopback connection that will basically just pass messages between objects that are...
virtual vrpn_bool doing_okay(void) const
Returns vrpn_true if the connection is okay, vrpn_false if not.
virtual int send_pending_reports(void)
send pending report, clear the buffer.
virtual vrpn_bool connected(void) const
Returns vrpn_true if the connection has been established, vrpn_false if not (For a networkless connec...
Generic connection class not specific to the transport mechanism.
int d_serverLogCount
Server logging w. multiconnection - TCH July 00 Use one "hidden" endpoint for outgoing logs (?...
virtual int send_pending_reports(void)=0
send pending report, clear the buffer. This function was protected, now is public,...
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...
vrpn_int32 d_numConnectedEndpoints
We need to track the number of connected endpoints separately to properly send out got-first-connecti...
vrpn_bool d_updateEndpoint
vrpn_TypeDispatcher * d_dispatcher
Derived classes need access to d_dispatcher in their allocateEndpoint() routine. Several compilers wo...
vrpn_int32 d_serverLogMode
vrpn::EndpointContainer d_endpoints
Sockets used to talk to remote Connection(s) and other information needed on a per-connection basis.
vrpn_uint32 get_Jane_value(void)
void setAutoDeleteStatus(bool setvalue)
Specify whether this connection should be deleted automatically when it is no longer need (reference ...
int connectionStatus
Status of the connection.
virtual int mainloop(const struct timeval *timeout=NULL)=0
Call each time through program main loop to handle receiving any incoming messages and sending any pa...
timeval start_time
Timekeeping - TCH 30 June 98.
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 en...
vrpn::BoundEndpointAllocator d_boundEndpointAllocator
Function object wrapping an endpoint allocator and binding its arguments.
Encapsulation of the data and methods for a single IP-based connection to take care of one part of ma...
SOCKET d_udpInboundSocket
Inbound unreliable messages come here. Need one for each due to different clock synchronization for e...
SOCKET d_tcpListenSocket
This section deals with when a client connection is trying to establish (or re-establish) a connectio...
vrpn_int32 d_udpSequenceNumber
timeval d_last_connect_attempt
When the last UDP lob occurred.
char * d_remote_machine_name
Machine to call.
vrpn_bool d_tcp_only
For connections made through firewalls or NAT with the tcp: URL, we do not want to allow the endpoint...
int d_tcpListenPort
Socket and port that the client listens on when lobbing datagrams at the server and waiting for it to...
int d_remote_port_number
Port to connect to on remote machine.
SOCKET d_udpOutboundSocket
SOCKET d_udpLobSocket
Socket to use to lob UDP requests asking for the server to call us back.
vrpn_int32 d_tcpSequenceNumber
Encapsulation of the data and methods for a single generic connection to take care of one part of man...
void setConnection(vrpn_Connection *conn)
virtual vrpn_bool doing_okay(void) const =0
long d_remoteLogMode
Mode to put the remote logging in.
vrpn_TypeDispatcher * d_dispatcher
virtual int send_pending_reports(void)=0
send pending report, clear the buffer. This function was protected, now is public,...
virtual int setup_new_connection(void)=0
Sends the magic cookie and other information to its peer. It is called by both the client and server ...
virtual int mainloop(timeval *timeout)=0
vrpn_Connection * getConnection()
virtual void drop_connection(void)=0
Should only be called by vrpn_Connection::drop_connection(), since there's more housecleaning to do a...
vrpn_int32 * d_connectionCounter
char * d_remoteInLogName
Name of the remote log file.
virtual int pack_message(vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)=0
Pack a message that will be sent the next time mainloop() is called. Turn off the RELIABLE flag if yo...
virtual int finish_new_connection_setup(void)=0
virtual void poll_for_cookie(const timeval *timeout=NULL)=0
vrpn_TranslationTable * d_senders
vrpn_Connection * d_parent
virtual void clearBuffers(void)=0
Empties out the TCP and UDP send buffers. Needed by vrpn_FileConnection to get at {udp,...
vrpn_TranslationTable * d_types
char * d_remoteOutLogName
Name of the remote log file.
vrpn_LOGFILTER filter
routine to call
void * userdata
passed along
vrpnLogFilterEntry * next
Description of a callback entry for a user type.
vrpnMsgCallbackEntry * next
Next handler.
void * userdata
Passed along.
vrpn_int32 sender
Only if from sender.
vrpn_MESSAGEHANDLER handler
Routine to call.
This structure is what is passed to a vrpn_Connection message callback.
Placed here so vrpn_FileConnection can use it too.
vrpn_Connection * vrpn_create_server_connection(const char *cname, const char *local_in_logfile_name, const char *local_out_logfile_name)
Create a server connection of arbitrary type (VRPN UDP/TCP, TCP, File, Loopback, MPI).
vrpn_Connection * vrpn_get_connection_by_name(const char *cname, const char *local_in_logfile_name, const char *local_out_logfile_name, const char *remote_in_logfile_name, const char *remote_out_logfile_name, const char *NIC_IPaddress, bool force_connection)
Create a client connection of arbitrary type (VRPN UDP/TCP, TCP, File, Loopback, MPI).
const vrpn_int32 vrpn_CONNECTION_UDP_DESCRIPTION
const int vrpn_CONNECTION_UDP_BUFLEN
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
VRPN_API char * vrpn_copy_rsh_arguments(const char *hostspecifier)
const vrpn_int32 vrpn_CONNECTION_LOG_DESCRIPTION
const int vrpn_CONNECTION_MAX_SENDERS
Types now have their storage dynamically allocated, so we can afford to have large tables....
const vrpn_int32 vrpn_CONNECTION_TYPE_DESCRIPTION
const int vrpn_ANY_SENDER
vrpn_ANY_SENDER can be used to register callbacks on a given message type from any sender.
VRPN_API int check_vrpn_cookie(const char *buffer)
Checks the buffer to see if it is a valid VRPN header cookie. Returns -1 on total mismatch,...
VRPN_API int check_vrpn_file_cookie(const char *buffer)
const unsigned vrpn_ALIGN
VRPN buffers are aligned on 8 byte boundaries so that we can pack and unpack doubles into them on arc...
int VRPN_API vrpn_noint_select(int width, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
This routine will perform like a normal select() call, but it will restart if it quit because of an i...
VRPN_API int write_vrpn_cookie(char *buffer, size_t length, long remote_log_mode)
Writes the magic cookie into buffer with given length.
vrpn_Endpoint_IP *(* vrpn_EndpointAllocator)(vrpn_Connection *connection, vrpn_int32 *numActiveConnections)
Function pointer to an endpoint allocator.
const vrpn_uint32 vrpn_CONNECTION_FIXED_THROUGHPUT
const int vrpn_MAX_ENDPOINTS
Number of endpoints that a server connection can have. Arbitrary limit.
VRPN_API int vrpn_get_port_number(const char *hostspecifier)
VRPN_API char * vrpn_copy_file_name(const char *filespecifier)
Utility routines to parse file specifiers FROM service locations.
vrpn_MESSAGEHANDLER vrpn_LOGFILTER
Type of handler for filters on logfiles is the same as connection handler.
const int vrpn_ANY_TYPE
vrpn_ANY_TYPE can be used to register callbacks for any USER type of message from a given sender....
VRPN_API char * vrpn_copy_service_name(const char *fullname)
int(VRPN_CALLBACK * vrpn_MESSAGEHANDLER)(void *userdata, vrpn_HANDLERPARAM p)
Type of a message handler for vrpn_Connection messages.
VRPN_API const char * vrpn_CONTROL
vrpn_CONTROL is the sender used for notification messages sent to the user from the local VRPN implem...
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)
Create a server connection of arbitrary type (VRPN UDP/TCP, TCP, File, Loopback, MPI).
char cName[100]
Length of names within VRPN.
const vrpn_uint32 vrpn_CONNECTION_FIXED_LATENCY
VRPN_API char * vrpn_copy_service_location(const char *fullname)
class VRPN_API vrpn_TypeDispatcher
VRPN_API const char * vrpn_dropped_connection
VRPN_API const char * vrpn_got_first_connection
These are the strings that define the system-generated message types that tell when connections are r...
VRPN_API const char * vrpn_got_connection
class VRPN_API vrpn_TranslationTable
const int vrpn_CONNECTION_MAX_TYPES
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
VRPN_API char * vrpn_copy_rsh_program(const char *hostspecifier)
char * vrpn_set_service_name(const char *specifier, const char *newServiceName)
Utility routine to rename the service name of a given host specifier.
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_reopen=false)
Create a client connection of arbitrary type (VRPN UDP/TCP, TCP, File, Loopback, MPI).
const vrpn_int32 vrpn_CONNECTION_DISCONNECT_MESSAGE
const int vrpn_CONNECTION_TCP_BUFLEN
VRPN_API char * vrpn_copy_machine_name(const char *hostspecifier)
int VRPN_API vrpn_noint_block_write(int outfile, const char buffer[], size_t length)
const vrpn_int32 vrpn_CONNECTION_SENDER_DESCRIPTION
VRPN_API const char * vrpn_dropped_last_connection
const vrpn_uint32 vrpn_CONNECTION_HIGH_THROUGHPUT
vrpn_ConnectionStatus
This is the list of states that a connection can be in (possible values for status)....
const long vrpn_LOG_OUTGOING
const long vrpn_LOG_INCOMING
VRPN_API size_t vrpn_cookie_size(void)
Returns the size of the magic cookie buffer, plus any alignment overhead.
int VRPN_API vrpn_noint_block_read(int infile, char buffer[], size_t length)