vpr::Uint8 SerialPortImplWin32::getStopBits() const
{
   vpr::Uint8 num_bits;
   DCB dcb;

   if ( GetCommState(mHandle, &dcb) )
   {
      switch ( dcb.StopBits )
      {
         case ONESTOPBIT:
            num_bits = 1;
            break;
         case TWOSTOPBITS:
            num_bits = 2;
            break;
      }
   }
   else
   {
      std::stringstream msg_stream;
      msg_stream << "Number of stop bits is unavailable: "
                 << getErrorMessageWithCode(GetLastError());
      vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
         << clrOutBOLD(clrYELLOW, "WARNING") << ": " << msg_stream.str()
         << std::endl << vprDEBUG_FLUSH;
      throw IOException(msg_stream.str(), VPR_LOCATION);
   }

   return num_bits;
}
// Set the number of stop bits to use.  The value must be either 1 or 2.
void SerialPortImplWin32::setStopBits(const vpr::Uint8 numBits)
{
   DCB dcb;

   GetCommState(mHandle, &dcb);
   switch ( numBits )
   {
      case 1:
         dcb.StopBits = ONESTOPBIT;
         break;
      case 2:
         dcb.StopBits = TWOSTOPBITS;
         break;
   }

   if ( ! SetCommState(mHandle, &dcb) )
   {
      std::stringstream msg_stream;
      msg_stream << "Failed to set stop bits: "
                 << getErrorMessageWithCode(GetLastError());
      vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
         << clrOutBOLD(clrYELLOW, "WARNING") << ": " << msg_stream.str()
         << std::endl << vprDEBUG_FLUSH;
      throw IOException(msg_stream.str(), VPR_LOCATION);
   }
}
// Set the current character size (the bits per byte) to the size in the given
// value.  This is used for both reding and writing, and the size does not
// include the parity bit (if any).
void SerialPortImplWin32::setCharacterSize(const vpr::SerialTypes::CharacterSizeOption bpb)
{
   DCB dcb;
   GetCommState(mHandle, &dcb);
   switch ( bpb )
   {
      case vpr::SerialTypes::CS_BITS_5:
         dcb.ByteSize = 5;
         break;
      case vpr::SerialTypes::CS_BITS_6:
         dcb.ByteSize = 6;
         break;
      case vpr::SerialTypes::CS_BITS_7:
         dcb.ByteSize = 7;
         break;
      case vpr::SerialTypes::CS_BITS_8:
         dcb.ByteSize = 8;
         break;
   }

   if ( ! SetCommState(mHandle,&dcb) )
   {
      std::stringstream msg_stream;
      msg_stream << "Failed to set bits/byte: "
                 << getErrorMessageWithCode(GetLastError());
      vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
         << clrOutBOLD(clrYELLOW, "WARNING") << ": " << msg_stream.str()
         << std::endl << vprDEBUG_FLUSH;
      throw IOException(msg_stream.str(), VPR_LOCATION);
   }
}
// Reconfigure the file handle so that writes are synchronous.
void FileHandleImplUNIX::setSynchronousWrite(bool sync)
{
#if ! defined(_POSIX_SOURCE) && defined(O_SYNC) && defined(O_ASYNC)
   int cur_flags, new_flags, retval;

   // Get the current flags.
   cur_flags = getFlags();

   // Synchronous writes.
   if ( sync )
   {
      new_flags = cur_flags | O_SYNC;
   }
   // Asynchronous writes.
   else
   {
      new_flags = cur_flags | O_ASYNC;
   }

   // Set the file descriptor to be blocking with the new flags.
   retval = setFlags(new_flags);

   if ( retval == -1 )
   {
      vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
         << "[vpr::FileHandleImplUNIX::setSynchronousWrite()] Failed to enable "
         << (sync ? "synchronous" : "asynchronous") << " writes on "
         << mName << ": " << strerror(errno) << std::endl << vprDEBUG_FLUSH;

      std::ostringstream msg_stream;
      msg_stream << "Failed to enable "
                 << (sync ? "synchronous" : "asynchronous") << " writes on "
                 << mName << ": " << strerror(errno);
      throw IOException(msg_stream.str(), VPR_LOCATION);
   }
#else
   vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
      << "[vpr::FileHandleImplUNIX::setSynchronousWrite()] Cannot enable "
      << (sync ? "synchronous" : "asynchronous")
      << " writes on this platform!\n" << vprDEBUG_FLUSH;

   std::ostringstream msg_stream;
   msg_stream << "Cannot enable " << (sync ? "synchronous" : "asynchronous")
              << " writes on this platform!";
   throw IOException(msg_stream.str(), VPR_LOCATION);
#endif
}
Example #5
0
void Header::readData(vpr::SocketStream* stream, bool dumpHeader)
{
   vprASSERT( NULL != stream && "Can not create a Header using a NULL SocketStream" );

   // - Is stream is a valid SocketStream?
   //   - Read in the packet from the socket
   //   - Set the BufferObjectReader and BufferObjectWriter to use mData  <====We only need BufferObjectReader
   if (NULL == stream)
   {
      vprDEBUG( gadgetDBG_RIM, vprDBG_CONFIG_LVL )
         << clrOutBOLD( clrRED, "ERROR:" )
         << " SocketSteam is NULL"
         << std::endl << vprDEBUG_FLUSH;

      throw cluster::ClusterException("Header::Header() - SocketStream is NULL");
   }

   vpr::Uint32 bytes_read;   
   std::vector<vpr::Uint8> header_data; 
   try
   {
      bytes_read = stream->readn(header_data, Header::RIM_PACKET_HEAD_SIZE);
   }
   catch (vpr::IOException& ex)
   {
      vprDEBUG( gadgetDBG_RIM, vprDBG_CRITICAL_LVL )
         << "Header::readData() - Could not read the header!\n"
         << ex.what()
         << std::endl << vprDEBUG_FLUSH;
      throw ex;
   }

   vprASSERT( RIM_PACKET_HEAD_SIZE == bytes_read && "Header::Header() - Bytes read != RIM_PACKET_HEAD_SIZE" );

   parseHeader(header_data);

   if(dumpHeader)
   {
      std::cout << "Dumping Header(" << header_data.size() << " bytes): ";
      for ( std::vector<vpr::Uint8>::const_iterator i = header_data.begin();
            i != header_data.end(); i++ )
      {
         std::cout << (int)*i << " ";
      }
      std::cout << std::endl;
   }
}
Example #6
0
void ConfigPacket::printData(int debugLevel) const
{
   vprDEBUG_BEGIN(gadgetDBG_RIM,debugLevel) 
      <<  clrOutBOLD(clrYELLOW,"==== Config Packet Data ====\n") << vprDEBUG_FLUSH;
   
   Packet::printData(debugLevel);

   vprDEBUG(gadgetDBG_RIM,debugLevel) 
      << clrOutBOLD(clrYELLOW, "Config:       ") << mConfig
      << std::endl << vprDEBUG_FLUSH;
   vprDEBUG(gadgetDBG_RIM,debugLevel) 
      << clrOutBOLD(clrYELLOW, "Type          ") << mType
      << std::endl << vprDEBUG_FLUSH;

   vprDEBUG_END(gadgetDBG_RIM,debugLevel) 
      <<  clrOutBOLD(clrYELLOW,"====================================\n") << vprDEBUG_FLUSH;
}
Example #7
0
void EventPacket::printData(int debugLevel) const
{
   vprDEBUG_BEGIN(gadgetDBG_RIM,debugLevel) 
      <<  clrOutBOLD(clrYELLOW,"==== Event Packet ====\n") << vprDEBUG_FLUSH;
   
   Packet::printData(debugLevel);

   vprDEBUG(gadgetDBG_RIM,debugLevel) 
      << clrOutBOLD(clrYELLOW, "Plugin ID: ") << mPluginId.toString()
      << std::endl << vprDEBUG_FLUSH;
   vprDEBUG(gadgetDBG_RIM,debugLevel) 
      << clrOutBOLD(clrYELLOW, "Name: ") << mName
      << std::endl << vprDEBUG_FLUSH;

   vprDEBUG_END(gadgetDBG_RIM,debugLevel) 
      <<  clrOutBOLD(clrYELLOW,"============================\n") << vprDEBUG_FLUSH;
}
Example #8
0
void VRPN_CALLBACK handleAnalogChange(void* userdata, vrpn_ANALOGCB b)
{
   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
      << "VRPN driver handleAnalogChange() called\n" << vprDEBUG_FLUSH;

   gadget::Vrpn* this_ptr = static_cast<gadget::Vrpn*>(userdata);
   this_ptr->analogChange(b);
}
char* StringSubjectImpl::getValue()
   throw(CORBA::SystemException)
{
   vpr::Guard<vpr::Mutex> val_guard(mValueLock);
   vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
      << "Returning '" << mValue << "' to caller\n" << vprDEBUG_FLUSH;
   return CORBA::string_dup(mValue.c_str());
}
Example #10
0
void VRPN_CALLBACK handleTrackerChange(void* userdata, vrpn_TRACKERCB t)
{
   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
      << "VRPN driver handleTrackerChange() called\n" << vprDEBUG_FLUSH;

   gadget::Vrpn* this_ptr = static_cast<gadget::Vrpn*>(userdata);
   this_ptr->trackerChange(t);
}
Example #11
0
bool DataGlove::startSampling()
{
   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
         << "[dataglove] Begin sampling\n"
         << vprDEBUG_FLUSH;

   bool started(false);

   if (mThread == NULL)
   {
      int maxAttempts=0;
      bool result = false;
      while (result == false && maxAttempts < 5)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
               << "[dataglove] Connecting to "
               << mPortName << " at "
               << mBaudRate << "...\n"
               << vprDEBUG_FLUSH;
         result = mGlove->connectToHardware( mPortName , mBaudRate);
         if (result == false)
         {
            vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
               << "[dataglove] ERROR: Can't open or it is already opened."
               << vprDEBUG_FLUSH;
            vpr::System::usleep(14500);
            maxAttempts++;
         }
      }

      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "[dataglove] Successfully connected, Now sampling dataglove data."
         << vprDEBUG_FLUSH;
      // Create a new thread to handle the control and set exit flag to false
      mExitFlag = false;
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "[dataglove] Spawning control thread\n" << vprDEBUG_FLUSH;

      try
      {
         mThread = new vpr::Thread(boost::bind(&DataGlove::controlLoop, this));
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
            << "[dataglove] DataGlove is active " << std::endl
            << vprDEBUG_FLUSH;
         mActive = true;
         started = true;
      }
      catch (vpr::Exception& ex)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << clrOutBOLD(clrRED, "ERROR")
            << ": Failed to spawn thread for 5DT DataGlove driver!\n"
            << vprDEBUG_FLUSH;
         vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << ex.what() << std::endl << vprDEBUG_FLUSH;
      }
   }

   return started;
}
Example #12
0
bool SdlJoystick::startSampling()
{
   //return init();
   if (!init())
   {
      vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED,"ERROR:")
         << " gadget::SdlJoystick::startSampling() SDL init failed.\n"
         << vprDEBUG_FLUSH;
      return false;
   }

   if(mThread != NULL)
   {
      vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED,"ERROR:")
         << " gadget::SdlJoystick::startSampling() called, when already "
         << "sampling.\n" << vprDEBUG_FLUSH;
      return false;
   }

   // Set flag that will later allow us to stop the control loop.
   mDone = false;

   bool started(true);

   // Create a new thread to handle the control
   try
   {
      mThread = new vpr::Thread(boost::bind(&SdlJoystick::controlLoop,
                                this));
   }
   catch (vpr::Exception& ex)
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << clrOutBOLD(clrRED, "ERROR")
         << ": Failed to spawn thread for SDL Joystick driver!\n"
         << vprDEBUG_FLUSH;
      vprDEBUG_NEXT(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
         << ex.what() << std::endl << vprDEBUG_FLUSH;
      started = false;
   }

   return started;
}
Example #13
0
void Node::debugDump(int debug_level)
{

   vpr::DebugOutputGuard dbg_output(gadgetDBG_NET_MGR, debug_level,
                              std::string("-------------- Node --------------\n"),
                              std::string("-----------------------------------------\n"));

   vprDEBUG(gadgetDBG_NET_MGR, debug_level) << "Node Name: "
      << mName << std::endl << vprDEBUG_FLUSH;
   vprDEBUG(gadgetDBG_NET_MGR, debug_level) << "Hostname:  "
      << mHostname << std::endl << vprDEBUG_FLUSH;
   vprDEBUG(gadgetDBG_NET_MGR, debug_level) << "Port:      "
      << mPort << std::endl << vprDEBUG_FLUSH;
   vprDEBUG(gadgetDBG_NET_MGR, debug_level) << "SockStream "
      << (NULL == mSockStream ? "is NULL" : "is NOT NULL") << std::endl << vprDEBUG_FLUSH;
   if (CONNECTED == getStatus())
   {
      vprDEBUG(gadgetDBG_NET_MGR, debug_level) << clrOutBOLD(clrGREEN,"CONNECTED") << std::endl << vprDEBUG_FLUSH;
   }
   else if (NEWCONNECTION == getStatus())
   {
      vprDEBUG(gadgetDBG_NET_MGR, debug_level) << clrOutBOLD(clrRED,"NEW CONNECTION") << std::endl << vprDEBUG_FLUSH;
   }
   else
   {
      vprDEBUG(gadgetDBG_NET_MGR, debug_level) << clrOutBOLD(clrRED,"DISCONNECTED") << std::endl << vprDEBUG_FLUSH;
   }
}
 void ClusterDelta::receiveResponce()
 {
    getPacket(1);
    mAccept = mReader->readBool();
    if ( mAccept == false )
    {
       vprDEBUG(gadgetDBG_RIM,vprDBG_VERB_LVL) << clrOutNORM(clrRED,"[SYNC]FAILED SYNC") << "\n" << vprDEBUG_FLUSH;
    }
 }
