vrpn
07.33
Virtual Reality Peripheral Network
|
Go to the documentation of this file.
32 vrpn_float32 startTime, vrpn_float32 sampleRate,
35 for( vrpn_uint32 i = 0; i <= nValues - 1; i++ )
39 return startTime + nValues / sampleRate;
77 this->
script =
new char[1];
85 this->script =
new char[ strlen(
script ) + 1 ];
86 strcpy( this->script,
script );
112 for( vrpn_uint32 i = 0; i <= nValues - 1; i++ )
116 return startTime + nValues / sampleRate;
123 vrpn_uint32 length =
static_cast<vrpn_uint32
>(strlen( this->
script ));
124 vrpn_int32 bytes = length +
sizeof( vrpn_uint32 );
127 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::encode_to: "
128 "payload error (wanted %d got %d).\n", bytes, len );
134 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::encode_to: "
135 "payload error (couldn't buffer length).\n" );
141 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::encode_to: "
142 "payload error (couldn't buffer script).\n" );
156 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::decode_from: "
157 "payload error (couldn't unbuffer length).\n" );
161 len -=
sizeof( vrpn_uint32);
165 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::decode_from: "
166 "payload error (wanted %d got %d).\n", newlen, len );
171 char* newscript =
new char[ newlen + 1 ];
174 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::decode_from: "
175 "payload error (couldn't unbuffer).\n" );
180 newscript[newlen] =
'\0';
181 if( this->
script != NULL )
185 return newlen +
sizeof( vrpn_uint32 );
198 char* retval =
new char[ strlen( this->
script ) + 1 ];
199 strcpy( retval, this->
script );
207 if(
script == NULL )
return false;
208 if( this->script != NULL )
210 this->script =
new char[ strlen(
script ) + 1 ];
211 strcpy( this->script,
script );
236 this->
function =
function->clone();
250 delete (this->
function);
251 this->
function =
function->clone();
260 fprintf( stderr,
"vrpn_FunctionGenerator_channel::encode_to: "
261 "insufficient buffer space given (got %d, wanted %lud).\n",
268 fprintf( stderr,
"vrpn_FunctionGenerator_channel::encode_to: "
269 "unable to buffer function type.\n" );
273 return function->encode_to( buf, len );
282 fprintf( stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
283 "insufficient buffer space given (got %d, wanted %lud).\n",
291 fprintf( stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
292 "unable to unbuffer function type.\n" );
312 fprintf( stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
313 "unknown function type.\n" );
372 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
373 fprintf( stdout,
"FG::register_types\n" );
402 fprintf( stderr,
"vrpn_FunctionGenerator::register_types: error registering types.\n" );
431 fprintf( stderr,
"vrpn_FunctionGenerator_Server: Can't get connection!\n" );
438 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register change channel request handler\n" );
445 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register channel request handler\n" );
452 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register all-channel request handler\n" );
459 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register start request handler\n" );
466 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register stop request handler\n" );
473 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register sample-rate request handler\n" );
480 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register interpreter request handler\n" );
516 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
517 fprintf( stdout,
"FG::handle_channel_message\n" );
545 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
546 fprintf( stdout,
"FG::handle_channelRequest_message\n" );
554 fprintf( stderr,
"vrpn_FunctionGenerator_Server::handle_channelRequest_message: "
555 "unable to decode channel number.\n" );
561 fprintf( stderr,
"vrpn_FunctionGenerator_Server::handle_channelRequest_message: "
562 "invalid channel number %d.\n", channelNum );
576 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
577 fprintf( stdout,
"FG::handle_allChannelRequest_message\n" );
596 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
597 fprintf( stdout,
"FG::handle_start_message\n" );
610 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
611 fprintf( stdout,
"FG::handle_stop_message\n" );
624 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
625 fprintf( stdout,
"FG::handle_sample_rate_message\n" );
629 vrpn_float32 rate = 0;
632 fprintf( stderr,
"vrpn_FunctionGenerator_Server::handle_sample_rate_message: "
633 "unable to decode.\n" );
647 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
648 fprintf( stdout,
"FG::handle_interpreter_request_message\n" );
661 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
662 fprintf( stdout,
"FG::sendChannelReply\n" );
672 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendChannelReply: "
673 "could not buffer message.\n" );
678 this->channelReplyMessageID, this->d_sender_id,
681 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendChannelReply: "
682 "could not write message.\n" );
694 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
695 fprintf( stdout,
"FG::sendSampleRateReply\n" );
705 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendSampleRateReply: "
706 "could not buffer message.\n" );
711 this->sampleRateReplyMessageID, this->d_sender_id,
714 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendSampleRateReply: "
715 "could not write message.\n" );
727 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
728 fprintf( stdout,
"FG::sendStartReply\n" );
738 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStartReply: "
739 "could not buffer message.\n" );
744 this->startFunctionReplyMessageID, this->d_sender_id,
747 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStartReply: "
748 "could not write message.\n" );
760 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
761 fprintf( stdout,
"FG::sendStopReply\n" );
771 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStopReply: "
772 "could not buffer message.\n" );
777 this->stopFunctionReplyMessageID, this->d_sender_id,
780 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStopReply: "
781 "could not write message.\n" );
793 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
794 fprintf( stdout,
"FG::sendInterpreterDescription\n" );
804 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendInterpreterDescription: "
805 "could not buffer message.\n" );
810 this->interpreterReplyMessageID, this->d_sender_id,
813 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendInterpreterDescription: "
814 "could not write message.\n" );
826 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
827 fprintf( stdout,
"FG::sendError\n" );
837 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendError: "
838 "could not buffer message.\n" );
843 this->errorMessageID, this->d_sender_id,
846 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendError: "
847 "could not write message.\n" );
877 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: Can't get connection!\n" );
884 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register channel reply handler\n" );
891 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register start reply handler\n" );
898 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register stop reply handler\n" );
905 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register sample-rate reply handler\n" );
912 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register interpreter reply handler\n" );
919 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register error message handler\n" );
930 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
931 fprintf( stdout,
"FG::setChannel\n" );
939 if( 0 > this->
encode_channel( &buf, buflen, channelNum, channel ) )
941 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::setChannel: "
942 "could not buffer message.\n" );
947 this->channelMessageID, this->d_sender_id,
msgbuf,
950 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::setChannel: "
951 "could not write message.\n" );
958 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::setChannel: "
959 "no connection.\n" );
970 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
971 fprintf( stdout,
"FG::requestChannel\n" );
981 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestChannel: "
982 "could not buffer message.\n" );
987 this->requestChannelMessageID, this->d_sender_id,
msgbuf,
990 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestChannel: "
991 "could not write message.\n" );
998 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestChannel: "
999 "no connection.\n" );
1011 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1012 fprintf( stdout,
"FG::requestAllChannels\n" );
1022 this->requestAllChannelsMessageID, this->d_sender_id, buf,
1025 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestAllChannels: "
1026 "could not write message.\n" );
1033 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestAllChannels: "
1034 "no connection.\n" );
1045 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1046 fprintf( stdout,
"FG::requestStart\n" );
1056 this->startFunctionMessageID, this->d_sender_id, buf,
1059 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStart: "
1060 "could not write message.\n" );
1067 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStart: "
1068 "no connection.\n" );
1079 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1080 fprintf( stdout,
"FG::requestStop\n" );
1090 this->stopFunctionMessageID, this->d_sender_id, buf,
1093 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStop: "
1094 "could not write message.\n" );
1101 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStop: "
1102 "no connection.\n" );
1113 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1114 fprintf( stdout,
"FG::requestSampleRate\n" );
1124 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestSampleRate: "
1125 "could not buffer message.\n" );
1130 this->sampleRateMessageID, this->d_sender_id,
msgbuf,
1133 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestSampleRate: "
1134 "could not write message.\n" );
1141 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestSampleRate: "
1142 "no connection.\n" );
1153 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1154 fprintf( stdout,
"FG::requestInterpreterDescription\n" );
1164 this->requestInterpreterMessageID, this->d_sender_id, buf,
1167 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestInterpreterDescription: "
1168 "could not write message.\n" );
1175 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestInterpreterDescription: "
1176 "no connection.\n" );
1295 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1296 fprintf( stdout,
"FG::handle_channelReply_message\n" );
1303 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_channelReply_message: "
1304 "unable to decode.\n" );
1310 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_channelReply_message: "
1311 "invalid channel %d.\n", channelNum );
1316 vrpn_FUNCTION_CHANNEL_REPLY_CB cb;
1317 cb.msg_time.tv_sec = p.
msg_time.tv_sec;
1318 cb.msg_time.tv_usec = p.
msg_time.tv_usec;
1319 cb.channelNum = channelNum;
1320 cb.channel = me->
channels[channelNum];
1331 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1332 fprintf( stdout,
"FG::handle_startReply_message\n" );
1336 vrpn_bool isStarted =
false;
1339 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_startReply_message: "
1340 "unable to decode.\n" );
1345 vrpn_FUNCTION_START_REPLY_CB cb;
1346 cb.msg_time.tv_sec = p.
msg_time.tv_sec;
1347 cb.msg_time.tv_usec = p.
msg_time.tv_usec;
1348 cb.isStarted = isStarted;
1359 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1360 fprintf( stdout,
"FG::handle_stopReply_message\n" );
1364 vrpn_bool isStopped =
false;
1367 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_stopReply_message: "
1368 "unable to decode.\n" );
1373 vrpn_FUNCTION_STOP_REPLY_CB cb;
1374 cb.msg_time.tv_sec = p.
msg_time.tv_sec;
1375 cb.msg_time.tv_usec = p.
msg_time.tv_usec;
1376 cb.isStopped = isStopped;
1387 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1388 fprintf( stdout,
"FG::handle_sampleRateReply_message\n" );
1394 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_sampleRateReply_message: "
1395 "unable to decode.\n" );
1400 vrpn_FUNCTION_SAMPLE_RATE_REPLY_CB cb;
1401 cb.msg_time.tv_sec = p.
msg_time.tv_sec;
1402 cb.msg_time.tv_usec = p.
msg_time.tv_usec;
1414 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1415 fprintf( stdout,
"FG::handle_interpreterReply_message\n" );
1418 vrpn_FUNCTION_INTERPRETER_REPLY_CB cb;
1422 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_interpreterReply_message: "
1423 "unable to decode.\n" );
1428 cb.msg_time.tv_sec = p.
msg_time.tv_sec;
1429 cb.msg_time.tv_usec = p.
msg_time.tv_usec;
1440 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1441 fprintf( stdout,
"FG::handle_error_message\n" );
1444 vrpn_FUNCTION_ERROR_CB cb;
1448 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_error_message: "
1449 "unable to decode.\n" );
1454 cb.msg_time.tv_sec = p.
msg_time.tv_sec;
1455 cb.msg_time.tv_usec = p.
msg_time.tv_usec;
1481 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1482 fprintf( stdout,
"FG::encode_channel\n" );
1487 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1488 "invalid channel nubmer %d.\n", channelNum );
1492 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1497 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1498 "couldn't buffer (got %d, wanted at least %lud).\n",
1499 len,
static_cast<unsigned long>(
sizeof( vrpn_int32)) );
1505 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1506 "message payload error (couldn't buffer channel number).\n" );
1510 if( 0 > channel->
encode_to( buf, len ) )
1512 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1513 "message payload error (couldn't buffer channel).\n" );
1525 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1526 fprintf( stdout,
"FG::decode_channel\n" );
1529 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1534 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel: "
1535 "channel message payload error (got %d, wanted at least %lud).\n",
1536 len,
static_cast<unsigned long>(
sizeof( vrpn_int32)) );
1540 const char* mybuf = buf;
1541 vrpn_int32 mylen = len;
1542 vrpn_uint32 myNum = 0;
1545 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel: "
1546 "message payload error (couldn't unbuffer)\n" );
1550 mylen -=
sizeof( myNum );
1554 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel: "
1555 "error while decoding channel %d\n", channelNum );
1567 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1568 fprintf( stdout,
"FG::encode_channel_reply\n" );
1573 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1574 "invalid channel\n" );
1578 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1583 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1584 "insufficient buffer space given (got %d, wanted %lud).\n",
1585 len,
static_cast<unsigned long>(
sizeof( vrpn_uint32)) );
1591 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1592 "unable to buffer channel number.\n" );
1596 if( 0 >
channels[channelNum]->encode_to( buf, len ) )
1598 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1599 "unable to encode channel.\n" );
1610 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1611 fprintf( stdout,
"FG::decode_channel_reply\n" );
1614 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1619 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1620 "insufficient buffer space given (got %d, wanted %lud).\n",
1621 len,
static_cast<unsigned long>(
sizeof( vrpn_uint32)) );
1625 const char* mybuf = buf;
1626 vrpn_int32 mylen = len;
1627 vrpn_uint32 myNum = 0;
1630 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1631 "unable to unbuffer channel number.\n" );
1637 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1638 "invalid channel: %d\n", myNum );
1643 mylen -=
sizeof( vrpn_uint32 );
1651 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1652 fprintf( stdout,
"FG::encode_channel_request\n" );
1655 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1657 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel_request: "
1658 "channel message payload error (got %d, wanted at least %lud).\n",
1659 len,
static_cast<unsigned long>(
sizeof( vrpn_int32)) );
1663 vrpn_int32 mylen = len;
1666 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel_request: "
1667 "unable to buffer channel %d", channelNum );
1679 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1680 fprintf( stdout,
"FG::decode_channel_request\n" );
1683 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1688 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel_request: "
1689 "channel message payload error (got %d, wanted at least %lud).\n",
1690 len,
static_cast<unsigned long>(
sizeof( vrpn_int32)) );
1694 const char* mybuf = buf;
1697 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel_request: "
1698 "unable to unbuffer channel %d", channelNum );
1709 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1710 fprintf( stdout,
"FG::encode_sampleRate_request\n" );
1713 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
1715 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_sampleRate_request: "
1716 "channel message payload error (got %d, wanted at least %lud).\n",
1717 len,
static_cast<unsigned long>(
sizeof( vrpn_float32)) );
1721 vrpn_int32 mylen = len;
1724 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_sampleRate_request: "
1725 "unable to buffer sample rate" );
1737 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1738 fprintf( stdout,
"FG::decode_sampleRate_request\n" );
1741 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
1743 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_sampleRate_request: "
1744 "channel message payload error (got %d, wanted at least %lud).\n",
1745 len,
static_cast<unsigned long>(
sizeof( vrpn_float32)) );
1749 const char* mybuf = buf;
1752 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_sampleRate_request: "
1753 "unable to unbuffer sample rate" );
1764 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1765 fprintf( stdout,
"FG::encode_start_reply\n" );
1768 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
1770 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_start_reply: "
1771 "insufficient buffer space given (got %d, wanted %lud).\n",
1772 len,
static_cast<unsigned long>(
sizeof( vrpn_bool)) );
1783 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1784 fprintf( stdout,
"FG::decode_start_reply\n" );
1787 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
1789 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_start_reply: "
1790 "insufficient buffer space given (got %d, wanted %lud).\n",
1791 len,
static_cast<unsigned long>(
sizeof( vrpn_bool)) );
1795 const char* mybuf = buf;
1798 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_start_reply: "
1799 "unable to unbuffer stop condition.\n" );
1810 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1811 fprintf( stdout,
"FG::encode_stop_reply\n" );
1814 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
1816 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_stop_reply: "
1817 "insufficient buffer space given (got %d, wanted %lud).\n",
1818 len,
static_cast<unsigned long>(
sizeof( vrpn_bool)) );
1829 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1830 fprintf( stdout,
"FG::decode_stop_reply\n" );
1833 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
1835 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_stop_reply: "
1836 "insufficient buffer space given (got %d, wanted %lud).\n",
1837 len,
static_cast<unsigned long>(
sizeof( vrpn_bool)) );
1843 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_stop_reply: "
1844 "unable to unbuffer stop condition.\n" );
1855 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1856 fprintf( stdout,
"FG::encode_sampleRate_reply\n" );
1859 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
1861 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_sampleRate_reply: "
1862 "insufficient buffer space given (got %d, wanted %lud).\n",
1863 len,
static_cast<unsigned long>(
sizeof( vrpn_float32)) );
1874 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1875 fprintf( stdout,
"FG::decode_sampleRate_reply\n" );
1878 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
1880 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_sampleRate_reply: "
1881 "insufficient buffer space given (got %d, wanted %lud).\n",
1882 len,
static_cast<unsigned long>(
sizeof( vrpn_float32)) );
1886 vrpn_float32 myRate = 0;
1889 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_sampleRate_reply: "
1890 "unable to unbuffer sample rate.\n" );
1902 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1903 fprintf( stdout,
"FG::encode_interpreterDescription_reply\n" );
1906 vrpn_int32 dlength =
static_cast<vrpn_int32
>(strlen( desc ));
1907 if( len < dlength + (vrpn_int32)
sizeof( vrpn_int32 ) )
1909 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_interpreterDescription_reply: "
1910 "insufficient buffer space given (got %d, wanted %lud).\n",
1911 len, dlength +
static_cast<unsigned long>(
sizeof( vrpn_int32 )) );
1917 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_interpreterDescription_reply: "
1918 "unable to buffer description length.\n" );
1930 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1931 fprintf( stdout,
"FG::decode_interpreterDescription_reply\n" );
1934 if(
static_cast<unsigned>(len) <
sizeof( vrpn_int32 ) )
1936 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_interpreterDescription_reply: "
1937 "insufficient buffer space given (got %d, wanted at least %lud).\n",
1938 len,
static_cast<unsigned long>(
sizeof( vrpn_int32)) );
1942 vrpn_int32 dlength = 0;
1945 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_interpreterDescription_reply: "
1946 "unable to unbuffer description length.\n" );
1950 *desc =
new char[ dlength + 1 ];
1952 (*desc)[dlength] =
'\0';
1960 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1961 fprintf( stdout,
"FG::encode_error_report\n" );
1964 if(
static_cast<unsigned>(len) <
sizeof(
FGError ) +
sizeof( vrpn_int32 ) )
1966 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_error_report: "
1967 "insufficient buffer space given (got %d, wanted %lud).\n",
1968 len,
static_cast<unsigned long>(
sizeof(
FGError) +
sizeof( vrpn_int32 )) );
1972 vrpn_int32 mylen = len;
1975 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_error_report: "
1976 "unable to buffer error & channel" );
1988 #ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1989 fprintf( stdout,
"FG::decode_error_reply\n" );
1992 if(
static_cast<unsigned>(len) <
sizeof(
FGError ) +
sizeof( vrpn_int32 ) )
1994 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_error_reply: "
1995 "insufficient buffer space given (got %d, wanted %lud).\n",
1996 len,
static_cast<unsigned long>(
sizeof(
FGError) +
sizeof( vrpn_int32 )) );
2001 vrpn_int32 myChannel = -1;
2005 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_error_reply: "
2006 "unable to unbuffer error & channel.\n" );
2011 channel = myChannel;
vrpn_int32 decode_from(const char **buf, vrpn_int32 &len)
virtual int register_error_handler(void *userdata, vrpn_FUNCTION_ERROR_HANDLER handler)
static int VRPN_CALLBACK handle_channelReply_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_FunctionGenerator_channel * channels[vrpn_FUNCTION_CHANNELS_MAX]
vrpn_int32 decode_sampleRate_request(const char *buf, const vrpn_int32 len, vrpn_float32 &sampleRate)
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_int32 decode_interpreterDescription_reply(const char *buf, const vrpn_int32 len, char **desc)
virtual int pack_message(vrpn_uint32 len, struct timeval time, vrpn_int32 type, vrpn_int32 sender, const char *buffer, vrpn_uint32 class_of_service)
Pack a message that will be sent the next time mainloop() is called. Turn off the RELIABLE flag if yo...
vrpn_Callback_List< vrpn_FUNCTION_SAMPLE_RATE_REPLY_CB > sample_rate_reply_list
void client_mainloop(void)
Handles functions that all clients should provide in their mainloop() (warning of no server,...
static int VRPN_CALLBACK handle_channel_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 errorMessageID
const char * vrpn_got_connection
static int VRPN_CALLBACK handle_sample_rate_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_FunctionGenerator_function * clone() const
vrpn_int32 requestInterpreterMessageID
virtual int unregister_stop_reply_handler(void *userdata, vrpn_FUNCTION_STOP_REPLY_HANDLER handler)
void(VRPN_CALLBACK * vrpn_FUNCTION_INTERPRETER_REPLY_HANDLER)(void *userdata, const vrpn_FUNCTION_INTERPRETER_REPLY_CB info)
vrpn_FunctionGenerator_function_script()
virtual vrpn_float32 generateValues(vrpn_float32 *buf, vrpn_uint32 nValues, vrpn_float32 startTime, vrpn_float32 sampleRate, vrpn_FunctionGenerator_channel *channel) const
int sendStopReply(vrpn_bool stopped)
static int VRPN_CALLBACK handle_stop_message(void *userdata, vrpn_HANDLERPARAM p)
virtual int register_types()
Register the types of messages this device sends/receives. Return 0 on success, -1 on fail.
static int VRPN_CALLBACK handle_startReply_message(void *userdata, vrpn_HANDLERPARAM p)
static int VRPN_CALLBACK handle_channelRequest_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 sampleRateReplyMessageID
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
vrpn_int32 encode_to(char **buf, vrpn_int32 &len) const
vrpn_Callback_List< vrpn_FUNCTION_CHANNEL_REPLY_CB > channel_reply_list
vrpn_int32 requestChannelMessageID
vrpn_Callback_List< vrpn_FUNCTION_INTERPRETER_REPLY_CB > interpreter_reply_list
const char * vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL_REPLY
vrpn_int32 encode_error_report(char **buf, vrpn_int32 &len, const FGError err, const vrpn_int32 channel)
const char * vrpn_FUNCTION_MESSAGE_TYPE_INTERPRETER_REPLY
const char * vrpn_FUNCTION_MESSAGE_TYPE_START
const char * vrpn_FUNCTION_MESSAGE_TYPE_ALL_CHANNEL_REQUEST
int sendInterpreterDescription()
vrpn_FunctionGenerator_function * clone() const
vrpn_int32 encode_channel(char **buf, vrpn_int32 &len, const vrpn_uint32 channelNum, const vrpn_FunctionGenerator_channel *channel)
vrpn_int32 startFunctionMessageID
virtual int unregister_interpreter_reply_handler(void *userdata, vrpn_FUNCTION_INTERPRETER_REPLY_HANDLER handler)
vrpn_Callback_List< vrpn_FUNCTION_STOP_REPLY_CB > stop_reply_list
vrpn_int32 sampleRateMessageID
vrpn_int32 encode_channel_request(char **buf, vrpn_int32 &len, const vrpn_uint32 channelNum)
virtual int register_stop_reply_handler(void *userdata, vrpn_FUNCTION_STOP_REPLY_HANDLER handler)
virtual FunctionCode getFunctionCode() const =0
void(VRPN_CALLBACK * vrpn_FUNCTION_ERROR_HANDLER)(void *userdata, const vrpn_FUNCTION_ERROR_CB info)
virtual int unregister_channel_reply_handler(void *userdata, vrpn_FUNCTION_CHANGE_REPLY_HANDLER handler)
vrpn_int32 encode_to(char **buf, vrpn_int32 &len) const
const char * vrpn_FUNCTION_MESSAGE_TYPE_STOP
virtual void setSampleRate(vrpn_float32 rate)=0
const int vrpn_CONNECTION_TCP_BUFLEN
int sendChannelReply(vrpn_uint32 channelNum)
int sendStartReply(vrpn_bool started)
const char * vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL_REQUEST
char msgbuf[vrpn_CONNECTION_TCP_BUFLEN]
int register_handler(void *userdata, HANDLER_TYPE handler)
Call this to add a handler to the list.
static int VRPN_CALLBACK handle_stopReply_message(void *userdata, vrpn_HANDLERPARAM p)
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.
virtual ~vrpn_FunctionGenerator_function()=0
vrpn_int32 encode_start_reply(char **buf, vrpn_int32 &len, const vrpn_bool isStarted)
vrpn_Connection * d_connection
Connection that this object talks to.
const char * vrpn_FUNCTION_MESSAGE_TYPE_START_REPLY
virtual int register_start_reply_handler(void *userdata, vrpn_FUNCTION_START_REPLY_HANDLER handler)
vrpn_int32 requestAllChannelsMessageID
virtual vrpn_int32 register_message_type(const char *name)
vrpn_int32 gotConnectionMessageID
vrpn_FunctionGenerator_channel()
virtual ~vrpn_FunctionGenerator_function_script()
vrpn_int32 decode_error_reply(const char *buf, const vrpn_int32 len, FGError &error, vrpn_int32 &channel)
const char * vrpn_FUNCTION_MESSAGE_TYPE_CHANNEL
const vrpn_uint32 vrpn_CONNECTION_RELIABLE
Classes of service for messages, specify multiple by ORing them together Priority of satisfying these...
This structure is what is passed to a vrpn_Connection message callback.
void(VRPN_CALLBACK * vrpn_FUNCTION_STOP_REPLY_HANDLER)(void *userdata, const vrpn_FUNCTION_STOP_REPLY_CB info)
virtual int register_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)
void setFunction(vrpn_FunctionGenerator_function *function)
vrpn_FunctionGenerator_function * function
static int VRPN_CALLBACK handle_interpreterReply_message(void *userdata, vrpn_HANDLERPARAM p)
vrpn_int32 encode_channel_reply(char **buf, vrpn_int32 &len, const vrpn_uint32 channelNum)
vrpn_int32 d_sender_id
Sender ID registered with the connection.
int sendError(FGError error, vrpn_int32 channel)
static int VRPN_CALLBACK handle_start_message(void *userdata, vrpn_HANDLERPARAM p)
virtual int register_sample_rate_reply_handler(void *userdata, vrpn_FUNCTION_SAMPLE_RATE_REPLY_HANDLER handler)
vrpn_int32 decode_from(const char **buf, vrpn_int32 &len)
vrpn_float32 generateValues(vrpn_float32 *buf, vrpn_uint32 nValues, vrpn_float32 startTime, vrpn_float32 sampleRate, vrpn_FunctionGenerator_channel *channel) const
virtual int register_interpreter_reply_handler(void *userdata, vrpn_FUNCTION_INTERPRETER_REPLY_HANDLER handler)
int requestSampleRate(const vrpn_float32 rate)
virtual int mainloop(const struct timeval *timeout=NULL)=0
Call each time through program main loop to handle receiving any incoming messages and sending any pa...
int requestChannel(const vrpn_uint32 channelNum)
void(VRPN_CALLBACK * vrpn_FUNCTION_SAMPLE_RATE_REPLY_HANDLER)(void *userdata, const vrpn_FUNCTION_SAMPLE_RATE_REPLY_CB info)
vrpn_uint32 setNumChannels(vrpn_uint32 numChannels)
Generic connection class not specific to the transport mechanism.
int requestInterpreterDescription()
vrpn_Callback_List< vrpn_FUNCTION_ERROR_CB > error_list
const char * vrpn_FUNCTION_MESSAGE_TYPE_SAMPLE_RATE_REPLY
vrpn_int32 interpreterReplyMessageID
vrpn_int32 decode_start_reply(const char *buf, const vrpn_int32 len, vrpn_bool &isStarted)
vrpn_int32 stopFunctionReplyMessageID
#define vrpn_gettimeofday
virtual const char * getInterpreterDescription()=0
void(VRPN_CALLBACK * vrpn_FUNCTION_CHANGE_REPLY_HANDLER)(void *userdata, const vrpn_FUNCTION_CHANNEL_REPLY_CB info)
vrpn_int32 channelMessageID
const char * vrpn_FUNCTION_MESSAGE_TYPE_INTERPRETER_REQUEST
vrpn_int32 decode_sampleRate_reply(const char *buf, const vrpn_int32 len)
int sendSampleRateReply()
vrpn_int32 encode_interpreterDescription_reply(char **buf, vrpn_int32 &len, const char *desc)
static int VRPN_CALLBACK handle_error_message(void *userdata, vrpn_HANDLERPARAM p)
const vrpn_uint32 vrpn_FUNCTION_CHANNELS_MAX
vrpn_int32 encode_to(char **buf, vrpn_int32 &len) const
vrpn_int32 channelReplyMessageID
virtual int unregister_sample_rate_reply_handler(void *userdata, vrpn_FUNCTION_SAMPLE_RATE_REPLY_HANDLER handler)
virtual vrpn_int32 decode_from(const char **buf, vrpn_int32 &len)=0
vrpn_int32 encode_stop_reply(char **buf, vrpn_int32 &len, const vrpn_bool isStopped)
vrpn_int32 decode_from(const char **buf, vrpn_int32 &len)
vrpn_bool setScript(char *script)
vrpn_int32 startFunctionReplyMessageID
const char * vrpn_FUNCTION_MESSAGE_TYPE_ERROR
const char * vrpn_FUNCTION_MESSAGE_TYPE_SAMPLE_RATE
vrpn_int32 encode_sampleRate_request(char **buf, vrpn_int32 &len, const vrpn_float32 sampleRate)
virtual ~vrpn_FunctionGenerator_Server()
virtual ~vrpn_FunctionGenerator_channel()
virtual int init(void)
Initialize things that the constructor can't. Returns 0 on success, -1 on failure.
vrpn_int32 decode_channel(const char *buf, const vrpn_int32 len, vrpn_uint32 &channelNum, vrpn_FunctionGenerator_channel &channel)
vrpn_int32 stopFunctionMessageID
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.
void(VRPN_CALLBACK * vrpn_FUNCTION_START_REPLY_HANDLER)(void *userdata, const vrpn_FUNCTION_START_REPLY_CB info)
const vrpn_FunctionGenerator_channel * getChannel(vrpn_uint32 channelNum)
vrpn_FunctionGenerator_Server(const char *name, vrpn_uint32 numChannels=vrpn_FUNCTION_CHANNELS_MAX, vrpn_Connection *c=NULL)
vrpn_int32 decode_channel_reply(const char *buf, const vrpn_int32 len, vrpn_uint32 &channelNum)
static int VRPN_CALLBACK handle_sampleRateReply_message(void *userdata, vrpn_HANDLERPARAM p)
virtual void mainloop()
Called once through each main loop iteration to handle updates. Remote object mainloop() should call ...
void call_handlers(const CALLBACK_STRUCT &info)
This will pass the referenced parameter as a const to all the callbacks.
static int VRPN_CALLBACK handle_interpreter_request_message(void *userdata, vrpn_HANDLERPARAM p)
int unregister_handler(void *userdata, HANDLER_TYPE handler)
Call this to remove a handler from the list (if it exists)
vrpn_int32 encode_sampleRate_reply(char **buf, vrpn_int32 &len, const vrpn_float32 sampleRate)
int setChannel(const vrpn_uint32 channelNum, const vrpn_FunctionGenerator_channel *channel)
virtual void setChannel(vrpn_uint32 channelNum, vrpn_FunctionGenerator_channel *channel)=0
vrpn_Callback_List< vrpn_FUNCTION_START_REPLY_CB > start_reply_list
virtual int unregister_start_reply_handler(void *userdata, vrpn_FUNCTION_START_REPLY_HANDLER handler)
const char * vrpn_FUNCTION_MESSAGE_TYPE_STOP_REPLY
vrpn_FunctionGenerator_function_NULL()
virtual ~vrpn_FunctionGenerator()
static int VRPN_CALLBACK handle_allChannelRequest_message(void *userdata, vrpn_HANDLERPARAM p)
virtual int unregister_error_handler(void *userdata, vrpn_FUNCTION_ERROR_HANDLER handler)
vrpn_int32 decode_channel_request(const char *buf, const vrpn_int32 len, vrpn_uint32 &channelNum)
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Class from which all user-level (and other) classes that communicate with vrpn_Connections should der...
class VRPN_API vrpn_FunctionGenerator_channel
vrpn_FunctionGenerator(const char *name, vrpn_Connection *c=NULL)
vrpn_FunctionGenerator_Remote(const char *name, vrpn_Connection *c=NULL)
vrpn_MESSAGEHANDLER handler