vrpn 07.36
Virtual Reality Peripheral Network
Loading...
Searching...
No Matches
vrpn_FunctionGenerator.C
Go to the documentation of this file.
1
2#include <stdio.h> // for fflush, fprintf, stderr
3#include <string.h> // for NULL, strlen, strcpy
4
6
7//#define DEBUG_VRPN_FUNCTION_GENERATOR
8
9const char* vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL = "vrpn_FunctionGenerator channel";
10const char* vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL_REQUEST = "vrpn_FunctionGenerator channel request";
11const char* vrpn_FUNCTION_MESSAGE_TYPE_ALL_CHANNEL_REQUEST = "vrpn_FunctionGenerator all channel request";
12const char* vrpn_FUNCTION_MESSAGE_TYPE_SAMPLE_RATE = "vrpn_FunctionGenerator sample rate";
13const char* vrpn_FUNCTION_MESSAGE_TYPE_START = "vrpn_FunctionGenerator start";
14const char* vrpn_FUNCTION_MESSAGE_TYPE_STOP = "vrpn_FunctionGenerator stop";
15const char* vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL_REPLY = "vrpn_FunctionGenerator channel reply";
16const char* vrpn_FUNCTION_MESSAGE_TYPE_START_REPLY = "vrpn_FunctionGenerator start reply";
17const char* vrpn_FUNCTION_MESSAGE_TYPE_STOP_REPLY = "vrpn_FunctionGenerator stop reply";
18const char* vrpn_FUNCTION_MESSAGE_TYPE_SAMPLE_RATE_REPLY = "vrpn_FunctionGenerator sample rate reply";
19const char* vrpn_FUNCTION_MESSAGE_TYPE_INTERPRETER_REQUEST = "vrpn_FunctionGenerator interpreter-description request";
20const char* vrpn_FUNCTION_MESSAGE_TYPE_INTERPRETER_REPLY = "vrpn_FunctionGenerator interpreter-description reply";
21const char* vrpn_FUNCTION_MESSAGE_TYPE_ERROR = "vrpn_FunctionGenerator error report";
22
24
27//
28// class vrpn_FunctionGenerator_function_NULL
29
31generateValues( vrpn_float32* buf, vrpn_uint32 nValues,
32 vrpn_float32 startTime, vrpn_float32 sampleRate,
34{
35 for( vrpn_uint32 i = 0; i <= nValues - 1; i++ )
36 {
37 buf[i] = 0;
38 }
39 return startTime + nValues / sampleRate;
40}
41
42
44encode_to( char** , vrpn_int32& ) const
45{
46 return 0;
47}
48
49
51decode_from( const char** , vrpn_int32& )
52{
53 return 0;
54}
55
57clone( ) const
58{
60 try { ret = new vrpn_FunctionGenerator_function_NULL(); }
61 catch (...) { return NULL; }
62 return ret;
63}
64
65
66//
67// end vrpn_FunctionGenerator_function_NULL
70
71
74//
75// class vrpn_FunctionGenerator_function_script
78: script( NULL )
79{
80 try {
81 this->script = new char[1];
82 script[0] = '\0';
83 } catch (...) {}
84}
85
86
89 : script( NULL )
90{
91 try {
92 this->script = new char[strlen(script) + 1];
93 vrpn_strncpynull(this->script, script, strlen(script) + 1);
94 } catch (...) {}
95}
96
97
100 : script(NULL)
101{
102 try {
103 script = new char[strlen(s.script) + 1];
104 vrpn_strncpynull(script, s.script, strlen(s.script) + 1);
105 } catch (...) {}
106}
107
110{
111 delete[] script;
112 try {
113 script = new char[strlen(s.script) + 1];
114 vrpn_strncpynull(script, s.script, strlen(s.script) + 1);
115 }
116 catch (...) {}
117 return *this;
118}
119
120
122{
123 if( script != NULL ) {
124 try {
125 delete[] script;
126 } catch (...) {
127 fprintf(stderr, "vrpn_FunctionGenerator_function_script::~vrpn_FunctionGenerator_function_script(): delete failed\n");
128 return;
129 }
130 script = NULL;
131 }
132}
133
135generateValues( vrpn_float32* buf, vrpn_uint32 nValues, vrpn_float32 startTime,
136 vrpn_float32 sampleRate, vrpn_FunctionGenerator_channel* /*channel*/ ) const
137{
138 for( vrpn_uint32 i = 0; i <= nValues - 1; i++ )
139 {
140 buf[i] = 0;
141 }
142 return startTime + nValues / sampleRate;
143};
144
145
147encode_to( char** buf, vrpn_int32& len ) const
148{
149 vrpn_uint32 length = static_cast<vrpn_uint32>(strlen( this->script ));
150 vrpn_int32 bytes = length + sizeof( vrpn_uint32 );
151 if( len < bytes )
152 {
153 fprintf( stderr, "vrpn_FunctionGenerator_function_script::encode_to: "
154 "payload error (wanted %d got %d).\n", bytes, len );
155 fflush( stderr );
156 return -1;
157 }
158 if( 0 > vrpn_buffer( buf, &len, length ) )
159 {
160 fprintf( stderr, "vrpn_FunctionGenerator_function_script::encode_to: "
161 "payload error (couldn't buffer length).\n" );
162 fflush( stderr );
163 return -1;
164 }
165 if( 0 > vrpn_buffer( buf, &len, this->script, length ) )
166 {
167 fprintf( stderr, "vrpn_FunctionGenerator_function_script::encode_to: "
168 "payload error (couldn't buffer script).\n" );
169 fflush( stderr );
170 return -1;
171 }
172 return bytes;
173}
174
175
177decode_from( const char** buf, vrpn_int32& len )
178{
179 vrpn_int32 newlen;
180 if( 0 > vrpn_unbuffer( buf, &newlen ) )
181 {
182 fprintf( stderr, "vrpn_FunctionGenerator_function_script::decode_from: "
183 "payload error (couldn't unbuffer length).\n" );
184 fflush( stderr );
185 return -1;
186 }
187 len -= sizeof( vrpn_uint32);
188
189 if( len < newlen )
190 {
191 fprintf( stderr, "vrpn_FunctionGenerator_function_script::decode_from: "
192 "payload error (wanted %d got %d).\n", newlen, len );
193 fflush( stderr );
194 return -1;
195 }
196
197 char* newscript = NULL;
198 try { newscript = new char[newlen + 1]; }
199 catch (...) {
200 fprintf(stderr, "vrpn_FunctionGenerator_function_script:: "
201 "Out of memory.\n");
202 fflush(stderr);
203 return -1;
204 }
205 if( 0 > vrpn_unbuffer( buf, newscript, newlen ) )
206 {
207 fprintf( stderr, "vrpn_FunctionGenerator_function_script::decode_from: "
208 "payload error (couldn't unbuffer).\n" );
209 try {
210 delete[] newscript;
211 } catch (...) {
212 fprintf(stderr, "vrpn_FunctionGenerator_function_script::decode_from(): delete failed\n");
213 return -1;
214 }
215 fflush( stderr );
216 return -1;
217 }
218 newscript[newlen] = '\0';
219 if (this->script != NULL) {
220 try {
221 delete[] this->script;
222 } catch (...) {
223 fprintf(stderr, "vrpn_FunctionGenerator_function_script::decode_from(): delete failed\n");
224 return -1;
225 }
226 }
227 this->script = newscript;
228 len -= newlen;
229 return newlen + sizeof( vrpn_uint32 );
230}
231
232
238
240getScript( ) const
241{
242 char* retval = NULL;
243 try {
244 retval = new char[strlen(this->script) + 1];
245 } catch (...) {
246 return NULL;
247 }
248 if (this->script) { vrpn_strncpynull(retval, this->script, strlen(this->script) + 1); }
249 return retval;
250}
251
252
254{
255 if( script == NULL ) return false;
256 if (this->script != NULL) {
257 try {
258 delete[] this->script;
259 } catch (...) {
260 fprintf(stderr, "vrpn_FunctionGenerator_function_script::setScript(): delete failed\n");
261 return false;
262 }
263 }
264 try {
265 this->script = new char[strlen(script) + 1];
266 vrpn_strncpynull(this->script, script, strlen(script) + 1);
267 } catch (...) { return false; }
268 return true;
269}
270
271//
272// end vrpn_FunctionGenerator_function_script
275
276
279//
280// class vrpn_FunctionGenerator_channel
281
288
289
295
296
298{
299 try {
300 delete function;
301 } catch (...) {
302 fprintf(stderr, "vrpn_FunctionGenerator_channel::~vrpn_FunctionGenerator_channel(): delete failed\n");
303 return;
304 }
305}
306
307
309{
310 try {
311 delete (this->function);
312 } catch (...) {
313 fprintf(stderr, "vrpn_FunctionGenerator_channel::setFunction(): delete failed\n");
314 return;
315 }
316 this->function = function->clone();
317}
318
319
321encode_to( char** buf, vrpn_int32& len ) const
322{
323 if( static_cast<unsigned>(len) < sizeof( vrpn_FunctionGenerator_function::FunctionCode ) )
324 {
325 fprintf( stderr, "vrpn_FunctionGenerator_channel::encode_to: "
326 "insufficient buffer space given (got %d, wanted %lud).\n",
327 len, static_cast<unsigned long>(sizeof( vrpn_FunctionGenerator_function::FunctionCode )) );
328 fflush( stderr );
329 return -1;
330 }
331 if( 0 > vrpn_buffer( buf, &len, (int) this->function->getFunctionCode() ) )
332 {
333 fprintf( stderr, "vrpn_FunctionGenerator_channel::encode_to: "
334 "unable to buffer function type.\n" );
335 fflush( stderr );
336 return -1;
337 }
338 return function->encode_to( buf, len );
339}
340
341
343decode_from( const char** buf, vrpn_int32& len )
344{
345 if( static_cast<unsigned>(len) < sizeof( vrpn_FunctionGenerator_function::FunctionCode ) )
346 {
347 fprintf( stderr, "vrpn_FunctionGenerator_channel::decode_from: "
348 "insufficient buffer space given (got %d, wanted %lud).\n",
349 len, static_cast<unsigned long>(sizeof( vrpn_FunctionGenerator_function::FunctionCode )) );
350 fflush( stderr );
351 return -1;
352 }
353 int myCode;
354 if( 0 > vrpn_unbuffer( buf, &myCode ) )
355 {
356 fprintf( stderr, "vrpn_FunctionGenerator_channel::decode_from: "
357 "unable to unbuffer function type.\n" );
358 fflush( stderr );
359 return -1;
360 }
361 // if we don't have the right function type, create a new
362 // one of the appropriate type and delete the old one
363 if( myCode != function->getFunctionCode() )
364 {
368 try {
369 switch( newCode )
370 {
373 break;
376 break;
377 default:
378 fprintf( stderr, "vrpn_FunctionGenerator_channel::decode_from: "
379 "unknown function type.\n" );
380 fflush( stderr );
381 return -1;
382 }
383 } catch (...) {
384 fprintf(stderr, "vrpn_FunctionGenerator_channel::decode_from: "
385 "Out of memory.\n");
386 fflush(stderr);
387 return -1;
388 }
389 try {
390 delete oldFunc;
391 } catch (...) {
392 fprintf(stderr, "vrpn_FunctionGenerator_channel::decode_from(): delete failed\n");
393 return -1;
394 }
395 }
396 return this->function->decode_from( buf, len );
397}
398
399//
400// end vrpn_FunctionGenerator_channel
403
404
407//
408// class vrpn_FunctionGenerator
409
411vrpn_FunctionGenerator( const char* name, vrpn_Connection * c )
412: vrpn_BaseClass( name, c ),
413 sampleRate( 0 ),
414 numChannels( 0 )
415{
417
418 unsigned i;
419 for( i = 0; i <= vrpn_FUNCTION_CHANNELS_MAX - 1; i++ )
420 {
422 }
423}
424
425
427{
428 unsigned i;
429 for( i = 0; i <= vrpn_FUNCTION_CHANNELS_MAX - 1; i++ )
430 {
431 try {
432 delete channels[i];
433 } catch (...) {
434 fprintf(stderr, "vrpn_FunctionGenerator::~vrpn_FunctionGenerator(): delete failed\n");
435 return;
436 }
437 }
438}
439
440
442getChannel( vrpn_uint32 channelNum )
443{
444 if( channelNum > vrpn_FUNCTION_CHANNELS_MAX - 1 )
445 return NULL;
446 return channels[channelNum];
447}
448
449
452{
453#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
454 fprintf( stdout, "FG::register_types\n" );
455 fflush( stdout );
456#endif
464
471
472 gotConnectionMessageID = d_connection->register_message_type( vrpn_got_connection );
473
481 || errorMessageID == -1 )
482 {
483 fprintf( stderr, "vrpn_FunctionGenerator::register_types: error registering types.\n" );
484 fflush( stderr );
485 return -1;
486 }
487 return 0;
488}
489
490//
491// end of vrpn_FunctionGenerator
492//
495
496
497
500//
501// vrpn_FunctionGenerator_Server
502//
503
505vrpn_FunctionGenerator_Server( const char* name, vrpn_uint32 numChannels, vrpn_Connection * c )
506: vrpn_FunctionGenerator( name, c )
507{
508 this->numChannels = numChannels;
509 // Check if we have a connection
510 if( d_connection == NULL )
511 {
512 fprintf( stderr, "vrpn_FunctionGenerator_Server: Can't get connection!\n" );
513 fflush( stderr );
514 return;
515 }
516
518 {
519 fprintf( stderr, "vrpn_FunctionGenerator_Server: can't register change channel request handler\n" );
520 fflush( stderr );
521 d_connection = NULL;
522 }
523
525 {
526 fprintf( stderr, "vrpn_FunctionGenerator_Server: can't register channel request handler\n" );
527 fflush( stderr );
528 d_connection = NULL;
529 }
530
532 {
533 fprintf( stderr, "vrpn_FunctionGenerator_Server: can't register all-channel request handler\n" );
534 fflush( stderr );
535 d_connection = NULL;
536 }
537
539 {
540 fprintf( stderr, "vrpn_FunctionGenerator_Server: can't register start request handler\n" );
541 fflush( stderr );
542 d_connection = NULL;
543 }
544
546 {
547 fprintf( stderr, "vrpn_FunctionGenerator_Server: can't register stop request handler\n" );
548 fflush( stderr );
549 d_connection = NULL;
550 }
551
553 {
554 fprintf( stderr, "vrpn_FunctionGenerator_Server: can't register sample-rate request handler\n" );
555 fflush( stderr );
556 d_connection = NULL;
557 }
558
560 {
561 fprintf( stderr, "vrpn_FunctionGenerator_Server: can't register interpreter request handler\n" );
562 fflush( stderr );
563 d_connection = NULL;
564 }
565}
566
567
573
574
576setNumChannels( vrpn_uint32 numChannels )
577{
580 this->numChannels = numChannels;
581 return this->numChannels;
582}
583
584
586mainloop( )
587{
588 // call the base class' server mainloop
590}
591
592
593//static
596{
597#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
598 fprintf( stdout, "FG::handle_channel_message\n" );
599 fflush( stdout );
600#endif
602 vrpn_FunctionGenerator_channel* channel = NULL;
603 try { channel = new vrpn_FunctionGenerator_channel(); }
604 catch (...) { return -1; }
605 vrpn_uint32 channelNum = vrpn_FUNCTION_CHANNELS_MAX + 1; // an invalid number
606 if( 0 > me->decode_channel( p.buffer, p.payload_len, channelNum, *channel ) )
607 {
608 if( channelNum < vrpn_FUNCTION_CHANNELS_MAX )
609 {
610 // the decode function was able to decode the channel
611 // number, but must have had some problem decoding the channel.
612 // let the remotes know the channel didn't change
613 me->sendChannelReply( channelNum );
614 }
615 // else, we couldn't even decode the channel number
616 }
617
618 // let the server implementation see if this channel is acceptable
619 me->setChannel( channelNum, channel );
620 return 0;
621}
622
623
624//static
627{
628#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
629 fprintf( stdout, "FG::handle_channelRequest_message\n" );
630 fflush( stdout );
631#endif
633 vrpn_uint32 channelNum = vrpn_FUNCTION_CHANNELS_MAX + 1; // an invalid number
634 if( 0 > me->decode_channel_request( p.buffer, p.payload_len, channelNum ) )
635 {
636 // the decode failed
637 fprintf( stderr, "vrpn_FunctionGenerator_Server::handle_channelRequest_message: "
638 "unable to decode channel number.\n" );
639 fflush( stderr );
640 return -1;
641 }
642 if( channelNum > vrpn_FUNCTION_CHANNELS_MAX )
643 {
644 fprintf( stderr, "vrpn_FunctionGenerator_Server::handle_channelRequest_message: "
645 "invalid channel number %d.\n", channelNum );
646 fflush( stderr );
647 return -1;
648 }
649 me->sendChannelReply( channelNum );
650
651 return 0;
652}
653
654
655//static
658{
659#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
660 fprintf( stdout, "FG::handle_allChannelRequest_message\n" );
661 fflush( stdout );
662#endif
664 unsigned i;
665 for( i = 0; i < vrpn_FUNCTION_CHANNELS_MAX; i++ )
666 {
667 // XXX will this work as-is, or do we need to
668 // force buffers to be flushed periodically?
669 me->sendChannelReply( i );
670 }
671 return 0;
672}
673
674
675//static
678{
679#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
680 fprintf( stdout, "FG::handle_start_message\n" );
681 fflush( stdout );
682#endif
684 me->start( );
685 return 0;
686}
687
688
689//static
692{
693#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
694 fprintf( stdout, "FG::handle_stop_message\n" );
695 fflush( stdout );
696#endif
698 me->stop( );
699 return 0;
700}
701
702
703//static
706{
707#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
708 fprintf( stdout, "FG::handle_sample_rate_message\n" );
709 fflush( stdout );
710#endif
712 vrpn_float32 rate = 0;
713 if( 0 > me->decode_sampleRate_request( p.buffer, p.payload_len, rate ) )
714 {
715 fprintf( stderr, "vrpn_FunctionGenerator_Server::handle_sample_rate_message: "
716 "unable to decode.\n" );
717 fflush( stderr );
718 me->sendSampleRateReply( );
719 return -1;
720 }
721 me->setSampleRate( rate );
722 return 0;
723}
724
725
726//static
729{
730#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
731 fprintf( stdout, "FG::handle_interpreter_request_message\n" );
732 fflush( stdout );
733#endif
736 return 0;
737}
738
739
740
742sendChannelReply( vrpn_uint32 channelNum )
743{
744#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
745 fprintf( stdout, "FG::sendChannelReply\n" );
746 fflush( stdout );
747#endif
749 if( this->d_connection )
750 {
751 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
752 char* buf = &msgbuf[0];
753 if( 0 > this->encode_channel_reply( &buf, buflen, channelNum ) )
754 {
755 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendChannelReply: "
756 "could not buffer message.\n" );
757 fflush( stderr );
758 return -1;
759 }
760 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
761 this->channelReplyMessageID, this->d_sender_id,
763 {
764 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendChannelReply: "
765 "could not write message.\n" );
766 fflush( stderr );
767 return -1;
768 }
769 }
770 return 0;
771}
772
773
776{
777#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
778 fprintf( stdout, "FG::sendSampleRateReply\n" );
779 fflush( stdout );
780#endif
782 if( this->d_connection )
783 {
784 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
785 char* buf = &msgbuf[0];
786 if( this->encode_sampleRate_reply( &buf, buflen, sampleRate ) )
787 {
788 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendSampleRateReply: "
789 "could not buffer message.\n" );
790 fflush( stderr );
791 return -1;
792 }
793 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
794 this->sampleRateReplyMessageID, this->d_sender_id,
796 {
797 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendSampleRateReply: "
798 "could not write message.\n" );
799 fflush( stderr );
800 return -1;
801 }
802 }
803 return 0;
804}
805
806
808sendStartReply( vrpn_bool started )
809{
810#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
811 fprintf( stdout, "FG::sendStartReply\n" );
812 fflush( stdout );
813#endif
815 if( this->d_connection )
816 {
817 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
818 char* buf = &msgbuf[0];
819 if( 0 > this->encode_start_reply( &buf, buflen, started ) )
820 {
821 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendStartReply: "
822 "could not buffer message.\n" );
823 fflush( stderr );
824 return -1;
825 }
826 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
827 this->startFunctionReplyMessageID, this->d_sender_id,
829 {
830 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendStartReply: "
831 "could not write message.\n" );
832 fflush( stderr );
833 return -1;
834 }
835 }
836 return 0;
837}
838
839
841sendStopReply( vrpn_bool stopped )
842{
843#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
844 fprintf( stdout, "FG::sendStopReply\n" );
845 fflush( stdout );
846#endif
848 if( this->d_connection )
849 {
850 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
851 char* buf = &msgbuf[0];
852 if( 0 > this->encode_stop_reply( &buf, buflen, stopped ) )
853 {
854 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendStopReply: "
855 "could not buffer message.\n" );
856 fflush( stderr );
857 return -1;
858 }
859 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
860 this->stopFunctionReplyMessageID, this->d_sender_id,
862 {
863 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendStopReply: "
864 "could not write message.\n" );
865 fflush( stderr );
866 return -1;
867 }
868 }
869 return 0;
870}
871
872
875{
876#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
877 fprintf( stdout, "FG::sendInterpreterDescription\n" );
878 fflush( stdout );
879#endif
881 if( this->d_connection )
882 {
883 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
884 char* buf = &msgbuf[0];
885 if( 0 > this->encode_interpreterDescription_reply( &buf, buflen, getInterpreterDescription() ) )
886 {
887 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendInterpreterDescription: "
888 "could not buffer message.\n" );
889 fflush( stderr );
890 return -1;
891 }
892 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
893 this->interpreterReplyMessageID, this->d_sender_id,
895 {
896 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendInterpreterDescription: "
897 "could not write message.\n" );
898 fflush( stderr );
899 return -1;
900 }
901 }
902 return 0;
903}
904
905
907sendError( FGError error, vrpn_int32 channel )
908{
909#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
910 fprintf( stdout, "FG::sendError\n" );
911 fflush( stdout );
912#endif
914 if( this->d_connection )
915 {
916 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
917 char* buf = &msgbuf[0];
918 if( this->encode_error_report( &buf, buflen, error, channel ) )
919 {
920 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendError: "
921 "could not buffer message.\n" );
922 fflush( stderr );
923 return -1;
924 }
925 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
926 this->errorMessageID, this->d_sender_id,
928 {
929 fprintf( stderr, "vrpn_FunctionGenerator_Server::sendError: "
930 "could not write message.\n" );
931 fflush( stderr );
932 return -1;
933 }
934 }
935 return 0;
936}
937
938//
939// end vrpn_FunctionGenerator_Server
940// (except for encode and decode functions)
943
944
945
946
949//
950// vrpn_FunctionGenerator_Remote
951//
952
954vrpn_FunctionGenerator_Remote( const char* name, vrpn_Connection * c )
955: vrpn_FunctionGenerator( name, c )
956{
957 // Check if we have a connection
958 if( d_connection == NULL )
959 {
960 fprintf( stderr, "vrpn_FunctionGenerator_Remote: Can't get connection!\n" );
961 fflush( stderr );
962 return;
963 }
964
966 {
967 fprintf( stderr, "vrpn_FunctionGenerator_Remote: can't register channel reply handler\n" );
968 fflush( stderr );
969 d_connection = NULL;
970 }
971
973 {
974 fprintf( stderr, "vrpn_FunctionGenerator_Remote: can't register start reply handler\n" );
975 fflush( stderr );
976 d_connection = NULL;
977 }
978
980 {
981 fprintf( stderr, "vrpn_FunctionGenerator_Remote: can't register stop reply handler\n" );
982 fflush( stderr );
983 d_connection = NULL;
984 }
985
987 {
988 fprintf( stderr, "vrpn_FunctionGenerator_Remote: can't register sample-rate reply handler\n" );
989 fflush( stderr );
990 d_connection = NULL;
991 }
992
994 {
995 fprintf( stderr, "vrpn_FunctionGenerator_Remote: can't register interpreter reply handler\n" );
996 fflush( stderr );
997 d_connection = NULL;
998 }
999
1001 {
1002 fprintf( stderr, "vrpn_FunctionGenerator_Remote: can't register error message handler\n" );
1003 fflush( stderr );
1004 d_connection = NULL;
1005 }
1006
1007}
1008
1009
1011setChannel( const vrpn_uint32 channelNum, const vrpn_FunctionGenerator_channel* channel )
1012{
1013#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1014 fprintf( stdout, "FG::setChannel\n" );
1015 fflush( stdout );
1016#endif
1017 vrpn_gettimeofday( &timestamp, NULL );
1018 if( this->d_connection )
1019 {
1020 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
1021 char* buf = &msgbuf[0];
1022 if( 0 > this->encode_channel( &buf, buflen, channelNum, channel ) )
1023 {
1024 fprintf( stderr, "vrpn_FunctionGenerator_Remote::setChannel: "
1025 "could not buffer message.\n" );
1026 fflush( stderr );
1027 return -1;
1028 }
1029 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
1030 this->channelMessageID, this->d_sender_id, msgbuf,
1032 {
1033 fprintf( stderr, "vrpn_FunctionGenerator_Remote::setChannel: "
1034 "could not write message.\n" );
1035 fflush( stderr );
1036 return -1;
1037 }
1038 }
1039 else
1040 {
1041 fprintf( stderr, "vrpn_FunctionGenerator_Remote::setChannel: "
1042 "no connection.\n" );
1043 fflush( stderr );
1044 return -1;
1045 }
1046 return 0;
1047}
1048
1049
1051requestChannel( const vrpn_uint32 channelNum )
1052{
1053#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1054 fprintf( stdout, "FG::requestChannel\n" );
1055 fflush( stdout );
1056#endif
1057 vrpn_gettimeofday( &timestamp, NULL );
1058 if( this->d_connection )
1059 {
1060 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
1061 char* buf = &msgbuf[0];
1062 if( 0 > this->encode_channel_request( &buf, buflen, channelNum ) )
1063 {
1064 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestChannel: "
1065 "could not buffer message.\n" );
1066 fflush( stderr );
1067 return -1;
1068 }
1069 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
1070 this->requestChannelMessageID, this->d_sender_id, msgbuf,
1072 {
1073 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestChannel: "
1074 "could not write message.\n" );
1075 fflush( stderr );
1076 return -1;
1077 }
1078 }
1079 else
1080 {
1081 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestChannel: "
1082 "no connection.\n" );
1083 fflush( stderr );
1084 return -1;
1085 }
1086 return 0;
1087}
1088
1089
1090
1093{
1094#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1095 fprintf( stdout, "FG::requestAllChannels\n" );
1096 fflush( stdout );
1097#endif
1098 vrpn_gettimeofday( &timestamp, NULL );
1099 if( this->d_connection )
1100 {
1101 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
1102 char* buf = &msgbuf[0];
1103 // nothing to encode; the message type is the symbol
1104 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
1105 this->requestAllChannelsMessageID, this->d_sender_id, buf,
1107 {
1108 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestAllChannels: "
1109 "could not write message.\n" );
1110 fflush( stderr );
1111 return -1;
1112 }
1113 }
1114 else
1115 {
1116 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestAllChannels: "
1117 "no connection.\n" );
1118 fflush( stderr );
1119 return -1;
1120 }
1121 return 0;
1122}
1123
1124
1126requestStart( )
1127{
1128#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1129 fprintf( stdout, "FG::requestStart\n" );
1130 fflush( stdout );
1131#endif
1132 vrpn_gettimeofday( &timestamp, NULL );
1133 if( this->d_connection )
1134 {
1135 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
1136 char* buf = &msgbuf[0];
1137 // nothing to encode; the message type is the symbol
1138 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
1139 this->startFunctionMessageID, this->d_sender_id, buf,
1141 {
1142 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestStart: "
1143 "could not write message.\n" );
1144 fflush( stderr );
1145 return -1;
1146 }
1147 }
1148 else
1149 {
1150 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestStart: "
1151 "no connection.\n" );
1152 fflush( stderr );
1153 return -1;
1154 }
1155 return 0;
1156}
1157
1158
1160requestStop( )
1161{
1162#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1163 fprintf( stdout, "FG::requestStop\n" );
1164 fflush( stdout );
1165#endif
1166 vrpn_gettimeofday( &timestamp, NULL );
1167 if( this->d_connection )
1168 {
1169 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
1170 char* buf = &msgbuf[0];
1171 // nothing to encode; the message type is the symbol
1172 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
1173 this->stopFunctionMessageID, this->d_sender_id, buf,
1175 {
1176 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestStop: "
1177 "could not write message.\n" );
1178 fflush( stderr );
1179 return -1;
1180 }
1181 }
1182 else
1183 {
1184 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestStop: "
1185 "no connection.\n" );
1186 fflush( stderr );
1187 return -1;
1188 }
1189 return 0;
1190}
1191
1192
1194requestSampleRate( vrpn_float32 rate )
1195{
1196#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1197 fprintf( stdout, "FG::requestSampleRate\n" );
1198 fflush( stdout );
1199#endif
1200 vrpn_gettimeofday( &timestamp, NULL );
1201 if( this->d_connection )
1202 {
1203 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
1204 char* buf = &msgbuf[0];
1205 if( 0 > this->encode_sampleRate_request( &buf, buflen, rate ) )
1206 {
1207 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestSampleRate: "
1208 "could not buffer message.\n" );
1209 fflush( stderr );
1210 return -1;
1211 }
1212 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
1213 this->sampleRateMessageID, this->d_sender_id, msgbuf,
1215 {
1216 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestSampleRate: "
1217 "could not write message.\n" );
1218 fflush( stderr );
1219 return -1;
1220 }
1221 }
1222 else
1223 {
1224 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestSampleRate: "
1225 "no connection.\n" );
1226 fflush( stderr );
1227 return -1;
1228 }
1229 return 0;
1230}
1231
1232
1235{
1236#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1237 fprintf( stdout, "FG::requestInterpreterDescription\n" );
1238 fflush( stdout );
1239#endif
1240 vrpn_gettimeofday( &timestamp, NULL );
1241 if( this->d_connection )
1242 {
1243 int buflen = vrpn_CONNECTION_TCP_BUFLEN;
1244 char* buf = &msgbuf[0];
1245 // nothing to encode; the message type is the symbol
1246 if( d_connection->pack_message( vrpn_CONNECTION_TCP_BUFLEN - buflen, timestamp,
1247 this->requestInterpreterMessageID, this->d_sender_id, buf,
1249 {
1250 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestInterpreterDescription: "
1251 "could not write message.\n" );
1252 fflush( stderr );
1253 return -1;
1254 }
1255 }
1256 else
1257 {
1258 fprintf( stderr, "vrpn_FunctionGenerator_Remote::requestInterpreterDescription: "
1259 "no connection.\n" );
1260 fflush( stderr );
1261 return -1;
1262 }
1263 return 0;
1264}
1265
1266
1268mainloop( )
1269{
1270 if( d_connection != NULL )
1271 {
1272 d_connection->mainloop( );
1273 client_mainloop( );
1274 }
1275}
1276
1277
1284
1285
1292
1293
1300
1301
1308
1309
1316
1317
1324
1325
1332
1333
1340
1341
1348
1349
1356
1357
1364
1365
1372
1373
1374//static
1377{
1378#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1379 fprintf( stdout, "FG::handle_channelReply_message\n" );
1380 fflush( stdout );
1381#endif
1383 vrpn_uint32 channelNum = vrpn_FUNCTION_CHANNELS_MAX + 1; // an invalid number
1384 if( 0 > me->decode_channel_reply( p.buffer, p.payload_len, channelNum ) )
1385 {
1386 fprintf( stderr, "vrpn_FunctionGenerator_Remote::handle_channelReply_message: "
1387 "unable to decode.\n" );
1388 fflush( stderr );
1389 return -1;
1390 }
1391 if( channelNum >= vrpn_FUNCTION_CHANNELS_MAX )
1392 {
1393 fprintf( stderr, "vrpn_FunctionGenerator_Remote::handle_channelReply_message: "
1394 "invalid channel %d.\n", channelNum );
1395 fflush( stderr );
1396 return -1;
1397 }
1398
1400 cb.msg_time.tv_sec = p.msg_time.tv_sec;
1401 cb.msg_time.tv_usec = p.msg_time.tv_usec;
1402 cb.channelNum = channelNum;
1403 cb.channel = me->channels[channelNum];
1404
1406 return 0;
1407}
1408
1409
1410//static
1413{
1414#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1415 fprintf( stdout, "FG::handle_startReply_message\n" );
1416 fflush( stdout );
1417#endif
1419 vrpn_bool isStarted = false;
1420 if( 0 > me->decode_start_reply( p.buffer, p.payload_len, isStarted ) )
1421 {
1422 fprintf( stderr, "vrpn_FunctionGenerator_Remote::handle_startReply_message: "
1423 "unable to decode.\n" );
1424 fflush( stderr );
1425 return -1;
1426 }
1427
1429 cb.msg_time.tv_sec = p.msg_time.tv_sec;
1430 cb.msg_time.tv_usec = p.msg_time.tv_usec;
1431 cb.isStarted = isStarted;
1432
1434 return 0;
1435}
1436
1437
1438//static
1441{
1442#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1443 fprintf( stdout, "FG::handle_stopReply_message\n" );
1444 fflush( stdout );
1445#endif
1447 vrpn_bool isStopped = false;
1448 if( 0 > me->decode_stop_reply( p.buffer, p.payload_len, isStopped ) )
1449 {
1450 fprintf( stderr, "vrpn_FunctionGenerator_Remote::handle_stopReply_message: "
1451 "unable to decode.\n" );
1452 fflush( stderr );
1453 return -1;
1454 }
1455
1457 cb.msg_time.tv_sec = p.msg_time.tv_sec;
1458 cb.msg_time.tv_usec = p.msg_time.tv_usec;
1459 cb.isStopped = isStopped;
1460
1462 return 0;
1463}
1464
1465
1466//static
1469{
1470#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1471 fprintf( stdout, "FG::handle_sampleRateReply_message\n" );
1472 fflush( stdout );
1473#endif
1475 if( 0 > me->decode_sampleRate_reply( p.buffer, p.payload_len ) )
1476 {
1477 fprintf( stderr, "vrpn_FunctionGenerator_Remote::handle_sampleRateReply_message: "
1478 "unable to decode.\n" );
1479 fflush( stderr );
1480 return -1;
1481 }
1482
1484 cb.msg_time.tv_sec = p.msg_time.tv_sec;
1485 cb.msg_time.tv_usec = p.msg_time.tv_usec;
1486 cb.sampleRate = me->sampleRate;
1487
1489 return 0;
1490}
1491
1492
1493//static
1496{
1497#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1498 fprintf( stdout, "FG::handle_interpreterReply_message\n" );
1499 fflush( stdout );
1500#endif
1504 {
1505 fprintf( stderr, "vrpn_FunctionGenerator_Remote::handle_interpreterReply_message: "
1506 "unable to decode.\n" );
1507 fflush( stderr );
1508 return -1;
1509 }
1510
1511 cb.msg_time.tv_sec = p.msg_time.tv_sec;
1512 cb.msg_time.tv_usec = p.msg_time.tv_usec;
1513
1515 return 0;
1516}
1517
1518
1519// static
1522{
1523#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1524 fprintf( stdout, "FG::handle_error_message\n" );
1525 fflush( stdout );
1526#endif
1529 if( 0 > me->decode_error_reply( p.buffer, p.payload_len, cb.err, cb.channel ) )
1530 {
1531 fprintf( stderr, "vrpn_FunctionGenerator_Remote::handle_error_message: "
1532 "unable to decode.\n" );
1533 fflush( stderr );
1534 return -1;
1535 }
1536
1537 cb.msg_time.tv_sec = p.msg_time.tv_sec;
1538 cb.msg_time.tv_usec = p.msg_time.tv_usec;
1539
1540 me->error_list.call_handlers( cb );
1541 return 0;
1542}
1543
1544//
1545// end vrpn_FunctionGenerator_Remote
1546// (except for encode and decode functions)
1549
1550
1551
1554//
1555// encode and decode functions for
1556// vrpn_FunctionGenerator_Server and
1557// vrpn_FunctionGenerator_Remote
1558//
1559
1561encode_channel( char** buf, vrpn_int32& len, const vrpn_uint32 channelNum,
1562 const vrpn_FunctionGenerator_channel* channel )
1563{
1564#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1565 fprintf( stdout, "FG::encode_channel\n" );
1566 fflush( stdout );
1567#endif
1568 if( channelNum > vrpn_FUNCTION_CHANNELS_MAX )
1569 {
1570 fprintf( stderr, "vrpn_FunctionGenerator_Remote::encode_channel: "
1571 "invalid channel nubmer %d.\n", channelNum );
1572 fflush( stderr );
1573 return -1;
1574 }
1575 if( static_cast<unsigned>(len) < sizeof( vrpn_uint32 ) )
1576 {
1577 // the channel's encode_to function will check that the length is
1578 // sufficient for the channel's info, so just check that we can
1579 // at least encode the channel number.
1580 fprintf( stderr, "vrpn_FunctionGenerator_Remote::encode_channel: "
1581 "couldn't buffer (got %d, wanted at least %lud).\n",
1582 len, static_cast<unsigned long>(sizeof( vrpn_int32)) );
1583 fflush( stderr );
1584 return -1;
1585 }
1586 if( 0 > vrpn_buffer( buf, &len, channelNum ) )
1587 {
1588 fprintf( stderr, "vrpn_FunctionGenerator_Remote::encode_channel: "
1589 "message payload error (couldn't buffer channel number).\n" );
1590 fflush( stderr );
1591 return -1;
1592 }
1593 if( 0 > channel->encode_to( buf, len ) )
1594 {
1595 fprintf( stderr, "vrpn_FunctionGenerator_Remote::encode_channel: "
1596 "message payload error (couldn't buffer channel).\n" );
1597 fflush( stderr );
1598 return -1;
1599 }
1600 return 0;
1601}
1602
1603
1605decode_channel( const char* buf, const vrpn_int32 len, vrpn_uint32& channelNum,
1607{
1608#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1609 fprintf( stdout, "FG::decode_channel\n" );
1610 fflush( stdout );
1611#endif
1612 if( static_cast<unsigned>(len) < sizeof( vrpn_uint32 ) )
1613 {
1614 // the channel's decode_from function will check that the length is
1615 // sufficient for the channel's info, so just check that we can
1616 // at least decode the channel number.
1617 fprintf( stderr, "vrpn_FunctionGenerator_Server::decode_channel: "
1618 "channel message payload error (got %d, wanted at least %lud).\n",
1619 len, static_cast<unsigned long>(sizeof( vrpn_int32)) );
1620 fflush( stderr );
1621 return -1;
1622 }
1623 const char* mybuf = buf;
1624 vrpn_int32 mylen = len;
1625 vrpn_uint32 myNum = 0;
1626 if( 0 > vrpn_unbuffer( &mybuf, &myNum ) )
1627 {
1628 fprintf( stderr, "vrpn_FunctionGenerator_Server::decode_channel: "
1629 "message payload error (couldn't unbuffer)\n" );
1630 fflush( stderr );
1631 return -1;
1632 }
1633 mylen -= sizeof( myNum );
1634 channelNum = myNum;
1635 if( 0 > channel.decode_from( &mybuf, mylen ) )
1636 {
1637 fprintf( stderr, "vrpn_FunctionGenerator_Server::decode_channel: "
1638 "error while decoding channel %d\n", channelNum );
1639 fflush( stderr );
1640 return -1;
1641 }
1642
1643 return 0;
1644}
1645
1646
1648encode_channel_reply( char** buf, vrpn_int32& len, const vrpn_uint32 channelNum )
1649{
1650#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1651 fprintf( stdout, "FG::encode_channel_reply\n" );
1652 fflush( stdout );
1653#endif
1654 if( channelNum >= vrpn_FUNCTION_CHANNELS_MAX )
1655 {
1656 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_channel_reply: "
1657 "invalid channel\n" );
1658 fflush( stderr );
1659 return -1;
1660 }
1661 if( static_cast<unsigned>(len) < sizeof( vrpn_uint32 ) )
1662 {
1663 // the channel's encode_to function will check that the length is
1664 // sufficient for the channel's info, so just check that we can
1665 // at least encode the channel number.
1666 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_channel_reply: "
1667 "insufficient buffer space given (got %d, wanted %lud).\n",
1668 len, static_cast<unsigned long>(sizeof( vrpn_uint32)) );
1669 fflush( stderr );
1670 return -1;
1671 }
1672 if( 0 > vrpn_buffer( buf, &len, channelNum ) )
1673 {
1674 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_channel_reply: "
1675 "unable to buffer channel number.\n" );
1676 fflush( stderr );
1677 return -1;
1678 }
1679 if( 0 > channels[channelNum]->encode_to( buf, len ) )
1680 {
1681 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_channel_reply: "
1682 "unable to encode channel.\n" );
1683 fflush( stderr );
1684 return -1;
1685 }
1686 return 0;
1687}
1688
1689
1691decode_channel_reply( const char* buf, const vrpn_int32 len, vrpn_uint32& channelNum )
1692{
1693#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1694 fprintf( stdout, "FG::decode_channel_reply\n" );
1695 fflush( stdout );
1696#endif
1697 if( static_cast<unsigned>(len) < sizeof( vrpn_uint32 ) )
1698 {
1699 // the channel's decode_to function will check that the length is
1700 // sufficient for the channel's info, so just check that we can
1701 // at least decode the channel number.
1702 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1703 "insufficient buffer space given (got %d, wanted %lud).\n",
1704 len, static_cast<unsigned long>(sizeof( vrpn_uint32)) );
1705 fflush( stderr );
1706 return -1;
1707 }
1708 const char* mybuf = buf;
1709 vrpn_int32 mylen = len;
1710 vrpn_uint32 myNum = 0;
1711 if( 0 > vrpn_unbuffer( &mybuf, &myNum ) )
1712 {
1713 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1714 "unable to unbuffer channel number.\n" );
1715 fflush( stderr );
1716 return -1;
1717 }
1718 if( myNum >= vrpn_FUNCTION_CHANNELS_MAX )
1719 {
1720 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1721 "invalid channel: %d\n", myNum );
1722 fflush( stderr );
1723 return -1;
1724 }
1725 channelNum = myNum;
1726 mylen -= sizeof( vrpn_uint32 );
1727 return channels[channelNum]->decode_from( &mybuf, mylen );
1728}
1729
1730
1732encode_channel_request( char** buf, vrpn_int32& len, const vrpn_uint32 channelNum )
1733{
1734#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1735 fprintf( stdout, "FG::encode_channel_request\n" );
1736 fflush( stdout );
1737#endif
1738 if( static_cast<unsigned>(len) < sizeof( vrpn_uint32 ) )
1739 {
1740 fprintf( stderr, "vrpn_FunctionGenerator_Remote::encode_channel_request: "
1741 "channel message payload error (got %d, wanted at least %lud).\n",
1742 len, static_cast<unsigned long>(sizeof( vrpn_int32)) );
1743 fflush( stderr );
1744 return -1;
1745 }
1746 vrpn_int32 mylen = len;
1747 if( 0 > vrpn_buffer( buf, &mylen, channelNum ) )
1748 {
1749 fprintf( stderr, "vrpn_FunctionGenerator_Remote::encode_channel_request: "
1750 "unable to buffer channel %d", channelNum );
1751 fflush( stderr );
1752 return -1;
1753 }
1754 len = mylen;
1755 return 0;
1756}
1757
1758
1760decode_channel_request( const char* buf, const vrpn_int32 len, vrpn_uint32& channelNum )
1761{
1762#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1763 fprintf( stdout, "FG::decode_channel_request\n" );
1764 fflush( stdout );
1765#endif
1766 if( static_cast<unsigned>(len) < sizeof( vrpn_uint32 ) )
1767 {
1768 // the channel's encode_to function will check that the length is
1769 // sufficient for the channel's info, so just check that we can
1770 // at least encode the channel number.
1771 fprintf( stderr, "vrpn_FunctionGenerator_Server::decode_channel_request: "
1772 "channel message payload error (got %d, wanted at least %lud).\n",
1773 len, static_cast<unsigned long>(sizeof( vrpn_int32)) );
1774 fflush( stderr );
1775 return -1;
1776 }
1777 const char* mybuf = buf;
1778 if( 0 > vrpn_unbuffer( &mybuf, &channelNum ) )
1779 {
1780 fprintf( stderr, "vrpn_FunctionGenerator_Server::decode_channel_request: "
1781 "unable to unbuffer channel %d", channelNum );
1782 fflush( stderr );
1783 return -1;
1784 }
1785 return 0;
1786}
1787
1788
1790encode_sampleRate_request( char** buf, vrpn_int32& len, const vrpn_float32 sampleRate )
1791{
1792#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1793 fprintf( stdout, "FG::encode_sampleRate_request\n" );
1794 fflush( stdout );
1795#endif
1796 if( static_cast<unsigned>(len) < sizeof( vrpn_float32 ) )
1797 {
1798 fprintf( stderr, "vrpn_FunctionGenerator_Remote::encode_sampleRate_request: "
1799 "channel message payload error (got %d, wanted at least %lud).\n",
1800 len, static_cast<unsigned long>(sizeof( vrpn_float32)) );
1801 fflush( stderr );
1802 return -1;
1803 }
1804 vrpn_int32 mylen = len;
1805 if( 0 > vrpn_buffer( buf, &mylen, sampleRate ) )
1806 {
1807 fprintf( stderr, "vrpn_FunctionGenerator_Remote::encode_sampleRate_request: "
1808 "unable to buffer sample rate" );
1809 fflush( stderr );
1810 return -1;
1811 }
1812 len = mylen;
1813 return 0;
1814}
1815
1816
1818decode_sampleRate_request( const char* buf, const vrpn_int32 len, vrpn_float32& sampleRate )
1819{
1820#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1821 fprintf( stdout, "FG::decode_sampleRate_request\n" );
1822 fflush( stdout );
1823#endif
1824 if( static_cast<unsigned>(len) < sizeof( vrpn_float32 ) )
1825 {
1826 fprintf( stderr, "vrpn_FunctionGenerator_Server::decode_sampleRate_request: "
1827 "channel message payload error (got %d, wanted at least %lud).\n",
1828 len, static_cast<unsigned long>(sizeof( vrpn_float32)) );
1829 fflush( stderr );
1830 return -1;
1831 }
1832 const char* mybuf = buf;
1833 if( 0 > vrpn_unbuffer( &mybuf, &sampleRate ) )
1834 {
1835 fprintf( stderr, "vrpn_FunctionGenerator_Server::decode_sampleRate_request: "
1836 "unable to unbuffer sample rate" );
1837 fflush( stderr );
1838 return -1;
1839 }
1840 return 0;
1841}
1842
1843
1845encode_start_reply( char** buf, vrpn_int32& len, const vrpn_bool isStarted )
1846{
1847#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1848 fprintf( stdout, "FG::encode_start_reply\n" );
1849 fflush( stdout );
1850#endif
1851 if( static_cast<unsigned>(len) < sizeof( vrpn_bool ) )
1852 {
1853 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_start_reply: "
1854 "insufficient buffer space given (got %d, wanted %lud).\n",
1855 len, static_cast<unsigned long>(sizeof( vrpn_bool)) );
1856 fflush( stderr );
1857 return -1;
1858 }
1859 return vrpn_buffer( buf, &len, isStarted );
1860}
1861
1862
1864decode_start_reply( const char* buf, const vrpn_int32 len, vrpn_bool& isStarted )
1865{
1866#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1867 fprintf( stdout, "FG::decode_start_reply\n" );
1868 fflush( stdout );
1869#endif
1870 if( static_cast<unsigned>(len) < sizeof( vrpn_bool ) )
1871 {
1872 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_start_reply: "
1873 "insufficient buffer space given (got %d, wanted %lud).\n",
1874 len, static_cast<unsigned long>(sizeof( vrpn_bool)) );
1875 fflush( stderr );
1876 return -1;
1877 }
1878 const char* mybuf = buf;
1879 if( 0 > vrpn_unbuffer( &mybuf, &isStarted ) )
1880 {
1881 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_start_reply: "
1882 "unable to unbuffer stop condition.\n" );
1883 fflush( stderr );
1884 return -1;
1885 }
1886 return 0;
1887}
1888
1889
1891encode_stop_reply( char** buf, vrpn_int32& len, const vrpn_bool isStopped )
1892{
1893#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1894 fprintf( stdout, "FG::encode_stop_reply\n" );
1895 fflush( stdout );
1896#endif
1897 if( static_cast<unsigned>(len) < sizeof( vrpn_bool ) )
1898 {
1899 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_stop_reply: "
1900 "insufficient buffer space given (got %d, wanted %lud).\n",
1901 len, static_cast<unsigned long>(sizeof( vrpn_bool)) );
1902 fflush( stderr );
1903 return -1;
1904 }
1905 return vrpn_buffer( buf, &len, isStopped );
1906}
1907
1908
1910decode_stop_reply( const char* buf, const vrpn_int32 len, vrpn_bool& isStopped )
1911{
1912#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1913 fprintf( stdout, "FG::decode_stop_reply\n" );
1914 fflush( stdout );
1915#endif
1916 if( static_cast<unsigned>(len) < sizeof( vrpn_bool ) )
1917 {
1918 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_stop_reply: "
1919 "insufficient buffer space given (got %d, wanted %lud).\n",
1920 len, static_cast<unsigned long>(sizeof( vrpn_bool)) );
1921 fflush( stderr );
1922 return -1;
1923 }
1924 if( 0 > vrpn_unbuffer( &buf, &isStopped ) )
1925 {
1926 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_stop_reply: "
1927 "unable to unbuffer stop condition.\n" );
1928 fflush( stderr );
1929 return -1;
1930 }
1931 return 0;
1932}
1933
1934
1936encode_sampleRate_reply( char** buf, vrpn_int32& len, const vrpn_float32 sampleRate )
1937{
1938#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1939 fprintf( stdout, "FG::encode_sampleRate_reply\n" );
1940 fflush( stdout );
1941#endif
1942 if( static_cast<unsigned>(len) < sizeof( vrpn_float32 ) )
1943 {
1944 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_sampleRate_reply: "
1945 "insufficient buffer space given (got %d, wanted %lud).\n",
1946 len, static_cast<unsigned long>(sizeof( vrpn_float32)) );
1947 fflush( stderr );
1948 return -1;
1949 }
1950 return vrpn_buffer( buf, &len, sampleRate );
1951}
1952
1953
1955decode_sampleRate_reply( const char* buf, const vrpn_int32 len )
1956{
1957#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1958 fprintf( stdout, "FG::decode_sampleRate_reply\n" );
1959 fflush( stdout );
1960#endif
1961 if( static_cast<unsigned>(len) < sizeof( vrpn_float32 ) )
1962 {
1963 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_sampleRate_reply: "
1964 "insufficient buffer space given (got %d, wanted %lud).\n",
1965 len, static_cast<unsigned long>(sizeof( vrpn_float32)) );
1966 fflush( stderr );
1967 return -1;
1968 }
1969 vrpn_float32 myRate = 0;
1970 if( 0 > vrpn_unbuffer( &buf, &myRate ) )
1971 {
1972 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_sampleRate_reply: "
1973 "unable to unbuffer sample rate.\n" );
1974 fflush( stderr );
1975 return -1;
1976 }
1977 this->sampleRate = myRate;
1978 return 0;
1979}
1980
1981
1983encode_interpreterDescription_reply( char** buf, vrpn_int32& len, const char* desc )
1984{
1985#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1986 fprintf( stdout, "FG::encode_interpreterDescription_reply\n" );
1987 fflush( stdout );
1988#endif
1989 vrpn_int32 dlength = static_cast<vrpn_int32>(strlen( desc ));
1990 if( len < dlength + (vrpn_int32) sizeof( vrpn_int32 ) )
1991 {
1992 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_interpreterDescription_reply: "
1993 "insufficient buffer space given (got %d, wanted %lud).\n",
1994 len, dlength + static_cast<unsigned long>(sizeof( vrpn_int32 )) );
1995 fflush( stderr );
1996 return -1;
1997 }
1998 if( 0 > vrpn_buffer( buf, &len, dlength ) )
1999 {
2000 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_interpreterDescription_reply: "
2001 "unable to buffer description length.\n" );
2002 fflush( stderr );
2003 return -1;
2004 }
2005
2006 return vrpn_buffer( buf, &len, desc, dlength );
2007}
2008
2009
2011decode_interpreterDescription_reply( const char* buf, const vrpn_int32 len, char** desc )
2012{
2013#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
2014 fprintf( stdout, "FG::decode_interpreterDescription_reply\n" );
2015 fflush( stdout );
2016#endif
2017 if( static_cast<unsigned>(len) < sizeof( vrpn_int32 ) )
2018 {
2019 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_interpreterDescription_reply: "
2020 "insufficient buffer space given (got %d, wanted at least %lud).\n",
2021 len, static_cast<unsigned long>(sizeof( vrpn_int32)) );
2022 fflush( stderr );
2023 return -1;
2024 }
2025 vrpn_int32 dlength = 0;
2026 if( 0 > vrpn_unbuffer( &buf, &dlength ) )
2027 {
2028 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_interpreterDescription_reply: "
2029 "unable to unbuffer description length.\n" );
2030 fflush( stderr );
2031 return -1;
2032 }
2033 try { *desc = new char[dlength + 1]; }
2034 catch (...) {
2035 fprintf(stderr, "vrpn_FunctionGenerator_Remote::decode_interpreterDescription_reply: "
2036 "Out of memory.\n");
2037 fflush(stderr);
2038 return -1;
2039 }
2040 int retval = vrpn_unbuffer( &buf, *desc, dlength );
2041 (*desc)[dlength] = '\0';
2042 return retval;
2043}
2044
2045
2047encode_error_report( char** buf, vrpn_int32& len, const FGError error, const vrpn_int32 channel )
2048{
2049#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
2050 fprintf( stdout, "FG::encode_error_report\n" );
2051 fflush( stdout );
2052#endif
2053 if( static_cast<unsigned>(len) < sizeof( FGError ) + sizeof( vrpn_int32 ) )
2054 {
2055 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_error_report: "
2056 "insufficient buffer space given (got %d, wanted %lud).\n",
2057 len, static_cast<unsigned long>(sizeof( FGError) + sizeof( vrpn_int32 )) );
2058 fflush( stderr );
2059 return -1;
2060 }
2061 vrpn_int32 mylen = len;
2062 if( 0 > vrpn_buffer( buf, &mylen, error ) || 0 > vrpn_buffer( buf, &mylen, channel ) )
2063 {
2064 fprintf( stderr, "vrpn_FunctionGenerator_Server::encode_error_report: "
2065 "unable to buffer error & channel" );
2066 fflush( stderr );
2067 return -1;
2068 }
2069 len = mylen;
2070 return 0;
2071}
2072
2073
2075decode_error_reply( const char* buf, const vrpn_int32 len, FGError& error, vrpn_int32& channel )
2076{
2077#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
2078 fprintf( stdout, "FG::decode_error_reply\n" );
2079 fflush( stdout );
2080#endif
2081 if( static_cast<unsigned>(len) < sizeof( FGError ) + sizeof( vrpn_int32 ) )
2082 {
2083 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_error_reply: "
2084 "insufficient buffer space given (got %d, wanted %lud).\n",
2085 len, static_cast<unsigned long>(sizeof( FGError) + sizeof( vrpn_int32 )) );
2086 fflush( stderr );
2087 return -1;
2088 }
2089 int myError = NO_FG_ERROR;
2090 vrpn_int32 myChannel = -1;
2091 if( 0 > vrpn_unbuffer( &buf, &myError )
2092 || 0 > vrpn_unbuffer( &buf, &myChannel ) )
2093 {
2094 fprintf( stderr, "vrpn_FunctionGenerator_Remote::decode_error_reply: "
2095 "unable to unbuffer error & channel.\n" );
2096 fflush( stderr );
2097 return -1;
2098 }
2099 error = FGError( myError );
2100 channel = myChannel;
2101 return 0;
2102}
2103
2104
2105
2106//
2107// end encode & decode functions for
2108// vrpn_FunctionGenerator_Remote and
2109// vrpn_FunctionGenerator_Server
2111
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.
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
vrpn_int32 d_sender_id
Sender ID registered with the connection.
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.
void call_handlers(const CALLBACK_STRUCT &info)
This will pass the referenced parameter as a const to all the callbacks.
Generic connection class not specific to the transport mechanism.
static int VRPN_CALLBACK handle_sampleRateReply_message(void *userdata, vrpn_HANDLERPARAM p)
virtual int register_sample_rate_reply_handler(void *userdata, vrpn_FUNCTION_SAMPLE_RATE_REPLY_HANDLER handler)
virtual int unregister_start_reply_handler(void *userdata, vrpn_FUNCTION_START_REPLY_HANDLER handler)
vrpn_int32 decode_channel_reply(const char *buf, const vrpn_int32 len, vrpn_uint32 &channelNum)
virtual int register_error_handler(void *userdata, vrpn_FUNCTION_ERROR_HANDLER handler)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_FunctionGenerator_Remote(const char *name, vrpn_Connection *c=NULL)
vrpn_int32 encode_channel_request(char **buf, vrpn_int32 &len, const vrpn_uint32 channelNum)
virtual int unregister_channel_reply_handler(void *userdata, vrpn_FUNCTION_CHANGE_REPLY_HANDLER handler)
vrpn_int32 decode_stop_reply(const char *buf, const vrpn_int32 len, vrpn_bool &isStopped)
vrpn_Callback_List< vrpn_FUNCTION_ERROR_CB > error_list
static int VRPN_CALLBACK handle_error_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 decode_start_reply(const char *buf, const vrpn_int32 len, vrpn_bool &isStarted)
vrpn_Callback_List< vrpn_FUNCTION_STOP_REPLY_CB > stop_reply_list
vrpn_int32 decode_error_reply(const char *buf, const vrpn_int32 len, FGError &error, vrpn_int32 &channel)
static int VRPN_CALLBACK handle_interpreterReply_message(void *userdata, vrpn_HANDLERPARAM p)
static int VRPN_CALLBACK handle_stopReply_message(void *userdata, vrpn_HANDLERPARAM p)
virtual int unregister_stop_reply_handler(void *userdata, vrpn_FUNCTION_STOP_REPLY_HANDLER handler)
vrpn_Callback_List< vrpn_FUNCTION_START_REPLY_CB > start_reply_list
vrpn_Callback_List< vrpn_FUNCTION_CHANNEL_REPLY_CB > channel_reply_list
virtual int unregister_interpreter_reply_handler(void *userdata, vrpn_FUNCTION_INTERPRETER_REPLY_HANDLER handler)
vrpn_Callback_List< vrpn_FUNCTION_INTERPRETER_REPLY_CB > interpreter_reply_list
virtual int unregister_error_handler(void *userdata, vrpn_FUNCTION_ERROR_HANDLER handler)
virtual int register_start_reply_handler(void *userdata, vrpn_FUNCTION_START_REPLY_HANDLER handler)
vrpn_Callback_List< vrpn_FUNCTION_SAMPLE_RATE_REPLY_CB > sample_rate_reply_list
virtual int unregister_sample_rate_reply_handler(void *userdata, vrpn_FUNCTION_SAMPLE_RATE_REPLY_HANDLER handler)
static int VRPN_CALLBACK handle_channelReply_message(void *userdata, vrpn_HANDLERPARAM p)
virtual int register_stop_reply_handler(void *userdata, vrpn_FUNCTION_STOP_REPLY_HANDLER handler)
vrpn_int32 decode_sampleRate_reply(const char *buf, const vrpn_int32 len)
int setChannel(const vrpn_uint32 channelNum, const vrpn_FunctionGenerator_channel *channel)
vrpn_int32 decode_interpreterDescription_reply(const char *buf, const vrpn_int32 len, char **desc)
static int VRPN_CALLBACK handle_startReply_message(void *userdata, vrpn_HANDLERPARAM p)
int requestChannel(const vrpn_uint32 channelNum)
virtual int register_interpreter_reply_handler(void *userdata, vrpn_FUNCTION_INTERPRETER_REPLY_HANDLER handler)
vrpn_int32 encode_channel(char **buf, vrpn_int32 &len, const vrpn_uint32 channelNum, const vrpn_FunctionGenerator_channel *channel)
int requestSampleRate(const vrpn_float32 rate)
vrpn_int32 encode_sampleRate_request(char **buf, vrpn_int32 &len, const vrpn_float32 sampleRate)
virtual int register_channel_reply_handler(void *userdata, vrpn_FUNCTION_CHANGE_REPLY_HANDLER handler)
virtual void setSampleRate(vrpn_float32 rate)=0
virtual const char * getInterpreterDescription()=0
vrpn_int32 decode_sampleRate_request(const char *buf, const vrpn_int32 len, vrpn_float32 &sampleRate)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
int sendError(FGError error, vrpn_int32 channel)
vrpn_int32 decode_channel(const char *buf, const vrpn_int32 len, vrpn_uint32 &channelNum, vrpn_FunctionGenerator_channel &channel)
static int VRPN_CALLBACK handle_allChannelRequest_message(void *userdata, vrpn_HANDLERPARAM p)
int sendChannelReply(vrpn_uint32 channelNum)
static int VRPN_CALLBACK handle_start_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_FunctionGenerator_Server(const char *name, vrpn_uint32 numChannels=vrpn_FUNCTION_CHANNELS_MAX, vrpn_Connection *c=NULL)
static int VRPN_CALLBACK handle_stop_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 encode_stop_reply(char **buf, vrpn_int32 &len, const vrpn_bool isStopped)
vrpn_int32 encode_error_report(char **buf, vrpn_int32 &len, const FGError err, const vrpn_int32 channel)
vrpn_int32 encode_start_reply(char **buf, vrpn_int32 &len, const vrpn_bool isStarted)
vrpn_int32 encode_channel_reply(char **buf, vrpn_int32 &len, const vrpn_uint32 channelNum)
static int VRPN_CALLBACK handle_channel_message(void *userdata, vrpn_HANDLERPARAM p)
static int VRPN_CALLBACK handle_channelRequest_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 encode_sampleRate_reply(char **buf, vrpn_int32 &len, const vrpn_float32 sampleRate)
static int VRPN_CALLBACK handle_sample_rate_message(void *userdata, vrpn_HANDLERPARAM p)
static int VRPN_CALLBACK handle_interpreter_request_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_uint32 setNumChannels(vrpn_uint32 numChannels)
vrpn_int32 decode_channel_request(const char *buf, const vrpn_int32 len, vrpn_uint32 &channelNum)
vrpn_int32 encode_interpreterDescription_reply(char **buf, vrpn_int32 &len, const char *desc)
virtual void setChannel(vrpn_uint32 channelNum, vrpn_FunctionGenerator_channel *channel)=0
void setFunction(vrpn_FunctionGenerator_function *function)
vrpn_int32 decode_from(const char **buf, vrpn_int32 &len)
vrpn_int32 encode_to(char **buf, vrpn_int32 &len) const
vrpn_FunctionGenerator_function * function
vrpn_int32 encode_to(char **buf, vrpn_int32 &len) const
vrpn_float32 generateValues(vrpn_float32 *buf, vrpn_uint32 nValues, vrpn_float32 startTime, vrpn_float32 sampleRate, vrpn_FunctionGenerator_channel *channel) const
vrpn_int32 decode_from(const char **buf, vrpn_int32 &len)
vrpn_FunctionGenerator_function * clone() const
vrpn_FunctionGenerator_function_script & operator=(const vrpn_FunctionGenerator_function_script &s)
virtual vrpn_float32 generateValues(vrpn_float32 *buf, vrpn_uint32 nValues, vrpn_float32 startTime, vrpn_float32 sampleRate, vrpn_FunctionGenerator_channel *channel) const
vrpn_FunctionGenerator_function * clone() const
vrpn_int32 encode_to(char **buf, vrpn_int32 &len) const
vrpn_int32 decode_from(const char **buf, vrpn_int32 &len)
char msgbuf[vrpn_CONNECTION_TCP_BUFLEN]
vrpn_FunctionGenerator_channel * channels[vrpn_FUNCTION_CHANNELS_MAX]
vrpn_FunctionGenerator(const char *name, vrpn_Connection *c=NULL)
virtual int register_types()
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail.
const vrpn_FunctionGenerator_channel * getChannel(vrpn_uint32 channelNum)
vrpn_FunctionGenerator_channel * channel
vrpn_FunctionGenerator::FGError err
This structure is what is passed to a vrpn_Connection message callback.
const char * buffer
struct timeval msg_time
#define VRPN_CALLBACK
const char * vrpn_got_connection
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
const int vrpn_CONNECTION_TCP_BUFLEN
const char * vrpn_FUNCTION_MESSAGE_TYPE_SAMPLE_RATE_REPLY
const char * vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL_REPLY
const char * vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL_REQUEST
const char * vrpn_FUNCTION_MESSAGE_TYPE_INTERPRETER_REQUEST
const char * vrpn_FUNCTION_MESSAGE_TYPE_ALL_CHANNEL_REQUEST
const char * vrpn_FUNCTION_MESSAGE_TYPE_SAMPLE_RATE
const char * vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL
const char * vrpn_FUNCTION_MESSAGE_TYPE_ERROR
const char * vrpn_FUNCTION_MESSAGE_TYPE_INTERPRETER_REPLY
const char * vrpn_FUNCTION_MESSAGE_TYPE_START
const char * vrpn_FUNCTION_MESSAGE_TYPE_START_REPLY
const char * vrpn_FUNCTION_MESSAGE_TYPE_STOP_REPLY
const char * vrpn_FUNCTION_MESSAGE_TYPE_STOP
const vrpn_uint32 vrpn_FUNCTION_CHANNELS_MAX
void(VRPN_CALLBACK * vrpn_FUNCTION_CHANGE_REPLY_HANDLER)(void *userdata, const vrpn_FUNCTION_CHANNEL_REPLY_CB info)
const char * vrpn_FUNCTION_MESSAGE_TYPE_SAMPLE_RATE_REPLY
void(VRPN_CALLBACK * vrpn_FUNCTION_INTERPRETER_REPLY_HANDLER)(void *userdata, const vrpn_FUNCTION_INTERPRETER_REPLY_CB info)
const char * vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL_REPLY
const char * vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL_REQUEST
const char * vrpn_FUNCTION_MESSAGE_TYPE_INTERPRETER_REQUEST
const char * vrpn_FUNCTION_MESSAGE_TYPE_ALL_CHANNEL_REQUEST
const char * vrpn_FUNCTION_MESSAGE_TYPE_SAMPLE_RATE
const char * vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL
void(VRPN_CALLBACK * vrpn_FUNCTION_SAMPLE_RATE_REPLY_HANDLER)(void *userdata, const vrpn_FUNCTION_SAMPLE_RATE_REPLY_CB info)
const char * vrpn_FUNCTION_MESSAGE_TYPE_ERROR
const char * vrpn_FUNCTION_MESSAGE_TYPE_INTERPRETER_REPLY
class VRPN_API vrpn_FunctionGenerator_channel
const char * vrpn_FUNCTION_MESSAGE_TYPE_START
const char * vrpn_FUNCTION_MESSAGE_TYPE_START_REPLY
const char * vrpn_FUNCTION_MESSAGE_TYPE_STOP_REPLY
void(VRPN_CALLBACK * vrpn_FUNCTION_ERROR_HANDLER)(void *userdata, const vrpn_FUNCTION_ERROR_CB info)
void(VRPN_CALLBACK * vrpn_FUNCTION_START_REPLY_HANDLER)(void *userdata, const vrpn_FUNCTION_START_REPLY_CB info)
void(VRPN_CALLBACK * vrpn_FUNCTION_STOP_REPLY_HANDLER)(void *userdata, const vrpn_FUNCTION_STOP_REPLY_CB info)
const char * vrpn_FUNCTION_MESSAGE_TYPE_STOP
VRPN_API int vrpn_unbuffer(const char **buffer, timeval *t)
Utility routine for taking a struct timeval from a buffer that was sent as a message.
VRPN_API int vrpn_buffer(char **insertPt, vrpn_int32 *buflen, const timeval t)
Utility routine for placing a timeval struct into a buffer that is to be sent as a message.
#define vrpn_gettimeofday
char * vrpn_strncpynull(char *dst, const char *src, size_t size)
Version of strncpy that ensures the resulting string is alyways NULL terminated. It also only writes ...