1 #ifndef VRPN_CONNECTION_H 2 #define VRPN_CONNECTION_H 10 #if !(defined(_WIN32) && defined(VRPN_USE_WINSOCK_SOCKETS)) 11 #include <sys/select.h> 18 #pragma warning(disable : 4995 4996) 21 #if defined(__ANDROID__) 204 vrpn_int32 *connectedEndpointCounter);
211 int local_type_id(vrpn_int32 remote_type)
const;
214 int local_sender_id(vrpn_int32 remote_sender)
const;
216 virtual vrpn_bool doing_okay(
void)
const = 0;
224 virtual int mainloop(timeval *timeout) = 0;
229 void clear_other_senders_and_types(
void);
234 int newLocalSender(
const char *name, vrpn_int32 which);
235 int newLocalType(
const char *name, vrpn_int32 which);
240 int newRemoteType(
cName type_name, vrpn_int32 remote_id,
241 vrpn_int32 local_id);
242 int newRemoteSender(
cName sender_name, vrpn_int32 remote_id,
243 vrpn_int32 local_id);
248 virtual int pack_message(vrpn_uint32 len,
struct timeval time,
249 vrpn_int32 type, vrpn_int32 sender,
251 vrpn_uint32 class_of_service) = 0;
256 virtual int send_pending_reports(
void) = 0;
258 int pack_log_description(
void);
261 virtual int setup_new_connection(
void) = 0;
265 virtual void poll_for_cookie(
const timeval *timeout = NULL) = 0;
266 virtual int finish_new_connection_setup(
void) = 0;
268 virtual void drop_connection(
void) = 0;
273 virtual void clearBuffers(
void) = 0;
277 int pack_sender_description(vrpn_int32 which);
280 int pack_type_description(vrpn_int32 which);
307 void setLogNames(
const char *inName,
const char *outName);
329 virtual int dispatch(vrpn_int32 type, vrpn_int32 sender, timeval time,
330 vrpn_uint32 payload_len,
char *bufptr);
332 int tryToMarshall(
char *outbuf, vrpn_int32 &buflen, vrpn_int32 &numOut,
333 vrpn_uint32 len, timeval time, vrpn_int32 type,
334 vrpn_int32 sender,
const char *buffer,
335 vrpn_uint32 classOfService);
340 int marshall_message(
char *outbuf, vrpn_uint32 outbuf_size,
341 vrpn_uint32 initial_out, vrpn_uint32 len,
342 struct timeval time, vrpn_int32 type,
343 vrpn_int32 sender,
const char *buffer,
344 vrpn_uint32 sequenceNumber);
373 vrpn_int32 *connectedEndpointCounter);
381 vrpn_bool outbound_udp_open(
void)
const;
383 vrpn_int32 tcp_outbuf_size(
void)
const;
384 vrpn_int32 udp_outbuf_size(
void)
const;
398 int pack_message(vrpn_uint32 len,
struct timeval time, vrpn_int32 type,
399 vrpn_int32 sender,
const char *buffer,
400 vrpn_uint32 class_of_service);
408 int pack_udp_description(
int portno);
410 int handle_tcp_messages(
const timeval *timeout);
411 int handle_udp_messages(
const timeval *timeout);
413 int connect_tcp_to(
const char *msg);
414 int connect_tcp_to(
const char *addr,
int port);
417 int connect_udp_to(
const char *addr,
int port);
422 vrpn_int32 set_tcp_outbuf_size(vrpn_int32 bytecount);
440 void setNICaddress(
const char *);
473 int getOneTCPMessage(
int fd,
char *buf,
size_t buflen);
474 int getOneUDPMessage(
char *buf,
size_t buflen);
518 const char *local_out_logfile_name,
520 vrpn_int32 *) = allocateEndpoint);
526 const char *local_out_logfile_name,
527 const char *remote_in_logfile_name,
528 const char *remote_out_logfile_name,
530 vrpn_int32 *) = allocateEndpoint);
536 virtual vrpn_bool doing_okay(
void)
const;
540 virtual vrpn_bool connected(
void)
const;
548 void get_log_names(
char **local_in_logname,
char **local_out_logname,
549 char **remote_in_logname,
char **remote_out_logname);
558 virtual int mainloop(
const struct timeval *timeout = NULL) = 0;
562 virtual vrpn_int32 register_sender(
const char *name);
563 virtual vrpn_int32 register_message_type(
const char *name);
579 virtual int pack_message(vrpn_uint32 len,
struct timeval time,
580 vrpn_int32 type, vrpn_int32 sender,
581 const char *buffer, vrpn_uint32 class_of_service);
586 virtual int send_pending_reports(
void) = 0;
590 virtual int time_since_connection_open(
struct timeval *elapsed_time);
594 virtual timeval get_time();
599 virtual const char *sender_name(vrpn_int32 sender);
600 virtual const char *message_type_name(vrpn_int32 type);
609 virtual int register_log_filter(
vrpn_LOGFILTER filter,
void *userdata);
612 virtual int save_log_so_far();
640 d_stop_processing_messages_after = stop_looking_after;
644 return d_stop_processing_messages_after;
651 vrpn_uint32 d_stop_processing_messages_after;
656 vrpn_int32 *connectedEC);
682 virtual void init(
void);
684 int delete_endpoint(
int whichEndpoint);
685 int compact_endpoints(
void);
687 virtual int pack_sender_description(vrpn_int32 which);
690 virtual int pack_type_description(vrpn_int32 which);
693 virtual int do_callbacks_for(vrpn_int32 type, vrpn_int32 sender,
694 struct timeval time, vrpn_uint32 len,
698 int message_type_is_registered(
const char *)
const;
707 void removeReference();
727 bool d_autoDeleteStatus;
757 virtual void updateEndpoints(
void);
781 const char *local_in_logfile_name = NULL,
782 const char *local_out_logfile_name = NULL,
783 const char *remote_in_logfile_name = NULL,
784 const char *remote_out_logfile_name = NULL,
785 const char *NIC_IPaddress = NULL,
795 const char *local_in_logfile_name = NULL,
796 const char *local_out_logfile_name = NULL,
797 const char *NIC_IPaddress = NULL,
799 vrpn_int32 *) = allocateEndpoint);
805 virtual int connect_to_client(
const char *machine,
int port);
814 virtual int mainloop(
const struct timeval *timeout = NULL);
824 const char *cname,
const char *local_in_logfile_name,
825 const char *local_out_logfile_name,
const char *remote_in_logfile_name,
826 const char *remote_out_logfile_name,
const char *NIC_IPaddress,
827 bool force_connection);
830 const char *local_in_logfile_name,
831 const char *local_out_logfile_name);
844 virtual void init(
void);
856 server_check_for_incoming_connections(
const struct timeval *timeout = NULL);
861 virtual void handle_connection(
int whichEndpoint);
863 virtual void drop_connection(
int whichEndpoint);
891 virtual int mainloop(
const struct timeval *timeout = NULL);
894 virtual vrpn_bool
doing_okay(
void)
const {
return vrpn_true; }
898 virtual vrpn_bool
connected(
void)
const {
return vrpn_true; }
903 const char *local_in_logfile_name,
904 const char *local_out_logfile_name);
923 const char *cname,
const char *local_in_logfile_name = NULL,
924 const char *local_out_logfile_name = NULL,
925 const char *remote_in_logfile_name = NULL,
926 const char *remote_out_logfile_name = NULL,
927 const char *NIC_IPaddress = NULL,
bool force_reopen =
false);
947 const char *local_in_logfile_name = NULL,
948 const char *local_out_logfile_name = NULL);
956 const char *local_in_logfile_name = NULL,
957 const char *local_out_logfile_name = NULL,
958 const char *NIC_NAME = NULL)
961 if (NIC_NAME == NULL) {
962 sprintf(name,
":%d", port);
965 sprintf(name,
"%s:%d", NIC_NAME, port);
968 local_out_logfile_name);
1026 long remote_log_mode);
1031 #ifndef VRPN_USE_WINSOCK_SOCKETS 1036 fd_set *exceptfds,
struct timeval *timeout);
1086 struct knownConnection {
1089 knownConnection *next;
1093 knownConnection *d_kcList;
1096 knownConnection *d_anonList;
1106 #endif // VRPN_CONNECTION_H 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...
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
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_int32 d_numEndpoints
const vrpn_uint32 vrpn_CONNECTION_FIXED_THROUGHPUT
char * vrpn_set_service_name(const char *specifier, const char *newServiceName)
Utility routine to rename the service name of a given host specifier.
void * userdata
passed along
vrpn_uint32 get_Jane_value(void)
char * d_remoteOutLogName
Name of the remote log file.
virtual int mainloop(timeval *timeout)=0
int d_tcpListenPort
Socket and port that the client listens on when lobbing datagrams at the server and waiting for it to...
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).
class VRPN_API vrpn_Connection
vrpn_int32 d_serverLogMode
int VRPN_API vrpn_noint_block_read(int infile, char buffer[], size_t length)
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
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...
Encapsulation of the data and methods for a single IP-based connection to take care of one part of ma...
virtual int send_pending_reports(void)
send pending report, clear the buffer.
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_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...
Description of a callback entry for a user type.
VRPN_API int vrpn_get_port_number(const char *hostspecifier)
int d_remote_port_number
Port to connect to on remote machine.
const vrpn_int32 vrpn_CONNECTION_UDP_DESCRIPTION
virtual int finish_new_connection_setup(void)=0
SOCKET d_udpOutboundSocket
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...
VRPN_API const char * vrpn_got_connection
vrpn_Connection * d_parent
const vrpn_int32 vrpn_CONNECTION_SENDER_DESCRIPTION
virtual int send_pending_reports(void)=0
send pending report, clear the buffer. This function was protected, now is public,...
VRPN_API const char * vrpn_dropped_last_connection
const vrpn_int32 vrpn_CONNECTION_DISCONNECT_MESSAGE
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...
Generic connection class not specific to the transport mechanism.
char * d_remote_machine_name
Machine to call.
const unsigned vrpn_ALIGN
VRPN buffers are aligned on 8 byte boundaries so that we can pack and unpack doubles into them on arc...
virtual void clearBuffers(void)=0
Empties out the TCP and UDP send buffers. Needed by vrpn_FileConnection to get at {udp,...
VRPN_API size_t vrpn_cookie_size(void)
Returns the size of the magic cookie buffer, plus any alignment overhead.
vrpn_MESSAGEHANDLER handler
Routine to call.
int(VRPN_CALLBACK * vrpn_MESSAGEHANDLER)(void *userdata, vrpn_HANDLERPARAM p)
Type of a message handler for vrpn_Connection messages.
VRPN_API const char * vrpn_dropped_connection
vrpn_LOGFILTER filter
routine to call
const vrpn_int32 vrpn_CONNECTION_LOG_DESCRIPTION
VRPN_API int check_vrpn_file_cookie(const char *buffer)
virtual int send_pending_reports(void)=0
send pending report, clear the buffer. This function was protected, now is public,...
Constructor for a Loopback connection that will basically just pass messages between objects that are...
vrpn_int32 d_udpSequenceNumber
const long vrpn_LOG_OUTGOING
const vrpn_int32 vrpn_CONNECTION_TYPE_DESCRIPTION
SOCKET listen_tcp_sock
TCP Connection requests come here.
VRPN_API char * vrpn_copy_file_name(const char *filespecifier)
Utility routines to parse file specifiers FROM service locations.
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_int32 d_tcpSequenceNumber
vrpn_Connection * getConnection()
char cName[100]
Length of names within VRPN.
void setConnection(vrpn_Connection *conn)
vrpnLogFilterEntry * next
This structure is what is passed to a vrpn_Connection message callback.
void setAutoDeleteStatus(bool setvalue)
Specify whether this connection should be deleted automatically when it is no longer need (reference ...
vrpn_ConnectionStatus
This is the list of states that a connection can be in (possible values for status)....
virtual void init(void)
Base initialization for all constructors.
Singleton class that keeps track of all known VRPN connections and makes sure they're deleted on shut...
class VRPN_API vrpn_TranslationTable
int connectionStatus
Status of the connection.
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 ...
void * userdata
Passed along.
VRPN_API char * vrpn_copy_service_location(const char *fullname)
vrpn_int32 sender
Only if from sender.
timeval start_time
Timekeeping - TCH 30 June 98.
char * d_remoteInLogName
Name of the remote log file.
vrpn_MESSAGEHANDLER vrpn_LOGFILTER
Type of handler for filters on logfiles is the same as connection handler.
int VRPN_API vrpn_noint_block_write(int outfile, const char buffer[], size_t length)
long d_remoteLogMode
Mode to put the remote logging in.
Encapsulation of the data and methods for a single generic connection to take care of one part of man...
vrpn_int32 * d_connectionCounter
const vrpn_uint32 vrpn_CONNECTION_FIXED_LATENCY
int d_serverLogCount
Server logging w. multiconnection - TCH July 00 Use one "hidden" endpoint for outgoing logs (?...
virtual void drop_connection(void)=0
Should only be called by vrpn_Connection::drop_connection(), since there's more housecleaning to do a...
const long vrpn_LOG_INCOMING
virtual vrpn_bool connected(void) const
Returns vrpn_true if the connection has been established, vrpn_false if not (For a networkless connec...
const int vrpn_CONNECTION_MAX_TYPES
SOCKET listen_udp_sock
UDP Connect requests come here.
vrpn_TranslationTable * d_senders
vrpn_bool d_updateEndpoint
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_API char * vrpn_copy_rsh_arguments(const char *hostspecifier)
const int vrpn_CONNECTION_MAX_SENDERS
Types now have their storage dynamically allocated, so we can afford to have large tables....
vrpn_int32 d_numConnectedEndpoints
We need to track the number of connected endpoints separately to properly send out got-first-connecti...
const vrpn_uint32 vrpn_CONNECTION_HIGH_THROUGHPUT
class VRPN_API vrpn_TypeDispatcher
VRPN_API char * vrpn_copy_rsh_program(const char *hostspecifier)
virtual void poll_for_cookie(const timeval *timeout=NULL)=0
virtual vrpn_bool doing_okay(void) const
Returns vrpn_true if the connection is okay, vrpn_false if not.
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,...
const int vrpn_CONNECTION_TCP_BUFLEN
vrpnMsgCallbackEntry * next
Next handler.
timeval d_last_connect_attempt
When the last UDP lob occurred.
VRPN_API char * vrpn_copy_machine_name(const char *hostspecifier)
const int vrpn_CONNECTION_UDP_BUFLEN
SOCKET d_udpInboundSocket
Inbound unreliable messages come here. Need one for each due to different clock synchronization for e...
vrpn_bool d_tcp_only
For connections made through firewalls or NAT with the tcp: URL, we do not want to allow the endpoint...
const int vrpn_MAX_ENDPOINTS
Number of endpoints that a server connection can have. Arbitrary limit.
vrpn_TypeDispatcher * d_dispatcher
Derived classes need access to d_dispatcher in their allocateEndpoint() routine. Several compilers wo...
virtual vrpn_bool doing_okay(void) const =0
vrpn_TypeDispatcher * d_dispatcher
VRPN_API char * vrpn_copy_service_name(const char *fullname)
SOCKET d_tcpListenSocket
This section deals with when a client connection is trying to establish (or re-establish) a connectio...
Placed here so vrpn_FileConnection can use it too.
vrpn_TranslationTable * d_types
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).
SOCKET d_udpLobSocket
Socket to use to lob UDP requests asking for the server to call us back.
const int vrpn_ANY_SENDER
vrpn_ANY_SENDER can be used to register callbacks on a given message type from any sender.