~hitmuri/vjpirate/trunk

« back to all changes in this revision

Viewing changes to os/win/include/vrpn_Text.h

  • Committer: Florent Berthaut
  • Date: 2014-07-26 18:53:16 UTC
  • mfrom: (5.1.12 mac)
  • Revision ID: flo@localhost.localdomain-20140726185316-c2ucnwmgm5kij4e2
Merged mac branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
10
#ifndef _WIN32
 
11
#include <sys/time.h>
 
12
#endif
 
13
 
 
14
#include "vrpn_Connection.h"
 
15
#include "vrpn_BaseClass.h"
 
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
 
 
20
/// Structure passed back to user-level code from a vrpn_Text_Receiver.
 
21
typedef struct _vrpn_TEXTCB {
 
22
        struct timeval  msg_time;       // Time of the message
 
23
        char            message[vrpn_MAX_TEXT_LEN];     // The message
 
24
        vrpn_TEXT_SEVERITY      type;
 
25
        vrpn_uint32             level;
 
26
} vrpn_TEXTCB;
 
27
 
 
28
/// Description of the callback function type.
 
29
typedef void (VRPN_CALLBACK *vrpn_TEXTHANDLER)(void *userdata, const vrpn_TEXTCB info);
 
30
 
 
31
//----------------------------------------------------------
 
32
//************** Users deal with the following *************
 
33
 
 
34
/// Allows a user to send text messages from a device (usually,
 
35
// the send_text_message() function is protected).  It provides
 
36
// the needed function definitions for vrpn_BaseClass.
 
37
 
 
38
class VRPN_API vrpn_Text_Sender: public vrpn_BaseClass {
 
39
  public:
 
40
        vrpn_Text_Sender(const char *name, vrpn_Connection *c = NULL) :
 
41
                vrpn_BaseClass(name, c) { init(); };
 
42
 
 
43
        /// Mainloop the connection to send the message.
 
44
        void mainloop(void) { server_mainloop(); if (d_connection) d_connection->mainloop(); };
 
45
 
 
46
        /// Send a text message.
 
47
        int send_message(const char *msg, 
 
48
                            vrpn_TEXT_SEVERITY type = vrpn_TEXT_NORMAL,
 
49
                            vrpn_uint32 level = 0,
 
50
                            const struct timeval time = vrpn_TEXT_NOW);
 
51
  protected:
 
52
      /// No types to register beyond the text, which is done in BaseClass.
 
53
      virtual int register_types(void) { return 0; };
 
54
};
 
55
 
 
56
/// Allows a user to handle text messages directly, in addition too having the
 
57
// standard VRPN printing functions handle them.
 
58
 
 
59
class VRPN_API vrpn_Text_Receiver: public vrpn_BaseClass {
 
60
  public:
 
61
        vrpn_Text_Receiver (const char * name, vrpn_Connection * c = NULL);
 
62
        virtual ~vrpn_Text_Receiver (void);
 
63
        virtual int register_message_handler(void *userdata,
 
64
                vrpn_TEXTHANDLER handler) {
 
65
          return d_callback_list.register_handler(userdata, handler);
 
66
        };
 
67
 
 
68
        virtual int unregister_message_handler(void *userdata,
 
69
                vrpn_TEXTHANDLER handler) {
 
70
          return d_callback_list.unregister_handler(userdata, handler);
 
71
        }
 
72
 
 
73
        virtual void mainloop(void) { if (d_connection) { d_connection->mainloop(); }; client_mainloop(); };
 
74
 
 
75
  protected:
 
76
        static int VRPN_CALLBACK handle_message (void * userdata, vrpn_HANDLERPARAM p);
 
77
        vrpn_Callback_List<vrpn_TEXTCB> d_callback_list;
 
78
 
 
79
        /// No types to register beyond the text, which is done in BaseClass.
 
80
        virtual int register_types(void) { return 0; };
 
81
};
 
82
 
 
83
#define VRPN_TEXT_H
 
84
#endif