void DataGloveUltraWireless::controlLoop()
{
   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
         << "[DataGloveUltraWireless] Entered control thread\n"
         << vprDEBUG_FLUSH;

   // Go until mDone is set to true
   while( !mDone )
   {
      sample();

      vpr::System::msleep(10);
   }

   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
         << "[DataGloveUltraWireless] Exited control thread\n"
         << vprDEBUG_FLUSH;
}
Example #16
0
// Stop sampling.
bool MotionStar::stopSampling()
{
   bool retval;

   // If we are not active, we cannot stop the device.
   if ( isActive() == false )
   {
      retval = false;
   }
   // If the sampling thread was started, stop it and the device.
   else if ( mMyThread != NULL )
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "Stopping the MotionStar thread ...\n" << vprDEBUG_FLUSH;
      mExitFlag = true;
      mMyThread->join();
      delete mMyThread;
      mMyThread = NULL;

      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "  Stopping the MotionStar ...\n" << vprDEBUG_FLUSH;

      try
      {
         mMotionStar.stop();
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
            << "MotionStar server shut down.\n" << vprDEBUG_FLUSH;
         retval = true;
      }
      catch(mstar::CommandException&)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
            << "MotionStar server did not shut down.\n" << vprDEBUG_FLUSH;
         retval = false;
      }
   }
   // If the thread was not started, then the device is stopped.
   else
   {
      retval = true;
   }

   return retval;
}
// Reconfigure the file handle so that it is in blocking mode.
void FileHandleImplUNIX::setBlocking(bool blocking)
{
   if ( ! mOpen )
   {
      mOpenBlocking = blocking;
   }
   else
   {
      int cur_flags, new_flags;

      // Get the current flags.
      cur_flags = getFlags();

      if ( blocking )
      {
#ifdef _SGI_SOURCE
         // On IRIX, mask FNONBLK and FNDELAY.  We mask FNDELAY to ensure that
         // it is not set by the operating system at some level.
         new_flags = cur_flags & ~(FNONBLK | FNDELAY);
#else
         // On everything else, mask O_NONBLOCK and O_NDELAY.  We mask O_NDELAY
         // to ensure that it is not set by the operating system at some level.
         new_flags = cur_flags & ~(O_NONBLOCK | O_NDELAY);
#endif
      }
      else
      {
#ifdef _SVR4_SOURCE
         // On SysV, set FNONBLK.  We do not set FNDELAY because it just adds
         // confusion.  FNONBLK is preferred.
         new_flags = cur_flags | FNONBLK;
#else
         // On everything else, set O_NONBLOCK.  We do not set O_NDELAY because
         // it just adds confusion.  O_NONBLOCK is preferred.
         new_flags = cur_flags | O_NONBLOCK;
#endif
      }

      // Set the file descriptor to be blocking with the new flags.
      if ( setFlags(new_flags) == -1 )
      {
         vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
            << "[vpr::FileHandleImplUNIX::setBlocking()] Failed to set "
            << (blocking ? "blocking" : "non-blocking") << " state on "
            << mName << ": " << strerror(errno) << std::endl << vprDEBUG_FLUSH;

         throw IOException("[vpr::FileHandleImplUNIX::setBlocking()] Failed to set "
            + std::string(blocking ? "blocking" : "non-blocking") + " state on "
            + mName + ": " + std::string(strerror(errno)), VPR_LOCATION);
      }
      else
      {
         mBlocking = blocking;
      }
   }
}
Example #18
0
void X_IST::controlLoop()
{
   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
      << "[X-IST] Entered control thread\n" << vprDEBUG_FLUSH;
// Go until mExitFlag is set to true
   while ( ! mExitFlag )
   {
      sample();
   }
}
void ApplicationBarrierManager::handlePacket(PacketPtr packet, gadget::NodePtr node)
{
   vprDEBUG(gadgetDBG_RIM, vprDBG_HVERB_LVL)
         << clrOutBOLD(clrMAGENTA,"[ApplicationBarrierManager::handlePacket()]")
         << "In handlePacket.\n" << vprDEBUG_FLUSH;

   if ( NULL != packet.get() && NULL != node.get() )
   {
      switch ( packet->getPacketType() )
      {
      case cluster::Header::RIM_DATA_PACKET:
      {
         DataPacketPtr data_packet = boost::dynamic_pointer_cast<DataPacket>(packet);
         vprASSERT(NULL != data_packet.get() && "Dynamic cast failed!");

         // Find the ApplicationBarrier Object that we have received data
         // for.
         ApplicationBarrier* barrier =
            getApplicationBarrier(data_packet->getObjectId());

         if (barrier != NULL)
         {
            // Parse the object's data using the temporary ObjectReader
            barrier->incWaitingNodes();
         }
         else
         {
            vprDEBUG(gadgetDBG_RIM,vprDBG_WARNING_LVL)
               << clrOutBOLD(clrCYAN,"[ApplicationBarrierManager] ")
               << "Got data for an unknown ApplicationBarrier object: "
               << data_packet->getObjectId() << std::endl << vprDEBUG_FLUSH;
         }
         break;
      }
      default:
         vprDEBUG(gadgetDBG_RIM,vprDBG_WARNING_LVL)
            << clrOutBOLD(clrCYAN,"[ApplicationBarrierManager] ")
            << "Don't know how to handle a packet of type: "
            << packet->getPacketType() << std::endl << vprDEBUG_FLUSH;
         break;
      }
   }
}
Example #20
0
void Vrpn::buttonChange(const vrpn_BUTTONCB& b)
{
   vpr::Guard<vpr::Mutex> g(mButtonMutex);

   if ( b.button > mButtonNumber )
   {
      vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
         << "Vrpn: button " << b.button
         << " out of declared range ("<<mButtons.size()<<")"<<std::endl
         << vprDEBUG_FLUSH;
      mButtons.resize(b.button + 1);
   }

   vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_VERB_LVL)
      << "Button #" << b.button << " state " << b.state << std::endl
      << vprDEBUG_FLUSH;

   mButtons[b.button] = static_cast<DigitalState::State>(b.state);
}
   /**
    * Adds a new plugin to the ClusterManager.
    */
   void AbstractNetworkManager::addHandler(PacketHandler* new_handler)
   {
         std::pair<vpr::GUID, PacketHandler*> p 
            = std::make_pair( new_handler->getHandlerGUID(), new_handler );
         mHandlerMap.insert( p );

         vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL )
            << clrOutBOLD( clrMAGENTA, "[Reactor] " )
            << "Adding Handler: " << new_handler->getHandlerName() << std::endl << vprDEBUG_FLUSH;
   }
