~hitmuri/vjpirate/trunk

« back to all changes in this revision

Viewing changes to os/win/include/vrpn_Tracker_JsonNet.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
#ifndef VRPN_TRACKER_JSONNET
 
2
#define VRPN_TRACKER_JSONNET
 
3
 
 
4
#include "vrpn_Configure.h"
 
5
#if defined(VRPN_USE_JSONNET)
 
6
 
 
7
#include "vrpn_Tracker.h"
 
8
#include "vrpn_Button.h"
 
9
#include "vrpn_Analog.h"
 
10
 
 
11
namespace Json {
 
12
        class Reader;
 
13
        class Value;
 
14
}
 
15
 
 
16
/**
 
17
 * A tracker class that accepts network updates in JSON format.
 
18
 *
 
19
 * This tracker is used by the Vrpn Android widgets. 
 
20
 * Any other application that can send UDP packets with a JSON payload 
 
21
 * and feed this tracker.
 
22
 * 
 
23
 * @Author Philippe Crassous / ENSAM ParisTech-Institut Image
 
24
 */
 
25
class vrpn_Tracker_JsonNet :
 
26
        public vrpn_Tracker, public vrpn_Button, public vrpn_Analog
 
27
{
 
28
public:
 
29
        vrpn_Tracker_JsonNet(
 
30
                const char* name,
 
31
                vrpn_Connection* c,
 
32
                int udpPort
 
33
                );
 
34
        ~vrpn_Tracker_JsonNet(void);
 
35
 
 
36
        void mainloop();
 
37
 
 
38
        enum {
 
39
                TILT_TRACKER_ID = 0,
 
40
        };
 
41
 
 
42
        
 
43
private:
 
44
        /*
 
45
         * Network part
 
46
         */
 
47
        bool _network_init(int udp_port);
 
48
        int _network_receive(void *buffer, int maxlen, int tout_us);
 
49
        void _network_release();
 
50
#ifdef _WIN32
 
51
    typedef SOCKET socket_type;
 
52
#else
 
53
    typedef int socket_type;
 
54
#endif
 
55
        socket_type _socket;
 
56
        enum {
 
57
                _NETWORK_BUFFER_SIZE = 2000,
 
58
 
 
59
        };
 
60
        char _network_buffer[_NETWORK_BUFFER_SIZE];
 
61
 
 
62
        /*
 
63
         * Json part
 
64
         */
 
65
        bool _parse(const char* buffer, int length);
 
66
        bool _parse_tracker_data(const Json::Value& root);
 
67
        bool _parse_analog(const Json::Value& root);
 
68
        bool _parse_button(const Json::Value& root);
 
69
        Json::Reader* _pJsonReader;
 
70
};
 
71
 
 
72
#endif // ifdef JSONNET
 
73
#endif