vrpn
07.35
Virtual Reality Peripheral Network
Toggle main menu visibility
Loading...
Searching...
No Matches
vrpn_Text.C
Go to the documentation of this file.
1
#include "
vrpn_Text.h
"
2
3
int
vrpn_Text_Sender::send_message
(
const
char
*msg,
vrpn_TEXT_SEVERITY
type
,
4
vrpn_uint32 level,
const
struct
timeval time)
5
{
6
struct
timeval now;
7
8
// Replace the time value with the current time if the user passed in the
9
// constant time referring to "now".
10
if
((time.tv_sec ==
vrpn_TEXT_NOW
.tv_sec) &&
11
(time.tv_usec ==
vrpn_TEXT_NOW
.tv_usec)) {
12
vrpn_gettimeofday
(&now, NULL);
13
}
14
else
{
15
now = time;
16
}
17
// send message, time, type and level
18
return
send_text_message
(msg, now,
type
, level);
19
}
20
21
vrpn_Text_Receiver::vrpn_Text_Receiver
(
const
char
*name,
vrpn_Connection
*c)
22
:
vrpn_BaseClass
(name, c)
23
{
24
init
();
25
if
(
d_connection
) {
26
register_autodeleted_handler
(
d_text_message_id
,
handle_message
,
this
,
27
d_sender_id
);
28
}
29
};
30
31
vrpn_Text_Receiver::~vrpn_Text_Receiver
() {}
32
33
int
vrpn_Text_Receiver::handle_message
(
void
*
userdata
,
vrpn_HANDLERPARAM
p)
34
{
35
36
vrpn_Text_Receiver
*me = (
vrpn_Text_Receiver
*)
userdata
;
37
vrpn_TEXTCB
cp;
38
39
cp.
msg_time
= p.
msg_time
;
40
me->
decode_text_message_from_buffer
(cp.
message
, &cp.
type
, &cp.
level
,
41
p.
buffer
);
42
43
// Go down the list of callbacks that have been registered.
44
// Fill in the parameter and call each.
45
me->
d_callback_list
.
call_handlers
(cp);
46
return
0;
47
}
vrpn_BaseClassUnique::decode_text_message_from_buffer
static int decode_text_message_from_buffer(char *msg, vrpn_TEXT_SEVERITY *severity, vrpn_uint32 *level, const char *buf)
Decodes the body of the text message from a buffer from the connection.
Definition
vrpn_BaseClass.C:550
vrpn_BaseClassUnique::register_autodeleted_handler
int register_autodeleted_handler(vrpn_int32 type, vrpn_MESSAGEHANDLER handler, void *userdata, vrpn_int32 sender=vrpn_ANY_SENDER)
Registers a handler with the connection, and remembers to delete at destruction.
Definition
vrpn_BaseClass.C:504
vrpn_BaseClassUnique::d_connection
vrpn_Connection * d_connection
Connection that this object talks to.
Definition
vrpn_BaseClass.h:227
vrpn_BaseClassUnique::d_sender_id
vrpn_int32 d_sender_id
Sender ID registered with the connection.
Definition
vrpn_BaseClass.h:231
vrpn_BaseClassUnique::userdata
void * userdata
Definition
vrpn_BaseClass.h:290
vrpn_BaseClassUnique::d_text_message_id
vrpn_int32 d_text_message_id
ID for text messages.
Definition
vrpn_BaseClass.h:232
vrpn_BaseClassUnique::type
vrpn_int32 type
Definition
vrpn_BaseClass.h:289
vrpn_BaseClassUnique::send_text_message
int send_text_message(const char *msg, struct timeval timestamp, vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL, vrpn_uint32 level=0)
Sends a NULL-terminated text message from the device d_sender_id.
Definition
vrpn_BaseClass.C:569
vrpn_BaseClass::vrpn_BaseClass
vrpn_BaseClass(const char *name, vrpn_Connection *c=NULL)
Names the device and assigns or opens connection, calls registration methods.
Definition
vrpn_BaseClass.C:310
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:358
vrpn_Callback_List::call_handlers
void call_handlers(const CALLBACK_STRUCT &info)
This will pass the referenced parameter as a const to all the callbacks.
Definition
vrpn_BaseClass.h:467
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition
vrpn_Connection.h:561
vrpn_Text_Receiver::vrpn_Text_Receiver
vrpn_Text_Receiver(const char *name, vrpn_Connection *c=NULL)
Definition
vrpn_Text.C:21
vrpn_Text_Receiver::~vrpn_Text_Receiver
virtual ~vrpn_Text_Receiver(void)
Definition
vrpn_Text.C:31
vrpn_Text_Receiver::d_callback_list
vrpn_Callback_List< vrpn_TEXTCB > d_callback_list
Definition
vrpn_Text.h:96
vrpn_Text_Receiver::handle_message
static int VRPN_CALLBACK handle_message(void *userdata, vrpn_HANDLERPARAM p)
Definition
vrpn_Text.C:33
vrpn_Text_Sender::send_message
int send_message(const char *msg, vrpn_TEXT_SEVERITY type=vrpn_TEXT_NORMAL, vrpn_uint32 level=0, const struct timeval time=vrpn_TEXT_NOW)
Send a text message.
Definition
vrpn_Text.C:3
vrpn_HANDLERPARAM
This structure is what is passed to a vrpn_Connection message callback.
Definition
vrpn_Connection.h:41
vrpn_HANDLERPARAM::buffer
const char * buffer
Definition
vrpn_Connection.h:46
vrpn_HANDLERPARAM::msg_time
struct timeval msg_time
Definition
vrpn_Connection.h:44
vrpn_TEXTCB
Structure passed back to user-level code from a vrpn_Text_Receiver.
Definition
vrpn_Text.h:22
vrpn_TEXTCB::message
char message[vrpn_MAX_TEXT_LEN]
Definition
vrpn_Text.h:24
vrpn_TEXTCB::type
vrpn_TEXT_SEVERITY type
Definition
vrpn_Text.h:25
vrpn_TEXTCB::level
vrpn_uint32 level
Definition
vrpn_Text.h:26
vrpn_TEXTCB::msg_time
struct timeval msg_time
Definition
vrpn_Text.h:23
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_gettimeofday
#define vrpn_gettimeofday
Definition
vrpn_Shared.h:99
vrpn_Text.h
vrpn_TEXT_NOW
const struct timeval vrpn_TEXT_NOW
Definition
vrpn_Text.h:19
vrpn_Text.C
Generated by
1.17.0