vpr::IOSys::Handle FileHandleImplUNIX::getHandle() const
{
#ifdef VPR_USE_NSPR
   vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
       << "ERROR: Cannot get handle for UNIX file descriptor with NSPR!\n";
   return vpr::IOSys::NullHandle;
#else
   return mFdesc;
#endif
}
 bool AbstractNetworkManager::configRemove(jccl::ConfigElementPtr element)
 {
    if (recognizeClusterMachineConfig( element ))
    {
       vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL )
          << clrOutBOLD( clrMAGENTA, "[AbstractNetworkManager]" )
          << " Removing the Node: " << element->getName()
          << " from the Cluster Network\n" << vprDEBUG_FLUSH;
       return true;
    }
    else
    {
       vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL )
          << clrOutBOLD( clrMAGENTA, "[AbstractNetworkManager]" )
          << " ERROR, Something is seriously wrong, we should never get here\n"
          << vprDEBUG_FLUSH;
       return false;
    }
 }
Example #24
0
// Called by the spawn routine to start the user thread function.
void ThreadPosix::startThread()
{
   // WE are a new thread... yeah!!!!
   // TELL EVERYONE THAT WE LIVE!!!!
   ThreadManager::instance()->lock();      // Lock manager
   {
      threadIdKey().setspecific((void*)this);  // Store the pointer to me
      registerThread(true);                    // Finish thread initialization
   }
   ThreadManager::instance()->unlock();

   // Signal that thread registration is complete.
   mThreadStartCondVar.acquire();
   {
      mThreadStartCompleted = true;
      mThreadStartCondVar.signal();
   }
   mThreadStartCondVar.release();

   try
   {
      emitThreadStart(this);

      // --- CALL USER FUNCTOR --- //
      mUserThreadFunctor();

      emitThreadExit(this);
   }
   catch (std::exception& ex)
   {
      vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
         << clrOutNORM(clrYELLOW, "WARNING:")
         << " Caught an unhandled exception of type " << typeid(ex).name()
         << " in thread:" << std::endl
         << ex.what() << std::endl << vprDEBUG_FLUSH;
      vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
         << "Thread exiting due to uncaught exception\n" << vprDEBUG_FLUSH;

      mCaughtException = true;
      mException.setException(ex);
   }
}
Example #25
0
bool IntersenseAPI::stopSampling()
{
   // Make sure that we are sampling in the first place.
   if (this->isActive() == false)
   {
      return false;
   }

   if (mThread != NULL)
   {
      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "[gadget::IntersenseAPI::stopSampling()] Stopping the InterSense "
         << "thread...\n" << vprDEBUG_FLUSH;

      // Set the done flag to attempt to cause the control loop to exit
      // naturally.
      mDone = true;

      mThread->join();
      delete mThread;
      mThread = NULL;

      // Close the connection to the tracker
      mTracker.close();

      // If the tracker failed to stop
      if (isActive() == true)
      {
         vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CRITICAL_LVL)
            << clrOutNORM(clrRED,"\nERROR:")
            << " [gadget::IntersenseAPI::stopSampling()] InterSense tracker "
            << "failed to stop.\n" << vprDEBUG_FLUSH;
         return false;
      }

      vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
         << "*** IntersenseAPI has been shutdown. ***" << std::endl
         << vprDEBUG_FLUSH;
   }

   return true;
}
Example #26
0
bool Vrpn::stopSampling()
{
   if ( NULL != mThread )
   {
      vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
         << "[Vrpn::stopSampling()] Stopping sample thread" << std::endl
         << vprDEBUG_FLUSH;

      mExitFlag = true;

      // Wait for thread to exit..
      mThread->join();
      vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
         << "[Vrpn::stopSampling()] Sample thread stopped" << std::endl
         << vprDEBUG_FLUSH;
      delete mThread;
      mThread = NULL;
   }
   return true;
}
/**
 * kill the sound API, deallocating any sounds, etc...
 * @postconditions sound API is ready to go.
 * @semantics this function could be called any time, the function could be
 *            called multiple times, so it should be smart.
 */
