vrpn 07.35
Virtual Reality Peripheral Network
 
Loading...
Searching...
No Matches
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#define VRPN_TEXT_H
10#include <stddef.h> // for NULL
11
12#include "vrpn_BaseClass.h" // for vrpn_BaseClass, etc
13#include "vrpn_Configure.h" // for VRPN_API, VRPN_CALLBACK
14#include "vrpn_Connection.h" // for vrpn_Connection, etc
15#include "vrpn_Shared.h" // for timeval
16#include "vrpn_Types.h" // for vrpn_uint32
17
18// text-message time value meaning "go find out what time it is right now"
19const struct timeval vrpn_TEXT_NOW = {0, 0};
20
22typedef struct _vrpn_TEXTCB {
23 struct timeval msg_time; // Time of the message
24 char message[vrpn_MAX_TEXT_LEN]; // The message
26 vrpn_uint32 level;
28
30typedef void(VRPN_CALLBACK *vrpn_TEXTHANDLER)(void *userdata,
31 const vrpn_TEXTCB info);
32
33//----------------------------------------------------------
34//************** Users deal with the following *************
35
37// the send_text_message() function is protected). It provides
38// the needed function definitions for vrpn_BaseClass.
39
41public:
42 vrpn_Text_Sender(const char *name, vrpn_Connection *c = NULL)
43 : vrpn_BaseClass(name, c)
44 {
45 init();
46 };
47
49 void mainloop(void)
50 {
52 if (d_connection) d_connection->mainloop();
53 };
54
56 int send_message(const char *msg,
58 vrpn_uint32 level = 0,
59 const struct timeval time = vrpn_TEXT_NOW);
60
61protected:
63 virtual int register_types(void) { return 0; };
64};
65
67// standard VRPN printing functions handle them.
68
70public:
71 vrpn_Text_Receiver(const char *name, vrpn_Connection *c = NULL);
72 virtual ~vrpn_Text_Receiver(void);
75 {
76 return d_callback_list.register_handler(userdata, handler);
77 };
78
81 {
82 return d_callback_list.unregister_handler(userdata, handler);
83 }
84
85 virtual void mainloop(void)
86 {
87 if (d_connection) {
88 d_connection->mainloop();
89 };
91 };
92
93protected:
94 static int VRPN_CALLBACK
95 handle_message(void *userdata, vrpn_HANDLERPARAM p);
97
99 virtual int register_types(void) { return 0; };
100};
101
102#endif
vrpn_Connection * d_connection
Connection that this object talks to.
void client_mainloop(void)
Handles functions that all clients should provide in their mainloop() (warning of no server,...
vrpn_MESSAGEHANDLER handler
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
vrpn_BaseClass(const char *name, vrpn_Connection *c=NULL)
Names the device and assigns or opens connection, calls registration methods.
virtual int init(void)
Initialize things that the constructor can't. Returns 0 on success, -1 on failure.
Generic connection class not specific to the transport mechanism.
virtual int register_types(void)
No types to register beyond the text, which is done in BaseClass.
Definition vrpn_Text.h:99
virtual int unregister_message_handler(void *userdata, vrpn_TEXTHANDLER handler)
Definition vrpn_Text.h:79
vrpn_Text_Receiver(const char *name, vrpn_Connection *c=NULL)
Definition vrpn_Text.C:21
virtual void mainloop(void)
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
Definition vrpn_Text.h:85
vrpn_Callback_List< vrpn_TEXTCB > d_callback_list
Definition vrpn_Text.h:96
virtual int register_message_handler(void *userdata, vrpn_TEXTHANDLER handler)
Definition vrpn_Text.h:73
vrpn_Text_Sender(const char *name, vrpn_Connection *c=NULL)
Definition vrpn_Text.h:42
virtual int register_types(void)
No types to register beyond the text, which is done in BaseClass.
Definition vrpn_Text.h:63
void mainloop(void)
Mainloop the connection to send the message.
Definition vrpn_Text.h:49
This structure is what is passed to a vrpn_Connection message callback.
Structure passed back to user-level code from a vrpn_Text_Receiver.
Definition vrpn_Text.h:22
char message[vrpn_MAX_TEXT_LEN]
Definition vrpn_Text.h:24
vrpn_TEXT_SEVERITY type
Definition vrpn_Text.h:25
vrpn_uint32 level
Definition vrpn_Text.h:26
struct timeval msg_time
Definition vrpn_Text.h:23
All types of client/server/peer objects in VRPN should be derived from the vrpn_BaseClass type descri...
vrpn_TEXT_SEVERITY
Since the sending of text messages has been pulled into the base class (so that every object can send...
@ vrpn_TEXT_NORMAL
const unsigned vrpn_MAX_TEXT_LEN
#define VRPN_API
#define VRPN_CALLBACK
void(VRPN_CALLBACK * vrpn_TEXTHANDLER)(void *userdata, const vrpn_TEXTCB info)
Description of the callback function type.
Definition vrpn_Text.h:30
const struct timeval vrpn_TEXT_NOW
Definition vrpn_Text.h:19