// static int vrpn_Mutex_Server::handle_requestIndex(void *userdata, vrpn_HANDLERPARAM p) { vrpn_Mutex_Server *me = (vrpn_Mutex_Server *)userdata; timeval now; vrpn_int32 msg_len = sizeof(vrpn_int32) + p.payload_len; char *buffer = new char[msg_len]; char *b = buffer; vrpn_int32 bl = msg_len; #ifdef VERBOSE fprintf(stderr, "vrpn_Mutex_Server::handle_requestIndex: " "Initializing client %d (%lu %d).\n", me->d_remoteIndex, ntohl(*(vrpn_uint32 *)p.buffer), ntohl(*(vrpn_int32 *)(p.buffer + sizeof(vrpn_uint32)))); #endif if (me->d_connection) { vrpn_gettimeofday(&now, NULL); // echo back whatever the client gave us as a unique identifier vrpn_buffer(&b, &bl, p.buffer, p.payload_len); vrpn_buffer(&b, &bl, (me->d_remoteIndex)); me->d_connection->pack_message(msg_len, now, me->d_initialize_type, me->d_myId, buffer, vrpn_CONNECTION_RELIABLE); } me->d_remoteIndex++; delete[] buffer; return 0; }
void vrpn_Mutex_Remote::requestIndex(void) { timeval now; vrpn_int32 buflen = sizeof(vrpn_int32) + sizeof(vrpn_uint32); char *buf = NULL; try { buf = new char[buflen]; } catch (...) { return; } char *bufptr = buf; vrpn_int32 len = buflen; vrpn_uint32 ip_addr = getmyIP(); #ifdef _WIN32 vrpn_int32 pid = _getpid(); #else vrpn_int32 pid = getpid(); #endif vrpn_buffer(&bufptr, &len, ip_addr); vrpn_buffer(&bufptr, &len, pid); #ifdef VERBOSE printf("requesting index for %lu, %d\n", ip_addr, pid); #endif vrpn_gettimeofday(&now, NULL); d_connection->pack_message(buflen, now, d_requestIndex_type, d_myId, buf, vrpn_CONNECTION_RELIABLE); try { delete[] buf; } catch (...) { fprintf(stderr, "vrpn_Mutex_Remote::requestIndex(): delete failed\n"); return; } return; }
void vrpn_Shared_String::encode (char ** buffer, vrpn_int32 * len, const char * newValue, timeval when) const { // We reverse ordering from the other vrpn_SharedObject classes // so that the time value is guaranteed to be aligned. vrpn_buffer(buffer, len, when); vrpn_buffer(buffer, len, newValue, static_cast<vrpn_int32>(strlen(newValue))); }
vrpn_int32 vrpn_Sound::encodeSetPolyMaterial(const char * material, const vrpn_int32 tag, char* buf) { vrpn_int32 len = sizeof(vrpn_SoundID) + 128; vrpn_int32 ret = len; char *mptr = buf; vrpn_buffer(&mptr, &len, tag); vrpn_buffer(&mptr, &len, material, 128); return ret; }
vrpn_int32 vrpn_Sound::encodeSoundVolume(const vrpn_float64 volume, const vrpn_SoundID id, char* buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_SoundID) + sizeof(vrpn_float64); vrpn_int32 ret = len; vrpn_buffer(&mptr, &len, id); vrpn_buffer(&mptr, &len, volume); return ret; }
vrpn_int32 vrpn_Sound::encodeSoundPitch(const vrpn_float64 pitch, const vrpn_SoundID id, char* buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_SoundID) + sizeof(vrpn_float64); vrpn_int32 ret = len; vrpn_buffer(&mptr, &len, id); vrpn_buffer(&mptr, &len, pitch); return ret; }
vrpn_int32 vrpn_Sound::encodeSoundPlay(const vrpn_SoundID id, const vrpn_int32 repeat, char* buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_SoundID) + sizeof(vrpn_int32); vrpn_int32 ret = len; vrpn_buffer(&mptr, &len, repeat); vrpn_buffer(&mptr, &len, id); return ret; }
void vrpn_Shared_int32::encodeLamport (char ** buffer, vrpn_int32 * len, vrpn_int32 newValue, timeval when, vrpn_LamportTimestamp * t) const { int i; vrpn_buffer(buffer, len, newValue); vrpn_buffer(buffer, len, when); vrpn_buffer(buffer, len, t->size()); for (i = 0; i < t->size(); i++) { vrpn_buffer(buffer, len, (*t)[i]); } }
vrpn_int32 vrpn_Sound::encodeSetPolyOF(const vrpn_float64 openingfactor, const vrpn_int32 tag, char* buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_SoundID) + sizeof(vrpn_float64); vrpn_int32 ret = len; vrpn_buffer(&mptr, &len, tag); vrpn_buffer(&mptr, &len, openingfactor); return ret; }
vrpn_int32 vrpn_Button::encode_to(char *buf, vrpn_int32 button, vrpn_int32 state) { char *bufptr = buf; int buflen = 1000; // Message includes: vrpn_int32 buttonNum, vrpn_int32 state vrpn_buffer( &bufptr, &buflen, button ); vrpn_buffer( &bufptr, &buflen, state ); return 1000 - buflen; }
vrpn_int32 vrpn_Sound::encodeSetTriVert(const vrpn_float64 vertices[4][3], const vrpn_int32 tag, char* buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_int32) + sizeof(vrpn_float64)*9; vrpn_int32 ret = len; vrpn_buffer(&mptr, &len, tag); for (int i=0;i<3;i++) for (int j(0); j<3;j++) vrpn_buffer(&mptr, &len, vertices[i][j]); return ret; }
vrpn_int32 vrpn_Sound::encodeSoundEqFactor(const vrpn_float64 eqfactor, const vrpn_SoundID id, char * buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_SoundID) + sizeof(vrpn_float64); vrpn_int32 ret = len; vrpn_buffer(&mptr, &len, id); vrpn_buffer(&mptr, &len, eqfactor); return ret; }
vrpn_int32 vrpn_Sound::encodeSoundDoplerScale(const vrpn_float64 doplerfactor, const vrpn_SoundID id, char * buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_SoundID) + sizeof(vrpn_float64); vrpn_int32 ret = len; vrpn_buffer(&mptr, &len, id); vrpn_buffer(&mptr, &len, doplerfactor); return ret; }
vrpn_int32 vrpn_Sound::encodeSoundVelocity(const vrpn_float64 *velocity, const vrpn_SoundID id, char* buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_SoundID) + sizeof(vrpn_float64)*4; vrpn_int32 ret = len; int i; vrpn_buffer(&mptr, &len, id); for (i=0;i<4;i++) vrpn_buffer(&mptr, &len, velocity[i]); return ret; }
VRPN_API int vrpn_buffer (char ** insertPt, vrpn_int32 * buflen, const timeval t) { vrpn_int32 sec, usec; // tv_sec and usec are 64 bits on some architectures, but we // define them as 32 bit for network transmission sec = t.tv_sec; usec = t.tv_usec; if (vrpn_buffer(insertPt, buflen, sec)) return -1; return vrpn_buffer(insertPt, buflen, usec); }
int vrpn_BaseClassUnique::encode_text_message_to_buffer (char * buf, vrpn_TEXT_SEVERITY severity, vrpn_uint32 level, const char * msg) { char *bufptr = buf; int buflen = 2 * sizeof(vrpn_int32) + vrpn_MAX_TEXT_LEN; vrpn_uint32 severity_as_uint = severity; // Send the type, level and string message vrpn_buffer( &bufptr, &buflen, severity_as_uint ); vrpn_buffer( &bufptr, &buflen, level ); vrpn_buffer( &bufptr, &buflen, msg, -1 ); // -1 means "pack until NULL" return 0; }
vrpn_int32 vrpn_Analog_Output_Remote::encode_change_to(char *buf, vrpn_int32 chan, vrpn_float64 val) { // Message includes: int32 channel_number, int32 padding, float64 request_value // Byte order of each needs to be reversed to match network standard vrpn_int32 pad = 0; int buflen = 2 * sizeof(vrpn_int32) + sizeof(vrpn_float64); vrpn_buffer(&buf, &buflen, chan); vrpn_buffer(&buf, &buflen, pad); vrpn_buffer(&buf, &buflen, val); return 2 * sizeof(vrpn_int32) + sizeof(vrpn_float64); }
vrpn_int32 vrpn_Analog_Output_Remote::encode_change_channels_to(char* buf, vrpn_int32 num, vrpn_float64* vals) { int i; vrpn_int32 pad = 0; int buflen = 2 * sizeof(vrpn_int32) + num * sizeof(vrpn_float64); vrpn_buffer(&buf, &buflen, num); vrpn_buffer(&buf, &buflen, pad); for (i = 0; i < num; i++) { vrpn_buffer(&buf, &buflen, vals[i]); } return 2 * sizeof(vrpn_int32) + num * sizeof(vrpn_float64); }
void vrpn_PeerMutex::sendRelease(vrpn_Connection *c) { timeval now; char buffer[32]; char *b = buffer; vrpn_int32 bl = 32; vrpn_gettimeofday(&now, NULL); vrpn_buffer(&b, &bl, d_myIP); vrpn_buffer(&b, &bl, d_myPort); c->pack_message(32 - bl, now, c->register_message_type(release_type), c->register_sender(d_mutexName), buffer, vrpn_CONNECTION_RELIABLE); }
//Sends information about the listener. IE position, orientation and velocity vrpn_int32 vrpn_Sound::encodeListenerPose(const vrpn_PoseDef pose, char* buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_ListenerDef); vrpn_int32 ret = len; int i; for(i = 0; i < 3; i++) vrpn_buffer(&mptr, &len, pose.position[i]); for(i = 0; i < 4; i++) vrpn_buffer(&mptr, &len, pose.orientation[i]); return ret; }
void vrpn_PeerMutex::sendDenyRequest(vrpn_Connection *c, vrpn_uint32 IP, vrpn_uint32 port) { timeval now; char buffer[32]; char *b = buffer; vrpn_int32 bl = 32; vrpn_gettimeofday(&now, NULL); vrpn_buffer(&b, &bl, IP); vrpn_buffer(&b, &bl, port); c->pack_message(32 - bl, now, c->register_message_type(denyRequest_type), c->register_sender(d_mutexName), buffer, vrpn_CONNECTION_RELIABLE); }
vrpn_int32 vrpn_Button_Filter::encode_states_to(char *buf) { // Message includes: vrpn_int32 number_of_buttons, vrpn_int32 state // Byte order of each needs to be reversed to match network standard vrpn_int32 int_btn = num_buttons; int buflen = (vrpn_BUTTON_MAX_BUTTONS + 1) * sizeof(vrpn_int32); vrpn_buffer(&buf, &buflen, int_btn); for (int i = 0; i < num_buttons; i++) { vrpn_buffer(&buf, &buflen, buttonstate[i]); } return (num_buttons + 1) * sizeof(vrpn_int32); }
vrpn_int32 vrpn_Analog::encode_to(char *buf) { // Message includes: vrpn_float64 AnalogNum, vrpn_float64 state // Byte order of each needs to be reversed to match network standard vrpn_float64 double_chan = num_channel; int buflen = (vrpn_CHANNEL_MAX+1)*sizeof(vrpn_float64); vrpn_buffer(&buf, &buflen, double_chan); for (int i=0; i < num_channel; i++) { vrpn_buffer(&buf, &buflen, channel[i]); last[i] = channel[i]; } return (num_channel+1)*sizeof(vrpn_float64); }
vrpn_int32 vrpn_Sound::encodeLoadPolyTri(const vrpn_TriDef tri, char* buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_int32) + sizeof(vrpn_TriDef); vrpn_int32 ret = len; int i; vrpn_buffer(&mptr, &len, tri.subTri); vrpn_buffer(&mptr, &len, tri.openingFactor); vrpn_buffer(&mptr, &len, tri.tag); for (i=0;i<3;i++) for (int j(0); j<3;j++) vrpn_buffer(&mptr, &len, tri.vertices[i][j]); vrpn_buffer(&mptr, &len, tri.material_name, MAX_MATERIAL_NAME_LENGTH); return ret; }
vrpn_int32 vrpn_Sound::encodeSoundConeInfo(const vrpn_float64 cone_inner_angle, const vrpn_float64 cone_outer_angle, const vrpn_float64 cone_gain, const vrpn_SoundID id, char * buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_SoundID) + sizeof(vrpn_float64)*3; vrpn_int32 ret = len; vrpn_buffer(&mptr, &len, id); vrpn_buffer(&mptr, &len, cone_inner_angle); vrpn_buffer(&mptr, &len, cone_outer_angle); vrpn_buffer(&mptr, &len, cone_gain); return ret; }
vrpn_int32 vrpn_Sound::encodeLoadPolyQuad(const vrpn_QuadDef quad, char* buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_QuadDef); vrpn_int32 ret = len; int i; vrpn_buffer(&mptr, &len, quad.subQuad); vrpn_buffer(&mptr, &len, quad.openingFactor); vrpn_buffer(&mptr, &len, quad.tag); for (i=0;i<4;i++) for (int j(0); j<3;j++) vrpn_buffer(&mptr, &len, quad.vertices[i][j]); vrpn_buffer(&mptr, &len, quad.material_name, MAX_MATERIAL_NAME_LENGTH); return ret; }
vrpn_int32 vrpn_Analog_Output_Server:: encode_num_channels_to( char* buf, vrpn_int32 num ) { // Message includes: int32 number of active channels int buflen = sizeof(vrpn_int32); vrpn_buffer(&buf, &buflen, num); return sizeof(vrpn_int32); }
//Encodes the client sound ID vrpn_int32 vrpn_Sound::encodeSoundID(const vrpn_SoundID id, char* buf) { char* mptr = buf; vrpn_int32 len = sizeof(vrpn_SoundID); vrpn_buffer(&mptr,&len, id); return (sizeof(vrpn_SoundID)); }
vrpn_int32 vrpn_Dial::encode_to(char *buf, vrpn_int32 buflen, vrpn_int32 dial, vrpn_float64 delta) { vrpn_int32 buflensofar = buflen; // Message includes: vrpn_int32 dialNum, vrpn_float64 delta // We pack them with the delta first, so that everything is aligned // on the proper boundary. if (vrpn_buffer(&buf, &buflensofar, delta)) { fprintf(stderr, "vrpn_Dial::encode_to: Can't buffer delta\n"); return -1; } if (vrpn_buffer(&buf, &buflensofar, dial)) { fprintf(stderr, "vrpn_Dial::encode_to: Can't buffer dial\n"); return -1; } return sizeof(vrpn_float64) + sizeof(vrpn_int32); }
vrpn_int32 vrpn_Sound::encodeSoundDistInfo(const vrpn_float64 min_back, const vrpn_float64 max_back, const vrpn_float64 min_front, const vrpn_float64 max_front, const vrpn_SoundID id, char * buf) { char *mptr = buf; vrpn_int32 len = sizeof(vrpn_SoundID) + sizeof(vrpn_float64)*4; vrpn_int32 ret = len; vrpn_buffer(&mptr, &len, id); vrpn_buffer(&mptr, &len, min_back); vrpn_buffer(&mptr, &len, max_back); vrpn_buffer(&mptr, &len, min_front); vrpn_buffer(&mptr, &len, max_front); return ret; }