vrpn 07.35
Virtual Reality Peripheral Network
 
Loading...
Searching...
No Matches
vrpn_Event.C
Go to the documentation of this file.
1/**************************************************************************************************/
2/* */
3/* Copyright (C) 2004 Bauhaus University Weimar */
4/* Released into the public domain on 6/23/2007 as part of the VRPN project */
5/* by Jan P. Springer. */
6/* */
7/**************************************************************************************************/
8/* */
9/* module : vrpn_Linux.h */
10/* project : */
11/* description: provide functionality for Event interface */
12/* */
13/**************************************************************************************************/
14
15// includes, system
16
17#include <stdio.h> // for perror
18#if ! defined(_WIN32)
19 #include <fcntl.h> // for open, O_RDONLY
20 #include <unistd.h> // for close, read
21#endif
22
23// includes project
24#include "vrpn_Event.h"
25
26
27namespace vrpn_Event {
28
29 /************************************************************************************************/
30 /* open the specified event interface */
31 /************************************************************************************************/
32 int
33 vrpn_open_event( const char* file) {
34
35 #if defined(_WIN32)
36
37 fprintf( stderr, "vrpn_Event::vrpn_open_event(): Not yet implemented on this architecture.");
38 return -1;
39
40 #else // #if defined(LINUX)
41
42 return open( file, O_RDONLY);
43
44 #endif
45 }
46
47 /************************************************************************************************/
48 /* close the event interface */
49 /************************************************************************************************/
50 void
51 vrpn_close_event( const int fd) {
52
53 #if defined(_WIN32)
54
55 fprintf( stderr, "vrpn_Event::vrpn_close_event(): Not yet implemented on this architecture.");
56
57 #else // #if defined(LINUX)
58
59 close(fd);
60
61 #endif
62 }
63
64 /************************************************************************************************/
65 /* read data from the interface */
66 /************************************************************************************************/
67 int
68 vrpn_read_event( int fd, input_event * data, int max_elements) {
69
70 #if defined(_WIN32)
71
72 fprintf( stderr, "vrpn_Event::vrpn_read_event(): Not yet implemented on this architecture.");
73 return -1;
74
75 #else
76
77 int read_bytes = read(fd, data, sizeof(struct input_event) * max_elements);
78
79 if (read_bytes < (int) sizeof(struct input_event)) {
80
81 perror("vrpn_Event_Linux::vrpn_read_event() : short read");
82 }
83
84 return (read_bytes / sizeof(struct input_event));
85
86 #endif
87 }
88
89} // end namespace vrpn_Event
90
void vrpn_close_event(const int fd)
Definition vrpn_Event.C:51
int vrpn_open_event(const char *file)
Definition vrpn_Event.C:33
int vrpn_read_event(int fd, input_event *data, int max_elements)
Definition vrpn_Event.C:68