Changeset 447 in flair-src


Ignore:
Timestamp:
Sep 16, 2021, 2:01:56 PM (3 years ago)
Author:
Sanahuja Guillaume
Message:

vrpnlite handle disconection

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSensorActuator/src/VrpnClient_impl.cpp

    r438 r447  
    128128    mutex->ReleaseMutex();
    129129  } else if (connectionType==VrpnClient::VrpnLite) {
    130     if(trackables.size()<0xffff) {
    131       uint16_t id=trackables.size();
     130    if(trackables.size()<INT16_MAX) {
     131      int16_t id=trackables.size()+1;//avoid 0; positive values for adding, negative for removing
    132132      mutex->GetMutex();
    133133      trackables.push_back(obj);
     
    162162void VrpnClient_impl::RemoveTrackable(VrpnObject_impl *obj) {
    163163  mutex->GetMutex();
     164  //send remove notification to vrpnlite
     165  if (connectionType==VrpnClient::VrpnLite) {
     166    for (size_t i = 0; i < trackables.size(); i++) {
     167      if(trackables.at(i)==obj) {
     168        int16_t id=-(i+1);//avoid 0; positive values for adding, negative for removing
     169       
     170        char char_array[obj->self->ObjectName().length() + sizeof(id)];
     171        strcpy(char_array, obj->self->ObjectName().c_str());
     172        dataSocket->HostToNetwork((char*)(&id),sizeof(id));
     173        memcpy(&char_array[obj->self->ObjectName().length()],&id,sizeof(id));
     174        dataSocket->SendMessage(char_array,obj->self->ObjectName().length() + sizeof(id));
     175        break;
     176      }
     177    }
     178  }
     179 
     180  //update vector
    164181  if (connectionType==VrpnClient::Vrpn || connectionType==VrpnClient::VrpnLite) {
    165182    for (vector<VrpnObject_impl *>::iterator it = trackables.begin();it < trackables.end(); it++) {
  • trunk/tools/VrpnLite/src/VrpnLite.cpp

    r446 r447  
    2323#include <Quaternion.h>
    2424#include <string.h>
     25#include <bits/stdc++.h>
    2526
    2627using namespace std;
     
    6162    ssize_t rcv=dataSocket->RecvMessage(msg,sizeof(msg),dataSocketTimeout,NULL,NULL,&src_id);
    6263    if(rcv>0) {
    63       string object=msg;
    64       uint16_t id;
    65       memcpy(&id,&msg[rcv-2],sizeof(id));
     64      int16_t id;
     65      string object=string(msg,rcv-sizeof(id));
     66      memcpy(&id,&msg[rcv-sizeof(id)],sizeof(id));
    6667      dataSocket->HostToNetwork((char*)&id,sizeof(id));
    67      
    68       if(src_id==vrpnobjects_list.size()) {
    69         vector<VrpnObject*> vect;
    70         vrpnobjects_list.push_back(vect);
    71         //Printf("add vect %i\n",src_id);
    72       }
    73       //assume we receive it in the good order
    74       if(id==vrpnobjects_list.at(src_id).size()) {
    75         Printf("adding object %s with id %i from %i\n",object.c_str(),id,src_id);
    76         VrpnObject* vrpnobject = new VrpnObject(object,vrpnclient->GetTabWidget());
    77         vrpnobjects.push_back(vrpnobject);
    78         vrpnobjects_list.at(src_id).push_back(vrpnobject);
    79       }else {
    80         Err("adding object %s failed, expected id %i, got %i\n",object.c_str(),vrpnobjects.size(),id);
     68      Printf("src id %i\n",src_id);
     69      if(id>0) { //add object
     70        if(src_id==vrpnobjects_list.size()) {
     71          vector<VrpnObject*> vect;
     72          vrpnobjects_list.push_back(vect);
     73          //Printf("add vect %i\n",src_id);
     74        }
     75        //assume we receive it in the good order
     76        if(id==vrpnobjects_list.at(src_id).size()+1) {//id 0 is not used as we use positive and negative id for add/remove
     77          Printf("adding object %s with id %i from client %i\n",object.c_str(),id,src_id);
     78          VrpnObject* vrpnobject = new VrpnObject(object,vrpnclient->GetTabWidget());
     79          vrpnobjects.push_back(vrpnobject);
     80          vrpnobjects_list.at(src_id).push_back(vrpnobject);
     81        }else {
     82          Err("adding object %s failed, expected id %i, got %i\n",object.c_str(),vrpnobjects_list.at(src_id).size()+1,id);
     83        }
     84      } else { //remove object
     85        for (vector<VrpnObject*>::iterator it = vrpnobjects.begin();it < vrpnobjects.end(); it++) {
     86          if ((*it)->ObjectName() == object) {
     87            Printf("removing object %s with id %i from client %i\n",object.c_str(),-id,src_id);
     88            auto iteratorEnd=remove(vrpnobjects_list.at(src_id).begin(), vrpnobjects_list.at(src_id).end(),(*it));
     89            vrpnobjects_list.at(src_id).erase(iteratorEnd, vrpnobjects_list.at(src_id).end());
     90            if(vrpnobjects_list.at(src_id).size()==0) {
     91              Printf("not removing empty vrpnobjects_list (need code rewrite\n");
     92              //le src_id va continuer a augmenter cote udtsocket et la comparaison if(src_id==vrpnobjects_list.size()) {
     93                //ne va pas marcher; il faut identifier autrement les src
     94              //auto iteratorEnd=remove(vrpnobjects_list.begin(), vrpnobjects_list.end(),vrpnobjects_list.at(src_id));
     95              //vrpnobjects_list.erase(iteratorEnd, vrpnobjects_list.end());
     96            }
     97            delete (*it);
     98            vrpnobjects.erase(it);
     99            break;
     100          }
     101        }
     102       
    81103      }
    82104    }
Note: See TracChangeset for help on using the changeset viewer.