Changeset 19965

Show
Ignore:
Timestamp:
04/21/07 10:53:02 (2 years ago)
Author:
patrick
Message:

If the connection to the hardware fails, do not spawn a sampling thread.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/gadgeteer/drivers/EssentialReality/P5Glove/P5GloveWrapper.cpp

    r19964 r19965  
    116116         << "[p5glove] Begin sampling\n" << vprDEBUG_FLUSH; 
    117117    
    118       int maxAttempts(0); 
     118      int max_attempts(0); 
    119119      bool result(false); 
    120120 
    121       while ( result == false && maxAttempts < 5 ) 
     121      while ( result == false && max_attempts < 5 ) 
    122122      { 
    123123         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) 
     
    132132               << vprDEBUG_FLUSH; 
    133133            vpr::System::usleep(14500); 
    134             ++maxAttempts; 
     134            ++max_attempts; 
    135135         } 
    136136      } 
    137137 
    138       vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) 
    139          << "[p5glove] Successfully connected, Now sampling dataglove data.\n" 
    140          << vprDEBUG_FLUSH; 
    141  
    142       // Create a new thread to handle the control and set exit flag to false 
    143       mExitFlag = false; 
    144       vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) 
    145          << "[p5glove] Spawning control thread.\n" << vprDEBUG_FLUSH; 
    146  
    147       try 
     138      if ( result ) 
    148139      { 
    149          mThread = new vpr::Thread(boost::bind(&P5GloveWrapper::controlLoop, 
    150                                                this)); 
    151          mActive = true; 
    152          started = true; 
    153  
    154140         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) 
    155             << "[p5glove] P5Glove is active.\n" << vprDEBUG_FLUSH; 
    156       } 
    157       catch (vpr::Exception& ex) 
    158       { 
    159          vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) 
    160             << clrOutBOLD(clrRED, "ERROR") 
    161             << ": Failed to spawn thread for P5 Glove driver!\n" 
    162             << vprDEBUG_FLUSH; 
    163          vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) 
    164             << ex.what() << std::endl << vprDEBUG_FLUSH; 
    165          started = false; 
     141            << "[p5glove] Successfully connected, Now sampling dataglove " 
     142            << "data.\n" << vprDEBUG_FLUSH; 
     143 
     144         // Create a new thread to handle the control and set exit flag to 
     145         // false. 
     146         mExitFlag = false; 
     147         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) 
     148            << "[p5glove] Spawning control thread.\n" << vprDEBUG_FLUSH; 
     149 
     150         try 
     151         { 
     152            mThread = 
     153               new vpr::Thread(boost::bind(&P5GloveWrapper::controlLoop, 
     154                                           this)); 
     155            mActive = true; 
     156            started = true; 
     157 
     158            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) 
     159               << "[p5glove] P5Glove is active.\n" << vprDEBUG_FLUSH; 
     160         } 
     161         catch (vpr::Exception& ex) 
     162         { 
     163            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) 
     164               << clrOutBOLD(clrRED, "ERROR") 
     165               << ": Failed to spawn thread for P5 Glove driver!\n" 
     166               << vprDEBUG_FLUSH; 
     167            vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL) 
     168               << ex.what() << std::endl << vprDEBUG_FLUSH; 
     169            started = false; 
     170         } 
    166171      } 
    167172   }