32 vrpn_float32 startTime, vrpn_float32 sampleRate,
35 for( vrpn_uint32 i = 0; i <= nValues - 1; i++ )
39 return startTime + nValues / sampleRate;
61 catch (...) {
return NULL; }
81 this->
script =
new char[1];
92 this->script =
new char[strlen(
script) + 1];
127 fprintf(stderr,
"vrpn_FunctionGenerator_function_script::~vrpn_FunctionGenerator_function_script(): delete failed\n");
135generateValues( vrpn_float32* buf, vrpn_uint32 nValues, vrpn_float32 startTime,
138 for( vrpn_uint32 i = 0; i <= nValues - 1; i++ )
142 return startTime + nValues / sampleRate;
147encode_to(
char** buf, vrpn_int32& len )
const
149 vrpn_uint32 length =
static_cast<vrpn_uint32
>(strlen( this->
script ));
150 vrpn_int32 bytes = length +
sizeof( vrpn_uint32 );
153 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::encode_to: "
154 "payload error (wanted %d got %d).\n", bytes, len );
160 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::encode_to: "
161 "payload error (couldn't buffer length).\n" );
167 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::encode_to: "
168 "payload error (couldn't buffer script).\n" );
182 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::decode_from: "
183 "payload error (couldn't unbuffer length).\n" );
187 len -=
sizeof( vrpn_uint32);
191 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::decode_from: "
192 "payload error (wanted %d got %d).\n", newlen, len );
197 char* newscript = NULL;
198 try { newscript =
new char[newlen + 1]; }
200 fprintf(stderr,
"vrpn_FunctionGenerator_function_script:: "
207 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::decode_from: "
208 "payload error (couldn't unbuffer).\n" );
212 fprintf(stderr,
"vrpn_FunctionGenerator_function_script::decode_from(): delete failed\n");
218 newscript[newlen] =
'\0';
219 if (this->
script != NULL) {
223 fprintf(stderr,
"vrpn_FunctionGenerator_function_script::decode_from(): delete failed\n");
229 return newlen +
sizeof( vrpn_uint32 );
244 retval =
new char[strlen(this->
script) + 1];
255 if(
script == NULL )
return false;
256 if (this->script != NULL) {
258 delete[] this->script;
260 fprintf(stderr,
"vrpn_FunctionGenerator_function_script::setScript(): delete failed\n");
265 this->script =
new char[strlen(
script) + 1];
267 }
catch (...) {
return false; }
302 fprintf(stderr,
"vrpn_FunctionGenerator_channel::~vrpn_FunctionGenerator_channel(): delete failed\n");
311 delete (this->function);
313 fprintf(stderr,
"vrpn_FunctionGenerator_channel::setFunction(): delete failed\n");
321encode_to(
char** buf, vrpn_int32& len )
const
325 fprintf( stderr,
"vrpn_FunctionGenerator_channel::encode_to: "
326 "insufficient buffer space given (got %d, wanted %lud).\n",
333 fprintf( stderr,
"vrpn_FunctionGenerator_channel::encode_to: "
334 "unable to buffer function type.\n" );
338 return function->encode_to( buf, len );
347 fprintf( stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
348 "insufficient buffer space given (got %d, wanted %lud).\n",
356 fprintf( stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
357 "unable to unbuffer function type.\n" );
363 if( myCode !=
function->getFunctionCode() )
378 fprintf( stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
379 "unknown function type.\n" );
384 fprintf(stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
392 fprintf(stderr,
"vrpn_FunctionGenerator_channel::decode_from(): delete failed\n");
396 return this->
function->decode_from( buf, len );
434 fprintf(stderr,
"vrpn_FunctionGenerator::~vrpn_FunctionGenerator(): delete failed\n");
453#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
454 fprintf( stdout,
"FG::register_types\n" );
483 fprintf( stderr,
"vrpn_FunctionGenerator::register_types: error registering types.\n" );
512 fprintf( stderr,
"vrpn_FunctionGenerator_Server: Can't get connection!\n" );
519 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register change channel request handler\n" );
526 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register channel request handler\n" );
533 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register all-channel request handler\n" );
540 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register start request handler\n" );
547 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register stop request handler\n" );
554 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register sample-rate request handler\n" );
561 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register interpreter request handler\n" );
581 return this->numChannels;
597#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
598 fprintf( stdout,
"FG::handle_channel_message\n" );
604 catch (...) {
return -1; }
628#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
629 fprintf( stdout,
"FG::handle_channelRequest_message\n" );
637 fprintf( stderr,
"vrpn_FunctionGenerator_Server::handle_channelRequest_message: "
638 "unable to decode channel number.\n" );
644 fprintf( stderr,
"vrpn_FunctionGenerator_Server::handle_channelRequest_message: "
645 "invalid channel number %d.\n", channelNum );
659#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
660 fprintf( stdout,
"FG::handle_allChannelRequest_message\n" );
679#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
680 fprintf( stdout,
"FG::handle_start_message\n" );
693#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
694 fprintf( stdout,
"FG::handle_stop_message\n" );
707#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
708 fprintf( stdout,
"FG::handle_sample_rate_message\n" );
712 vrpn_float32 rate = 0;
715 fprintf( stderr,
"vrpn_FunctionGenerator_Server::handle_sample_rate_message: "
716 "unable to decode.\n" );
730#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
731 fprintf( stdout,
"FG::handle_interpreter_request_message\n" );
744#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
745 fprintf( stdout,
"FG::sendChannelReply\n" );
755 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendChannelReply: "
756 "could not buffer message.\n" );
761 this->channelReplyMessageID, this->d_sender_id,
764 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendChannelReply: "
765 "could not write message.\n" );
777#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
778 fprintf( stdout,
"FG::sendSampleRateReply\n" );
788 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendSampleRateReply: "
789 "could not buffer message.\n" );
794 this->sampleRateReplyMessageID, this->d_sender_id,
797 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendSampleRateReply: "
798 "could not write message.\n" );
810#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
811 fprintf( stdout,
"FG::sendStartReply\n" );
821 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStartReply: "
822 "could not buffer message.\n" );
827 this->startFunctionReplyMessageID, this->d_sender_id,
830 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStartReply: "
831 "could not write message.\n" );
843#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
844 fprintf( stdout,
"FG::sendStopReply\n" );
854 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStopReply: "
855 "could not buffer message.\n" );
860 this->stopFunctionReplyMessageID, this->d_sender_id,
863 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStopReply: "
864 "could not write message.\n" );
876#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
877 fprintf( stdout,
"FG::sendInterpreterDescription\n" );
887 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendInterpreterDescription: "
888 "could not buffer message.\n" );
893 this->interpreterReplyMessageID, this->d_sender_id,
896 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendInterpreterDescription: "
897 "could not write message.\n" );
909#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
910 fprintf( stdout,
"FG::sendError\n" );
920 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendError: "
921 "could not buffer message.\n" );
926 this->errorMessageID, this->d_sender_id,
929 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendError: "
930 "could not write message.\n" );
960 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: Can't get connection!\n" );
967 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register channel reply handler\n" );
974 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register start reply handler\n" );
981 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register stop reply handler\n" );
988 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register sample-rate reply handler\n" );
995 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register interpreter reply handler\n" );
1002 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register error message handler\n" );
1013#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1014 fprintf( stdout,
"FG::setChannel\n" );
1022 if( 0 > this->
encode_channel( &buf, buflen, channelNum, channel ) )
1024 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::setChannel: "
1025 "could not buffer message.\n" );
1030 this->channelMessageID, this->d_sender_id,
msgbuf,
1033 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::setChannel: "
1034 "could not write message.\n" );
1041 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::setChannel: "
1042 "no connection.\n" );
1053#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1054 fprintf( stdout,
"FG::requestChannel\n" );
1064 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestChannel: "
1065 "could not buffer message.\n" );
1070 this->requestChannelMessageID, this->d_sender_id,
msgbuf,
1073 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestChannel: "
1074 "could not write message.\n" );
1081 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestChannel: "
1082 "no connection.\n" );
1094#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1095 fprintf( stdout,
"FG::requestAllChannels\n" );
1105 this->requestAllChannelsMessageID, this->d_sender_id, buf,
1108 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestAllChannels: "
1109 "could not write message.\n" );
1116 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestAllChannels: "
1117 "no connection.\n" );
1128#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1129 fprintf( stdout,
"FG::requestStart\n" );
1139 this->startFunctionMessageID, this->d_sender_id, buf,
1142 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStart: "
1143 "could not write message.\n" );
1150 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStart: "
1151 "no connection.\n" );
1162#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1163 fprintf( stdout,
"FG::requestStop\n" );
1173 this->stopFunctionMessageID, this->d_sender_id, buf,
1176 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStop: "
1177 "could not write message.\n" );
1184 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStop: "
1185 "no connection.\n" );
1196#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1197 fprintf( stdout,
"FG::requestSampleRate\n" );
1207 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestSampleRate: "
1208 "could not buffer message.\n" );
1213 this->sampleRateMessageID, this->d_sender_id,
msgbuf,
1216 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestSampleRate: "
1217 "could not write message.\n" );
1224 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestSampleRate: "
1225 "no connection.\n" );
1236#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1237 fprintf( stdout,
"FG::requestInterpreterDescription\n" );
1247 this->requestInterpreterMessageID, this->d_sender_id, buf,
1250 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestInterpreterDescription: "
1251 "could not write message.\n" );
1258 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestInterpreterDescription: "
1259 "no connection.\n" );
1378#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1379 fprintf( stdout,
"FG::handle_channelReply_message\n" );
1386 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_channelReply_message: "
1387 "unable to decode.\n" );
1393 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_channelReply_message: "
1394 "invalid channel %d.\n", channelNum );
1414#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1415 fprintf( stdout,
"FG::handle_startReply_message\n" );
1419 vrpn_bool isStarted =
false;
1422 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_startReply_message: "
1423 "unable to decode.\n" );
1442#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1443 fprintf( stdout,
"FG::handle_stopReply_message\n" );
1447 vrpn_bool isStopped =
false;
1450 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_stopReply_message: "
1451 "unable to decode.\n" );
1470#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1471 fprintf( stdout,
"FG::handle_sampleRateReply_message\n" );
1477 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_sampleRateReply_message: "
1478 "unable to decode.\n" );
1497#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1498 fprintf( stdout,
"FG::handle_interpreterReply_message\n" );
1505 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_interpreterReply_message: "
1506 "unable to decode.\n" );
1523#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1524 fprintf( stdout,
"FG::handle_error_message\n" );
1531 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_error_message: "
1532 "unable to decode.\n" );
1561encode_channel(
char** buf, vrpn_int32& len,
const vrpn_uint32 channelNum,
1564#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1565 fprintf( stdout,
"FG::encode_channel\n" );
1570 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1571 "invalid channel nubmer %d.\n", channelNum );
1575 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
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)) );
1588 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1589 "message payload error (couldn't buffer channel number).\n" );
1593 if( 0 > channel->
encode_to( buf, len ) )
1595 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1596 "message payload error (couldn't buffer channel).\n" );
1605decode_channel(
const char* buf,
const vrpn_int32 len, vrpn_uint32& channelNum,
1608#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1609 fprintf( stdout,
"FG::decode_channel\n" );
1612 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
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)) );
1623 const char* mybuf = buf;
1624 vrpn_int32 mylen = len;
1625 vrpn_uint32 myNum = 0;
1628 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel: "
1629 "message payload error (couldn't unbuffer)\n" );
1633 mylen -=
sizeof( myNum );
1637 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel: "
1638 "error while decoding channel %d\n", channelNum );
1650#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1651 fprintf( stdout,
"FG::encode_channel_reply\n" );
1656 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1657 "invalid channel\n" );
1661 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
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)) );
1674 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1675 "unable to buffer channel number.\n" );
1679 if( 0 >
channels[channelNum]->encode_to( buf, len ) )
1681 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1682 "unable to encode channel.\n" );
1693#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1694 fprintf( stdout,
"FG::decode_channel_reply\n" );
1697 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
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)) );
1708 const char* mybuf = buf;
1709 vrpn_int32 mylen = len;
1710 vrpn_uint32 myNum = 0;
1713 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1714 "unable to unbuffer channel number.\n" );
1720 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1721 "invalid channel: %d\n", myNum );
1726 mylen -=
sizeof( vrpn_uint32 );
1727 return channels[channelNum]->decode_from( &mybuf, mylen );
1734#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1735 fprintf( stdout,
"FG::encode_channel_request\n" );
1738 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
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)) );
1746 vrpn_int32 mylen = len;
1749 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel_request: "
1750 "unable to buffer channel %d", channelNum );
1762#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1763 fprintf( stdout,
"FG::decode_channel_request\n" );
1766 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
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)) );
1777 const char* mybuf = buf;
1780 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel_request: "
1781 "unable to unbuffer channel %d", channelNum );
1792#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1793 fprintf( stdout,
"FG::encode_sampleRate_request\n" );
1796 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
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)) );
1804 vrpn_int32 mylen = len;
1807 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_sampleRate_request: "
1808 "unable to buffer sample rate" );
1820#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1821 fprintf( stdout,
"FG::decode_sampleRate_request\n" );
1824 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
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)) );
1832 const char* mybuf = buf;
1835 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_sampleRate_request: "
1836 "unable to unbuffer sample rate" );
1847#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1848 fprintf( stdout,
"FG::encode_start_reply\n" );
1851 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
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)) );
1866#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1867 fprintf( stdout,
"FG::decode_start_reply\n" );
1870 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
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)) );
1878 const char* mybuf = buf;
1881 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_start_reply: "
1882 "unable to unbuffer stop condition.\n" );
1893#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1894 fprintf( stdout,
"FG::encode_stop_reply\n" );
1897 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
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)) );
1912#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1913 fprintf( stdout,
"FG::decode_stop_reply\n" );
1916 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
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)) );
1926 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_stop_reply: "
1927 "unable to unbuffer stop condition.\n" );
1938#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1939 fprintf( stdout,
"FG::encode_sampleRate_reply\n" );
1942 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
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)) );
1957#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1958 fprintf( stdout,
"FG::decode_sampleRate_reply\n" );
1961 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
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)) );
1969 vrpn_float32 myRate = 0;
1972 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_sampleRate_reply: "
1973 "unable to unbuffer sample rate.\n" );
1985#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1986 fprintf( stdout,
"FG::encode_interpreterDescription_reply\n" );
1989 vrpn_int32 dlength =
static_cast<vrpn_int32
>(strlen( desc ));
1990 if( len < dlength + (vrpn_int32)
sizeof( vrpn_int32 ) )
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 )) );
2000 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_interpreterDescription_reply: "
2001 "unable to buffer description length.\n" );
2013#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
2014 fprintf( stdout,
"FG::decode_interpreterDescription_reply\n" );
2017 if(
static_cast<unsigned>(len) <
sizeof( vrpn_int32 ) )
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)) );
2025 vrpn_int32 dlength = 0;
2028 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_interpreterDescription_reply: "
2029 "unable to unbuffer description length.\n" );
2033 try { *desc =
new char[dlength + 1]; }
2035 fprintf(stderr,
"vrpn_FunctionGenerator_Remote::decode_interpreterDescription_reply: "
2036 "Out of memory.\n");
2041 (*desc)[dlength] =
'\0';
2049#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
2050 fprintf( stdout,
"FG::encode_error_report\n" );
2053 if(
static_cast<unsigned>(len) <
sizeof(
FGError ) +
sizeof( vrpn_int32 ) )
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 )) );
2061 vrpn_int32 mylen = len;
2064 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_error_report: "
2065 "unable to buffer error & channel" );
2077#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
2078 fprintf( stdout,
"FG::decode_error_reply\n" );
2081 if(
static_cast<unsigned>(len) <
sizeof(
FGError ) +
sizeof( vrpn_int32 ) )
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 )) );
2090 vrpn_int32 myChannel = -1;
2094 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_error_reply: "
2095 "unable to unbuffer error & channel.\n" );
2100 channel = myChannel;
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 requestInterpreterDescription()
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
int sendSampleRateReply()
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)
int sendStopReply(vrpn_bool stopped)
int sendInterpreterDescription()
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)
int sendStartReply(vrpn_bool started)
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)
virtual ~vrpn_FunctionGenerator_Server()
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
virtual ~vrpn_FunctionGenerator_channel()
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_channel()
vrpn_FunctionGenerator_function * function
vrpn_FunctionGenerator_function_NULL()
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
virtual ~vrpn_FunctionGenerator_function_script()
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_bool setScript(char *script)
vrpn_FunctionGenerator_function_script()
vrpn_int32 encode_to(char **buf, vrpn_int32 &len) const
vrpn_int32 decode_from(const char **buf, vrpn_int32 &len)
virtual ~vrpn_FunctionGenerator_function()=0
vrpn_int32 channelReplyMessageID
vrpn_int32 requestInterpreterMessageID
vrpn_int32 errorMessageID
virtual ~vrpn_FunctionGenerator()
char msgbuf[vrpn_CONNECTION_TCP_BUFLEN]
vrpn_int32 stopFunctionMessageID
vrpn_int32 requestAllChannelsMessageID
vrpn_int32 interpreterReplyMessageID
vrpn_int32 requestChannelMessageID
vrpn_FunctionGenerator_channel * channels[vrpn_FUNCTION_CHANNELS_MAX]
vrpn_int32 startFunctionMessageID
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.
vrpn_int32 sampleRateReplyMessageID
vrpn_int32 channelMessageID
vrpn_int32 startFunctionReplyMessageID
vrpn_int32 stopFunctionReplyMessageID
const vrpn_FunctionGenerator_channel * getChannel(vrpn_uint32 channelNum)
vrpn_int32 sampleRateMessageID
vrpn_int32 gotConnectionMessageID
vrpn_FunctionGenerator_channel * channel
vrpn_FunctionGenerator::FGError err
This structure is what is passed to a vrpn_Connection message 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 ...