vrpn 07.36
Virtual Reality Peripheral Network
Loading...
Searching...
No Matches
vrpn_Connection.h
Go to the documentation of this file.
1#ifndef VRPN_CONNECTION_H
2#define VRPN_CONNECTION_H
3
4#include <stdio.h> // for NULL, snprintf
5
6#include "vrpn_Configure.h" // for VRPN_API, VRPN_CALLBACK, etc
7#include "vrpn_Shared.h" // for vrpn_SOCKET, timeval
8#include "vrpn_Types.h" // for vrpn_int32, vrpn_uint32, etc
10
11#if !(defined(_WIN32) && defined(VRPN_USE_WINSOCK_SOCKETS))
12#include <sys/select.h> // for fd_set
13#endif
14
15struct timeval;
16
17// Turn off warnings for deprecated calls when compiling on Microsoft Visual Studio
18#ifdef _MSC_VER
19#pragma warning(disable : 4995 4996)
20#endif
21
33
34class VRPN_API
35 vrpn_File_Connection; // Forward declaration for get_File_Connection()
36
42 vrpn_int32 type;
43 vrpn_int32 sender;
44 struct timeval msg_time;
45 vrpn_int32 payload_len;
46 const char *buffer;
47};
48
50typedef int(VRPN_CALLBACK *vrpn_MESSAGEHANDLER)(void *userdata,
52
56
60const unsigned vrpn_ALIGN = 8;
61
70
73
74const int vrpn_ANY_SENDER = -1;
75
78
79const int vrpn_ANY_TYPE = -1;
80
92
96
99
100const int vrpn_MAX_ENDPOINTS = 256;
101
105const vrpn_int32 vrpn_CONNECTION_TYPE_DESCRIPTION = (-2);
106const vrpn_int32 vrpn_CONNECTION_UDP_DESCRIPTION = (-3);
107const vrpn_int32 vrpn_CONNECTION_LOG_DESCRIPTION = (-4);
110
117
118const vrpn_uint32 vrpn_CONNECTION_RELIABLE = (1 << 0);
119const vrpn_uint32 vrpn_CONNECTION_FIXED_LATENCY = (1 << 1);
120const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY = (1 << 2);
121const vrpn_uint32 vrpn_CONNECTION_FIXED_THROUGHPUT = (1 << 3);
122const vrpn_uint32 vrpn_CONNECTION_HIGH_THROUGHPUT = (1 << 4);
123
125
128const long vrpn_LOG_NONE = (0);
129const long vrpn_LOG_INCOMING = (1 << 0);
130const long vrpn_LOG_OUTGOING = (1 << 1);
132
133// If defined, will filter out messages: if the remote side hasn't
134// registered a type, messages of that type won't be sent over the
135// link. WARNING: auto-type-registration breaks this.
136//#define vrpn_FILTER_MESSAGES
137
141extern VRPN_API const char *vrpn_got_first_connection;
142extern VRPN_API const char *vrpn_got_connection;
143extern VRPN_API const char *vrpn_dropped_connection;
144extern VRPN_API const char *vrpn_dropped_last_connection;
146
152
153extern VRPN_API const char *vrpn_CONTROL;
154
156const unsigned vrpn_CNAME_LENGTH = 100;
158
165
168
170typedef vrpn_Endpoint_IP *(*vrpn_EndpointAllocator)(
171 vrpn_Connection *connection, vrpn_int32 *numActiveConnections);
172
173namespace vrpn {
174
179 public:
181 : epa_(NULL)
182 , conn_(NULL)
183 , numActiveEndpoints_(NULL)
184 {
185 }
187 vrpn_Connection *conn,
188 vrpn_int32 *numActiveEndpoints = NULL)
189 : epa_(epa)
190 , conn_(conn)
191 , numActiveEndpoints_(numActiveEndpoints)
192 {
193 }
194
196
199 {
200 if (!epa_) {
201 return NULL;
202 }
203 return (*epa_)(conn_, numActiveEndpoints_);
204 }
205
207 return_type operator()(vrpn_int32 *alternateNumActiveEndpoints) const
208 {
209 if (!epa_) {
210 return NULL;
211 }
212 return (*epa_)(conn_, alternateNumActiveEndpoints);
213 }
214
215 private:
217 vrpn_Connection *conn_;
218 vrpn_int32 *numActiveEndpoints_;
219 };
220} // namespace vrpn
226
234
240
241
244class VRPN_API vrpn_TranslationTable;
245class VRPN_API vrpn_TypeDispatcher;
246
253
255
256public:
258 vrpn_int32 *connectedEndpointCounter);
259 virtual ~vrpn_Endpoint(void);
260
263
265 int local_type_id(vrpn_int32 remote_type) const;
266
268 int local_sender_id(vrpn_int32 remote_sender) const;
269
270 virtual vrpn_bool doing_okay(void) const = 0;
272
275
276 void init(void);
277
278 virtual int mainloop(timeval *timeout) = 0;
279
284
288 int newLocalSender(const char *name, vrpn_int32 which);
289 int newLocalType(const char *name, vrpn_int32 which);
290
294 int newRemoteType(vrpn_CNAME type_name, vrpn_int32 remote_id,
295 vrpn_int32 local_id);
296 int newRemoteSender(vrpn_CNAME sender_name, vrpn_int32 remote_id,
297 vrpn_int32 local_id);
299
302 virtual int pack_message(vrpn_uint32 len, struct timeval time,
303 vrpn_int32 type, vrpn_int32 sender,
304 const char *buffer,
305 vrpn_uint32 class_of_service) = 0;
306
310 virtual int send_pending_reports(void) = 0;
311
312 int pack_log_description(void);
314
315 virtual int setup_new_connection(void) = 0;
318
319 virtual void poll_for_cookie(const timeval *timeout = NULL) = 0;
320 virtual int finish_new_connection_setup(void) = 0;
321
322 virtual void drop_connection(void) = 0;
326
327 virtual void clearBuffers(void) = 0;
330
331 int pack_sender_description(vrpn_int32 which);
333
334 int pack_type_description(vrpn_int32 which);
336
339
343
347
351 char rhostname[150];
352
357
360
361 void setLogNames(const char *inName, const char *outName);
362 int openLogs(void);
364
369 static int VRPN_CALLBACK
370 handle_sender_message(void *userdata, vrpn_HANDLERPARAM p);
371 static int VRPN_CALLBACK
372 handle_type_message(void *userdata, vrpn_HANDLERPARAM p);
374
378 void setConnection(vrpn_Connection *conn) { d_parent = conn; }
381
382protected:
383 virtual int dispatch(vrpn_int32 type, vrpn_int32 sender, timeval time,
384 vrpn_uint32 payload_len, char *bufptr);
385
386 int tryToMarshall(char *outbuf, vrpn_int32 &buflen, vrpn_int32 &numOut,
387 vrpn_uint32 len, timeval time, vrpn_int32 type,
388 vrpn_int32 sender, const char *buffer,
389 vrpn_uint32 classOfService);
393
394 int marshall_message(char *outbuf, vrpn_uint32 outbuf_size,
395 vrpn_uint32 initial_out, vrpn_uint32 len,
396 struct timeval time, vrpn_int32 type,
397 vrpn_int32 sender, const char *buffer,
398 vrpn_uint32 sequenceNumber);
399
400 // The senders and types we know about that have been described by
401 // the other end of the connection. Also, record the local mapping
402 // for ones that have been described with the same name locally.
403 // The arrays are indexed by the ID from the other side, and store
404 // the name and local ID that corresponds to each.
405
408
411
413};
414
422
424
425public:
427 vrpn_int32 *connectedEndpointCounter);
428 virtual ~vrpn_Endpoint_IP(void);
429
432 virtual vrpn_bool doing_okay(void) const;
433
435 vrpn_bool outbound_udp_open(void) const;
436
437 vrpn_int32 tcp_outbuf_size(void) const;
438 vrpn_int32 udp_outbuf_size(void) const;
440
443
444 void init(void);
445
446 int mainloop(timeval *timeout);
447
452 int pack_message(vrpn_uint32 len, struct timeval time, vrpn_int32 type,
453 vrpn_int32 sender, const char *buffer,
454 vrpn_uint32 class_of_service);
455
460 virtual int send_pending_reports(void);
461
462 int pack_udp_description(int portno);
463
464 int handle_tcp_messages(const timeval *timeout);
465 int handle_udp_messages(const timeval *timeout);
466
467 int connect_tcp_to(const char *msg);
468 int connect_tcp_to(const char *addr, int port);
471 int connect_udp_to(const char *addr, int port);
475
476 int setup_new_connection(void);
479
480 void poll_for_cookie(const timeval *timeout = NULL);
482
483 void drop_connection(void);
487
488 void clearBuffers(void);
491
492 void setNICaddress(const char *);
493
497
499
503
509
513
517
518 vrpn_bool d_tcp_only;
523
524protected:
525 int getOneTCPMessage(int fd, char *buf, size_t buflen);
526 int getOneUDPMessage(char *buf, size_t buflen);
527
535
538 vrpn_int32 d_tcpBuflen;
539 vrpn_int32 d_udpBuflen;
540 vrpn_int32 d_tcpNumOut;
541 vrpn_int32 d_udpNumOut;
542
545
546 vrpn_float64
548 1];
549 vrpn_float64
551 1];
554
556};
557
563
564protected:
569 vrpn_Connection(const char *local_in_logfile_name,
570 const char *local_out_logfile_name,
572
576 vrpn_Connection(const char *local_in_logfile_name,
577 const char *local_out_logfile_name,
578 const char *remote_in_logfile_name,
579 const char *remote_out_logfile_name,
581
582public:
583 virtual ~vrpn_Connection(void);
584
586 virtual vrpn_bool doing_okay(void) const;
587
591 virtual vrpn_bool connected(void) const;
592
599 void get_log_names(char **local_in_logname, char **local_out_logname,
600 char **remote_in_logname, char **remote_out_logname);
601
609 virtual int mainloop(const struct timeval *timeout = NULL) = 0;
610
613 virtual vrpn_int32 register_sender(const char *name);
614 virtual vrpn_int32 register_message_type(const char *name);
615
621 virtual int register_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler,
622 void *userdata,
623 vrpn_int32 sender = vrpn_ANY_SENDER);
624 virtual int unregister_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler,
625 void *userdata,
626 vrpn_int32 sender = vrpn_ANY_SENDER);
627
630 virtual int pack_message(vrpn_uint32 len, struct timeval time,
631 vrpn_int32 type, vrpn_int32 sender,
632 const char *buffer, vrpn_uint32 class_of_service);
633
637 virtual int send_pending_reports(void) = 0;
638
641 virtual int time_since_connection_open(struct timeval *elapsed_time);
642
645 virtual timeval get_time();
646
650 virtual const char *sender_name(vrpn_int32 sender);
651 virtual const char *message_type_name(vrpn_int32 type);
652
660 virtual int register_log_filter(vrpn_LOGFILTER filter, void *userdata);
661
663 virtual int save_log_so_far();
664
668
689 void Jane_stop_this_crazy_thing(vrpn_uint32 stop_looking_after)
690 {
691 d_stop_processing_messages_after = stop_looking_after;
692 };
693 vrpn_uint32 get_Jane_value(void)
694 {
696 };
697
698protected:
703
705
712 vrpn_int32 *connectedEC);
713
714#ifdef _MSC_VER
715#pragma warning(push)
716// Disable "need dll interface" warning on these members
717#pragma warning(disable : 4251)
718#endif
722
726
727#ifdef _MSC_VER
728#pragma warning(pop)
729#endif
735
738 static int VRPN_CALLBACK
739 handle_log_message(void *userdata, vrpn_HANDLERPARAM p);
740 static int VRPN_CALLBACK
743
744private:
745 void init(vrpn_EndpointAllocator
746 epa);
747protected:
748 int delete_endpoint(vrpn_Endpoint *endpoint);
749 int compact_endpoints(void);
750
751 virtual int pack_sender_description(vrpn_int32 which);
753
754 virtual int pack_type_description(vrpn_int32 which);
756
757 virtual int do_callbacks_for(vrpn_int32 type, vrpn_int32 sender,
758 struct timeval time, vrpn_uint32 len,
759 const char *buffer);
760
762 int message_type_is_registered(const char *) const;
763
765 timeval start_time;
766
767 //
769public:
770 void addReference();
771 void removeReference();
772
773private:
774 int d_references;
775
776 //
787public:
788 void setAutoDeleteStatus(bool setvalue) { d_autoDeleteStatus = setvalue; }
789
790private:
791 bool d_autoDeleteStatus;
792
793public:
798
800
801protected:
803
812
813 // vrpn_Endpoint * d_serverLogEndpoint;
815 vrpn_int32 d_serverLogMode;
817
819
820 virtual void updateEndpoints(void);
826};
827
829
830protected:
842 vrpn_Connection_IP(const char *server_name,
844 const char *local_in_logfile_name = NULL,
845 const char *local_out_logfile_name = NULL,
846 const char *remote_in_logfile_name = NULL,
847 const char *remote_out_logfile_name = NULL,
848 const char *NIC_IPaddress = NULL,
850
851public:
856 unsigned short listen_port_no = vrpn_DEFAULT_LISTEN_PORT_NO,
857 const char *local_in_logfile_name = NULL,
858 const char *local_out_logfile_name = NULL,
859 const char *NIC_IPaddress = NULL,
861 vrpn_int32 *) = allocateEndpoint);
862
863 virtual ~vrpn_Connection_IP(void);
864
867 virtual int connect_to_client(const char *machine, int port);
868
876 virtual int mainloop(const struct timeval *timeout = NULL);
877
878protected:
883
885 const char *cname, const char *local_in_logfile_name,
886 const char *local_out_logfile_name, const char *remote_in_logfile_name,
887 const char *remote_out_logfile_name, const char *NIC_IPaddress,
888 bool force_connection);
890 vrpn_create_server_connection(const char *cname,
891 const char *local_in_logfile_name,
892 const char *local_out_logfile_name);
893
899
901 static int VRPN_CALLBACK
902 handle_UDP_message(void *userdata, vrpn_HANDLERPARAM p);
903
905 void init(void);
906
911 virtual int send_pending_reports(void);
912
916 virtual void
917 server_check_for_incoming_connections(const struct timeval *timeout = NULL);
918
922 virtual void handle_connection(vrpn_Endpoint *endpoint);
923
927 virtual void drop_connection(vrpn_Endpoint *endpoint);
928
933
934 char *d_NIC_IP;
935};
936
942
944
945protected:
951
952public:
953 virtual ~vrpn_Connection_Loopback(void);
954
961 virtual int mainloop(const struct timeval *timeout = NULL);
962
964 virtual vrpn_bool doing_okay(void) const { return vrpn_true; }
965
969 virtual vrpn_bool connected(void) const { return vrpn_true; }
970
971protected:
973 vrpn_create_server_connection(const char *cname,
974 const char *local_in_logfile_name,
975 const char *local_out_logfile_name);
976
981 virtual int send_pending_reports(void) { return 0; }
982};
983
994 const char *cname, const char *local_in_logfile_name = NULL,
995 const char *local_out_logfile_name = NULL,
996 const char *remote_in_logfile_name = NULL,
997 const char *remote_out_logfile_name = NULL,
998 const char *NIC_IPaddress = NULL, bool force_reopen = false);
999
1017vrpn_create_server_connection(const char *cname,
1018 const char *local_in_logfile_name = NULL,
1019 const char *local_out_logfile_name = NULL);
1020
1027 const char *local_in_logfile_name = NULL,
1028 const char *local_out_logfile_name = NULL,
1029 const char *NIC_NAME = NULL)
1030{
1031 char name[256];
1032 if (NIC_NAME == NULL) {
1033 snprintf(name, 256, ":%d", port);
1034 }
1035 else {
1036 snprintf(name, 256, "%.200s:%d", NIC_NAME, port);
1037 }
1038 return vrpn_create_server_connection(name, local_in_logfile_name,
1039 local_out_logfile_name);
1040}
1041
1046VRPN_API char *vrpn_copy_service_name(const char *fullname);
1047VRPN_API char *vrpn_copy_service_location(const char *fullname);
1049
1057VRPN_API char *vrpn_copy_file_name(const char *filespecifier);
1058
1074VRPN_API char *vrpn_copy_machine_name(const char *hostspecifier);
1075VRPN_API int vrpn_get_port_number(const char *hostspecifier);
1076VRPN_API char *vrpn_copy_rsh_program(const char *hostspecifier);
1077VRPN_API char *vrpn_copy_rsh_arguments(const char *hostspecifier);
1079
1081char *vrpn_set_service_name(const char *specifier, const char *newServiceName);
1082
1088VRPN_API int check_vrpn_cookie(const char *buffer);
1089VRPN_API int check_vrpn_file_cookie(const char *buffer);
1091
1094VRPN_API size_t vrpn_cookie_size(void);
1095
1096VRPN_API int write_vrpn_cookie(char *buffer, size_t length,
1097 long remote_log_mode);
1098
1102#ifndef VRPN_USE_WINSOCK_SOCKETS
1103int VRPN_API
1104vrpn_noint_block_write(int outfile, const char buffer[], size_t length);
1105int VRPN_API vrpn_noint_block_read(int infile, char buffer[], size_t length);
1106int VRPN_API vrpn_noint_select(int width, fd_set *readfds, fd_set *writefds,
1107 fd_set *exceptfds, struct timeval *timeout);
1108#else /* winsock sockets */
1109int VRPN_API
1110vrpn_noint_block_write(vrpn_SOCKET outsock, char *buffer, size_t length);
1111int VRPN_API vrpn_noint_block_read(vrpn_SOCKET insock, char *buffer, size_t length);
1112#endif /* VRPN_USE_WINSOCK_SOCKETS */
1114
1126
1127// This section holds data structures and functions to open
1128// connections by name.
1129// The intention of this section is that it can open connections for
1130// objects that are in different libraries (trackers, buttons and sound),
1131// even if they all refer to the same connection.
1132// Even though each individual vrpn_Connection class is not yet thread
1133// safe, so should only have its methods called from a single thread,
1134// the vrpn_ConnectionManager should be thread safe to allow connections
1135// to be created and destroyed by different threads.
1136
1137class VRPN_API vrpn_ConnectionManager {
1138
1139public:
1140 ~vrpn_ConnectionManager(void);
1141
1147 static vrpn_ConnectionManager &instance(void);
1148
1152 void addConnection(vrpn_Connection *, const char *name);
1155
1158 vrpn_Connection *getByName(const char *name);
1159
1160private:
1162 vrpn_Semaphore d_semaphore;
1163
1164 struct knownConnection {
1165 char name[1000];
1166 vrpn_Connection *connection;
1167 knownConnection *next;
1168 };
1169
1171 knownConnection *d_kcList;
1172
1174 knownConnection *d_anonList;
1175
1176 vrpn_ConnectionManager(void);
1177
1178 // @brief copy constructor undefined to prevent instantiations
1179 vrpn_ConnectionManager(const vrpn_ConnectionManager &);
1180
1181 void deleteConnection(vrpn_Connection *, knownConnection **);
1182};
1183
1184#endif // VRPN_CONNECTION_H
Combines the function pointer for an Endpoint Allocator with its two arguments into a single callable...
return_type operator()() const
Default, fully pre-bound.
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.
void addConnection(vrpn_Connection *, const char *name)
NB implementation is not particularly efficient; we expect to have O(10) connections,...
vrpn_Connection * getByName(const char *name)
Searches through d_kcList but NOT d_anonList (Connections constructed with no name)
void deleteConnection(vrpn_Connection *)
static vrpn_ConnectionManager & instance(void)
The only way to get access to an instance of this class. Guarantees that there is only one,...
vrpn_SOCKET listen_udp_sock
UDP Connect requests come here.
virtual void handle_connection(vrpn_Endpoint *endpoint)
This routine is called by a server-side connection when a new connection has just been established,...
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...
virtual int mainloop(const struct timeval *timeout=NULL)
Call each time through program main loop to handle receiving any incoming messages and sending any pa...
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()....
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,...
virtual int send_pending_reports(void)
send pending report, clear the buffer.
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 serv...
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 ...
virtual void server_check_for_incoming_connections(const struct timeval *timeout=NULL)
static int VRPN_CALLBACK handle_UDP_message(void *userdata, vrpn_HANDLERPARAM p)
Routines that handle system messages.
vrpn_SOCKET listen_tcp_sock
TCP Connection requests come here.
void init(void)
Called by all constructors.
vrpn_Connection_Loopback()
Make a client connection. To access this from user code, call vrpn_create_server_connection() with a ...
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...
virtual int mainloop(const struct timeval *timeout=NULL)
Call each time through program main loop to handle receiving any incoming messages and sending any pa...
Generic connection class not specific to the transport mechanism.
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...
virtual int do_callbacks_for(vrpn_int32 type, vrpn_int32 sender, struct timeval time, vrpn_uint32 len, const char *buffer)
int delete_endpoint(vrpn_Endpoint *endpoint)
Deletes the endpoint and NULLs the entry in the list of open endpoints.
void addReference()
Counting references to this connection.
virtual int time_since_connection_open(struct timeval *elapsed_time)
Returns the time since the connection opened. Some subclasses may redefine time.
virtual void updateEndpoints(void)
This function will be called on the mainloop() iteration after *d_endpointAllocator is called,...
virtual timeval get_time()
returns the current time in the connection (since the epoch – UTC time).
static int VRPN_CALLBACK handle_log_message(void *userdata, vrpn_HANDLERPARAM p)
Routines that handle system messages.
int message_type_is_registered(const char *) const
Returns message type ID, or -1 if unregistered.
virtual const char * sender_name(vrpn_int32 sender)
Returns the name of the specified sender/type, or NULL if the parameter is invalid....
int doSystemCallbacksFor(vrpn_HANDLERPARAM, void *)
virtual vrpn_int32 register_message_type(const char *name)
virtual vrpn_bool connected(void) const
Returns vrpn_true if the connection has been established, vrpn_false if not (For a networkless connec...
virtual int pack_sender_description(vrpn_int32 which)
Send the sender description to ALL endpoints.
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...
int compact_endpoints(void)
Makes sure the endpoint array is set up cleanly for the next pass through.
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,...
static vrpn_Endpoint_IP * allocateEndpoint(vrpn_Connection *, vrpn_int32 *connectedEC)
Redefining this and passing it to constructors allows a subclass to use a different subclass of Endpo...
virtual vrpn_File_Connection * get_File_Connection(void)
vrpn_File_Connection implements this as "return this" so it can be used to detect a File_Connection a...
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...
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 yo...
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
virtual int pack_type_description(vrpn_int32 which)
Send the type description to ALL endpoints.
vrpn::EndpointContainer d_endpoints
Sockets used to talk to remote Connection(s) and other information needed on a per-connection basis.
virtual int save_log_so_far()
Save any messages on any endpoints which have been logged so far.
virtual const char * message_type_name(vrpn_int32 type)
vrpn_uint32 get_Jane_value(void)
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 failur...
virtual vrpn_bool doing_okay(void) const
Returns vrpn_true if the connection is okay, vrpn_false if not.
virtual int unregister_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
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 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...
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.
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 handl...
static int VRPN_CALLBACK handle_disconnect_message(void *userdata, vrpn_HANDLERPARAM p)
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...
vrpn_int32 tcp_outbuf_size(void) const
vrpn_float64 d_udpAlignedInbuf[vrpn_CONNECTION_UDP_BUFLEN/sizeof(vrpn_float64)+1]
vrpn_SOCKET d_tcpSocket
int handle_udp_messages(const timeval *timeout)
void setNICaddress(const char *)
int connect_tcp_to(const char *msg)
void clearBuffers(void)
Empties out the TCP and UDP send buffers. Needed by vrpn_FileConnection to get at {udp,...
virtual vrpn_bool doing_okay(void) const
vrpn_SOCKET d_udpOutboundSocket
vrpn_int32 d_udpSequenceNumber
virtual int send_pending_reports(void)
send pending report, clear the buffer.
timeval d_last_connect_attempt
When the last UDP lob occurred.
vrpn_bool outbound_udp_open(void) const
True if the UDP outbound is open, False if not.
int handle_tcp_messages(const timeval *timeout)
char * d_remote_machine_name
Machine to call.
vrpn_SOCKET d_udpLobSocket
Socket to use to lob UDP requests asking for the server to call us back.
int getOneTCPMessage(int fd, char *buf, size_t buflen)
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...
vrpn_Endpoint_IP(vrpn_TypeDispatcher *dispatcher, vrpn_int32 *connectedEndpointCounter)
int d_remote_port_number
Port to connect to on remote machine.
int pack_udp_description(int portno)
vrpn_SOCKET d_tcpListenSocket
This section deals with when a client connection is trying to establish (or re-establish) a connectio...
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.
vrpn_SOCKET d_udpInboundSocket
Inbound unreliable messages come here. Need one for each due to different clock synchronization for e...
int getOneUDPMessage(char *buf, size_t buflen)
int mainloop(timeval *timeout)
int connect_udp_to(const char *addr, int port)
Connects d_udpSocket to the specified address and port; returns 0 on success, sets status to BROKEN a...
vrpn_int32 udp_outbuf_size(void) const
vrpn_float64 d_tcpAlignedInbuf[vrpn_CONNECTION_TCP_BUFLEN/sizeof(vrpn_float64)+1]
int setup_new_connection(void)
Sends the magic cookie and other information to its peer. It is called by both the client and server ...
void poll_for_cookie(const timeval *timeout=NULL)
vrpn_int32 d_tcpSequenceNumber
int finish_new_connection_setup(void)
void drop_connection(void)
Should only be called by vrpn_Connection::drop_connection(), since there's more housecleaning to do a...
Encapsulation of the data and methods for a single generic connection to take care of one part of man...
void setConnection(vrpn_Connection *conn)
int local_type_id(vrpn_int32 remote_type) const
Returns the local mapping for the remote type (-1 if none).
vrpn_Log * d_outLog
static int VRPN_CALLBACK handle_type_message(void *userdata, vrpn_HANDLERPARAM p)
virtual vrpn_bool doing_okay(void) const =0
long d_remoteLogMode
Mode to put the remote logging in.
int newRemoteType(vrpn_CNAME type_name, vrpn_int32 remote_id, vrpn_int32 local_id)
Adds a new remote type/sender and returns its index. Returns -1 on error.
void clear_other_senders_and_types(void)
Clear out the remote mapping list. This is done when a connection is dropped and we want to try and r...
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 ...
int pack_sender_description(vrpn_int32 which)
Packs a sender description over our socket.
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...
char rhostname[150]
static int VRPN_CALLBACK handle_sender_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 * d_connectionCounter
int newRemoteSender(vrpn_CNAME sender_name, vrpn_int32 remote_id, vrpn_int32 local_id)
char * d_remoteInLogName
Name of the remote log file.
int pack_log_description(void)
Packs the log description set by setup_new_connection().
int newLocalType(const char *name, vrpn_int32 which)
vrpn_Endpoint(vrpn_TypeDispatcher *dispatcher, vrpn_int32 *connectedEndpointCounter)
int local_sender_id(vrpn_int32 remote_sender) const
Returns the local mapping for the remote sender (-1 if none).
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
int newLocalSender(const char *name, vrpn_int32 which)
A new local sender or type has been established; set the local type for it if the other side has decl...
int pack_type_description(vrpn_int32 which)
Packs a type description.
vrpn_Log * d_inLog
virtual void clearBuffers(void)=0
Empties out the TCP and UDP send buffers. Needed by vrpn_FileConnection to get at {udp,...
void setLogNames(const char *inName, const char *outName)
vrpn_TranslationTable * d_types
char * d_remoteOutLogName
Name of the remote log file.
Logs a VRPN stream.
Definition vrpn_Log.h:10
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.
const char * buffer
struct timeval msg_time
Placed here so vrpn_FileConnection can use it too.
vrpn_LOGLIST * next
vrpn_HANDLERPARAM data
vrpn_LOGLIST * prev
class VRPN_API vrpn_Connection
Definition vrpn_3Space.h:7
#define VRPN_API
#define vrpn_DEFAULT_LISTEN_PORT_NO
#define VRPN_CALLBACK
const char * vrpn_CONTROL
vrpn_CONTROL is the sender used for notification messages sent to the user from the local VRPN implem...
const char * vrpn_got_first_connection
These are the strings that define the system-generated message types that tell when connections are r...
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).
const char * vrpn_dropped_last_connection
const char * vrpn_dropped_connection
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 char * vrpn_got_connection
const long vrpn_LOG_NONE
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...
class VRPN_API vrpn_Log
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
class VRPN_API vrpn_Endpoint_IP
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 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).
const vrpn_uint32 vrpn_CONNECTION_FIXED_LATENCY
VRPN_API char * vrpn_copy_service_location(const char *fullname)
class VRPN_API vrpn_File_Connection
class VRPN_API vrpn_TypeDispatcher
class VRPN_API vrpn_TranslationTable
const int vrpn_CONNECTION_MAX_TYPES
const vrpn_uint32 vrpn_CONNECTION_LOW_LATENCY
const unsigned vrpn_CNAME_LENGTH
Length of names within VRPN.
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
char vrpn_CNAME[vrpn_CNAME_LENGTH]
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)....
@ LISTEN
@ CONNECTED
@ TRYING_TO_CONNECT
@ LOGGING
@ BROKEN
@ COOKIE_PENDING
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)
class VRPN_API vrpn_Endpoint
#define vrpn_SOCKET
Definition vrpn_Shared.h:54