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];
93 strcpy(this->script,
script);
115 fprintf(stderr,
"vrpn_FunctionGenerator_function_script::~vrpn_FunctionGenerator_function_script(): delete failed\n");
123generateValues( vrpn_float32* buf, vrpn_uint32 nValues, vrpn_float32 startTime,
126 for( vrpn_uint32 i = 0; i <= nValues - 1; i++ )
130 return startTime + nValues / sampleRate;
135encode_to(
char** buf, vrpn_int32& len )
const
137 vrpn_uint32 length =
static_cast<vrpn_uint32
>(strlen( this->
script ));
138 vrpn_int32 bytes = length +
sizeof( vrpn_uint32 );
141 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::encode_to: "
142 "payload error (wanted %d got %d).\n", bytes, len );
148 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::encode_to: "
149 "payload error (couldn't buffer length).\n" );
155 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::encode_to: "
156 "payload error (couldn't buffer script).\n" );
170 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::decode_from: "
171 "payload error (couldn't unbuffer length).\n" );
175 len -=
sizeof( vrpn_uint32);
179 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::decode_from: "
180 "payload error (wanted %d got %d).\n", newlen, len );
185 char* newscript = NULL;
186 try { newscript =
new char[newlen + 1]; }
188 fprintf(stderr,
"vrpn_FunctionGenerator_function_script:: "
195 fprintf( stderr,
"vrpn_FunctionGenerator_function_script::decode_from: "
196 "payload error (couldn't unbuffer).\n" );
200 fprintf(stderr,
"vrpn_FunctionGenerator_function_script::decode_from(): delete failed\n");
206 newscript[newlen] =
'\0';
207 if (this->
script != NULL) {
211 fprintf(stderr,
"vrpn_FunctionGenerator_function_script::decode_from(): delete failed\n");
217 return newlen +
sizeof( vrpn_uint32 );
232 retval =
new char[strlen(this->
script) + 1];
243 if(
script == NULL )
return false;
244 if (this->script != NULL) {
246 delete[] this->script;
248 fprintf(stderr,
"vrpn_FunctionGenerator_function_script::setScript(): delete failed\n");
253 this->script =
new char[strlen(
script) + 1];
254 strcpy(this->script,
script);
255 }
catch (...) {
return false; }
290 fprintf(stderr,
"vrpn_FunctionGenerator_channel::~vrpn_FunctionGenerator_channel(): delete failed\n");
299 delete (this->function);
301 fprintf(stderr,
"vrpn_FunctionGenerator_channel::setFunction(): delete failed\n");
309encode_to(
char** buf, vrpn_int32& len )
const
313 fprintf( stderr,
"vrpn_FunctionGenerator_channel::encode_to: "
314 "insufficient buffer space given (got %d, wanted %lud).\n",
321 fprintf( stderr,
"vrpn_FunctionGenerator_channel::encode_to: "
322 "unable to buffer function type.\n" );
326 return function->encode_to( buf, len );
335 fprintf( stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
336 "insufficient buffer space given (got %d, wanted %lud).\n",
344 fprintf( stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
345 "unable to unbuffer function type.\n" );
351 if( myCode !=
function->getFunctionCode() )
366 fprintf( stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
367 "unknown function type.\n" );
372 fprintf(stderr,
"vrpn_FunctionGenerator_channel::decode_from: "
380 fprintf(stderr,
"vrpn_FunctionGenerator_channel::decode_from(): delete failed\n");
384 return this->
function->decode_from( buf, len );
422 fprintf(stderr,
"vrpn_FunctionGenerator::~vrpn_FunctionGenerator(): delete failed\n");
441#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
442 fprintf( stdout,
"FG::register_types\n" );
471 fprintf( stderr,
"vrpn_FunctionGenerator::register_types: error registering types.\n" );
500 fprintf( stderr,
"vrpn_FunctionGenerator_Server: Can't get connection!\n" );
507 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register change channel request handler\n" );
514 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register channel request handler\n" );
521 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register all-channel request handler\n" );
528 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register start request handler\n" );
535 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register stop request handler\n" );
542 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register sample-rate request handler\n" );
549 fprintf( stderr,
"vrpn_FunctionGenerator_Server: can't register interpreter request handler\n" );
569 return this->numChannels;
585#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
586 fprintf( stdout,
"FG::handle_channel_message\n" );
592 catch (...) {
return -1; }
616#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
617 fprintf( stdout,
"FG::handle_channelRequest_message\n" );
625 fprintf( stderr,
"vrpn_FunctionGenerator_Server::handle_channelRequest_message: "
626 "unable to decode channel number.\n" );
632 fprintf( stderr,
"vrpn_FunctionGenerator_Server::handle_channelRequest_message: "
633 "invalid channel number %d.\n", channelNum );
647#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
648 fprintf( stdout,
"FG::handle_allChannelRequest_message\n" );
667#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
668 fprintf( stdout,
"FG::handle_start_message\n" );
681#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
682 fprintf( stdout,
"FG::handle_stop_message\n" );
695#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
696 fprintf( stdout,
"FG::handle_sample_rate_message\n" );
700 vrpn_float32 rate = 0;
703 fprintf( stderr,
"vrpn_FunctionGenerator_Server::handle_sample_rate_message: "
704 "unable to decode.\n" );
718#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
719 fprintf( stdout,
"FG::handle_interpreter_request_message\n" );
732#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
733 fprintf( stdout,
"FG::sendChannelReply\n" );
743 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendChannelReply: "
744 "could not buffer message.\n" );
749 this->channelReplyMessageID, this->d_sender_id,
752 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendChannelReply: "
753 "could not write message.\n" );
765#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
766 fprintf( stdout,
"FG::sendSampleRateReply\n" );
776 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendSampleRateReply: "
777 "could not buffer message.\n" );
782 this->sampleRateReplyMessageID, this->d_sender_id,
785 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendSampleRateReply: "
786 "could not write message.\n" );
798#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
799 fprintf( stdout,
"FG::sendStartReply\n" );
809 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStartReply: "
810 "could not buffer message.\n" );
815 this->startFunctionReplyMessageID, this->d_sender_id,
818 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStartReply: "
819 "could not write message.\n" );
831#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
832 fprintf( stdout,
"FG::sendStopReply\n" );
842 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStopReply: "
843 "could not buffer message.\n" );
848 this->stopFunctionReplyMessageID, this->d_sender_id,
851 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendStopReply: "
852 "could not write message.\n" );
864#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
865 fprintf( stdout,
"FG::sendInterpreterDescription\n" );
875 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendInterpreterDescription: "
876 "could not buffer message.\n" );
881 this->interpreterReplyMessageID, this->d_sender_id,
884 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendInterpreterDescription: "
885 "could not write message.\n" );
897#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
898 fprintf( stdout,
"FG::sendError\n" );
908 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendError: "
909 "could not buffer message.\n" );
914 this->errorMessageID, this->d_sender_id,
917 fprintf( stderr,
"vrpn_FunctionGenerator_Server::sendError: "
918 "could not write message.\n" );
948 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: Can't get connection!\n" );
955 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register channel reply handler\n" );
962 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register start reply handler\n" );
969 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register stop reply handler\n" );
976 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register sample-rate reply handler\n" );
983 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register interpreter reply handler\n" );
990 fprintf( stderr,
"vrpn_FunctionGenerator_Remote: can't register error message handler\n" );
1001#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1002 fprintf( stdout,
"FG::setChannel\n" );
1010 if( 0 > this->
encode_channel( &buf, buflen, channelNum, channel ) )
1012 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::setChannel: "
1013 "could not buffer message.\n" );
1018 this->channelMessageID, this->d_sender_id,
msgbuf,
1021 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::setChannel: "
1022 "could not write message.\n" );
1029 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::setChannel: "
1030 "no connection.\n" );
1041#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1042 fprintf( stdout,
"FG::requestChannel\n" );
1052 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestChannel: "
1053 "could not buffer message.\n" );
1058 this->requestChannelMessageID, this->d_sender_id,
msgbuf,
1061 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestChannel: "
1062 "could not write message.\n" );
1069 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestChannel: "
1070 "no connection.\n" );
1082#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1083 fprintf( stdout,
"FG::requestAllChannels\n" );
1093 this->requestAllChannelsMessageID, this->d_sender_id, buf,
1096 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestAllChannels: "
1097 "could not write message.\n" );
1104 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestAllChannels: "
1105 "no connection.\n" );
1116#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1117 fprintf( stdout,
"FG::requestStart\n" );
1127 this->startFunctionMessageID, this->d_sender_id, buf,
1130 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStart: "
1131 "could not write message.\n" );
1138 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStart: "
1139 "no connection.\n" );
1150#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1151 fprintf( stdout,
"FG::requestStop\n" );
1161 this->stopFunctionMessageID, this->d_sender_id, buf,
1164 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStop: "
1165 "could not write message.\n" );
1172 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestStop: "
1173 "no connection.\n" );
1184#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1185 fprintf( stdout,
"FG::requestSampleRate\n" );
1195 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestSampleRate: "
1196 "could not buffer message.\n" );
1201 this->sampleRateMessageID, this->d_sender_id,
msgbuf,
1204 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestSampleRate: "
1205 "could not write message.\n" );
1212 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestSampleRate: "
1213 "no connection.\n" );
1224#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1225 fprintf( stdout,
"FG::requestInterpreterDescription\n" );
1235 this->requestInterpreterMessageID, this->d_sender_id, buf,
1238 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestInterpreterDescription: "
1239 "could not write message.\n" );
1246 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::requestInterpreterDescription: "
1247 "no connection.\n" );
1366#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1367 fprintf( stdout,
"FG::handle_channelReply_message\n" );
1374 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_channelReply_message: "
1375 "unable to decode.\n" );
1381 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_channelReply_message: "
1382 "invalid channel %d.\n", channelNum );
1402#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1403 fprintf( stdout,
"FG::handle_startReply_message\n" );
1407 vrpn_bool isStarted =
false;
1410 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_startReply_message: "
1411 "unable to decode.\n" );
1430#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1431 fprintf( stdout,
"FG::handle_stopReply_message\n" );
1435 vrpn_bool isStopped =
false;
1438 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_stopReply_message: "
1439 "unable to decode.\n" );
1458#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1459 fprintf( stdout,
"FG::handle_sampleRateReply_message\n" );
1465 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_sampleRateReply_message: "
1466 "unable to decode.\n" );
1485#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1486 fprintf( stdout,
"FG::handle_interpreterReply_message\n" );
1493 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_interpreterReply_message: "
1494 "unable to decode.\n" );
1511#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1512 fprintf( stdout,
"FG::handle_error_message\n" );
1519 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::handle_error_message: "
1520 "unable to decode.\n" );
1549encode_channel(
char** buf, vrpn_int32& len,
const vrpn_uint32 channelNum,
1552#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1553 fprintf( stdout,
"FG::encode_channel\n" );
1558 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1559 "invalid channel nubmer %d.\n", channelNum );
1563 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1568 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1569 "couldn't buffer (got %d, wanted at least %lud).\n",
1570 len,
static_cast<unsigned long>(
sizeof( vrpn_int32)) );
1576 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1577 "message payload error (couldn't buffer channel number).\n" );
1581 if( 0 > channel->
encode_to( buf, len ) )
1583 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel: "
1584 "message payload error (couldn't buffer channel).\n" );
1593decode_channel(
const char* buf,
const vrpn_int32 len, vrpn_uint32& channelNum,
1596#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1597 fprintf( stdout,
"FG::decode_channel\n" );
1600 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1605 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel: "
1606 "channel message payload error (got %d, wanted at least %lud).\n",
1607 len,
static_cast<unsigned long>(
sizeof( vrpn_int32)) );
1611 const char* mybuf = buf;
1612 vrpn_int32 mylen = len;
1613 vrpn_uint32 myNum = 0;
1616 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel: "
1617 "message payload error (couldn't unbuffer)\n" );
1621 mylen -=
sizeof( myNum );
1625 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel: "
1626 "error while decoding channel %d\n", channelNum );
1638#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1639 fprintf( stdout,
"FG::encode_channel_reply\n" );
1644 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1645 "invalid channel\n" );
1649 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1654 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1655 "insufficient buffer space given (got %d, wanted %lud).\n",
1656 len,
static_cast<unsigned long>(
sizeof( vrpn_uint32)) );
1662 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1663 "unable to buffer channel number.\n" );
1667 if( 0 >
channels[channelNum]->encode_to( buf, len ) )
1669 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_channel_reply: "
1670 "unable to encode channel.\n" );
1681#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1682 fprintf( stdout,
"FG::decode_channel_reply\n" );
1685 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1690 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1691 "insufficient buffer space given (got %d, wanted %lud).\n",
1692 len,
static_cast<unsigned long>(
sizeof( vrpn_uint32)) );
1696 const char* mybuf = buf;
1697 vrpn_int32 mylen = len;
1698 vrpn_uint32 myNum = 0;
1701 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1702 "unable to unbuffer channel number.\n" );
1708 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_channel_reply: "
1709 "invalid channel: %d\n", myNum );
1714 mylen -=
sizeof( vrpn_uint32 );
1715 return channels[channelNum]->decode_from( &mybuf, mylen );
1722#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1723 fprintf( stdout,
"FG::encode_channel_request\n" );
1726 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1728 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel_request: "
1729 "channel message payload error (got %d, wanted at least %lud).\n",
1730 len,
static_cast<unsigned long>(
sizeof( vrpn_int32)) );
1734 vrpn_int32 mylen = len;
1737 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_channel_request: "
1738 "unable to buffer channel %d", channelNum );
1750#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1751 fprintf( stdout,
"FG::decode_channel_request\n" );
1754 if(
static_cast<unsigned>(len) <
sizeof( vrpn_uint32 ) )
1759 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel_request: "
1760 "channel message payload error (got %d, wanted at least %lud).\n",
1761 len,
static_cast<unsigned long>(
sizeof( vrpn_int32)) );
1765 const char* mybuf = buf;
1768 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_channel_request: "
1769 "unable to unbuffer channel %d", channelNum );
1780#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1781 fprintf( stdout,
"FG::encode_sampleRate_request\n" );
1784 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
1786 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_sampleRate_request: "
1787 "channel message payload error (got %d, wanted at least %lud).\n",
1788 len,
static_cast<unsigned long>(
sizeof( vrpn_float32)) );
1792 vrpn_int32 mylen = len;
1795 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::encode_sampleRate_request: "
1796 "unable to buffer sample rate" );
1808#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1809 fprintf( stdout,
"FG::decode_sampleRate_request\n" );
1812 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
1814 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_sampleRate_request: "
1815 "channel message payload error (got %d, wanted at least %lud).\n",
1816 len,
static_cast<unsigned long>(
sizeof( vrpn_float32)) );
1820 const char* mybuf = buf;
1823 fprintf( stderr,
"vrpn_FunctionGenerator_Server::decode_sampleRate_request: "
1824 "unable to unbuffer sample rate" );
1835#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1836 fprintf( stdout,
"FG::encode_start_reply\n" );
1839 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
1841 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_start_reply: "
1842 "insufficient buffer space given (got %d, wanted %lud).\n",
1843 len,
static_cast<unsigned long>(
sizeof( vrpn_bool)) );
1854#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1855 fprintf( stdout,
"FG::decode_start_reply\n" );
1858 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
1860 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_start_reply: "
1861 "insufficient buffer space given (got %d, wanted %lud).\n",
1862 len,
static_cast<unsigned long>(
sizeof( vrpn_bool)) );
1866 const char* mybuf = buf;
1869 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_start_reply: "
1870 "unable to unbuffer stop condition.\n" );
1881#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1882 fprintf( stdout,
"FG::encode_stop_reply\n" );
1885 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
1887 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_stop_reply: "
1888 "insufficient buffer space given (got %d, wanted %lud).\n",
1889 len,
static_cast<unsigned long>(
sizeof( vrpn_bool)) );
1900#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1901 fprintf( stdout,
"FG::decode_stop_reply\n" );
1904 if(
static_cast<unsigned>(len) <
sizeof( vrpn_bool ) )
1906 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_stop_reply: "
1907 "insufficient buffer space given (got %d, wanted %lud).\n",
1908 len,
static_cast<unsigned long>(
sizeof( vrpn_bool)) );
1914 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_stop_reply: "
1915 "unable to unbuffer stop condition.\n" );
1926#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1927 fprintf( stdout,
"FG::encode_sampleRate_reply\n" );
1930 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
1932 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_sampleRate_reply: "
1933 "insufficient buffer space given (got %d, wanted %lud).\n",
1934 len,
static_cast<unsigned long>(
sizeof( vrpn_float32)) );
1945#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1946 fprintf( stdout,
"FG::decode_sampleRate_reply\n" );
1949 if(
static_cast<unsigned>(len) <
sizeof( vrpn_float32 ) )
1951 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_sampleRate_reply: "
1952 "insufficient buffer space given (got %d, wanted %lud).\n",
1953 len,
static_cast<unsigned long>(
sizeof( vrpn_float32)) );
1957 vrpn_float32 myRate = 0;
1960 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_sampleRate_reply: "
1961 "unable to unbuffer sample rate.\n" );
1973#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
1974 fprintf( stdout,
"FG::encode_interpreterDescription_reply\n" );
1977 vrpn_int32 dlength =
static_cast<vrpn_int32
>(strlen( desc ));
1978 if( len < dlength + (vrpn_int32)
sizeof( vrpn_int32 ) )
1980 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_interpreterDescription_reply: "
1981 "insufficient buffer space given (got %d, wanted %lud).\n",
1982 len, dlength +
static_cast<unsigned long>(
sizeof( vrpn_int32 )) );
1988 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_interpreterDescription_reply: "
1989 "unable to buffer description length.\n" );
2001#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
2002 fprintf( stdout,
"FG::decode_interpreterDescription_reply\n" );
2005 if(
static_cast<unsigned>(len) <
sizeof( vrpn_int32 ) )
2007 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_interpreterDescription_reply: "
2008 "insufficient buffer space given (got %d, wanted at least %lud).\n",
2009 len,
static_cast<unsigned long>(
sizeof( vrpn_int32)) );
2013 vrpn_int32 dlength = 0;
2016 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_interpreterDescription_reply: "
2017 "unable to unbuffer description length.\n" );
2021 try { *desc =
new char[dlength + 1]; }
2023 fprintf(stderr,
"vrpn_FunctionGenerator_Remote::decode_interpreterDescription_reply: "
2024 "Out of memory.\n");
2029 (*desc)[dlength] =
'\0';
2037#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
2038 fprintf( stdout,
"FG::encode_error_report\n" );
2041 if(
static_cast<unsigned>(len) <
sizeof(
FGError ) +
sizeof( vrpn_int32 ) )
2043 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_error_report: "
2044 "insufficient buffer space given (got %d, wanted %lud).\n",
2045 len,
static_cast<unsigned long>(
sizeof(
FGError) +
sizeof( vrpn_int32 )) );
2049 vrpn_int32 mylen = len;
2052 fprintf( stderr,
"vrpn_FunctionGenerator_Server::encode_error_report: "
2053 "unable to buffer error & channel" );
2065#ifdef DEBUG_VRPN_FUNCTION_GENERATOR
2066 fprintf( stdout,
"FG::decode_error_reply\n" );
2069 if(
static_cast<unsigned>(len) <
sizeof(
FGError ) +
sizeof( vrpn_int32 ) )
2071 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_error_reply: "
2072 "insufficient buffer space given (got %d, wanted %lud).\n",
2073 len,
static_cast<unsigned long>(
sizeof(
FGError) +
sizeof( vrpn_int32 )) );
2078 vrpn_int32 myChannel = -1;
2082 fprintf( stderr,
"vrpn_FunctionGenerator_Remote::decode_error_reply: "
2083 "unable to unbuffer error & channel.\n" );
2088 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()
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