RflySimSDK v3.08
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_Connection.h
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
22/// This is the list of states that a connection can be in
23/// (possible values for status). doing_okay() returns VRPN_TRUE
24/// for connections > BROKEN.
25enum vrpn_ConnectionStatus {
26 LISTEN = (1),
27 CONNECTED = (0),
28 COOKIE_PENDING = (-1),
29 TRYING_TO_CONNECT = (-2),
30 BROKEN = (-3),
31 LOGGING = (-4)
32};
33
34class VRPN_API
35 vrpn_File_Connection; // Forward declaration for get_File_Connection()
36
37/// @brief This structure is what is passed to a vrpn_Connection message
38/// callback.
39///
40/// It is used by objects, but not normally by user code.
42 vrpn_int32 type;
43 vrpn_int32 sender;
44 struct timeval msg_time;
45 vrpn_int32 payload_len;
46 const char *buffer;
47};
48
49/// @brief Type of a message handler for vrpn_Connection messages.
50typedef int(VRPN_CALLBACK *vrpn_MESSAGEHANDLER)(void *userdata,
52
53/// @brief Type of handler for filters on logfiles is the same as connection
54/// handler
55typedef vrpn_MESSAGEHANDLER vrpn_LOGFILTER;
56
57/// VRPN buffers are aligned on 8 byte boundaries so that we can pack and
58/// unpack doubles into them on architectures that cannot handle unaligned
59/// access.
60const unsigned vrpn_ALIGN = 8;
61
62/// Types now have their storage dynamically allocated, so we can afford
63/// to have large tables. We need at least 150-200 for the microscope
64/// project as of Jan 98, and will eventually need two to three times that
65/// number.
66/// @{
67const int vrpn_CONNECTION_MAX_SENDERS = 2000;
68const int vrpn_CONNECTION_MAX_TYPES = 2000;
69/// @}
70
71/// @brief vrpn_ANY_SENDER can be used to register callbacks on a given message
72/// type from any sender.
73
74const int vrpn_ANY_SENDER = -1;
75
76/// @brief vrpn_ANY_TYPE can be used to register callbacks for any USER type of
77/// message from a given sender. System messages are handled separately.
78
79const int vrpn_ANY_TYPE = -1;
80
81/// @name Buffer lengths for TCP and UDP.
82///
83/// TCP is an arbitrary number but it must match the receiver's buffer
84/// size so it needs to remain the same for a given major VRPN version
85/// number.
86/// UDP is set based on Ethernet maximum transmission size; trying
87/// to send a message via UDP which is longer than the MTU of any
88/// intervening physical network may cause untraceable failures,
89/// so for now we do not expose any way to change the UDP output
90/// buffer size. (MTU = 1500 bytes, - 28 bytes of IP+UDP header)
91/// @{
92
93const int vrpn_CONNECTION_TCP_BUFLEN = 64000;
94const int vrpn_CONNECTION_UDP_BUFLEN = 1472;
95/// @}
96
97/// @brief Number of endpoints that a server connection can have. Arbitrary
98/// limit.
99
100const int vrpn_MAX_ENDPOINTS = 256;
101
102/// @name System message types
103/// @{
104const vrpn_int32 vrpn_CONNECTION_SENDER_DESCRIPTION = (-1);
105const vrpn_int32 vrpn_CONNECTION_TYPE_DESCRIPTION = (-2);
106const vrpn_int32 vrpn_CONNECTION_UDP_DESCRIPTION = (-3);
107const vrpn_int32 vrpn_CONNECTION_LOG_DESCRIPTION = (-4);
108const vrpn_int32 vrpn_CONNECTION_DISCONNECT_MESSAGE = (-5);
109/// @}
110
111/// Classes of service for messages, specify multiple by ORing them together
112/// Priority of satisfying these should go from the top down (RELIABLE will
113/// override all others).
114/// Most of these flags may be ignored, but RELIABLE is guaranteed
115/// to be available.
116/// @{
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
124/// @}
125
126/// @name What to log
127/// @{
128const long vrpn_LOG_NONE = (0);
129const long vrpn_LOG_INCOMING = (1 << 0);
130const long vrpn_LOG_OUTGOING = (1 << 1);
131/// @}
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
138/// These are the strings that define the system-generated message
139/// types that tell when connections are received and dropped.
140/// @{
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;
145/// @}
146
147/// @brief vrpn_CONTROL is the sender used for notification messages sent to the
148/// user
149/// from the local VRPN implementation (got_first_connection, etc.)
150/// and for control messages sent by auxiliary services. (Such as
151/// class vrpn_Controller, which will be introduced in a future revision.)
152
153extern VRPN_API const char *vrpn_CONTROL;
154
155/// @brief Length of names within VRPN
156const unsigned vrpn_CNAME_LENGTH = 100;
157typedef char vrpn_CNAME[vrpn_CNAME_LENGTH];
158
159/// Placed here so vrpn_FileConnection can use it too.
160struct VRPN_API vrpn_LOGLIST {
162 vrpn_LOGLIST *next;
163 vrpn_LOGLIST *prev;
164};
165
166class VRPN_API vrpn_Endpoint_IP;
167class VRPN_API vrpn_Connection;
168
169/// @brief Function pointer to an endpoint allocator.
170typedef vrpn_Endpoint_IP *(*vrpn_EndpointAllocator)(
171 vrpn_Connection *connection, vrpn_int32 *numActiveConnections);
172
173namespace vrpn {
174
175 /// @brief Combines the function pointer for an Endpoint Allocator with its
176 /// two arguments into a single callable object, with the ability to
177 /// override the last parameter at call time.
179 public:
181 : epa_(NULL)
182 , conn_(NULL)
183 , numActiveEndpoints_(NULL)
184 {
185 }
186 BoundEndpointAllocator(vrpn_EndpointAllocator epa,
187 vrpn_Connection *conn,
188 vrpn_int32 *numActiveEndpoints = NULL)
189 : epa_(epa)
190 , conn_(conn)
191 , numActiveEndpoints_(numActiveEndpoints)
192 {
193 }
194
196
197 /// @brief Default, fully pre-bound
199 {
200 if (!epa_) {
201 return NULL;
202 }
203 return (*epa_)(conn_, numActiveEndpoints_);
204 }
205
206 /// @brief Overload, with alternate num active connnection pointer.
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:
216 vrpn_EndpointAllocator epa_;
217 vrpn_Connection *conn_;
218 vrpn_int32 *numActiveEndpoints_;
219 };
220} // namespace vrpn
221/// @todo HACK
222/// These structs must be declared outside of vrpn_Connection
223/// (although we'd like to make them protected/private members)
224/// because aCC on PixelFlow doesn't handle nested classes correctly.
225/// @{
226
227/// @brief Description of a callback entry for a user type.
229 vrpn_MESSAGEHANDLER handler; ///< Routine to call
230 void *userdata; ///< Passed along
231 vrpn_int32 sender; ///< Only if from sender
232 vrpnMsgCallbackEntry *next; ///< Next handler
233};
234
236 vrpn_LOGFILTER filter; ///< routine to call
237 void *userdata; ///< passed along
238 vrpnLogFilterEntry *next;
239};
240/// @}
241
242class VRPN_API vrpn_Connection;
243class VRPN_API vrpn_Log;
244class VRPN_API vrpn_TranslationTable;
245class VRPN_API vrpn_TypeDispatcher;
246
247/// @brief Encapsulation of the data and methods for a single generic connection
248/// to take care of one part of many clients talking to a single server.
249///
250/// This will only be used from within the vrpn_Connection class; it should
251/// not be instantiated by users or devices.
252/// Should not be visible!
253
254class VRPN_API vrpn_Endpoint {
255
256public:
257 vrpn_Endpoint(vrpn_TypeDispatcher *dispatcher,
258 vrpn_int32 *connectedEndpointCounter);
259 virtual ~vrpn_Endpoint(void);
260
261 /// @name Accessors
262 /// @{
263
264 /// Returns the local mapping for the remote type (-1 if none).
265 int local_type_id(vrpn_int32 remote_type) const;
266
267 /// Returns the local mapping for the remote sender (-1 if none).
268 int local_sender_id(vrpn_int32 remote_sender) const;
269
270 virtual vrpn_bool doing_okay(void) const = 0;
271 /// @}
272
273 /// @name Manipulators
274 /// @{
275
276 void init(void);
277
278 virtual int mainloop(timeval *timeout) = 0;
279
280 /// Clear out the remote mapping list. This is done when a
281 /// connection is dropped and we want to try and re-establish
282 /// it.
284
285 /// A new local sender or type has been established; set
286 /// the local type for it if the other side has declared it.
287 /// Return 1 if the other side has one, 0 if not.
288 int newLocalSender(const char *name, vrpn_int32 which);
289 int newLocalType(const char *name, vrpn_int32 which);
290
291 /// Adds a new remote type/sender and returns its index.
292 /// Returns -1 on error.
293 /// @{
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);
298 /// @}
299
300 /// Pack a message that will be sent the next time mainloop() is called.
301 /// Turn off the RELIABLE flag if you want low-latency (UDP) send.
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
307 /// send pending report, clear the buffer.
308 /// This function was protected, now is public, so we can use it
309 /// to send out intermediate results without calling mainloop
310 virtual int send_pending_reports(void) = 0;
311
313 ///< Packs the log description set by setup_new_connection().
314
315 virtual int setup_new_connection(void) = 0;
316 ///< Sends the magic cookie and other information to its
317 ///< peer. It is called by both the client and server setup routines.
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;
323 ///< Should only be called by vrpn_Connection::drop_connection(),
324 ///< since there's more housecleaning to do at that level. I suppose
325 ///< that argues against separating this function out.
326
327 virtual void clearBuffers(void) = 0;
328 ///< Empties out the TCP and UDP send buffers.
329 ///< Needed by vrpn_FileConnection to get at {udp,tcp}NumOut.
330
331 int pack_sender_description(vrpn_int32 which);
332 ///< Packs a sender description over our socket.
333
334 int pack_type_description(vrpn_int32 which);
335 ///< Packs a type description.
336
337 /// @}
338 int status;
339
340 /// @todo XXX These should be protected; making them so will lead to making
341 /// the code split the functions between Endpoint and Connection
342 /// protected:
343
344 long d_remoteLogMode; ///< Mode to put the remote logging in
345 char *d_remoteInLogName; ///< Name of the remote log file
346 char *d_remoteOutLogName; ///< Name of the remote log file
347
348 ///< Name of the remote host we are connected to. This is kept for
349 ///< informational purposes. It is printed by the ceiling server,
350 ///< for example.
351 char rhostname[150];
352
353 /// @name Logging
354 ///
355 /// TCH 19 April 00; changed into two logs 16 Feb 01
356 /// @{
357
358 vrpn_Log *d_inLog;
359 vrpn_Log *d_outLog;
360
361 void setLogNames(const char *inName, const char *outName);
362 int openLogs(void);
363 /// @}
364
365 /// @name Routines that handle system messages
366 ///
367 /// Visible so that vrpn_Connection can pass them to the Dispatcher
368 /// @{
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);
373 /// @}
374
375 /// @name Routines to inform the endpoint of the connection of
376 /// which it is a part.
377 /// @{
378 void setConnection(vrpn_Connection *conn) { d_parent = conn; }
379 vrpn_Connection *getConnection() { return d_parent; }
380 /// @}
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);
390 ///< Calls marshall_message(); if that fails, calls
391 ///< send_pending_reports() and then marshalls again.
392 ///< Returns the number of characters successfully marshalled.
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
406 vrpn_TranslationTable *d_senders;
407 vrpn_TranslationTable *d_types;
408
409 vrpn_TypeDispatcher *d_dispatcher;
410 vrpn_int32 *d_connectionCounter;
411
412 vrpn_Connection *d_parent;
413};
414
415/// @brief Encapsulation of the data and methods for a single IP-based
416/// connection
417/// to take care of one part of many clients talking to a single server.
418///
419/// This will only be used from within the vrpn_Connection_IP class; it should
420/// not be instantiated by users or devices.
421/// Should not be visible!
422
423class VRPN_API vrpn_Endpoint_IP : public vrpn_Endpoint {
424
425public:
426 vrpn_Endpoint_IP(vrpn_TypeDispatcher *dispatcher,
427 vrpn_int32 *connectedEndpointCounter);
428 virtual ~vrpn_Endpoint_IP(void);
429
430 /// @name Accessors
431 /// @{
432 virtual vrpn_bool doing_okay(void) const;
433
434 /// True if the UDP outbound is open, False if not.
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;
439 /// @}
440
441 /// @name Manipulators
442 /// @{
443
444 void init(void);
445
446 int mainloop(timeval *timeout);
447
448 /// @brief Pack a message that will be sent the next time mainloop() is
449 /// called.
450 ///
451 /// Turn off the RELIABLE flag if you want low-latency (UDP) send.
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
456 /// @brief send pending report, clear the buffer.
457 ///
458 /// This function was protected, now is public, so we can use it
459 /// to send out intermediate results without calling mainloop
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);
469 ///< Connects d_tcpSocket to the specified address (msg = "IP port");
470 ///< sets status to COOKIE_PENDING; returns 0 on success, -1 on failure
471 int connect_udp_to(const char *addr, int port);
472 ///< Connects d_udpSocket to the specified address and port;
473 ///< returns 0 on success, sets status to BROKEN and returns -1
474 ///< on failure.
475
477 ///< Sends the magic cookie and other information to its
478 ///< peer. It is called by both the client and server setup routines.
479
480 void poll_for_cookie(const timeval *timeout = NULL);
481 int finish_new_connection_setup(void);
482
483 void drop_connection(void);
484 ///< Should only be called by vrpn_Connection::drop_connection(),
485 ///< since there's more housecleaning to do at that level. I suppose
486 ///< that argues against separating this function out.
487
488 void clearBuffers(void);
489 ///< Empties out the TCP and UDP send buffers.
490 ///< Needed by vrpn_FileConnection to get at {udp,tcp}NumOut.
491
492 void setNICaddress(const char *);
493
494 /// @todo XXX These should be protected; making them so will lead to making
495 /// the code split the functions between Endpoint and Connection
496 /// protected:
497
498 vrpn_SOCKET d_tcpSocket;
499
500 /// This section deals with when a client connection is trying to
501 /// establish (or re-establish) a connection with its server. It
502 /// keeps track of what we need to know to make this happen.
503
504 vrpn_SOCKET d_tcpListenSocket;
506 ///< Socket and port that the client listens on
507 ///< when lobbing datagrams at the server and
508 ///< waiting for it to call back.
509
510 /// Socket to use to lob UDP requests asking for the server to
511 /// call us back.
512 vrpn_SOCKET d_udpLobSocket;
513
514 char *d_remote_machine_name; ///< Machine to call
515 int d_remote_port_number; ///< Port to connect to on remote machine
516 timeval d_last_connect_attempt; ///< When the last UDP lob occurred
517
518 vrpn_bool d_tcp_only;
519 ///< For connections made through firewalls or NAT with the
520 ///< tcp: URL, we do not want to allow the endpoints on either
521 ///< end to open a UDP link to their counterparts. If this is
522 ///< the case, then this flag should be set to true.
523
524protected:
525 int getOneTCPMessage(int fd, char *buf, size_t buflen);
526 int getOneUDPMessage(char *buf, size_t buflen);
527
528 vrpn_SOCKET d_udpOutboundSocket;
530 ///< Inbound unreliable messages come here.
531 ///< Need one for each due to different
532 ///< clock synchronization for each; we
533 ///< need to know which server each message is from.
534 ///< @todo XXX Now that we don't need multiple clocks, can we collapse this?
535
536 char *d_tcpOutbuf;
537 char *d_udpOutbuf;
538 vrpn_int32 d_tcpBuflen;
539 vrpn_int32 d_udpBuflen;
540 vrpn_int32 d_tcpNumOut;
541 vrpn_int32 d_udpNumOut;
542
543 vrpn_int32 d_tcpSequenceNumber;
544 vrpn_int32 d_udpSequenceNumber;
545
546 vrpn_float64
547 d_tcpAlignedInbuf[vrpn_CONNECTION_TCP_BUFLEN / sizeof(vrpn_float64) +
548 1];
549 vrpn_float64
550 d_udpAlignedInbuf[vrpn_CONNECTION_UDP_BUFLEN / sizeof(vrpn_float64) +
551 1];
552 char *d_tcpInbuf;
553 char *d_udpInbuf;
554
555 char *d_NICaddress;
556};
557
558/// @brief Generic connection class not specific to the transport mechanism.
559///
560/// It abstracts all of the common functions. Specific implementations
561/// for IP, MPI, and other transport mechanisms follow.
562class VRPN_API vrpn_Connection {
563
564protected:
565 /// Constructor for server connection. This cannot be called
566 /// directly any more because vrpn_Connection is an abstract base
567 /// class. Call vrpn_create_server_connection() to make a server
568 /// of arbitrary type based on a name.
569 vrpn_Connection(const char *local_in_logfile_name,
570 const char *local_out_logfile_name,
571 vrpn_EndpointAllocator epa = allocateEndpoint);
572
573 /// Constructor for client connection. This cannot be called
574 /// directly because vrpn_Connection is an abstract base class.
575 /// Call vrpn_get_connection_by_name() to create a client connection.
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,
580 vrpn_EndpointAllocator epa = allocateEndpoint);
581
582public:
583 virtual ~vrpn_Connection(void);
584
585 /// Returns vrpn_true if the connection is okay, vrpn_false if not
586 virtual vrpn_bool doing_okay(void) const;
587
588 /// Returns vrpn_true if the connection has been established, vrpn_false if
589 /// not
590 /// (For a networkless connection, this is equivalent to doing_okay()).
591 virtual vrpn_bool connected(void) const;
592
593 /// This function returns the logfile names of this connection in
594 /// the parameters. It will allocate memory for the name of each
595 /// log file in use. If no logging of a particular type is happening,
596 /// then *(X_Y_logname) will be set to NULL.
597 /// IMPORTANT: code calling this function is responsible for freeing
598 /// the memory allocated for these strings.
599 void get_log_names(char **local_in_logname, char **local_out_logname,
600 char **remote_in_logname, char **remote_out_logname);
601
602 /// Call each time through program main loop to handle receiving any
603 /// incoming messages and sending any packed messages.
604 /// Returns -1 when connection dropped due to error, 0 otherwise.
605 /// (only returns -1 once per connection drop).
606 /// Optional argument is TOTAL time to block on select() calls;
607 /// there may be multiple calls to select() per call to mainloop(),
608 /// and this timeout will be divided evenly between them.
609 virtual int mainloop(const struct timeval *timeout = NULL) = 0;
610
611 /// Get a token to use for the string name of the sender or type.
612 /// Remember to check for -1 meaning failure.
613 virtual vrpn_int32 register_sender(const char *name);
614 virtual vrpn_int32 register_message_type(const char *name);
615
616 /// Set up (or remove) a handler for a message of a given type.
617 /// Optionally, specify which sender to handle messages from.
618 /// Handlers will be called during mainloop().
619 /// Your handler should return 0 or a communication error is assumed
620 /// and the connection will be shut down.
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
628 /// Pack a message that will be sent the next time mainloop() is called.
629 /// Turn off the RELIABLE flag if you want low-latency (UDP) send.
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
634 /// send pending report, clear the buffer.
635 /// This function was protected, now is public, so we can use it
636 /// to send out intermediate results without calling mainloop
637 virtual int send_pending_reports(void) = 0;
638
639 /// Returns the time since the connection opened.
640 /// Some subclasses may redefine time.
641 virtual int time_since_connection_open(struct timeval *elapsed_time);
642
643 /// returns the current time in the connection (since the epoch -- UTC
644 /// time).
645 virtual timeval get_time();
646
647 /// Returns the name of the specified sender/type, or NULL
648 /// if the parameter is invalid. Only works for user
649 /// messages (type >= 0).
650 virtual const char *sender_name(vrpn_int32 sender);
651 virtual const char *message_type_name(vrpn_int32 type);
652
653 /// @brief Sets up a filter function for logging.
654 /// Any user message to be logged is first passed to this function,
655 /// and will only be logged if the function returns zero (XXX).
656 /// NOTE: this only affects local logging - remote logging
657 /// is unfiltered! Only user messages are filtered; all system
658 /// messages are logged.
659 /// Returns nonzero on failure.
660 virtual int register_log_filter(vrpn_LOGFILTER filter, void *userdata);
661
662 /// Save any messages on any endpoints which have been logged so far.
663 virtual int save_log_so_far();
664
665 /// vrpn_File_Connection implements this as "return this" so it
666 /// can be used to detect a File_Connection and get the pointer for it
668
669 /// This function should be seldom used. It is here for the case of
670 /// the vrpn_Imager, whose servers do not follow "The VRPN Way" because
671 /// they try to jam more data into the network than there is bandwidth
672 /// to support it. As a result, a client may call mainloop() on the
673 /// connection and have it never return -- there is always more data
674 /// in the network to read, so we never hand control back to the main
675 /// program. The reason for the name comes from an old U.S. cartoon
676 /// called "The Jetsons". In it, George Jetson is running on a
677 /// treadmill when it goes out of control and starts spinning so fast
678 /// that he can't even run fast enough to reach the controls and turn
679 /// it off. He cries out to his wife, "Jane! Stop this crazy thing!"
680 /// The parameter specifies a trigger: if more than the specified number
681 /// of messages come in on a given input channel during one mainloop()
682 /// call, the connection should stop looking for more messages. NOTE:
683 /// this does not guarantee that only this many messages will be received,
684 /// only that the connection will stop looking for new ones on a given
685 /// channel once that many have been received (for example, UDP channels
686 /// will parse all the rest of the messages in a packet before stopping).
687 /// A value of 0 turns off the limit, and will cause all incoming messages
688 /// to be handled before returning.
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 {
695 return d_stop_processing_messages_after;
696 };
697
698protected:
699 /// If this value is greater than zero, the connection should stop
700 /// looking for new messages on a given endpoint after this many
701 /// are found.
703
704 int connectionStatus; ///< Status of the connection
705
706 /// Redefining this and passing it to constructors
707 /// allows a subclass to use a different subclass of Endpoint.
708 /// It should do NOTHING but return an endpoint
709 /// of the appropriate class; it may not access subclass data,
710 /// since it'll be called from a constructor
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
719 /// Function object wrapping an endpoint allocator and binding its
720 /// arguments.
722
723 /// Sockets used to talk to remote Connection(s)
724 /// and other information needed on a per-connection basis
726
727#ifdef _MSC_VER
728#pragma warning(pop)
729#endif
731 ///< We need to track the number of connected endpoints separately
732 ///< to properly send out got-first-connection/dropped-last-connection
733 ///< messages. This value is *managed* by the Endpoints, but we
734 ///< need exactly one copy per Connection, so it's on the Connection.
735
736 /// @brief Routines that handle system messages
737 /// @{
738 static int VRPN_CALLBACK
740 static int VRPN_CALLBACK
741 handle_disconnect_message(void *userdata, vrpn_HANDLERPARAM p);
742 /// @}
743
744private:
745 void init(vrpn_EndpointAllocator
746 epa); ///< Base initialization for all constructors.
747protected:
748 int delete_endpoint(vrpn_Endpoint *endpoint);
749 int compact_endpoints(void);
750
751 virtual int pack_sender_description(vrpn_int32 which);
752 ///< Send the sender description to ALL endpoints.
753
754 virtual int pack_type_description(vrpn_int32 which);
755 ///< Send the type description to ALL endpoints.
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
761 /// Returns message type ID, or -1 if unregistered
762 int message_type_is_registered(const char *) const;
763
764 /// Timekeeping - TCH 30 June 98
765 timeval start_time;
766
767 //
768 /// Counting references to this connection.
769public:
771 void removeReference();
772
773private:
774 int d_references;
775
776 //
777 /// Specify whether this connection should be deleted automatically when
778 /// it is no longer need (reference count reaches zero).
779 /// For connections created by the VRPN code (as is done in
780 /// get_connection_by_name) these should be auto-deleted.
781 /// Connections created by user code should not be auto-deleted;
782 /// that is up to the user to decide when finished.
783 /// By default, the constructor sets this to FALSE.
784 /// VRPN code (or user code) can set this to TRUE if it wants the
785 /// connection to be deleted automatically when the last service on it
786 /// is deleted
787public:
788 void setAutoDeleteStatus(bool setvalue) { d_autoDeleteStatus = setvalue; }
789
790private:
791 bool d_autoDeleteStatus; ///< FALSE by default.
792
793public:
794 /// Derived classes need access to d_dispatcher in their
795 /// allocateEndpoint() routine. Several compilers won't give it to
796 /// them, even if they do inherit publicly. Until we figure that
797 /// out, d_dispatcher needs to be public.
798
799 vrpn_TypeDispatcher *d_dispatcher;
800
801protected:
802 int doSystemCallbacksFor(vrpn_HANDLERPARAM, void *);
803
804 /// Server logging w. multiconnection - TCH July 00
805 /// Use one "hidden" endpoint for outgoing logs (?),
806 /// standard per-endpoint logs with augmented names for incoming.
807 /// To make a hidden endpoint we create d_endpoints[0] and increment
808 /// the d_numEndpoints, but DON'T pass it d_numConnectedEndpoints
809 /// (although it should be safe to do so, since it should never truly
810 /// become connected, but we might have to "fake" it to get it to log
811 /// correctly).
812
813 // vrpn_Endpoint * d_serverLogEndpoint;
815 vrpn_int32 d_serverLogMode;
816 char *d_serverLogName;
817
818 vrpn_bool d_updateEndpoint;
819
820 virtual void updateEndpoints(void);
821 ///< This function will be called on the mainloop() iteration
822 ///< after *d_endpointAllocator is called, which lets subclasses
823 ///< do initialization. (They can't do so during allocateEndpoint
824 ///< because it's called during the Connection constructor when
825 ///< their constructors haven't executed yet.)
826};
827
828class VRPN_API vrpn_Connection_IP : public vrpn_Connection {
829
830protected:
831 /// Make a client connection. To access this from user code,
832 /// call vrpn_get_connection_by_name().
833 /// Create a connection - if server_name is not a file: name,
834 /// makes an SDI-like connection to the named remote server
835 /// (otherwise functions as a non-networked messaging hub).
836 /// Port less than zero forces default.
837 /// Currently, server_name is an extended URL that defaults
838 /// to VRPN connections at the port, but can be file:: to read
839 /// from a file. Other extensions should maintain this, so
840 /// that VRPN uses URLs to name things that are to be connected
841 /// to.
842 vrpn_Connection_IP(const char *server_name,
843 int port = vrpn_DEFAULT_LISTEN_PORT_NO,
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,
849 vrpn_EndpointAllocator epa = allocateEndpoint);
850
851public:
852 /// Make a server that listens for client connections.
853 /// DEPRECATED: Call vrpn_create_server_connection() with the
854 /// NIC name and port number you want.
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
865 /// This is similar to check connection except that it can be
866 /// used to receive requests from before a server starts up
867 virtual int connect_to_client(const char *machine, int port);
868
869 /// Call each time through program main loop to handle receiving any
870 /// incoming messages and sending any packed messages.
871 /// Returns -1 when connection dropped due to error, 0 otherwise.
872 /// (only returns -1 once per connection drop).
873 /// Optional argument is TOTAL time to block on select() calls;
874 /// there may be multiple calls to select() per call to mainloop(),
875 /// and this timeout will be divided evenly between them.
876 virtual int mainloop(const struct timeval *timeout = NULL);
877
878protected:
879 /// If this value is greater than zero, the connection should stop
880 /// looking for new messages on a given endpoint after this many
881 /// are found.
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);
889 friend VRPN_API vrpn_Connection *
891 const char *local_in_logfile_name,
892 const char *local_out_logfile_name);
893
894 /// @name Only used for a vrpn_Connection that awaits incoming connections
895 /// @{
896 vrpn_SOCKET listen_udp_sock; ///< UDP Connect requests come here
897 vrpn_SOCKET listen_tcp_sock; ///< TCP Connection requests come here
898 /// @}
899
900 /// Routines that handle system messages
901 static int VRPN_CALLBACK
903
904 /// @brief Called by all constructors
905 void init(void);
906
907 /// @brief send pending report, clear the buffer.
908 ///
909 /// This function was protected, now is public, so we can use it
910 /// to send out intermediate results without calling mainloop
911 virtual int send_pending_reports(void);
912
913 //// This is called by a server-side process to see if there have
914 //// been any UDP packets come in asking for a connection. If there
915 //// are, it connects the TCP port and then calls handle_connection().
916 virtual void
917 server_check_for_incoming_connections(const struct timeval *timeout = NULL);
918
919 /// This routine is called by a server-side connection when a
920 /// new connection has just been established, and the tcp port
921 /// has been connected to it.
922 virtual void handle_connection(vrpn_Endpoint *endpoint);
923
924 /// Drops the connection with the given, non-NULL endpoint. Depending on if
925 /// we're a server or a client, this may result in the endpoints needing
926 /// compacting once you're no longer iterating on the endpoint container.
927 virtual void drop_connection(vrpn_Endpoint *endpoint);
928
929 /// Like drop_connection, except it includes the call to compact the
930 /// endpoints. Only safe to call if you can guarantee no iterators are open
931 /// to the container, since compact invalidates them.
933
934 char *d_NIC_IP;
935};
936
937/// @brief Constructor for a Loopback connection that will basically just
938/// pass messages between objects that are connected to it. It offers no
939/// external connections, via IP or any other mechanism. It is useful
940/// if you want to make the client and server in the same connection and
941/// you don't need to have anything else connect.
942
944
945protected:
946 /// Make a client connection. To access this from user code,
947 /// call vrpn_create_server_connection() with a service name
948 /// of 'loopback:'.
949 /// For now, we don't enable logging on a Loopback connection.
951
952public:
953 virtual ~vrpn_Connection_Loopback(void);
954
955 /// Call each time through program main loop to handle receiving any
956 /// incoming messages and sending any packed messages.
957 /// Returns -1 on error, 0 otherwise.
958 /// Optional argument is TOTAL time to block on select() calls;
959 /// there may be multiple calls to select() per call to mainloop(),
960 /// and this timeout will be divided evenly between them.
961 virtual int mainloop(const struct timeval *timeout = NULL);
962
963 /// Returns vrpn_true if the connection is okay, vrpn_false if not
964 virtual vrpn_bool doing_okay(void) const { return vrpn_true; }
965
966 /// Returns vrpn_true if the connection has been established, vrpn_false if
967 /// not
968 /// (For a networkless connection, this is equivalent to doing_okay()).
969 virtual vrpn_bool connected(void) const { return vrpn_true; }
970
971protected:
972 friend VRPN_API vrpn_Connection *
974 const char *local_in_logfile_name,
975 const char *local_out_logfile_name);
976
977 /// @brief send pending report, clear the buffer.
978 ///
979 /// This function was protected, now is public, so we can use it
980 /// to send out intermediate results without calling mainloop
981 virtual int send_pending_reports(void) { return 0; }
982};
983
984/// @brief Create a client connection of arbitrary type (VRPN UDP/TCP, TCP,
985/// File, Loopback, MPI).
986///
987/// WARNING: May not be thread safe.
988/// If no IP address for the NIC to use is specified, uses the default
989/// NIC. If the force_reopen flag is set, a new connection will be
990/// made even if there was already one to that server.
991/// When done with the object, call removeReference() on it (which will
992/// delete it if there are no other references).
993VRPN_API vrpn_Connection *vrpn_get_connection_by_name(
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
1000/// @brief Create a server connection of arbitrary type (VRPN UDP/TCP,
1001/// TCP, File, Loopback, MPI).
1002///
1003/// Returns NULL if the name is not understood or the connection cannot
1004/// be created.
1005/// WARNING: May not be thread safe.
1006/// To create a VRPN TCP/UDP server, use a name like:
1007/// vrpn:machine_name_or_ip:port
1008/// machine_name_or_ip:port
1009/// machine_name_or_ip
1010/// :port (This port on any network card.)
1011/// To create an MPI server, use a name like:
1012/// mpi:MPI_COMM_WORLD
1013/// mpi:comm_number
1014/// When done with the object, call removeReference() on it (which will
1015/// delete it if there are no other references).
1016VRPN_API vrpn_Connection *
1017vrpn_create_server_connection(const char *cname,
1018 const char *local_in_logfile_name = NULL,
1019 const char *local_out_logfile_name = NULL);
1020
1021/// Lets you make one with the default settings, or just ask for a specific
1022/// port number on the default NIC on this machine. This matches the
1023/// signature on the old constructor to make it easier to port existing
1024/// servers.
1025inline VRPN_API vrpn_Connection *
1026vrpn_create_server_connection(int port = vrpn_DEFAULT_LISTEN_PORT_NO,
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
1042/// @name Utility routines to parse names (<service>@<location specifier>)
1043/// Both return new char [], and it is the caller's responsibility
1044/// to delete this memory!
1045/// @{
1046VRPN_API char *vrpn_copy_service_name(const char *fullname);
1047VRPN_API char *vrpn_copy_service_location(const char *fullname);
1048/// @}
1049
1050/// @brief Utility routines to parse file specifiers FROM service locations
1051///
1052/// file:<filename>
1053///
1054/// file://<hostname>/<filename>
1055///
1056/// file:///<filename>
1057VRPN_API char *vrpn_copy_file_name(const char *filespecifier);
1058
1059/// @name Utility routines to parse host specifiers FROM service locations
1060///
1061/// <hostname>
1062///
1063/// <hostname>:<port number>
1064///
1065/// x-vrpn://<hostname>
1066///
1067/// x-vrpn://<hostname>:<port number>
1068///
1069/// x-vrsh://<hostname>/<server program>,<comma-separated server arguments>
1070///
1071/// The caller is responsible for calling delete [] on the returned character
1072/// pointer if it is not NULL.
1073/// @{
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);
1078/// @}
1079
1080/// @brief Utility routine to rename the service name of a given host specifier.
1081char *vrpn_set_service_name(const char *specifier, const char *newServiceName);
1082
1083/// Checks the buffer to see if it is a valid VRPN header cookie.
1084/// Returns -1 on total mismatch,
1085/// 1 on minor version mismatch or other acceptable difference,
1086/// and 0 on exact match.
1087/// @{
1088VRPN_API int check_vrpn_cookie(const char *buffer);
1089VRPN_API int check_vrpn_file_cookie(const char *buffer);
1090/// @}
1091
1092/// @brief Returns the size of the magic cookie buffer, plus any alignment
1093/// overhead.
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
1099/// @name Utility routines for reading from and writing to sockets/file
1100/// descriptors
1101/// @{
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 */
1113 /// @}
1114
1115/**
1116 * @brief Singleton class that keeps track of all known VRPN connections
1117 * and makes sure they're deleted on shutdown.
1118 *
1119 * We make it static to guarantee that the destructor is called
1120 * on program close so that the destructors of all the vrpn_Connections
1121 * that have been allocated are called so that all open logs are flushed
1122 * to disk. Each connection should add itself to this list in its
1123 * constructor and should remove itself from this list in its
1124 * destructor.
1125 */
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
1138
1139public:
1141
1142 /// @brief The only way to get access to an instance of this class.
1143 /// Guarantees that there is only one, global object.
1144 /// Also guarantees that it will be constructed the first time
1145 /// this function is called, and (hopefully?) destructed when
1146 /// the program terminates.
1148
1149 /// NB implementation is not particularly efficient; we expect
1150 /// to have O(10) connections, not O(1000).
1151 /// @{
1152 void addConnection(vrpn_Connection *, const char *name);
1153 void deleteConnection(vrpn_Connection *);
1154 /// @}
1155
1156 /// Searches through d_kcList but NOT d_anonList
1157 /// (Connections constructed with no name)
1158 vrpn_Connection *getByName(const char *name);
1159
1160private:
1161 /// Mutex to ensure thread safety;
1162 vrpn_Semaphore d_semaphore;
1163
1164 struct knownConnection {
1165 char name[1000];
1166 vrpn_Connection *connection;
1167 knownConnection *next;
1168 };
1169
1170 /// @brief named connections
1171 knownConnection *d_kcList;
1172
1173 /// @brief unnamed (server) connections
1174 knownConnection *d_anonList;
1175
1177
1178 // @brief copy constructor undefined to prevent instantiations
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...
定义 vrpn_Connection.h:178
return_type operator()(vrpn_int32 *alternateNumActiveEndpoints) const
Overload, with alternate num active connnection pointer.
定义 vrpn_Connection.h:207
return_type operator()() const
Default, fully pre-bound
定义 vrpn_Connection.h:198
Container for endpoints, held by pointer.
定义 vrpn_EndpointContainer.h:55
Singleton class that keeps track of all known VRPN connections and makes sure they're deleted on shut...
定义 vrpn_Connection.h:1137
void addConnection(vrpn_Connection *, const char *name)
static vrpn_ConnectionManager & instance(void)
The only way to get access to an instance of this class. Guarantees that there is only one,...
vrpn_Connection * getByName(const char *name)
定义 vrpn_Connection.h:828
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)
virtual int mainloop(const struct timeval *timeout=NULL)
void drop_connection_and_compact(vrpn_Endpoint *endpoint)
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
定义 vrpn_Connection.h:897
void init(void)
Called by all constructors
vrpn_uint32 d_stop_processing_messages_after
定义 vrpn_Connection.h:882
virtual void handle_connection(vrpn_Endpoint *endpoint)
friend VRPN_API 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).
virtual int send_pending_reports(void)
send pending report, clear the buffer.
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)
friend VRPN_API 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).
vrpn_SOCKET listen_udp_sock
UDP Connect requests come here
定义 vrpn_Connection.h:896
virtual int connect_to_client(const char *machine, int port)
virtual void drop_connection(vrpn_Endpoint *endpoint)
Constructor for a Loopback connection that will basically just pass messages between objects that are...
定义 vrpn_Connection.h:943
virtual int mainloop(const struct timeval *timeout=NULL)
virtual vrpn_bool doing_okay(void) const
Returns vrpn_true if the connection is okay, vrpn_false if not
定义 vrpn_Connection.h:964
virtual vrpn_bool connected(void) const
定义 vrpn_Connection.h:969
friend VRPN_API 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).
virtual int send_pending_reports(void)
send pending report, clear the buffer.
定义 vrpn_Connection.h:981
Generic connection class not specific to the transport mechanism.
定义 vrpn_Connection.h:562
vrpn_int32 d_numConnectedEndpoints
定义 vrpn_Connection.h:730
virtual int time_since_connection_open(struct timeval *elapsed_time)
virtual timeval get_time()
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)
vrpn::BoundEndpointAllocator d_boundEndpointAllocator
定义 vrpn_Connection.h:721
void addReference()
Counting references to this connection.
vrpn::EndpointContainer d_endpoints
定义 vrpn_Connection.h:725
virtual vrpn_bool doing_okay(void) const
Returns vrpn_true if the connection is okay, vrpn_false if not
virtual vrpn_int32 register_sender(const char *name)
static vrpn_Endpoint_IP * allocateEndpoint(vrpn_Connection *, vrpn_int32 *connectedEC)
void setAutoDeleteStatus(bool setvalue)
定义 vrpn_Connection.h:788
virtual vrpn_File_Connection * get_File_Connection(void)
virtual int pack_sender_description(vrpn_int32 which)
Send the sender description to ALL endpoints.
virtual void updateEndpoints(void)
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...
vrpn_Connection(const char *local_in_logfile_name, const char *local_out_logfile_name, vrpn_EndpointAllocator epa=allocateEndpoint)
virtual int register_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
vrpn_uint32 d_stop_processing_messages_after
定义 vrpn_Connection.h:702
virtual vrpn_bool connected(void) const
virtual int send_pending_reports(void)=0
void get_log_names(char **local_in_logname, char **local_out_logname, char **remote_in_logname, char **remote_out_logname)
vrpn_TypeDispatcher * d_dispatcher
定义 vrpn_Connection.h:799
virtual int save_log_so_far()
Save any messages on any endpoints which have been logged so far.
void Jane_stop_this_crazy_thing(vrpn_uint32 stop_looking_after)
定义 vrpn_Connection.h:689
virtual int pack_message(vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)
virtual int pack_type_description(vrpn_int32 which)
Send the type description to ALL endpoints.
int d_serverLogCount
定义 vrpn_Connection.h:814
timeval start_time
Timekeeping - TCH 30 June 98
定义 vrpn_Connection.h:765
static int VRPN_CALLBACK handle_log_message(void *userdata, vrpn_HANDLERPARAM p)
Routines that handle system messages
virtual const char * sender_name(vrpn_int32 sender)
virtual int mainloop(const struct timeval *timeout=NULL)=0
int connectionStatus
Status of the connection
定义 vrpn_Connection.h:704
int message_type_is_registered(const char *) const
Returns message type ID, or -1 if unregistered
Encapsulation of the data and methods for a single IP-based connection to take care of one part of ma...
定义 vrpn_Connection.h:423
vrpn_SOCKET d_udpInboundSocket
定义 vrpn_Connection.h:529
char * d_remote_machine_name
Machine to call
定义 vrpn_Connection.h:514
int d_tcpListenPort
定义 vrpn_Connection.h:505
vrpn_bool outbound_udp_open(void) const
True if the UDP outbound is open, False if not.
void clearBuffers(void)
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.
int d_remote_port_number
Port to connect to on remote machine
定义 vrpn_Connection.h:515
timeval d_last_connect_attempt
When the last UDP lob occurred
定义 vrpn_Connection.h:516
int setup_new_connection(void)
virtual int send_pending_reports(void)
send pending report, clear the buffer.
void drop_connection(void)
vrpn_SOCKET d_udpLobSocket
定义 vrpn_Connection.h:512
int connect_udp_to(const char *addr, int port)
vrpn_SOCKET d_tcpListenSocket
定义 vrpn_Connection.h:504
vrpn_bool d_tcp_only
定义 vrpn_Connection.h:518
vrpn_SOCKET d_tcpSocket
定义 vrpn_Connection.h:498
int connect_tcp_to(const char *addr, int port)
Encapsulation of the data and methods for a single generic connection to take care of one part of man...
定义 vrpn_Connection.h:254
char * d_remoteOutLogName
Name of the remote log file
定义 vrpn_Connection.h:346
int newLocalSender(const char *name, vrpn_int32 which)
int local_type_id(vrpn_int32 remote_type) const
Returns the local mapping for the remote type (-1 if none).
int local_sender_id(vrpn_int32 remote_sender) const
Returns the local mapping for the remote sender (-1 if none).
int pack_log_description(void)
Packs the log description set by setup_new_connection().
int tryToMarshall(char *outbuf, vrpn_int32 &buflen, vrpn_int32 &numOut, vrpn_uint32 len, timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 classOfService)
long d_remoteLogMode
Mode to put the remote logging in
定义 vrpn_Connection.h:344
int pack_type_description(vrpn_int32 which)
Packs a type description.
int newRemoteType(vrpn_CNAME type_name, vrpn_int32 remote_id, vrpn_int32 local_id)
char * d_remoteInLogName
Name of the remote log file
定义 vrpn_Connection.h:345
void clear_other_senders_and_types(void)
virtual void clearBuffers(void)=0
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
virtual int send_pending_reports(void)=0
virtual void drop_connection(void)=0
virtual int setup_new_connection(void)=0
int pack_sender_description(vrpn_int32 which)
Packs a sender description over our socket.
定义 vrpn_FileConnection.h:73
定义 vrpn_Log.h:10
定义 vrpn_Thread.h:63
定义 vrpn_Connection.h:235
vrpn_LOGFILTER filter
routine to call
定义 vrpn_Connection.h:236
void * userdata
passed along
定义 vrpn_Connection.h:237
Description of a callback entry for a user type.
定义 vrpn_Connection.h:228
vrpn_int32 sender
Only if from sender
定义 vrpn_Connection.h:231
vrpnMsgCallbackEntry * next
Next handler
定义 vrpn_Connection.h:232
vrpn_MESSAGEHANDLER handler
Routine to call
定义 vrpn_Connection.h:229
void * userdata
Passed along
定义 vrpn_Connection.h:230
This structure is what is passed to a vrpn_Connection message callback.
定义 vrpn_Connection.h:41
Placed here so vrpn_FileConnection can use it too.
定义 vrpn_Connection.h:160