Changeset 140 in flair-src


Ignore:
Timestamp:
Feb 15, 2017, 2:41:36 PM (8 years ago)
Author:
Sanahuja Guillaume
Message:

improved vprnobject added to vrpnclient

Location:
trunk/lib/FlairSensorActuator/src
Files:
6 edited

Legend:

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

    r139 r140  
    8282VrpnClient_impl::~VrpnClient_impl() {
    8383  if (!UseXbee()) {
    84     // on fait une copie car le delete touche a xbee_objects_copy via
     84    // on fait une copie car le delete touche a trackables_copy via
    8585    // RemoveTrackable
    86     vector<VrpnObject *> trackables_copy = trackables;
     86    vector<VrpnObject_impl *> trackables_copy = trackables;
    8787    for (unsigned int i = 0; i < trackables_copy.size(); i++)
    88       delete trackables_copy.at(i);
     88      delete trackables_copy.at(i)->self;
    8989    // trackables.clear();
    9090  } else {
     
    114114}
    115115
    116 void VrpnClient_impl::AddTrackable(VrpnObject *obj) {
     116void VrpnClient_impl::AddTrackable(VrpnObject_impl *obj) {
    117117  mutex->GetMutex();
    118118  trackables.push_back(obj);
     
    120120}
    121121
    122 void VrpnClient_impl::RemoveTrackable(VrpnObject *obj) {
     122void VrpnClient_impl::RemoveTrackable(VrpnObject_impl *obj) {
    123123  mutex->GetMutex();
    124   for (vector<VrpnObject *>::iterator it = trackables.begin();
     124  for (vector<VrpnObject_impl *>::iterator it = trackables.begin();
    125125       it < trackables.end(); it++) {
    126126    if (*it == obj) {
    127127      trackables.erase(it);
     128      break;
     129    }
     130  }
     131  for (vector<xbee_object>::iterator it = xbee_objects.begin();
     132       it < xbee_objects.end(); it++) {
     133    if ((*it).vrpnobject == obj) {
     134      xbee_objects.erase(it);
    128135      break;
    129136    }
     
    138145  mutex->GetMutex();
    139146  xbee_objects.push_back(tmp);
    140   mutex->ReleaseMutex();
    141 }
    142 
    143 void VrpnClient_impl::RemoveTrackable(VrpnObject_impl *obj) {
    144   mutex->GetMutex();
    145   for (vector<xbee_object>::iterator it = xbee_objects.begin();
    146        it < xbee_objects.end(); it++) {
    147     if ((*it).vrpnobject == obj) {
    148       xbee_objects.erase(it);
    149       break;
    150     }
    151   }
    152147  mutex->ReleaseMutex();
    153148}
     
    232227            mutex->GetMutex();
    233228            for (unsigned int i = 0; i < trackables.size(); i++)
    234                 trackables.at(i)->mainloop();
     229                trackables.at(i)->tracker->mainloop();
    235230            mutex->ReleaseMutex();
    236231        } else {
  • trunk/lib/FlairSensorActuator/src/VrpnObject.cpp

    r135 r140  
    4545}
    4646
    47 VrpnObject::~VrpnObject(void) { delete pimpl_; }
     47VrpnObject::~VrpnObject(void) {
     48  delete pimpl_;
     49}
    4850
    4951cvmatrix *VrpnObject::Output(void) const { return pimpl_->output; }
     
    7577}
    7678
    77 void VrpnObject::mainloop(void) { pimpl_->mainloop(); }
    78 
    7979} // end namespace sensor
    8080} // end namespace flair
  • trunk/lib/FlairSensorActuator/src/VrpnObject.h

    r135 r140  
    172172  void UpdateFrom(const core::io_data *data){};
    173173
    174   void mainloop(void);
    175174  class VrpnObject_impl *pimpl_;
    176175};
  • trunk/lib/FlairSensorActuator/src/VrpnObject_impl.cpp

    r139 r140  
    5555        "identifiant pour la connexion Xbee ignore car pas en mode Xbee\n");
    5656  }
    57 
     57 
    5858  // state
    5959  cvmatrix_descriptor *desc = new cvmatrix_descriptor(7, 1);
     
    8282  z_plot->AddCurve(output->Element(6));
    8383 
    84   if(parent->IsRunning()) {
    85     self->Warn("adding VrpnObject on running VrpnClient can crash\n");
    86   }
    87  
    8884  if (parent->UseXbee()) {
    8985    tracker = NULL;
     
    9389    tracker->register_change_handler(this, handle_pos);
    9490    tracker->shutup = true;
    95     parent->pimpl_->AddTrackable(self);
     91    parent->pimpl_->AddTrackable(this);
    9692  }
     93 
    9794}
    9895
    9996VrpnObject_impl::~VrpnObject_impl(void) {
    100   if (tracker != NULL) // normal
    101   {
    102     parent->pimpl_->RemoveTrackable(self);
     97  parent->pimpl_->RemoveTrackable(this);
     98  if (tracker != NULL) {// normal
    10399    tracker->unregister_change_handler(this, handle_pos);
    104100    delete tracker;
    105   } else // xbee
    106   {
    107     parent->pimpl_->RemoveTrackable(this);
    108101  }
    109102  delete plot_tab;
    110 }
    111 
    112 void VrpnObject_impl::mainloop(void) {
    113      tracker->mainloop();
    114103}
    115104
  • trunk/lib/FlairSensorActuator/src/unexported/VrpnClient_impl.h

    r136 r140  
    5151                  flair::core::SerialPort *serialport, uint16_t us_period);
    5252  ~VrpnClient_impl();
    53   void AddTrackable(flair::sensor::VrpnObject *obj);    // normal
    54   void RemoveTrackable(flair::sensor::VrpnObject *obj); // normal
     53  void AddTrackable(VrpnObject_impl *obj);    // normal
    5554  void AddTrackable(VrpnObject_impl *obj, uint8_t id);  // xbee
    56   void RemoveTrackable(VrpnObject_impl *obj);           // xbee
     55  void RemoveTrackable(VrpnObject_impl *obj);           // normal+xbee
    5756  void ComputeRotations(flair::core::Vector3D &point);
    5857  void ComputeRotations(flair::core::Quaternion &quat);
     
    6766  flair::core::Mutex *mutex;
    6867  uint16_t us_period;
    69   std::vector<flair::sensor::VrpnObject *> trackables;
     68  std::vector<VrpnObject_impl *> trackables;
    7069  typedef struct xbee_object {
    7170    VrpnObject_impl *vrpnobject;
  • trunk/lib/FlairSensorActuator/src/unexported/VrpnObject_impl.h

    r135 r140  
    5050  ~VrpnObject_impl(void);
    5151
    52   void mainloop(void);
    5352  void GetQuaternion(flair::core::Quaternion &quaternion);
    5453  void GetPosition(flair::core::Vector3D &point);
Note: See TracChangeset for help on using the changeset viewer.