vrpn  07.33
Virtual Reality Peripheral Network
vrpn_Text.h
Go to the documentation of this file.
1 /* vrpn_Text.h
2  Definition of user-level access to the text sending and retrieving
3  functions within VRPN. These are wrappers around the vrpn_BaseClass
4  routines, since basic text functions have been pulled into these
5  classes.
6 */
7 
8 #ifndef VRPN_TEXT_H
9 #include <stddef.h> // for NULL
10 
11 #include "vrpn_BaseClass.h" // for vrpn_BaseClass, etc
12 #include "vrpn_Configure.h" // for VRPN_API, VRPN_CALLBACK
13 #include "vrpn_Connection.h" // for vrpn_Connection, etc
14 #include "vrpn_Shared.h" // for timeval
15 #include "vrpn_Types.h" // for vrpn_uint32
16 
17 // text-message time value meaning "go find out what time it is right now"
18 const struct timeval vrpn_TEXT_NOW = {0, 0};
19 
21 typedef struct _vrpn_TEXTCB {
22  struct timeval msg_time; // Time of the message
23  char message[vrpn_MAX_TEXT_LEN]; // The message
25  vrpn_uint32 level;
26 } vrpn_TEXTCB;
27 
29 typedef void(VRPN_CALLBACK *vrpn_TEXTHANDLER)(void *userdata,
30  const vrpn_TEXTCB info);
31 
32 //----------------------------------------------------------
33 //************** Users deal with the following *************
34 
36 // the send_text_message() function is protected). It provides
37 // the needed function definitions for vrpn_BaseClass.
38 
40 public:
41  vrpn_Text_Sender(const char *name, vrpn_Connection *c = NULL)
42  : vrpn_BaseClass(name, c)
43  {
44  init();
45  };
46 
48  void mainloop(void)
49  {
51  if (d_connection) d_connection->mainloop();
52  };
53 
55  int send_message(const char *msg,
57  vrpn_uint32 level = 0,
58  const struct timeval time = vrpn_TEXT_NOW);
59 
60 protected:
62  virtual int register_types(void) { return 0; };
63 };
64 
66 // standard VRPN printing functions handle them.
67 
69 public:
70  vrpn_Text_Receiver(const char *name, vrpn_Connection *c = NULL);
71  virtual ~vrpn_Text_Receiver(void);
72  virtual int register_message_handler(void *userdata,
73  vrpn_TEXTHANDLER handler)
74  {
75  return d_callback_list.register_handler(userdata, handler);
76  };
77 
78  virtual int unregister_message_handler(void *userdata,
79  vrpn_TEXTHANDLER handler)
80  {
81  return d_callback_list.unregister_handler(userdata, handler);
82  }
83 
84  virtual void mainloop(void)
85  {
86  if (d_connection) {
87  d_connection->mainloop();
88  };
90  };
91 
92 protected:
93  static int VRPN_CALLBACK
94  handle_message(void *userdata, vrpn_HANDLERPARAM p);
96 
98  virtual int register_types(void) { return 0; };
99 };
100 
101 #define VRPN_TEXT_H
102 #endif
vrpn_Text_Sender::vrpn_Text_Sender
vrpn_Text_Sender(const char *name, vrpn_Connection *c=NULL)
Definition: vrpn_Text.h:41
vrpn_BaseClassUnique::client_mainloop
void client_mainloop(void)
Handles functions that all clients should provide in their mainloop() (warning of no server,...
Definition: vrpn_BaseClass.C:637
vrpn_TEXTCB::level
vrpn_uint32 level
Definition: vrpn_Text.h:25
vrpn_BaseClass.h
vrpn_Text_Receiver::mainloop
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition: vrpn_Text.h:84
vrpn_MAX_TEXT_LEN
const unsigned vrpn_MAX_TEXT_LEN
Definition: vrpn_BaseClass.h:105
vrpn_Types.h
vrpn_Text_Receiver
Allows a user to handle text messages directly, in addition too having the.
Definition: vrpn_Text.h:68
vrpn_Text_Receiver::register_types
virtual int register_types(void)
No types to register beyond the text, which is done in BaseClass.
Definition: vrpn_Text.h:98
vrpn_Text_Sender
Allows a user to send text messages from a device (usually,.
Definition: vrpn_Text.h:39
vrpn_Callback_List< vrpn_TEXTCB >
vrpn_Text_Sender::mainloop
void mainloop(void)
Mainloop the connection to send the message.
Definition: vrpn_Text.h:48
vrpn_TEXTHANDLER
void(VRPN_CALLBACK * vrpn_TEXTHANDLER)(void *userdata, const vrpn_TEXTCB info)
Description of the callback function type.
Definition: vrpn_Text.h:29
vrpn_Text_Receiver::register_message_handler
virtual int register_message_handler(void *userdata, vrpn_TEXTHANDLER handler)
Definition: vrpn_Text.h:72
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
Definition: vrpn_Connection.h:44
vrpn_Shared.h
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition: vrpn_Connection.h:510
vrpn_Connection.h
vrpn_TEXTCB
Structure passed back to user-level code from a vrpn_Text_Receiver.
Definition: vrpn_Text.h:21
vrpn_Text_Sender::register_types
virtual int register_types(void)
No types to register beyond the text, which is done in BaseClass.
Definition: vrpn_Text.h:62
VRPN_CALLBACK
#define VRPN_CALLBACK
Definition: vrpn_Configure.h:647
vrpn_TEXT_NORMAL
@ vrpn_TEXT_NORMAL
Definition: vrpn_BaseClass.h:101
vrpn_BaseClass::init
virtual int init(void)
Initialize things that the constructor can't. Returns 0 on success, -1 on failure.
Definition: vrpn_BaseClass.C:363
vrpn_TEXT_SEVERITY
vrpn_TEXT_SEVERITY
Since the sending of text messages has been pulled into the base class (so that every object can send...
Definition: vrpn_BaseClass.h:100
vrpn_TEXTCB::type
vrpn_TEXT_SEVERITY type
Definition: vrpn_Text.h:24
vrpn_Text_Receiver::unregister_message_handler
virtual int unregister_message_handler(void *userdata, vrpn_TEXTHANDLER handler)
Definition: vrpn_Text.h:78
vrpn_Configure.h
VRPN_API
#define VRPN_API
Definition: vrpn_Configure.h:646
vrpn_BaseClassUnique::server_mainloop
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Definition: vrpn_BaseClass.C:603
vrpn_BaseClass
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
Definition: vrpn_BaseClass.h:313
vrpn_TEXT_NOW
const struct timeval vrpn_TEXT_NOW
Definition: vrpn_Text.h:18
vrpn_Text_Receiver::d_callback_list
vrpn_Callback_List< vrpn_TEXTCB > d_callback_list
Definition: vrpn_Text.h:95