void AudiereSoundImplementation::shutdownAPI()
{
   if ( this->isStarted() == false )
   {
      vprDEBUG(snxDBG, vprDBG_CONFIG_LVL)
         << clrOutNORM(clrYELLOW, "Auidere| WARNING:")
         << "API not started, nothing to shutdown [dev="
         << std::hex << mDev.get() << std::dec << "]\n" << vprDEBUG_FLUSH;
      return;
   }

   this->unbindAll();

   mDev = NULL;

   vprDEBUG(snxDBG, vprDBG_CONFIG_LVL)
      << clrOutNORM(clrYELLOW, "Audiere| NOTICE:")
      << " Audiere API closed: [dev="
      << std::hex << mDev.get() << std::dec << "]\n" << vprDEBUG_FLUSH;
}
Example #28
0
bool Analog::config(jccl::ConfigElementPtr element)
{
   mMin = element->getProperty<float>("min");
   mMax = element->getProperty<float>("max");

   vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)
      << "[gadget::Analog::config()] min:" << mMin
      << " max:" << mMax << "\n" << vprDEBUG_FLUSH;

   return true;
}
Example #29
0
//: Start the main function
int SyncIncrementer::start()
{
    // Create a new thread to handle the control
    vpr::Thread* control_thread =
        new vpr::Thread(boost::bind(&SyncIncrementer::main, this));

    vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) << "SyncIncrementer::start: Just started main loop.  "
            << control_thread << std::endl << vprDEBUG_FLUSH;

    return 1;
}
   void AbstractNetworkManager::addNode(Node* node)
   {
      // -Add the given node to the AbstractNetworkManager
      
      vprDEBUG( gadgetDBG_NET_MGR, vprDBG_CONFIG_LVL )
         << clrOutBOLD( clrMAGENTA, "[AbstractNetworkManager]" )
         << " Adding node: " << node->getName()
         << std::endl << vprDEBUG_FLUSH;

      mNodes.push_back( node );
   }